Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Gimp/po-plug-ins/   (Gimp Bildeditor Version 3.2.0©)  Datei vom 14.2.2026 mit Größe 511 kB image not shown  

Quelle  SpinnerPresenter.swift   Sprache: JAVA

 

import MBProgressHUD
import UIKit

@MainActor
enum SpinnerPresenter {
    static func presentSpinner<T>(
        label: String,
        window: UIWindow?,
        while action: () throws -> T
    ) async throws -> T {
        guard let window else {
            fatalError("No window to present UI on")
        }

        let progressHUD = MBProgressHUD(view: window)
        progressHUD.label.numberOfLines = 0
        progressHUD.label.text = String(format: label, TargetManager.appName)
        progressHUD.mode = .indeterminate

        window.addSubview(progressHUD)
        progressHUD.show(animated: true)

        UIApplication.shared.isIdleTimerDisabled = true
        try await Task.sleep(seconds: 0.3)

        let result = try action()

        progressHUD.hide(animated: true)
        progressHUD.removeFromSuperview()

        UIApplication.shared.isIdleTimerDisabled = false
        return result
    }

    /// Shows an indeterminate spinner on top of `view` while the asynchronous `action` runs.
    ///
    /// Use this instead of `presentSpinner(label:window:while:)` if the work is asynchronous or if
    /// the spinner belongs to a specific view instead of the window. Note that the view has to be
    /// the one that is actually visible: a spinner added to the view of a view controller that is
    /// covered by a presented view controller (such as the onboarding wizard) never shows up.
    static func presentSpinner<T>(
        in view: UIView,
        while action: () async throws -> T
    ) async throws -> T {
        let progressHUD = MBProgressHUD.showAdded(to: view, animated: true)
        progressHUD.mode = .indeterminate

        defer {
            progressHUD.hide(animated: true)
        }

        return try await action()
    }
}

Messung
CHZG
88749585

¤ Dauer der Verarbeitung: 0.0 Sekunden  (vorverarbeitet am  2026-11-23) ¤

*© Formatika GbR, Deutschland