Files
suixinkan_ios_uikit/suixinkan_ios/App/AppUITestLaunchState.swift
2026-06-26 14:33:31 +08:00

56 lines
2.0 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// AppUITestLaunchState.swift
// suixinkan
//
// Created by Codex on 2026/6/26.
//
import Foundation
/// UI
enum AppUITestLaunchState {
/// UI Test
static let uiTestsArgument = "-suixinkan-ui-tests"
///
static let resetArgument = "-suixinkan-ui-tests-reset-state"
///
static let openMenuArgument = "-suixinkan-ui-tests-open-menu"
///
static let openProfileArgument = "-suixinkan-ui-tests-open-profile"
/// XCUITest
static var isRunningUITests: Bool {
ProcessInfo.processInfo.arguments.contains(uiTestsArgument)
}
///
static var pendingMenuTitle: String? {
argumentValue(following: openMenuArgument)
}
///
static var pendingProfileRouteRawValue: String? {
argumentValue(following: openProfileArgument)
}
/// flag
private static func argumentValue(following flag: String) -> String? {
let arguments = ProcessInfo.processInfo.arguments
guard let index = arguments.firstIndex(of: flag), index + 1 < arguments.count else {
return nil
}
let value = arguments[index + 1].trimmingCharacters(in: .whitespacesAndNewlines)
return value.isEmpty ? nil : value
}
/// token
static func resetIfNeeded(arguments: [String] = ProcessInfo.processInfo.arguments) {
guard arguments.contains(resetArgument) else { return }
try? SessionTokenStore().clear()
AccountSnapshotStore().clear()
let preferences = AppPreferencesStore()
preferences.clear()
}
}