diff --git "a/swift/InputSourcePro_function_bench.jsonl" "b/swift/InputSourcePro_function_bench.jsonl" new file mode 100644--- /dev/null +++ "b/swift/InputSourcePro_function_bench.jsonl" @@ -0,0 +1,3 @@ +{"repo_name": "InputSourcePro", "file_name": "/InputSourcePro/Input Source Pro/Models/PreferencesVM+AppKeyboardCache.swift", "inference_info": {"prefix_code": "import AppKit\n\nextension PreferencesVM {\n func appNeedCacheKeyboard(_ appKind: AppKind) -> Bool {\n if let browserRule = appKind.getBrowserInfo()?.rule,\n let keyboardRestoreStrategy = browserRule.keyboardRestoreStrategy\n {\n switch keyboardRestoreStrategy {\n case .RestorePreviouslyUsedOne:\n return true\n case .UseDefaultKeyboardInstead:\n return false\n }\n }\n\n let appRule = getAppCustomization(app: appKind.getApp())\n\n if preferences.isRestorePreviouslyUsedInputSource,\n appRule?.doNotRestoreKeyboard != true\n {\n return true\n }\n\n if !preferences.isRestorePreviouslyUsedInputSource,\n appRule?.doRestoreKeyboard == true\n {\n return true\n }\n\n return false\n }\n\n func cacheKeyboardFor(_ appKind: AppKind, keyboard: InputSource) {\n let defaultKeyboard = getAppDefaultKeyboard(appKind)\n\n if appNeedCacheKeyboard(appKind),\n defaultKeyboard?.id != keyboard.id\n {\n appKeyboardCache.save(appKind, keyboard: keyboard)\n } else {\n appKeyboardCache.remove(appKind)\n }\n }\n\n func removeKeyboardCacheFor(bundleId: String) {\n appKeyboardCache.remove(byBundleId: bundleId)\n }\n\n func clearKeyboardCache() {\n appKeyboardCache.clear()\n }\n\n enum AppAutoSwitchKeyboardStatus {\n case cached(InputSource), specified(InputSource)\n\n var inputSource: InputSource {\n switch self {\n case let .cached(i): return i\n case let .specified(i): return i\n }\n }\n }\n\n func getAppAutoSwitchKeyboard(\n _ appKind: AppKind\n ) -> AppAutoSwitchKeyboardStatus? {\n if let cachedKeyboard = getAppCachedKeyboard(appKind) {\n return .cached(cachedKeyboard)\n }\n\n if let defaultKeyboard = getAppDefaultKeyboard(appKind) {\n return .specified(defaultKeyboard)\n }\n\n // Fallback to system-wide default keyboard to prevent input method getting stuck\n // This ensures that apps without specific keyboard configuration will always\n // switch to the system default, resolving issues like ChatGPT → Terminal switching\n if let systemDefaultKeyboard = systemWideDefaultKeyboard {\n return .specified(systemDefaultKeyboard)\n }\n\n return nil\n }\n\n func getAppCachedKeyboard(_ appKind: AppKind) -> InputSource? {\n guard appNeedCacheKeyboard(appKind) else { return nil }\n return appKeyboardCache.retrieve(appKind)\n }\n\n ", "suffix_code": "\n}\n", "middle_code": "func getAppDefaultKeyboard(_ appKind: AppKind) -> InputSource? {\n if appKind.getBrowserInfo()?.isFocusedOnAddressBar == true,\n let browserAddressKeyboard = browserAddressDefaultKeyboard\n {\n return browserAddressKeyboard\n }\n if let inputSource = appKind.getBrowserInfo()?.rule?.forcedKeyboard {\n return inputSource\n }\n return getAppCustomization(app: appKind.getApp())?.forcedKeyboard ?? systemWideDefaultKeyboard\n }", "code_description": null, "fill_type": "FUNCTION_TYPE", "language_type": "swift", "sub_task_type": null}, "context_code": [["/InputSourcePro/Input Source Pro/Models/PreferencesVM.swift", "import AppKit\nimport AXSwift\nimport Combine\nimport CombineExt\nimport LaunchAtLogin\nimport Sparkle\nimport SwiftUI\n\nprivate enum UpdateFeed {\n static let stable = URL(string: \"https://inputsource.pro/stable/appcast.xml\")!\n static let beta = URL(string: \"https://inputsource.pro/beta/appcast.xml\")!\n}\n\n@MainActor\nfinal class PreferencesVM: NSObject, ObservableObject {\n @Published\n var preferences = Preferences()\n\n @Published\n var keyboardConfigs: [KeyboardConfig] = []\n\n var permissionsVM: PermissionsVM\n\n var updaterController: SPUStandardUpdaterController?\n\n var cancelBag = CancelBag()\n\n var appKeyboardCache = AppKeyboardCache()\n\n let container: NSPersistentContainer\n let mainStorage: MainStorage\n\n let versionStr = \"\\(Bundle.main.infoDictionary?[\"CFBundleShortVersionString\"] as? String ?? \"unknown\")\"\n\n let buildStr = \"\\(Bundle.main.infoDictionary?[\"CFBundleVersion\"] as? String ?? \"unknown\")\"\n\n @Published\n var automaticallyChecksForUpdates = false\n\n @Published\n var canChecksForUpdates = false\n\n init(permissionsVM: PermissionsVM) {\n self.permissionsVM = permissionsVM\n container = NSPersistentContainer(name: \"Main\")\n mainStorage = MainStorage(container: container)\n \n super.init();\n \n setupAutoUpdate()\n\n // TODO: - Move to MainStorage\n container.loadPersistentStores { _, error in\n if let error = error {\n print(\"Core Data 'Main' failed to load: \\(error.localizedDescription)\")\n } else {\n self.mainStorage.refresh()\n }\n }\n\n if preferences.prevInstalledBuildVersion == 0 {\n for filterApp in filterApps(NSWorkspace.shared.runningApplications) {\n addAppCustomization(filterApp)\n }\n }\n\n cleanRemovedAppCustomizationIfNeed()\n migratePreferncesIfNeed()\n migrateBoutiqueIfNeed()\n watchKeyboardConfigsChange()\n watchPreferenceChanges()\n }\n\n func update(_ change: (inout Preferences) -> Void) {\n var draft = preferences\n\n change(&draft)\n\n preferences = draft\n }\n\n func saveContext(_ callback: (() -> Void)? = nil) {\n if let callback = callback {\n container.viewContext.performAndWait {\n callback()\n save()\n }\n } else {\n save()\n }\n\n func save() {\n do {\n try container.viewContext.save()\n } catch {\n print(\"saveAppCustomization error: \\(error.localizedDescription)\")\n }\n }\n }\n}\n\nextension PreferencesVM {\n private func watchPreferenceChanges() {\n $preferences\n .map(\\.isLaunchAtLogin)\n .removeDuplicates()\n .sink { LaunchAtLogin.isEnabled = $0 }\n .store(in: cancelBag)\n }\n \n private func watchKeyboardConfigsChange() {\n mainStorage.keyboardConfigs\n .assign(to: &$keyboardConfigs)\n }\n}\n\nextension PreferencesVM: @preconcurrency SPUUpdaterDelegate {\n private func setupAutoUpdate() {\n updaterController = SPUStandardUpdaterController(\n startingUpdater: true,\n updaterDelegate: self,\n userDriverDelegate: nil\n )\n\n updaterController?.updater\n .publisher(for: \\.automaticallyChecksForUpdates)\n .removeDuplicates()\n .assign(to: &$automaticallyChecksForUpdates)\n\n $automaticallyChecksForUpdates\n .dropFirst()\n .sink { [weak self] in self?.updaterController?.updater.automaticallyChecksForUpdates = $0 }\n .store(in: cancelBag)\n\n updaterController?.updater\n .publisher(for: \\.canCheckForUpdates)\n .debounce(for: 0.5, scheduler: DispatchQueue.main)\n .assign(to: &$canChecksForUpdates)\n }\n\n func checkUpdates() {\n updaterController?.updater.checkForUpdates()\n }\n \n func feedURLString(for updater: SPUUpdater) -> String? {\n let url = preferences.receiveBetaUpdates ? UpdateFeed.beta : UpdateFeed.stable\n return url.absoluteString\n }\n}\n\nextension PreferencesVM {\n func getBrowserURL(_ bundleIdentifier: String?, application: Application?) -> URL? {\n guard\n permissionsVM.isAccessibilityEnabled,\n let bundleIdentifier = bundleIdentifier,\n let browser = Browser(rawValue: bundleIdentifier)\n else { return nil }\n\n switch browser {\n case .Safari:\n guard preferences.isEnableURLSwitchForSafari else { return nil }\n case .SafariTechnologyPreview:\n guard preferences.isEnableURLSwitchForSafariTechnologyPreview else { return nil }\n case .Chrome:\n guard preferences.isEnableURLSwitchForChrome else { return nil }\n case .Chromium:\n guard preferences.isEnableURLSwitchForChromium else { return nil }\n case .Arc:\n guard preferences.isEnableURLSwitchForArc else { return nil }\n case .Edge:\n guard preferences.isEnableURLSwitchForEdge else { return nil }\n case .Brave:\n guard preferences.isEnableURLSwitchForBrave else { return nil }\n case .BraveBeta:\n guard preferences.isEnableURLSwitchForBraveBeta else { return nil }\n case .BraveNightly:\n guard preferences.isEnableURLSwitchForBraveNightly else { return nil }\n case .Vivaldi:\n guard preferences.isEnableURLSwitchForVivaldi else { return nil }\n case .Opera:\n guard preferences.isEnableURLSwitchForOpera else { return nil }\n case .Thorium:\n guard preferences.isEnableURLSwitchForThorium else { return nil }\n case .Firefox:\n guard preferences.isEnableURLSwitchForFirefox else { return nil }\n case .FirefoxDeveloperEdition:\n guard preferences.isEnableURLSwitchForFirefoxDeveloperEdition else { return nil }\n case .FirefoxNightly:\n guard preferences.isEnableURLSwitchForFirefoxNightly else { return nil }\n case .Zen:\n guard preferences.isEnableURLSwitchForZen else { return nil }\n case .Dia:\n guard preferences.isEnableURLSwitchForDia else { return nil }\n }\n\n if let application = application,\n let focusedWindow: UIElement = try? application.attribute(.focusedWindow),\n let url = browser.getCurrentTabURL(focusedWindow: focusedWindow)\n {\n return url\n } else {\n if browser == .Safari || browser == .SafariTechnologyPreview {\n return .newtab\n } else {\n return nil\n }\n }\n }\n\n func filterApps(_ apps: [NSRunningApplication]) -> [NSRunningApplication] {\n let isDetectSpotlightLikeApp = preferences.isEnhancedModeEnabled\n\n return apps.filter { app in\n (isDetectSpotlightLikeApp && NSApplication.isFloatingApp(app.bundleIdentifier))\n || app.activationPolicy == .regular\n }\n }\n}\n\nstruct Preferences {\n enum AppearanceMode: String, CaseIterable, Codable, Equatable {\n case dark = \"Dark\"\n case light = \"Light\"\n }\n\n private enum Key {\n static let prevInstalledBuildVersion = \"prevInstalledBuildVersion\"\n\n static let isLaunchAtLogin = \"isLaunchAtLogin\"\n static let isShowIconInMenuBar = \"isShowIconInMenuBar\"\n static let isEnhancedModeEnabled = \"isDetectSpotlightLikeApp\"\n static let isCJKVFixEnabled = \"isCJKVFixEnabled\"\n\n static let systemWideDefaultKeyboardId = \"systemWideDefaultKeyboardId\"\n\n static let browserAddressDefaultKeyboardId = \"browserAddressDefaultKeyboardId\"\n static let isActiveWhenLongpressLeftMouse = \"isActiveWhenLongpressLeftMouse\"\n static let isActiveWhenFocusedElementChanges = \"isActiveWhenFocusedElementChanges\"\n static let isActiveWhenSwitchApp = \"isActiveWhenSwitchApp\"\n static let isHideWhenSwitchAppWithForceKeyboard = \"isHideWhenSwitchAppWithForceKeyboard\"\n static let isActiveWhenSwitchInputSource = \"isActiveWhenSwitchInputSource\"\n\n static let isRestorePreviouslyUsedInputSource = \"isRestorePreviouslyUsedInputSource\"\n\n static let isEnableURLSwitchForSafari = \"isEnableURLSwitchForSafari\"\n static let isEnableURLSwitchForSafariTechnologyPreview = \"isEnableURLSwitchForSafariTechnologyPreview\"\n static let isEnableURLSwitchForChrome = \"isEnableURLSwitchForChrome\"\n static let isEnableURLSwitchForChromium = \"isEnableURLSwitchForChromium\"\n static let isEnableURLSwitchForArc = \"isEnableURLSwitchForArc\"\n static let isEnableURLSwitchForEdge = \"isEnableURLSwitchForEdge\"\n static let isEnableURLSwitchForBrave = \"isEnableURLSwitchForBrave\"\n static let isEnableURLSwitchForBraveBeta = \"isEnableURLSwitchForBraveBeta\"\n static let isEnableURLSwitchForBraveNightly = \"isEnableURLSwitchForBraveNightly\"\n static let isEnableURLSwitchForVivaldi = \"isEnableURLSwitchForVivaldi\"\n static let isEnableURLSwitchForOpera = \"isEnableURLSwitchForOpera\"\n static let isEnableURLSwitchForThorium = \"isEnableURLSwitchForThorium\"\n static let isEnableURLSwitchForFirefox = \"isEnableURLSwitchForFirefox\"\n static let isEnableURLSwitchForFirefoxDeveloperEdition = \"isEnableURLSwitchForFirefoxDeveloperEdition\"\n static let isEnableURLSwitchForFirefoxNightly = \"isEnableURLSwitchForFirefoxNightly\"\n static let isEnableURLSwitchForZen = \"isEnableURLSwitchForZen\"\n static let isEnableURLSwitchForDia = \"isEnableURLSwitchForDia\"\n\n static let isAutoAppearanceMode = \"isAutoAppearanceMode\"\n static let appearanceMode = \"appearanceMode\"\n static let isShowInputSourcesLabel = \"isShowInputSourcesLabel\"\n static let indicatorBackground = \"indicatorBackground\"\n static let indicatorForgeground = \"indicatorForgeground\"\n\n static let tryToDisplayIndicatorNearCursor = \"tryToDisplayIndicatorNearCursor\"\n static let isEnableAlwaysOnIndicator = \"isEnableAlwaysOnIndicator\"\n\n static let indicatorPosition = \"indicatorPosition\"\n static let indicatorPositionAlignment = \"indicatorPositionAlignment\"\n static let indicatorPositionSpacing = \"indicatorPositionSpacing\"\n\n static let indicatorSize = \"indicatorSize\"\n static let indicatorInfo = \"indicatorInfo\"\n \n static let receiveBetaUpdates = \"receiveBetaUpdates\"\n }\n\n fileprivate init() {}\n\n @UserDefault(Preferences.Key.prevInstalledBuildVersion)\n var prevInstalledBuildVersion = 0\n\n // MARK: - General\n\n @UserDefault(Preferences.Key.isLaunchAtLogin)\n var isLaunchAtLogin = LaunchAtLogin.isEnabled\n\n @UserDefault(Preferences.Key.isShowIconInMenuBar)\n var isShowIconInMenuBar = true\n\n @UserDefault(Preferences.Key.isEnhancedModeEnabled)\n var isEnhancedModeEnabled = false\n\n @UserDefault(Preferences.Key.isCJKVFixEnabled)\n var isCJKVFixEnabled = false\n \n @UserDefault(Preferences.Key.receiveBetaUpdates)\n var receiveBetaUpdates = false\n\n // MARK: - Triggers\n\n @UserDefault(Preferences.Key.isActiveWhenLongpressLeftMouse)\n var isActiveWhenLongpressLeftMouse = true\n\n @UserDefault(Preferences.Key.isActiveWhenSwitchApp)\n var isActiveWhenSwitchApp = true\n\n @UserDefault(Preferences.Key.isHideWhenSwitchAppWithForceKeyboard)\n var isHideWhenSwitchAppWithForceKeyboard = false\n\n @UserDefault(Preferences.Key.isActiveWhenSwitchInputSource)\n var isActiveWhenSwitchInputSource = true\n\n @UserDefault(Preferences.Key.isActiveWhenFocusedElementChanges)\n var isActiveWhenFocusedElementChanges = true\n\n // MARK: - Input Source\n\n @UserDefault(Preferences.Key.isRestorePreviouslyUsedInputSource)\n var isRestorePreviouslyUsedInputSource = false\n\n // MARK: - App Rules\n\n @UserDefault(Preferences.Key.systemWideDefaultKeyboardId)\n var systemWideDefaultKeyboardId = \"\"\n\n // MARK: - Browser Rules\n\n @UserDefault(Preferences.Key.browserAddressDefaultKeyboardId)\n var browserAddressDefaultKeyboardId = \"\"\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForSafari)\n var isEnableURLSwitchForSafari = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForSafariTechnologyPreview)\n var isEnableURLSwitchForSafariTechnologyPreview = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForChrome)\n var isEnableURLSwitchForChrome = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForChromium)\n var isEnableURLSwitchForChromium = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForArc)\n var isEnableURLSwitchForArc = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForEdge)\n var isEnableURLSwitchForEdge = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForBrave)\n var isEnableURLSwitchForBrave = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForBraveBeta)\n var isEnableURLSwitchForBraveBeta = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForBraveNightly)\n var isEnableURLSwitchForBraveNightly = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForVivaldi)\n var isEnableURLSwitchForVivaldi = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForOpera)\n var isEnableURLSwitchForOpera = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForThorium)\n var isEnableURLSwitchForThorium = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForFirefox)\n var isEnableURLSwitchForFirefox = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForFirefoxDeveloperEdition)\n var isEnableURLSwitchForFirefoxDeveloperEdition = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForFirefoxNightly)\n var isEnableURLSwitchForFirefoxNightly = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForZen)\n var isEnableURLSwitchForZen = false\n \n @UserDefault(Preferences.Key.isEnableURLSwitchForDia)\n var isEnableURLSwitchForDia = false\n\n // MARK: - Appearance\n\n @available(*, deprecated, message: \"Use indicatorInfo instead\")\n @UserDefault(Preferences.Key.isShowInputSourcesLabel)\n var isShowInputSourcesLabel = true\n\n @CodableUserDefault(Preferences.Key.indicatorInfo)\n var indicatorInfo = IndicatorInfo.iconAndTitle\n\n @CodableUserDefault(Preferences.Key.indicatorSize)\n var indicatorSize = IndicatorSize.medium\n\n @UserDefault(Preferences.Key.isAutoAppearanceMode)\n var isAutoAppearanceMode = true\n\n @CodableUserDefault(Preferences.Key.appearanceMode)\n var appearanceMode = AppearanceMode.dark\n\n @CodableUserDefault(Preferences.Key.indicatorBackground)\n var indicatorBackground = IndicatorColor.background\n\n @CodableUserDefault(Preferences.Key.indicatorForgeground)\n var indicatorForgeground = IndicatorColor.forgeground\n\n @UserDefault(Preferences.Key.tryToDisplayIndicatorNearCursor)\n var tryToDisplayIndicatorNearCursor = true\n\n @UserDefault(Preferences.Key.isEnableAlwaysOnIndicator)\n var isEnableAlwaysOnIndicator = false\n\n @CodableUserDefault(Preferences.Key.indicatorPosition)\n var indicatorPosition = IndicatorPosition.nearMouse\n\n @CodableUserDefault(Preferences.Key.indicatorPositionAlignment)\n var indicatorPositionAlignment = IndicatorPosition.Alignment.bottomRight\n\n @CodableUserDefault(Preferences.Key.indicatorPositionSpacing)\n var indicatorPositionSpacing = IndicatorPosition.Spacing.s\n}\n\nextension Preferences {\n var shortVersion: String {\n Bundle.main.shortVersion\n }\n\n var buildVersion: Int {\n Bundle.main.buildVersion\n }\n\n var isActiveWhenFocusedElementChangesEnabled: Bool {\n return isEnhancedModeEnabled && isActiveWhenFocusedElementChanges\n }\n\n var indicatorKind: IndicatorKind {\n guard let indicatorInfo = indicatorInfo else { return .iconAndTitle }\n\n switch indicatorInfo {\n case .iconAndTitle:\n return .iconAndTitle\n case .iconOnly:\n return .icon\n case .titleOnly:\n return .title\n }\n }\n\n var indicatorBackgroundColor: Color {\n get {\n switch appearanceMode {\n case .dark?:\n return indicatorBackground?.dark ?? IndicatorColor.background.dark\n default:\n return indicatorBackground?.light ?? IndicatorColor.background.light\n }\n }\n\n set {\n guard let appearanceMode = appearanceMode,\n let indicatorBackground = indicatorBackground\n else { return }\n\n switch appearanceMode {\n case .dark:\n self.indicatorBackground = IndicatorColor(\n light: indicatorBackground.light,\n dark: newValue\n )\n case .light:\n self.indicatorBackground = IndicatorColor(\n light: newValue,\n dark: indicatorBackground.dark\n )\n }\n }\n }\n\n var indicatorForgegroundColor: Color {\n get {\n switch appearanceMode {\n case .dark?:\n return indicatorForgeground?.dark ?? IndicatorColor.forgeground.dark\n default:\n return indicatorForgeground?.light ?? IndicatorColor.forgeground.light\n }\n }\n\n set {\n guard let appearanceMode = appearanceMode,\n let indicatorForgeground = indicatorForgeground\n else { return }\n\n switch appearanceMode {\n case .dark:\n self.indicatorForgeground = IndicatorColor(\n light: indicatorForgeground.light,\n dark: newValue\n )\n case .light:\n self.indicatorForgeground = IndicatorColor(\n light: newValue,\n dark: indicatorForgeground.dark\n )\n }\n }\n }\n}\n\nextension PreferencesVM {\n var systemWideDefaultKeyboard: InputSource? {\n return InputSource.sources.first { $0.id == preferences.systemWideDefaultKeyboardId }\n }\n\n var browserAddressDefaultKeyboard: InputSource? {\n return InputSource.sources.first { $0.id == preferences.browserAddressDefaultKeyboardId }\n }\n}\n\nextension PreferencesVM {\n func isUseCJKVFix() -> Bool {\n return preferences.isEnhancedModeEnabled && preferences.isCJKVFixEnabled\n }\n\n func isAbleToQueryLocation(_ app: NSRunningApplication) -> Bool {\n if app.bundleIdentifier == \"com.tencent.WeWorkMac\" {\n return false\n } else {\n return true\n }\n }\n\n func isShowAlwaysOnIndicator(app: NSRunningApplication) -> Bool {\n if preferences.isEnableAlwaysOnIndicator,\n isAbleToQueryLocation(app)\n {\n return true\n } else {\n return false\n }\n }\n\n func needDetectFocusedFieldChanges(app: NSRunningApplication) -> Bool {\n if preferences.isActiveWhenFocusedElementChangesEnabled,\n isAbleToQueryLocation(app)\n {\n return true\n } else {\n return false\n }\n }\n\n func isHideIndicator(_ appKind: AppKind) -> Bool {\n if let browserRule = appKind.getBrowserInfo()?.rule,\n browserRule.hideIndicator\n {\n return true\n }\n\n return getAppCustomization(app: appKind.getApp())?.hideIndicator == true\n }\n\n func needDisplayEnhancedModePrompt(bundleIdentifier: String?) -> Bool {\n NSApplication.isFloatingApp(bundleIdentifier) && !preferences.isEnhancedModeEnabled\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/IndicatorVM.swift", "import AppKit\nimport AXSwift\nimport Carbon\nimport Combine\nimport CombineExt\nimport KeyboardShortcuts\nimport os\n\n@MainActor\nfinal class IndicatorVM: ObservableObject {\n private var cancelBag = CancelBag()\n\n let applicationVM: ApplicationVM\n let preferencesVM: PreferencesVM\n let inputSourceVM: InputSourceVM\n let permissionsVM: PermissionsVM\n\n let logger = ISPLogger(category: String(describing: IndicatorVM.self))\n\n @Published\n private(set) var state: State\n\n var actionSubject = PassthroughSubject()\n\n var refreshShortcutSubject = PassthroughSubject()\n\n private(set) lazy var activateEventPublisher = Publishers.MergeMany([\n longMouseDownPublisher(),\n stateChangesPublisher(),\n ])\n .share()\n\n private(set) lazy var screenIsLockedPublisher = Publishers.MergeMany([\n DistributedNotificationCenter.default()\n .publisher(for: Notification.Name(rawValue: \"com.apple.screenIsLocked\"))\n .mapTo(true),\n\n DistributedNotificationCenter.default()\n .publisher(for: NSWorkspace.willSleepNotification)\n .mapTo(true),\n\n DistributedNotificationCenter.default()\n .publisher(for: Notification.Name(rawValue: \"com.apple.screenIsUnlocked\"))\n .mapTo(false),\n\n DistributedNotificationCenter.default()\n .publisher(for: NSWorkspace.didWakeNotification)\n .mapTo(false),\n ])\n .receive(on: DispatchQueue.main)\n .prepend(false)\n .removeDuplicates()\n .share()\n\n init(\n permissionsVM: PermissionsVM,\n preferencesVM: PreferencesVM,\n applicationVM: ApplicationVM,\n inputSourceVM: InputSourceVM\n ) {\n self.permissionsVM = permissionsVM\n self.preferencesVM = preferencesVM\n self.applicationVM = applicationVM\n self.inputSourceVM = inputSourceVM\n state = .from(\n preferencesVM: preferencesVM,\n inputSourceChangeReason: .system,\n applicationVM.appKind,\n InputSource.getCurrentInputSource()\n )\n\n clearAppKeyboardCacheIfNeed()\n watchState()\n }\n\n private func clearAppKeyboardCacheIfNeed() {\n applicationVM.$appsDiff\n .sink { [weak self] appsDiff in\n appsDiff.removed\n .compactMap { $0.bundleIdentifier }\n .forEach { bundleId in\n self?.preferencesVM.removeKeyboardCacheFor(bundleId: bundleId)\n }\n }\n .store(in: cancelBag)\n\n preferencesVM.$preferences\n .map(\\.isRestorePreviouslyUsedInputSource)\n .filter { $0 == false }\n .sink { [weak self] _ in\n self?.preferencesVM.clearKeyboardCache()\n }\n .store(in: cancelBag)\n }\n}\n\nextension IndicatorVM {\n enum InputSourceChangeReason {\n case noChanges, system, shortcut, appSpecified(PreferencesVM.AppAutoSwitchKeyboardStatus)\n }\n\n @MainActor\n struct State {\n let appKind: AppKind?\n let inputSource: InputSource\n let inputSourceChangeReason: InputSourceChangeReason\n\n func isSame(with other: State) -> Bool {\n return State.isSame(self, other)\n }\n\n static func isSame(_ lhs: IndicatorVM.State, _ rhs: IndicatorVM.State) -> Bool {\n guard let appKind1 = lhs.appKind, let appKind2 = rhs.appKind\n else { return lhs.appKind == nil && rhs.appKind == nil }\n\n guard appKind1.isSameAppOrWebsite(with: appKind2, detectAddressBar: true)\n else { return false }\n\n guard lhs.inputSource.id == rhs.inputSource.id\n else { return false }\n\n return true\n }\n\n static func from(\n preferencesVM _: PreferencesVM,\n inputSourceChangeReason: InputSourceChangeReason,\n _ appKind: AppKind?,\n _ inputSource: InputSource\n ) -> State {\n return .init(\n appKind: appKind,\n inputSource: inputSource,\n inputSourceChangeReason: inputSourceChangeReason\n )\n }\n }\n\n enum Action {\n case start\n case appChanged(AppKind)\n case switchInputSourceByShortcut(InputSource)\n case inputSourceChanged(InputSource)\n }\n\n func send(_ action: Action) {\n actionSubject.send(action)\n }\n\n func refreshShortcut() {\n refreshShortcutSubject.send(())\n }\n\n func watchState() {\n actionSubject\n .scan(state) { [weak self] state, action -> State in\n guard let preferencesVM = self?.preferencesVM,\n let inputSourceVM = self?.inputSourceVM\n else { return state }\n\n @MainActor\n func updateState(appKind: AppKind?, inputSource: InputSource, inputSourceChangeReason: InputSourceChangeReason) -> State {\n // TODO: Move to outside\n if let appKind = appKind {\n preferencesVM.cacheKeyboardFor(appKind, keyboard: inputSource)\n }\n\n return .from(\n preferencesVM: preferencesVM,\n inputSourceChangeReason: inputSourceChangeReason,\n appKind,\n inputSource\n )\n }\n\n switch action {\n case .start:\n return state\n case let .appChanged(appKind):\n if let status = preferencesVM.getAppAutoSwitchKeyboard(appKind) {\n inputSourceVM.select(inputSource: status.inputSource)\n\n return updateState(\n appKind: appKind,\n inputSource: status.inputSource,\n inputSourceChangeReason: .appSpecified(status)\n )\n } else {\n return updateState(\n appKind: appKind,\n inputSource: state.inputSource,\n inputSourceChangeReason: .noChanges\n )\n }\n case let .inputSourceChanged(inputSource):\n guard inputSource.id != state.inputSource.id else { return state }\n\n return updateState(appKind: state.appKind, inputSource: inputSource, inputSourceChangeReason: .system)\n case let .switchInputSourceByShortcut(inputSource):\n inputSourceVM.select(inputSource: inputSource)\n\n return updateState(appKind: state.appKind, inputSource: inputSource, inputSourceChangeReason: .shortcut)\n }\n }\n .removeDuplicates(by: { $0.isSame(with: $1) })\n .assign(to: &$state)\n\n applicationVM.$appKind\n .compactMap { $0 }\n .sink(receiveValue: { [weak self] in self?.send(.appChanged($0)) })\n .store(in: cancelBag)\n\n inputSourceVM.inputSourceChangesPublisher\n .sink(receiveValue: { [weak self] in self?.send(.inputSourceChanged($0)) })\n .store(in: cancelBag)\n\n refreshShortcutSubject\n .sink { [weak self] _ in\n KeyboardShortcuts.removeAllHandlers()\n\n for inputSource in InputSource.sources {\n KeyboardShortcuts.onKeyUp(for: .init(inputSource.id)) {\n self?.send(.switchInputSourceByShortcut(inputSource))\n }\n }\n\n self?.preferencesVM.getHotKeyGroups().forEach { group in\n KeyboardShortcuts.onKeyUp(for: .init(group.id!)) {\n guard group.inputSources.count > 0 else { return }\n\n let currIps = InputSource.getCurrentInputSource()\n let nextIdx = (\n (group.inputSources.firstIndex(where: { currIps.id == $0.id }) ?? -1) + 1\n ) % group.inputSources.count\n\n self?.send(.switchInputSourceByShortcut(group.inputSources[nextIdx]))\n }\n }\n }\n .store(in: cancelBag)\n\n refreshShortcut()\n send(.start)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKind.swift", "import AppKit\nimport AXSwift\nimport Combine\nimport Foundation\n\n@MainActor\nenum AppKind {\n typealias BrowserInfo = (\n focusedElement: UIElement?,\n isFocusOnInputContainer: Bool,\n\n url: URL,\n rule: BrowserRule?,\n isFocusedOnAddressBar: Bool\n )\n\n typealias NormalInfo = (\n focusedElement: UIElement?,\n isFocusOnInputContainer: Bool\n )\n\n case normal(app: NSRunningApplication, info: NormalInfo)\n case browser(app: NSRunningApplication, info: BrowserInfo)\n\n func getId() -> String? {\n switch self {\n case let .normal(app, _):\n return app.bundleId()\n case let .browser(app, info):\n if !info.isFocusedOnAddressBar,\n info.url != .newtab,\n let bundleId = app.bundleId(),\n let addressId = info.rule?.id() ?? info.url.host\n {\n return \"\\(bundleId)_\\(addressId)\"\n } else {\n return nil\n }\n }\n }\n\n func getApp() -> NSRunningApplication {\n switch self {\n case let .normal(app, _):\n return app\n case let .browser(app, _):\n return app\n }\n }\n\n func getBrowserInfo() -> BrowserInfo? {\n switch self {\n case .normal:\n return nil\n case let .browser(_, info):\n return info\n }\n }\n\n func isFocusOnInputContainer() -> Bool {\n switch self {\n case let .normal(_, info):\n return info.isFocusOnInputContainer\n case let .browser(_, info):\n return info.isFocusOnInputContainer\n }\n }\n\n func getFocusedElement() -> UIElement? {\n switch self {\n case let .normal(_, info):\n return info.focusedElement\n case let .browser(_, info):\n return info.focusedElement\n }\n }\n\n func isSameAppOrWebsite(with otherKind: AppKind?, detectAddressBar: Bool = false) -> Bool {\n guard let otherKind = otherKind else { return false }\n guard getApp() == otherKind.getApp() else { return false }\n\n let isSameAddress = getBrowserInfo()?.url == otherKind.getBrowserInfo()?.url\n let isSameAddressBar = getBrowserInfo()?.isFocusedOnAddressBar == otherKind.getBrowserInfo()?.isFocusedOnAddressBar\n\n return detectAddressBar ? (isSameAddressBar && isSameAddress) : isSameAddress\n }\n}\n\n// MARK: - From\n\nextension AppKind {\n static func from(_ app: NSRunningApplication?, preferencesVM: PreferencesVM) -> AppKind? {\n if let app = app {\n return .from(app, preferencesVM: preferencesVM)\n } else {\n return nil\n }\n }\n\n static func from(_ app: NSRunningApplication, preferencesVM: PreferencesVM) -> AppKind {\n let application = app.getApplication(preferencesVM: preferencesVM)\n let focusedElement = app.focuedUIElement(application: application)\n let isFocusOnInputContainer = UIElement.isInputContainer(focusedElement)\n\n if let url = preferencesVM.getBrowserURL(app.bundleIdentifier, application: application)?.removeFragment() {\n let rule = preferencesVM.getBrowserRule(url: url)\n let isFocusOnBrowserAddress = preferencesVM.isFocusOnBrowserAddress(app: app, focusedElement: focusedElement)\n\n return .browser(\n app: app,\n info: (\n focusedElement,\n isFocusOnInputContainer,\n url,\n rule,\n isFocusOnBrowserAddress\n )\n )\n } else {\n return .normal(\n app: app,\n info: (\n focusedElement,\n isFocusOnInputContainer\n )\n )\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/PreferencesVM+AppCustomization.swift", "import AppKit\nimport Foundation\n\nextension PreferencesVM {\n @discardableResult\n func addAppCustomization(_ app: NSRunningApplication) -> AppRule? {\n guard let url = app.bundleURL ?? app.executableURL,\n let bundleId = app.bundleId()\n else { return nil }\n\n return addAppCustomization(url, bundleId: bundleId)\n }\n\n func addAppCustomization(_ url: URL, bundleId: String) -> AppRule {\n if let appCustomization = getAppCustomization(bundleId: bundleId) {\n return appCustomization\n }\n\n let appCustomization = AppRule(context: container.viewContext)\n\n appCustomization.createdAt = Date()\n appCustomization.url = url\n appCustomization.bundleId = url.bundleId()\n appCustomization.bundleName = FileManager.default.displayName(atPath: url.path)\n\n saveContext()\n\n return appCustomization\n }\n\n func removeAppCustomization(_ appCustomization: AppRule) {\n container.viewContext.delete(appCustomization)\n saveContext()\n }\n\n func setForceKeyboard(_ appCustomization: AppRule?, _ inputSourceId: String?) {\n guard let appCustomization = appCustomization else { return }\n\n saveContext {\n appCustomization.inputSourceId = inputSourceId\n }\n }\n\n func setDoRestoreKeyboard(_ appCustomization: AppRule?, _ doRestoreKeyboard: Bool) {\n guard let appCustomization = appCustomization else { return }\n\n saveContext {\n appCustomization.doRestoreKeyboard = doRestoreKeyboard\n }\n }\n\n func setDoNotRestoreKeyboard(_ appCustomization: AppRule?, _ doNotRestoreKeyboard: Bool) {\n guard let appCustomization = appCustomization else { return }\n\n saveContext {\n appCustomization.doNotRestoreKeyboard = doNotRestoreKeyboard\n }\n }\n\n func setHideIndicator(_ appCustomization: AppRule?, _ hideIndicator: Bool) {\n guard let appCustomization = appCustomization else { return }\n\n saveContext {\n appCustomization.hideIndicator = hideIndicator\n }\n }\n\n func getAppCustomization(app: NSRunningApplication) -> AppRule? {\n return getAppCustomization(bundleId: app.bundleId())\n }\n\n func getAppCustomization(bundleId: String?) -> AppRule? {\n guard let bundleId = bundleId else { return nil }\n\n let request = AppRule.fetchRequest()\n\n request.predicate = NSPredicate(format: \"bundleId == %@\", bundleId)\n\n do {\n return try container.viewContext.fetch(request).first\n } catch {\n print(\"getAppCustomization(bundleId) error: \\(error.localizedDescription)\")\n return nil\n }\n }\n\n func cleanRemovedAppCustomizationIfNeed() {\n guard preferences.prevInstalledBuildVersion < 308 else { return }\n\n let request = AppRule.fetchRequest()\n\n request.predicate = NSPredicate(format: \"removed == %@\", \"1\")\n\n do {\n let appRules = try container.viewContext.fetch(request)\n appRules.forEach { removeAppCustomization($0) }\n } catch {\n print(\"cleanRemovedAppCustomization error: \\(error.localizedDescription)\")\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/RulesApplicationDetail.swift", "import SwiftUI\n\n// 新增 ToggleLabel 组件\nstruct ToggleLabel: View {\n let systemImageName: String\n let text: String\n var body: some View {\n HStack(spacing: 6) {\n Image(systemName: systemImageName)\n Text(text)\n }\n }\n}\n\nstruct ApplicationDetail: View {\n @Binding var selectedApp: Set\n\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n @State var forceKeyboard: PickerItem?\n @State var doRestoreKeyboardState = NSToggleViewState.off\n @State var doNotRestoreKeyboardState = NSToggleViewState.off\n @State var hideIndicator = NSToggleViewState.off\n\n var mixed: Bool {\n Set(selectedApp.map { $0.forcedKeyboard?.id }).count > 1\n }\n\n var items: [PickerItem] {\n [mixed ? PickerItem.mixed : nil, PickerItem.empty].compactMap { $0 }\n + InputSource.sources.map { PickerItem(id: $0.id, title: $0.name, toolTip: $0.id) }\n }\n\n var body: some View {\n VStack(alignment: .leading) {\n Text(String(format: \"%@ App(s) Selected\".i18n(), \"\\(selectedApp.count)\"))\n .font(.subheadline.monospacedDigit())\n .opacity(0.5)\n .padding(.bottom, 5)\n\n VStack(alignment: .leading) {\n Text(\"Default Keyboard\".i18n())\n .fontWeight(.medium)\n\n PopUpButtonPicker(\n items: items,\n isItemEnabled: { $0?.id != \"mixed\" },\n isItemSelected: { $0 == forceKeyboard },\n getTitle: { $0?.title ?? \"\" },\n getToolTip: { $0?.toolTip },\n onSelect: handleSelect\n )\n }\n\n Divider()\n .padding(.vertical, 4)\n\n VStack(alignment: .leading) {\n Text(\"Keyboard Restore Strategy\".i18n())\n .fontWeight(.medium)\n\n HStack {\n Image(systemName: \"d.circle.fill\")\n .foregroundColor(.green)\n NSToggleView(\n label: restoreStrategyName(strategy: .UseDefaultKeyboardInstead),\n state: preferencesVM.preferences.isRestorePreviouslyUsedInputSource\n ? doNotRestoreKeyboardState\n : .on,\n onStateUpdate: handleToggleDoNotRestoreKeyboard\n )\n .fixedSize()\n .disabled(!preferencesVM.preferences.isRestorePreviouslyUsedInputSource)\n }\n\n HStack {\n Image(systemName: \"arrow.uturn.left.circle.fill\")\n .foregroundColor(.blue)\n NSToggleView(\n label: restoreStrategyName(strategy: .RestorePreviouslyUsedOne),\n state: preferencesVM.preferences.isRestorePreviouslyUsedInputSource\n ? .on\n : doRestoreKeyboardState,\n onStateUpdate: handleToggleDoRestoreKeyboard\n )\n .fixedSize()\n .disabled(preferencesVM.preferences.isRestorePreviouslyUsedInputSource)\n }\n }\n\n Divider()\n .padding(.vertical, 4)\n\n VStack(alignment: .leading) {\n Text(\"Indicator\".i18n())\n .fontWeight(.medium)\n HStack {\n Image(systemName: \"eye.slash.circle.fill\")\n .foregroundColor(.gray)\n NSToggleView(\n label: \"Hide Indicator\".i18n(),\n state: hideIndicator,\n onStateUpdate: handleToggleHideIndicator\n )\n .fixedSize()\n }\n }\n\n if selectedApp.contains(where: { preferencesVM.needDisplayEnhancedModePrompt(bundleIdentifier: $0.bundleId) }) {\n Divider().padding(.vertical, 4)\n\n EnhancedModeRequiredBadge()\n }\n\n Spacer()\n }\n .disabled(selectedApp.isEmpty)\n .onChange(of: selectedApp) { _ in\n updateForceKeyboardId()\n updateDoRestoreKeyboardState()\n updateDoNotRestoreKeyboardState()\n updateHideIndicatorState()\n }\n }\n\n func updateForceKeyboardId() {\n if mixed {\n forceKeyboard = PickerItem.mixed\n } else if let keyboard = selectedApp.first?.forcedKeyboard {\n forceKeyboard = PickerItem(id: keyboard.id, title: keyboard.name, toolTip: keyboard.id)\n } else {\n forceKeyboard = PickerItem.empty\n }\n }\n\n func updateDoRestoreKeyboardState() {\n let stateSet = Set(selectedApp.map { $0.doRestoreKeyboard })\n\n if stateSet.count > 1 {\n doRestoreKeyboardState = .mixed\n } else {\n doRestoreKeyboardState = stateSet.first == true ? .on : .off\n }\n }\n\n func updateDoNotRestoreKeyboardState() {\n let stateSet = Set(selectedApp.map { $0.doNotRestoreKeyboard })\n\n if stateSet.count > 1 {\n doNotRestoreKeyboardState = .mixed\n } else {\n doNotRestoreKeyboardState = stateSet.first == true ? .on : .off\n }\n }\n\n func updateHideIndicatorState() {\n let stateSet = Set(selectedApp.map { $0.hideIndicator })\n\n if stateSet.count > 1 {\n hideIndicator = .mixed\n } else {\n hideIndicator = stateSet.first == true ? .on : .off\n }\n }\n\n func handleSelect(_ index: Int) {\n forceKeyboard = items[index]\n\n for app in selectedApp {\n preferencesVM.setForceKeyboard(app, forceKeyboard?.id)\n }\n }\n\n func handleToggleDoNotRestoreKeyboard() -> NSControl.StateValue {\n switch doNotRestoreKeyboardState {\n case .on:\n selectedApp.forEach { preferencesVM.setDoNotRestoreKeyboard($0, false) }\n doNotRestoreKeyboardState = .off\n return .off\n case .off, .mixed:\n selectedApp.forEach { preferencesVM.setDoNotRestoreKeyboard($0, true) }\n doNotRestoreKeyboardState = .on\n return .on\n }\n }\n\n func handleToggleDoRestoreKeyboard() -> NSControl.StateValue {\n switch doRestoreKeyboardState {\n case .on:\n selectedApp.forEach { preferencesVM.setDoRestoreKeyboard($0, false) }\n doRestoreKeyboardState = .off\n return .off\n case .off, .mixed:\n selectedApp.forEach { preferencesVM.setDoRestoreKeyboard($0, true) }\n doRestoreKeyboardState = .on\n return .on\n }\n }\n\n func handleToggleHideIndicator() -> NSControl.StateValue {\n switch hideIndicator {\n case .on:\n selectedApp.forEach { preferencesVM.setHideIndicator($0, false) }\n hideIndicator = .off\n return .off\n case .off, .mixed:\n selectedApp.forEach { preferencesVM.setHideIndicator($0, true) }\n hideIndicator = .on\n return .on\n }\n }\n\n func restoreStrategyName(strategy: KeyboardRestoreStrategy) -> String {\n strategy.name + restoreStrategyTips(strategy: strategy)\n }\n\n func restoreStrategyTips(strategy: KeyboardRestoreStrategy) -> String {\n switch strategy {\n case .RestorePreviouslyUsedOne:\n return preferencesVM.preferences.isRestorePreviouslyUsedInputSource ? \" (\\(\"Default\".i18n()))\" : \"\"\n case .UseDefaultKeyboardInstead:\n return !preferencesVM.preferences.isRestorePreviouslyUsedInputSource ? \" (\\(\"Default\".i18n()))\" : \"\"\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKeyboardCache.swift", "import AppKit\nimport Foundation\nimport os\n\n@MainActor\nclass AppKeyboardCache {\n private var cache = [String: String]()\n\n let logger = ISPLogger(category: String(describing: AppKeyboardCache.self))\n\n func remove(_ kind: AppKind) {\n if let id = kind.getId(), cache[id] != nil {\n logger.debug { \"Remove #\\(id)\" }\n cache[id] = nil\n }\n }\n\n func save(_ kind: AppKind, keyboard: InputSource?) {\n guard let id = kind.getId() else { return }\n\n if let keyboardId = keyboard?.id {\n logger.debug { \"Save \\(id)#\\(keyboardId)\" }\n cache[id] = keyboardId\n }\n }\n\n func retrieve(_ kind: AppKind) -> InputSource? {\n guard let id = kind.getId(),\n let keyboardId = cache[id]\n else { return nil }\n\n logger.debug { \"Retrieve \\(id)#\\(keyboardId)\" }\n\n return InputSource.sources.first { $0.id == keyboardId }\n }\n\n func clear() {\n // FIXME: - Some apps/websites where 'restore' is selected should be ignored\n logger.debug { \"Clear All\" }\n cache.removeAll()\n }\n\n func remove(byBundleId bundleId: String) {\n for key in cache.keys {\n if key.starts(with: \"\\(bundleId)_\") {\n logger.debug { \"Remove \\(bundleId)#\\(key)\" }\n cache[key] = nil\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/IndicatorVM+Triggers.swift", "import AppKit\nimport AXSwift\nimport Combine\nimport CombineExt\n\nextension IndicatorVM {\n @MainActor\n enum ActivateEvent {\n case justHide\n case longMouseDown\n case appChanges(current: AppKind?, prev: AppKind?)\n case inputSourceChanges(InputSource, InputSourceChangeReason)\n\n func isAppChangesWithSameAppOrWebsite() -> Bool {\n switch self {\n case let .appChanges(current, prev):\n return current?.isSameAppOrWebsite(with: prev) == true\n case .inputSourceChanges:\n return false\n case .longMouseDown:\n return false\n case .justHide:\n return false\n }\n }\n\n var isJustHide: Bool {\n switch self {\n case .justHide: return true\n default: return false\n }\n }\n }\n\n func longMouseDownPublisher() -> AnyPublisher {\n AnyPublisher\n .create { observer in\n let monitor = NSEvent.addGlobalMonitorForEvents(\n matching: [.leftMouseDown, .leftMouseUp, .leftMouseDragged],\n handler: { observer.send($0) }\n )\n\n return AnyCancellable { NSEvent.removeMonitor(monitor!) }\n }\n .flatMapLatest { event -> AnyPublisher in\n if event.type == .leftMouseDown {\n return Timer\n .delay(seconds: 0.35)\n .mapToVoid()\n .eraseToAnyPublisher()\n } else {\n return Empty().eraseToAnyPublisher()\n }\n }\n .filter { [weak self] _ in\n self?.preferencesVM.preferences.isActiveWhenLongpressLeftMouse ?? false\n }\n .mapTo(.longMouseDown)\n }\n\n func stateChangesPublisher() -> AnyPublisher {\n $state\n .withPrevious()\n .map { [weak self] previous, current -> ActivateEvent in\n if let preferencesVM = self?.preferencesVM {\n if previous?.appKind?.getId() != current.appKind?.getId() {\n let event = ActivateEvent.appChanges(current: current.appKind, prev: previous?.appKind)\n\n if preferencesVM.preferences.isActiveWhenSwitchApp || preferencesVM.preferences.isActiveWhenFocusedElementChangesEnabled {\n if preferencesVM.preferences.isHideWhenSwitchAppWithForceKeyboard {\n switch current.inputSourceChangeReason {\n case let .appSpecified(status):\n switch status {\n case .cached:\n return event\n case .specified:\n return .justHide\n }\n default:\n return .justHide\n }\n } else {\n return event\n }\n } else {\n return .justHide\n }\n }\n\n if previous?.inputSource.id != current.inputSource.id {\n switch current.inputSourceChangeReason {\n case .noChanges:\n return .justHide\n case .system, .shortcut, .appSpecified:\n guard preferencesVM.preferences.isActiveWhenSwitchInputSource else { return .justHide }\n return .inputSourceChanges(current.inputSource, current.inputSourceChangeReason)\n }\n }\n }\n\n return .justHide\n }\n .eraseToAnyPublisher()\n }\n}\n\nextension IndicatorVM.ActivateEvent: @preconcurrency CustomStringConvertible {\n var description: String {\n switch self {\n case let .appChanges(current, prev):\n return \"appChanges(\\(String(describing: current)), \\(String(describing: prev))\"\n case .inputSourceChanges:\n return \"inputSourceChanges\"\n case .longMouseDown:\n return \"longMouseDown\"\n case .justHide:\n return \"justHide\"\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/AppRuleMenuItem.swift", "import AppKit\n\n@MainActor\nclass AppRuleMenuItem: NSMenuItem {\n let app: NSRunningApplication\n let preferencesVM: PreferencesVM\n let inputSource: InputSource?\n\n var cancelBag = CancelBag()\n\n var appCustomization: AppRule? {\n preferencesVM.getAppCustomization(app: app)\n }\n\n init(app: NSRunningApplication, preferencesVM: PreferencesVM, inputSource: InputSource?) {\n self.app = app\n self.preferencesVM = preferencesVM\n self.inputSource = inputSource\n\n super.init(title: inputSource?.name ?? \"\", action: #selector(forceKeyboard(_:)), keyEquivalent: \"\")\n\n target = self\n\n updateState()\n watchChanges()\n }\n\n @available(*, unavailable)\n required init(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n\n @objc func forceKeyboard(_: Any) {\n let inputSourceId = inputSource?.id ?? \"\"\n\n if let appCustomization = appCustomization {\n preferencesVM.setForceKeyboard(appCustomization, inputSourceId)\n } else {\n preferencesVM.setForceKeyboard(\n preferencesVM.addAppCustomization(app),\n inputSourceId\n )\n }\n\n inputSource?.select(useCJKVFix: preferencesVM.isUseCJKVFix())\n\n watchChanges()\n }\n\n func watchChanges() {\n cancelBag.cancel()\n\n appCustomization?.publisher(for: \\.inputSourceId)\n .sink { [weak self] _ in self?.updateState() }\n .store(in: cancelBag)\n }\n\n func updateState() {\n state = appCustomization?.inputSourceId == inputSource?.id ? .on : .off\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/BrowserRulesSettingsView.swift", "import SwiftUI\n\nstruct BrowserRulesSettingsView: View {\n @State var isPresented = false\n\n @State var permissionRequest: Browser? = nil\n\n @State var selectedRules = Set()\n\n @FetchRequest(sortDescriptors: [\n NSSortDescriptor(key: \"createdAt\", ascending: true),\n ])\n var browserRules: FetchedResults\n\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n @EnvironmentObject var permissionsVM: PermissionsVM\n\n var inputSourceItems: [PickerItem] {\n [PickerItem.empty]\n + InputSource.sources.map { PickerItem(id: $0.id, title: $0.name, toolTip: $0.id) }\n }\n\n var body: some View {\n let isShowPermissionRequest = Binding(\n get: { permissionRequest != nil },\n set: {\n if $0 == false {\n permissionRequest = nil\n }\n }\n )\n\n return VStack(spacing: 0) {\n VStack {\n HStack {\n Text(\"Default Keyboard for Address Bar\".i18n())\n\n PopUpButtonPicker(\n items: inputSourceItems,\n width: 150,\n isItemSelected: { $0?.id == preferencesVM.preferences.browserAddressDefaultKeyboardId },\n getTitle: { $0?.title ?? \"\" },\n getToolTip: { $0?.toolTip },\n onSelect: handleBrowserAddressDefaultKeyboardSelect\n )\n .disabled(!preferencesVM.preferences.isEnhancedModeEnabled)\n\n EnhancedModeRequiredBadge()\n\n Spacer(minLength: 0)\n }\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border.color)\n\n List(browserRules, id: \\.self, selection: $selectedRules) { rule in\n BrowserRuleRow(isSelected: selectedRules.contains(rule), rule: rule)\n }\n\n HStack(spacing: 0) {\n HStack(spacing: 5) {\n Button(action: addRule) {\n SwiftUI.Image(systemName: \"plus\")\n }\n\n Button(action: removeRules) {\n SwiftUI.Image(systemName: \"minus\")\n }\n .disabled(selectedRules.isEmpty)\n }\n\n Divider()\n .frame(height: 16)\n .padding(.horizontal, 8)\n\n ScrollView(.horizontal, showsIndicators: false) {\n HStack(spacing: 10) {\n ForEach(Browser.allCases.sorted { $0.rawValue < $1.rawValue }, id: \\.rawValue) { browser in\n if NSApplication.isBrowserInstalled(browser.rawValue) {\n Toggle(isOn: isEnableFor(browser)) {\n Text(\"\\(browser.displayName)\")\n }\n }\n }\n }\n }\n }\n .padding(10)\n .border(width: 1, edges: [.top], color: NSColor.gridColor.color)\n .sheet(isPresented: $isPresented, content: {\n BrowserRuleEditView(isPresented: $isPresented, rule: nil)\n })\n .sheet(isPresented: isShowPermissionRequest) {\n BrowserPermissionRequestView(\n isPresented: isShowPermissionRequest,\n onSuccess: permissionRequestSuccess\n )\n }\n }\n }\n\n func addRule() {\n isPresented = true\n }\n\n func removeRules() {\n for selectedRule in selectedRules {\n preferencesVM.deleteBrowserRule(selectedRule)\n }\n selectedRules.removeAll()\n }\n\n func isEnableFor(_ browser: Browser) -> Binding {\n Binding(\n get: { preferencesVM.isBrowserEnabled(browser) },\n set: { enableFor(browser, enable: $0) }\n )\n }\n\n func enableFor(_ browser: Browser, enable: Bool) {\n if enable {\n // TODO: replace `isAccessibilityEnabled` with enhance mode\n if permissionsVM.isAccessibilityEnabled {\n toggle(browser: browser, isEnable: true)\n } else {\n permissionRequest = browser\n }\n } else {\n toggle(browser: browser, isEnable: false)\n }\n }\n\n func permissionRequestSuccess() {\n guard let browser = permissionRequest\n else { return }\n\n toggle(browser: browser, isEnable: true)\n }\n\n func toggle(browser: Browser, isEnable: Bool) {\n preferencesVM.update {\n if isEnable {\n $0.isEnhancedModeEnabled = true\n }\n\n switch browser {\n case .Chrome:\n $0.isEnableURLSwitchForChrome = isEnable\n case .Chromium:\n $0.isEnableURLSwitchForChromium = isEnable\n case .Arc:\n $0.isEnableURLSwitchForArc = isEnable\n case .Safari:\n $0.isEnableURLSwitchForSafari = isEnable\n case .SafariTechnologyPreview:\n $0.isEnableURLSwitchForSafariTechnologyPreview = isEnable\n case .Edge:\n $0.isEnableURLSwitchForEdge = isEnable\n case .Brave:\n $0.isEnableURLSwitchForBrave = isEnable\n case .BraveBeta:\n $0.isEnableURLSwitchForBraveBeta = isEnable\n case .BraveNightly:\n $0.isEnableURLSwitchForBraveNightly = isEnable\n case .Vivaldi:\n $0.isEnableURLSwitchForVivaldi = isEnable\n case .Opera:\n $0.isEnableURLSwitchForOpera = isEnable\n case .Thorium:\n $0.isEnableURLSwitchForThorium = isEnable\n case .Firefox:\n $0.isEnableURLSwitchForFirefox = isEnable\n case .FirefoxDeveloperEdition:\n $0.isEnableURLSwitchForFirefoxDeveloperEdition = isEnable\n case .FirefoxNightly:\n $0.isEnableURLSwitchForFirefoxNightly = isEnable\n case .Zen:\n $0.isEnableURLSwitchForZen = isEnable\n case .Dia:\n $0.isEnableURLSwitchForDia = isEnable\n }\n }\n }\n\n func handleBrowserAddressDefaultKeyboardSelect(_ index: Int) {\n let browserAddressDefaultKeyboard = inputSourceItems[index]\n\n preferencesVM.update {\n $0.browserAddressDefaultKeyboardId = browserAddressDefaultKeyboard.id\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/GeneralSettingsView.swift", "import SwiftUI\n\nstruct GeneralSettingsView: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n @EnvironmentObject var permissionsVM: PermissionsVM\n\n @State var isDetectSpotlightLikeApp = false\n\n var items: [PickerItem] {\n [PickerItem.empty]\n + InputSource.sources.map { PickerItem(id: $0.id, title: $0.name, toolTip: $0.id) }\n }\n\n var body: some View {\n let keyboardRestoreStrategyBinding = Binding(\n get: { preferencesVM.preferences.isRestorePreviouslyUsedInputSource ?\n KeyboardRestoreStrategy.RestorePreviouslyUsedOne :\n KeyboardRestoreStrategy.UseDefaultKeyboardInstead\n },\n set: { newValue in\n preferencesVM.update {\n switch newValue {\n case .RestorePreviouslyUsedOne:\n $0.isRestorePreviouslyUsedInputSource = true\n case .UseDefaultKeyboardInstead:\n $0.isRestorePreviouslyUsedInputSource = false\n }\n }\n }\n )\n\n ScrollView {\n VStack(alignment: .leading, spacing: 18) {\n SettingsSection(title: \"\") {\n PromotionBadge()\n }\n \n SettingsSection(title: \"\") {\n EnhancedModeToggle()\n }\n\n SettingsSection(title: \"Default Keyboard\") {\n HStack {\n Text(\"For All Apps and Websites\".i18n())\n\n PopUpButtonPicker(\n items: items,\n isItemSelected: { $0?.id == preferencesVM.preferences.systemWideDefaultKeyboardId },\n getTitle: { $0?.title ?? \"\" },\n getToolTip: { $0?.toolTip },\n onSelect: handleSystemWideDefaultKeyboardSelect\n )\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n }\n\n SettingsSection(title: \"Keyboard Restore Strategy\") {\n VStack(alignment: .leading) {\n Text(\"When Switching Back to the App or Website\".i18n() + \":\")\n\n Picker(\"Keyboard Restore Strategy\", selection: keyboardRestoreStrategyBinding) {\n ForEach(KeyboardRestoreStrategy.allCases) { item in\n Text(item.name).tag(item)\n }\n }\n .pickerStyle(.segmented)\n }\n .padding()\n }\n\n Group {\n SettingsSection(title: \"Indicator Triggers\") {\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.isActiveWhenLongpressLeftMouse)\n\n Text(\"isActiveWhenLongpressLeftMouse\".i18n())\n\n Spacer()\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.isActiveWhenSwitchInputSource)\n\n Text(\"isActiveWhenSwitchInputSource\".i18n())\n\n Spacer()\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.isActiveWhenSwitchApp)\n\n Text(\"isActiveWhenSwitchApp\".i18n())\n\n Spacer()\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.isActiveWhenFocusedElementChanges)\n .disabled(!preferencesVM.preferences.isEnhancedModeEnabled)\n\n Text(\"isActiveWhenFocusedElementChanges\".i18n())\n\n Spacer()\n\n EnhancedModeRequiredBadge()\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n }\n\n SettingsSection(title: \"\") {\n HStack {\n Toggle(\"\",\n isOn: $preferencesVM.preferences.isHideWhenSwitchAppWithForceKeyboard)\n .disabled(!(\n preferencesVM.preferences.isActiveWhenSwitchApp ||\n preferencesVM.preferences.isActiveWhenSwitchInputSource ||\n preferencesVM.preferences.isActiveWhenFocusedElementChanges\n ))\n\n Text(\"isHideWhenSwitchAppWithForceKeyboard\")\n\n Spacer()\n }\n .padding()\n }\n }\n\n Group {\n SettingsSection(title: \"System\") {\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.isLaunchAtLogin)\n Text(\"Launch at Login\".i18n())\n Spacer()\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.isShowIconInMenuBar)\n Text(\"Display Icon in Menu Bar\".i18n())\n Spacer()\n }\n .padding()\n }\n\n SettingsSection(title: \"Updates\") {\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.receiveBetaUpdates)\n Text(\"Receive Beta Updates\".i18n())\n Spacer()\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n \n Button(action: { preferencesVM.checkUpdates() }, label: {\n HStack {\n Text(\"Check for Updates\".i18n() + \"...\")\n\n Spacer()\n\n Text(\" \\(preferencesVM.versionStr) (\\(preferencesVM.buildStr))\")\n .foregroundColor(Color.primary.opacity(0.5))\n }\n })\n .buttonStyle(SectionButtonStyle())\n }\n }\n\n Group {\n SettingsSection(title: \"Find Us\", tips: Text(\"Right click each section to copy link\").font(.subheadline).opacity(0.5)) {\n Button(action: { URL.website.open() }, label: {\n HStack {\n Text(\"Website\".i18n())\n .foregroundColor(Color.primary)\n\n Spacer()\n\n Text(URL.website.absoluteString)\n }\n })\n .buttonStyle(SectionButtonStyle())\n .contextMenu {\n Button(\"Copy\") {\n NSPasteboard.general.clearContents()\n NSPasteboard.general.setString(URL.website.absoluteString, forType: .string)\n }\n }\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n\n Button(action: { URL.twitter.open() }, label: {\n HStack {\n Text(\"Twitter\")\n .foregroundColor(Color.primary)\n\n Spacer()\n\n Text(\"@Runjuu\")\n }\n })\n .buttonStyle(SectionButtonStyle())\n .contextMenu {\n Button(\"Copy\") {\n NSPasteboard.general.clearContents()\n NSPasteboard.general.setString(URL.twitter.absoluteString, forType: .string)\n }\n }\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n\n Button(action: { URL.email.open() }, label: {\n HStack {\n Text(\"Email\")\n .foregroundColor(Color.primary)\n\n Spacer()\n\n Text(URL.emailString)\n }\n })\n .buttonStyle(SectionButtonStyle())\n .contextMenu {\n Button(\"Copy\") {\n NSPasteboard.general.clearContents()\n NSPasteboard.general.setString(URL.emailString, forType: .string)\n }\n }\n }\n\n SettingsSection(title: \"\") {\n FeedbackButton()\n }\n }\n\n SettingsSection(title: \"Privacy\") {\n HStack {\n Text(\"Privacy Content\".i18n())\n .multilineTextAlignment(.leading)\n .padding()\n .opacity(0.8)\n\n Spacer(minLength: 0)\n }\n }\n\n HStack {\n Spacer()\n Text(\"Created by Runjuu & Die2\")\n Spacer()\n }\n .font(.footnote)\n .opacity(0.5)\n }\n .padding()\n }\n .labelsHidden()\n .toggleStyle(.switch)\n .background(NSColor.background1.color)\n .onAppear(perform: disableIsDetectSpotlightLikeAppIfNeed)\n }\n\n func disableIsDetectSpotlightLikeAppIfNeed() {\n if !permissionsVM.isAccessibilityEnabled && preferencesVM.preferences.isEnhancedModeEnabled {\n preferencesVM.update {\n $0.isEnhancedModeEnabled = false\n }\n }\n }\n\n func handleSystemWideDefaultKeyboardSelect(_ index: Int) {\n let defaultKeyboard = items[index]\n\n preferencesVM.update {\n $0.systemWideDefaultKeyboardId = defaultKeyboard.id\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/PreferencesVM+BrowserRule.swift", "import AppKit\nimport AXSwift\nimport Foundation\n\nextension PreferencesVM {\n func addBrowserRule(\n type: BrowserRuleType,\n value: String,\n sample: String,\n inputSourceId: String,\n hideIndicator: Bool,\n keyboardRestoreStrategy: KeyboardRestoreStrategy?\n ) {\n let rule = BrowserRule(context: container.viewContext)\n\n rule.createdAt = Date()\n rule.type = type\n rule.value = value\n rule.sample = sample\n rule.inputSourceId = inputSourceId\n rule.keyboardRestoreStrategyRaw = keyboardRestoreStrategy?.rawValue\n rule.hideIndicator = hideIndicator\n rule.disabled = false\n\n saveContext()\n }\n\n func deleteBrowserRule(_ rule: BrowserRule) {\n container.viewContext.delete(rule)\n saveContext()\n }\n\n func updateBrowserRule(\n _ rule: BrowserRule,\n type: BrowserRuleType,\n value: String,\n sample: String,\n inputSourceId: String,\n hideIndicator: Bool,\n keyboardRestoreStrategy: KeyboardRestoreStrategy?\n ) {\n saveContext {\n rule.type = type\n rule.value = value\n rule.sample = sample\n rule.inputSourceId = inputSourceId\n rule.hideIndicator = hideIndicator\n rule.keyboardRestoreStrategyRaw = keyboardRestoreStrategy?.rawValue\n }\n }\n\n func toggleBrowserRule(_ rule: BrowserRule) {\n saveContext {\n rule.disabled.toggle()\n }\n }\n\n private func getBrowserRules() -> [BrowserRule] {\n let request = NSFetchRequest(entityName: \"BrowserRule\")\n\n do {\n return try container.viewContext.fetch(request)\n } catch {\n print(\"getBrowserRules() error: \\(error.localizedDescription)\")\n return []\n }\n }\n\n func getBrowserRule(url: URL) -> BrowserRule? {\n return getBrowserRules().first { $0.validate(url: url) }\n }\n}\n\nextension PreferencesVM {\n var isNeedToDetectBrowserTabChanges: Bool {\n guard preferences.isEnhancedModeEnabled else { return false }\n\n return Browser.allCases.contains(where: isBrowserEnabled)\n }\n\n func isBrowserAndEnabled(_ app: NSRunningApplication) -> Bool {\n guard let browser = NSApplication.getBrowser(app)\n else { return false }\n\n return isBrowserEnabled(browser)\n }\n\n func isBrowserEnabled(_ browser: Browser) -> Bool {\n switch browser {\n case .Safari:\n return preferences.isEnableURLSwitchForSafari\n case .SafariTechnologyPreview:\n return preferences.isEnableURLSwitchForSafariTechnologyPreview\n case .Chrome:\n return preferences.isEnableURLSwitchForChrome\n case .Chromium:\n return preferences.isEnableURLSwitchForChromium\n case .Arc:\n return preferences.isEnableURLSwitchForArc\n case .Edge:\n return preferences.isEnableURLSwitchForEdge\n case .Brave:\n return preferences.isEnableURLSwitchForBrave\n case .BraveBeta:\n return preferences.isEnableURLSwitchForBraveBeta\n case .BraveNightly:\n return preferences.isEnableURLSwitchForBraveNightly\n case .Vivaldi:\n return preferences.isEnableURLSwitchForVivaldi\n case .Opera:\n return preferences.isEnableURLSwitchForOpera\n case .Thorium:\n return preferences.isEnableURLSwitchForThorium\n case .Firefox:\n return preferences.isEnableURLSwitchForFirefox\n case .FirefoxDeveloperEdition:\n return preferences.isEnableURLSwitchForFirefoxDeveloperEdition\n case .FirefoxNightly:\n return preferences.isEnableURLSwitchForFirefoxNightly\n case .Zen:\n return preferences.isEnableURLSwitchForZen\n case .Dia:\n return preferences.isEnableURLSwitchForDia\n }\n }\n\n func getBrowserInfo(app: NSRunningApplication) -> (url: URL, rule: BrowserRule?)? {\n guard let url = getBrowserURL(app.bundleIdentifier, application: Application(app)) else { return nil }\n\n return (url, getBrowserRule(url: url))\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/RulesApplicationPicker.swift", "import SwiftUI\n\nstruct ApplicationPicker: View {\n @Binding var selectedApp: Set\n\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n @FetchRequest(sortDescriptors: [NSSortDescriptor(key: \"bundleName\", ascending: true)])\n var appCustomizations: FetchedResults\n\n let appIconSize: CGFloat = 18\n let keyboardIconSize: CGFloat = 16\n\n var body: some View {\n VStack(spacing: 0) {\n List(appCustomizations, id: \\.self, selection: $selectedApp) { app in\n HStack {\n if let image = app.image {\n SwiftUI.Image(nsImage: image)\n .resizable()\n .frame(width: appIconSize, height: appIconSize)\n } else {\n SwiftUI.Image(systemName: \"app.dashed\")\n .resizable()\n .frame(width: appIconSize, height: appIconSize)\n }\n\n Text(app.bundleName ?? \"(unknown)\")\n .lineLimit(1)\n\n Spacer()\n\n if app.hideIndicator {\n SwiftUI.Image(systemName: \"eye.slash.circle.fill\")\n .opacity(0.7)\n }\n\n if preferencesVM.needDisplayEnhancedModePrompt(bundleIdentifier: app.bundleId) {\n SwiftUI.Image(systemName: \"exclamationmark.triangle.fill\")\n .foregroundColor(Color(red: 1.0, green: 0.84, blue: 0.0))\n }\n\n if preferencesVM.preferences.isRestorePreviouslyUsedInputSource {\n if app.doNotRestoreKeyboard {\n SwiftUI.Image(systemName: \"d.circle.fill\")\n .foregroundColor(selectedApp.contains(app) ? .primary : .green)\n .opacity(selectedApp.contains(app) ? 0.7 : 1.0)\n }\n } else {\n if app.doRestoreKeyboard {\n SwiftUI.Image(systemName: \"arrow.uturn.left.circle.fill\")\n .foregroundColor(selectedApp.contains(app) ? .primary : .blue)\n .opacity(selectedApp.contains(app) ? 0.7 : 1.0)\n }\n }\n\n if let icon = app.forcedKeyboard?.icon {\n SwiftUI.Image(nsImage: icon)\n .resizable()\n .scaledToFit()\n .frame(width: keyboardIconSize, height: keyboardIconSize)\n .opacity(0.7)\n }\n }\n .help(app.bundleName ?? app.url?.path ?? \"(unknown)\")\n }\n .listRowInsets(EdgeInsets())\n }\n .onAppear {\n if let app = appCustomizations.first {\n selectedApp.update(with: app)\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Controllers/IndicatorWindowController+Activation.swift", "import AppKit\nimport AXSwift\nimport Combine\nimport CombineExt\n\n// MARK: - Default indicator: auto hide\n\nextension IndicatorWindowController {\n func autoHidePublisher(\n event: IndicatorVM.ActivateEvent,\n inputSource: InputSource,\n appKind: AppKind\n ) -> AnyPublisher {\n return Just(event)\n .tap { [weak self] in self?.updateIndicator(event: $0, inputSource: inputSource) }\n .flatMapLatest { [weak self] _ -> AnyPublisher in\n guard let self = self,\n let appSize = self.getAppSize()\n else { return Empty().eraseToAnyPublisher() }\n\n return self.preferencesVM\n .getIndicatorPositionPublisher(appSize: appSize, app: appKind.getApp())\n .compactMap { $0 }\n .first()\n .tap { self.moveIndicator(position: $0) }\n .flatMapLatest { _ -> AnyPublisher in\n Publishers.Merge(\n Timer.delay(seconds: 1).mapToVoid(),\n // hover event\n self.indicatorVC.hoverableView.hoverdPublisher\n .filter { $0 }\n .first()\n .flatMapLatest { _ in\n Timer.delay(seconds: 0.15)\n }\n .mapToVoid()\n )\n .first()\n .mapTo(false)\n .prepend(true)\n .tap { isActive in\n self.isActive = isActive\n }\n .eraseToAnyPublisher()\n }\n .mapToVoid()\n .eraseToAnyPublisher()\n }\n .mapToVoid()\n .eraseToAnyPublisher()\n }\n}\n\n// MARK: - Default indicator: auto show\n\nextension IndicatorWindowController {\n func autoShowPublisher(\n event: IndicatorVM.ActivateEvent,\n inputSource: InputSource,\n appKind: AppKind\n ) -> AnyPublisher {\n let app = appKind.getApp()\n let application = app.getApplication(preferencesVM: preferencesVM)\n\n let needActivateAtFirstTime = {\n if preferencesVM.preferences.isActiveWhenSwitchApp {\n return true\n }\n\n if preferencesVM.preferences.isActiveWhenFocusedElementChangesEnabled,\n let focusedUIElement = app.focuedUIElement(application: application),\n UIElement.isInputContainer(focusedUIElement)\n {\n return true\n }\n\n return false\n }()\n\n if !needActivateAtFirstTime, isActive {\n isActive = false\n }\n\n return app\n .watchAX([.focusedUIElementChanged], [.application, .window])\n .compactMap { _ in app.focuedUIElement(application: application) }\n .removeDuplicates()\n .filter { UIElement.isInputContainer($0) }\n .mapTo(true)\n .prepend(needActivateAtFirstTime)\n .filter { $0 }\n .compactMap { [weak self] _ in self?.autoHidePublisher(event: event, inputSource: inputSource, appKind: appKind) }\n .switchToLatest()\n .eraseToAnyPublisher()\n }\n}\n\n// MARK: - Just hide indicator\n\nextension IndicatorWindowController {\n func justHidePublisher() -> AnyPublisher {\n Just(true)\n .tap { [weak self] _ in self?.isActive = false }\n .mapToVoid()\n .eraseToAnyPublisher()\n }\n}\n\n// MARK: - AlwaysOn\n\nextension IndicatorWindowController {\n @MainActor\n enum AlwaysOn {\n enum Event {\n case cursorMoved, showAlwaysOnIndicator, scrollStart, scrollEnd\n }\n\n struct State {\n typealias Changes = (current: State, prev: State)\n\n static let initial = State(isShowAlwaysOnIndicator: false, isScrolling: false)\n\n var isShowAlwaysOnIndicator: Bool\n var isScrolling: Bool\n\n func reducer(_ event: Event) -> State {\n switch event {\n case .scrollStart:\n return update {\n $0.isScrolling = true\n }\n case .scrollEnd:\n return update {\n $0.isScrolling = false\n }\n case .showAlwaysOnIndicator:\n return update {\n $0.isShowAlwaysOnIndicator = true\n }\n case .cursorMoved:\n return self\n }\n }\n\n func update(_ change: (inout State) -> Void) -> State {\n var draft = self\n\n change(&draft)\n\n return draft\n }\n }\n\n static func statePublisher(app: NSRunningApplication) -> AnyPublisher {\n let show = app.watchAX(\n [.selectedTextChanged],\n [.application, .window] + Role.validInputElms\n )\n .mapTo(Event.cursorMoved)\n\n let checkIfUnfocusedTimer = Timer.interval(seconds: 1)\n .mapTo(Event.cursorMoved)\n\n let showAlwaysOnIndicatorTimer = Timer.delay(seconds: 0.8)\n .mapTo(Event.showAlwaysOnIndicator)\n\n let hide = NSEvent.watch(matching: [.scrollWheel])\n .flatMapLatest { _ in Timer\n .delay(seconds: 0.3)\n .mapTo(Event.scrollEnd)\n .prepend(Event.scrollStart)\n }\n .removeDuplicates()\n .eraseToAnyPublisher()\n\n return Publishers.MergeMany([show, hide, checkIfUnfocusedTimer, showAlwaysOnIndicatorTimer])\n .prepend(.cursorMoved)\n .scan((State.initial, State.initial)) { changes, event -> State.Changes in\n (changes.current.reducer(event), changes.current)\n }\n .receive(on: DispatchQueue.main)\n .eraseToAnyPublisher()\n }\n }\n\n func alwaysOnPublisher(\n event: IndicatorVM.ActivateEvent,\n inputSource: InputSource,\n appKind: AppKind\n ) -> AnyPublisher {\n typealias Action = () -> Void\n\n let app = appKind.getApp()\n var isAlwaysOnIndicatorShowed = false\n\n updateIndicator(\n event: event,\n inputSource: inputSource\n )\n\n return AlwaysOn\n .statePublisher(app: app)\n .flatMapLatest { [weak self] state -> AnyPublisher in\n let ACTION_HIDE: Action = { self?.isActive = false }\n let ACTION_SHOW: Action = { self?.isActive = true }\n let ACTION_SHOW_ALWAYS_ON_INDICATOR: Action = { self?.indicatorVC.showAlwaysOnView() }\n\n if !state.current.isScrolling,\n let self = self,\n let appSize = self.getAppSize()\n {\n return self.preferencesVM.getIndicatorPositionPublisher(appSize: appSize, app: app)\n .map { position -> Action in\n guard let position = position\n else { return ACTION_HIDE }\n\n return {\n if state.current.isShowAlwaysOnIndicator,\n !isAlwaysOnIndicatorShowed\n {\n isAlwaysOnIndicatorShowed = true\n ACTION_SHOW_ALWAYS_ON_INDICATOR()\n }\n\n if position.kind.isInputArea {\n self.moveIndicator(position: position)\n ACTION_SHOW()\n } else {\n if state.current.isShowAlwaysOnIndicator {\n ACTION_HIDE()\n } else {\n self.moveIndicator(position: position)\n ACTION_SHOW()\n }\n }\n }\n }\n .eraseToAnyPublisher()\n } else {\n return Just(ACTION_HIDE).eraseToAnyPublisher()\n }\n }\n .tap { $0() }\n .mapToVoid()\n .eraseToAnyPublisher()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/BrowserRuleMenuItem.swift", "import AppKit\n\n@MainActor\nclass BrowserRuleMenuItem: NSMenuItem {\n let url: URL\n let preferencesVM: PreferencesVM\n let inputSource: InputSource?\n\n var cancelBag = CancelBag()\n\n var browserRule: BrowserRule? {\n preferencesVM.getBrowserRule(url: url)\n }\n\n init(url: URL, preferencesVM: PreferencesVM, inputSource: InputSource?) {\n self.url = url\n self.preferencesVM = preferencesVM\n self.inputSource = inputSource\n\n super.init(title: inputSource?.name ?? \"\", action: #selector(forceKeyboard(_:)), keyEquivalent: \"\")\n\n target = self\n\n updateState()\n watchChanges()\n }\n\n @available(*, unavailable)\n required init(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n\n @objc func forceKeyboard(_: Any) {\n let inputSourceId = inputSource?.id ?? \"\"\n let host = url.host ?? \"\"\n\n if let browserRule = browserRule {\n preferencesVM.updateBrowserRule(\n browserRule,\n type: .domain,\n value: host,\n sample: url.absoluteString,\n inputSourceId: inputSourceId,\n hideIndicator: browserRule.hideIndicator,\n keyboardRestoreStrategy: browserRule.keyboardRestoreStrategy\n )\n } else {\n preferencesVM.addBrowserRule(\n type: .domain,\n value: host,\n sample: url.absoluteString,\n inputSourceId: inputSourceId,\n hideIndicator: false,\n keyboardRestoreStrategy: nil\n )\n }\n\n inputSource?.select(useCJKVFix: preferencesVM.isUseCJKVFix())\n\n watchChanges()\n }\n\n func watchChanges() {\n cancelBag.cancel()\n\n browserRule?.publisher(for: \\.inputSourceId)\n .sink { [weak self] _ in self?.updateState() }\n .store(in: cancelBag)\n }\n\n func updateState() {\n state = browserRule?.inputSourceId == inputSource?.id ? .on : .off\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Controllers/StatusItemController.swift", "import Cocoa\nimport Combine\n\n@MainActor\nclass StatusItemController {\n let navigationVM: NavigationVM\n let permissionsVM: PermissionsVM\n let preferencesVM: PreferencesVM\n let applicationVM: ApplicationVM\n let indicatorVM: IndicatorVM\n let feedbackVM: FeedbackVM\n let inputSourceVM: InputSourceVM\n\n let cancelBag = CancelBag()\n\n var statusItem: NSStatusItem?\n var hasPreferencesShown = false\n\n var addRuleMenu: NSMenuItem? {\n guard let app = applicationVM.appKind?.getApp() else { return nil }\n\n var items: [NSMenuItem] = [\n AppRuleMenuItem(app: app, preferencesVM: preferencesVM, inputSource: nil),\n NSMenuItem.separator(),\n ]\n\n items[0].toolTip = \"Default Keyboard Tooltip\".i18n()\n\n items += InputSource.sources.map {\n AppRuleMenuItem(app: app, preferencesVM: preferencesVM, inputSource: $0)\n }\n\n items\n .filter { (($0 as? AppRuleMenuItem) != nil) ? true : false }\n .enumerated()\n .forEach { index, item in\n if index < 10 {\n item.keyEquivalent = \"\\(index)\"\n item.keyEquivalentModifierMask = .command\n }\n }\n\n let menu = NSMenuItem(\n title: String(format: \"Default Keyboard for %@\".i18n(), app.localizedName ?? \"Current App\".i18n()),\n submenuItems: items\n )\n\n menu.toolTip = app.bundleIdentifier\n\n return menu\n }\n\n var addBrowserRuleMenu: NSMenuItem? {\n guard let browserInfo = applicationVM.appKind?.getBrowserInfo(),\n let host = browserInfo.url.host\n else { return nil }\n\n var items: [NSMenuItem] = [\n BrowserRuleMenuItem(url: browserInfo.url, preferencesVM: preferencesVM, inputSource: nil),\n NSMenuItem.separator(),\n ]\n\n items[0].toolTip = \"Default Keyboard Tooltip\".i18n()\n\n items += InputSource.sources.map {\n BrowserRuleMenuItem(url: browserInfo.url, preferencesVM: preferencesVM, inputSource: $0)\n }\n\n items\n .filter { (($0 as? BrowserRuleMenuItem) != nil) ? true : false }\n .enumerated()\n .forEach { index, item in\n if index < 10 {\n item.keyEquivalent = \"\\(index)\"\n item.keyEquivalentModifierMask = .command\n }\n }\n\n return NSMenuItem(\n title: String(format: \"Default Keyboard for %@\".i18n(), host),\n submenuItems: items\n )\n }\n\n var settingsMenu: NSMenuItem? {\n NSMenuItem(\n title: \"Preferences\".i18n() + \"...\",\n target: self,\n action: #selector(openPreferences),\n keyEquivalent: \",\"\n )\n }\n\n var changelogMenu: NSMenuItem? {\n NSMenuItem(\n title: \"Changelog\".i18n(),\n target: self,\n action: #selector(openChangelog),\n keyEquivalent: \"\"\n )\n }\n\n var checkUpdatesMenu: NSMenuItem? {\n NSMenuItem(\n title: \"Check for Updates\".i18n() + \"...\",\n target: self,\n action: #selector(checkForUpdates),\n keyEquivalent: \"\"\n )\n }\n\n var menu: NSMenu {\n let menu = NSMenu()\n\n let items = [\n NSMenuItem(title: \"Input Source Pro\".i18n(), action: nil, keyEquivalent: \"\"),\n addBrowserRuleMenu ?? addRuleMenu,\n NSMenuItem.separator(),\n changelogMenu,\n checkUpdatesMenu,\n settingsMenu,\n NSMenuItem.separator(),\n NSMenuItem(\n title: \"Quit\".i18n(),\n action: #selector(NSApplication.shared.terminate(_:)),\n keyEquivalent: \"q\"\n ),\n ]\n .compactMap { $0 }\n\n items.forEach { menu.addItem($0) }\n\n return menu\n }\n\n lazy var preferencesWindowController = PreferencesWindowController(\n navigationVM: self.navigationVM,\n permissionsVM: self.permissionsVM,\n preferencesVM: self.preferencesVM,\n indicatorVM: self.indicatorVM,\n feedbackVM: self.feedbackVM,\n inputSourceVM: self.inputSourceVM\n )\n\n init(\n navigationVM: NavigationVM,\n permissionsVM: PermissionsVM,\n preferencesVM: PreferencesVM,\n applicationVM: ApplicationVM,\n indicatorVM: IndicatorVM,\n feedbackVM: FeedbackVM,\n inputSourceVM: InputSourceVM\n ) {\n self.navigationVM = navigationVM\n self.permissionsVM = permissionsVM\n self.preferencesVM = preferencesVM\n self.applicationVM = applicationVM\n self.indicatorVM = indicatorVM\n self.feedbackVM = feedbackVM\n self.inputSourceVM = inputSourceVM\n\n preferencesVM.$preferences\n .map(\\.isShowIconInMenuBar)\n .removeDuplicates()\n .map { isShow -> AnyPublisher in\n if isShow {\n return AnyPublisher.create { [unowned self] _ in\n statusItem = NSStatusBar.system.statusItem(\n withLength: NSStatusItem.squareLength\n )\n\n statusItem?.button?.image = NSImage(named: \"MenuBarIcon\")\n statusItem?.button?.image?.size = NSSize(width: 16, height: 16)\n statusItem?.button?.image?.isTemplate = true\n statusItem?.button?.target = self\n statusItem?.button?.action = #selector(self.displayMenu)\n\n return AnyCancellable { [unowned self] in\n self.statusItem = nil\n }\n }\n } else {\n return Empty().eraseToAnyPublisher()\n }\n }\n .switchToLatest()\n .sink {}\n .store(in: cancelBag)\n }\n\n @objc func displayMenu() {\n // https://stackoverflow.com/a/57612963\n statusItem?.menu = menu\n statusItem?.button?.performClick(nil)\n statusItem?.menu = nil\n }\n\n @objc func openPreferences() {\n NSApp.setActivationPolicy(.regular)\n NSApplication.shared.activate(ignoringOtherApps: true)\n if let window = preferencesWindowController.window {\n DispatchQueue.main.async {\n if !self.hasPreferencesShown {\n self.hasPreferencesShown = true\n window.center()\n }\n \n window.makeKeyAndOrderFront(nil)\n }\n }\n }\n\n @objc func openChangelog() {\n if let url = URL(string: \"https://inputsource.pro/changelog\") {\n NSWorkspace.shared.open(url)\n }\n }\n\n @objc func checkForUpdates() {\n preferencesVM.checkUpdates()\n }\n\n @objc func openFeedback() {\n feedbackVM.show()\n navigationVM.selection = .troubleshooting\n openPreferences()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/PreferencesVM+KeyboardConfig.swift", "import AppKit\nimport Bodega\nimport Boutique\nimport Foundation\nimport SwiftUI\n\nextension PreferencesVM {\n func addKeyboardConfig(_ inputSource: InputSource) -> KeyboardConfig {\n if let config = getKeyboardConfig(inputSource) {\n return config\n } else {\n let config = KeyboardConfig(context: container.viewContext)\n\n config.id = inputSource.id\n\n saveContext()\n\n return config\n }\n }\n\n func update(_ config: KeyboardConfig, textColor: Color, bgColor: Color) {\n saveContext {\n config.textColor = textColor == self.preferences.indicatorForgegroundColor ? nil : textColor\n config.bgColor = bgColor == self.preferences.indicatorBackgroundColor ? nil : bgColor\n }\n }\n\n func getKeyboardConfig(_ inputSource: InputSource) -> KeyboardConfig? {\n return keyboardConfigs.first(where: { $0.id == inputSource.id })\n }\n\n func getOrCreateKeyboardConfig(_ inputSource: InputSource) -> KeyboardConfig {\n return getKeyboardConfig(inputSource) ?? addKeyboardConfig(inputSource)\n }\n}\n\nextension PreferencesVM {\n func getTextNSColor(_ inputSource: InputSource) -> NSColor? {\n let isAutoAppearanceMode = preferences.isAutoAppearanceMode\n\n if let keyboardColor = getKeyboardConfig(inputSource)?.textColor {\n return NSColor(keyboardColor)\n } else {\n return isAutoAppearanceMode\n ? preferences.indicatorForgeground?.dynamicColor\n : NSColor(preferences.indicatorForgegroundColor)\n }\n }\n\n func getTextColor(_ inputSource: InputSource) -> Color {\n if let nsColor = getTextNSColor(inputSource) {\n return Color(nsColor)\n } else {\n return preferences.indicatorForgegroundColor\n }\n }\n\n func getBgNSColor(_ inputSource: InputSource) -> NSColor? {\n let isAutoAppearanceMode = preferences.isAutoAppearanceMode\n\n if let bgColor = getKeyboardConfig(inputSource)?.bgColor {\n return NSColor(bgColor)\n } else {\n return isAutoAppearanceMode\n ? preferences.indicatorBackground?.dynamicColor\n : NSColor(preferences.indicatorBackgroundColor)\n }\n }\n\n func getBgColor(_ inputSource: InputSource) -> Color {\n if let nsColor = getBgNSColor(inputSource) {\n return Color(nsColor)\n } else {\n return preferences.indicatorBackgroundColor\n }\n }\n}\n\nextension PreferencesVM {\n struct DeprecatedKeyboardSettings: Codable & Equatable & Identifiable {\n let id: String\n\n var textColorHex: String?\n var bgColorHex: String?\n }\n\n func migratePreferncesIfNeed() {\n if preferences.prevInstalledBuildVersion <= 462 {\n update {\n $0.indicatorInfo = $0.isShowInputSourcesLabel ? .iconAndTitle : .iconOnly\n }\n }\n }\n\n func migrateBoutiqueIfNeed() {\n let storagePath = Store.documentsDirectory(appendingPath: \"KeyboardSettings\")\n\n guard preferences.prevInstalledBuildVersion == 316,\n FileManager.default.fileExists(atPath: storagePath.path) else { return }\n\n let store = Store(storagePath: storagePath)\n let inputSources = InputSource.sources\n\n store.$items\n .filter { $0.count > 0 }\n .first()\n .sink { [weak self] items in\n self?.saveContext {\n for item in items {\n guard let inputSource = inputSources.first(where: { $0.id == item.id }),\n let config = self?.getOrCreateKeyboardConfig(inputSource)\n else { continue }\n\n config.textColorHex = item.textColorHex\n config.bgColorHex = item.bgColorHex\n }\n }\n\n do {\n try FileManager.default.removeItem(at: storagePath)\n } catch {\n print(\"Boutique migration error: \\(error.localizedDescription)\")\n }\n }\n .store(in: cancelBag)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Controllers/IndicatorWindowController.swift", "import AppKit\nimport AXSwift\nimport Carbon\nimport Combine\nimport CombineExt\nimport SnapKit\n\n@MainActor\nclass IndicatorWindowController: FloatWindowController {\n let permissionsVM: PermissionsVM\n let preferencesVM: PreferencesVM\n let indicatorVM: IndicatorVM\n let applicationVM: ApplicationVM\n let inputSourceVM: InputSourceVM\n\n let indicatorVC = IndicatorViewController()\n\n var isActive = false {\n didSet {\n if isActive {\n indicatorVC.view.animator().alphaValue = 1\n window?.displayIfNeeded()\n active()\n } else {\n indicatorVC.view.animator().alphaValue = 0\n deactive()\n }\n }\n }\n\n var cancelBag = CancelBag()\n\n init(\n permissionsVM: PermissionsVM,\n preferencesVM: PreferencesVM,\n indicatorVM: IndicatorVM,\n applicationVM: ApplicationVM,\n inputSourceVM: InputSourceVM\n ) {\n self.permissionsVM = permissionsVM\n self.preferencesVM = preferencesVM\n self.indicatorVM = indicatorVM\n self.applicationVM = applicationVM\n self.inputSourceVM = inputSourceVM\n\n super.init()\n\n contentViewController = indicatorVC\n\n let indicatorPublisher = indicatorVM.activateEventPublisher\n .receive(on: DispatchQueue.main)\n .map { (event: $0, inputSource: self.indicatorVM.state.inputSource) }\n .flatMapLatest { [weak self] params -> AnyPublisher in\n let event = params.event\n let inputSource = params.inputSource\n\n guard let self = self else { return Empty().eraseToAnyPublisher() }\n guard let appKind = self.applicationVM.appKind,\n !event.isJustHide,\n !preferencesVM.isHideIndicator(appKind)\n else { return self.justHidePublisher() }\n\n let app = appKind.getApp()\n\n if preferencesVM.isShowAlwaysOnIndicator(app: app) {\n return self.alwaysOnPublisher(event: event, inputSource: inputSource, appKind: appKind)\n } else if preferencesVM.needDetectFocusedFieldChanges(app: app) {\n return self.autoShowPublisher(event: event, inputSource: inputSource, appKind: appKind)\n } else {\n return self.autoHidePublisher(event: event, inputSource: inputSource, appKind: appKind)\n }\n }\n .eraseToAnyPublisher()\n\n indicatorVM.screenIsLockedPublisher\n .flatMapLatest { isLocked in isLocked ? Empty().eraseToAnyPublisher() : indicatorPublisher }\n .sink { _ in }\n .store(in: cancelBag)\n }\n\n @available(*, unavailable)\n required init?(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/ApplicationVM.swift", "import AppKit\nimport AXSwift\nimport Combine\nimport CombineExt\nimport os\n\n@MainActor\nfinal class ApplicationVM: ObservableObject {\n @Published private(set) var appKind: AppKind? = nil\n @Published private(set) var appsDiff: AppsDiff = .empty\n\n let logger = ISPLogger(category: String(describing: ApplicationVM.self))\n\n let cancelBag = CancelBag()\n let preferencesVM: PreferencesVM\n\n lazy var windowAXNotificationPublisher = ApplicationVM\n .createWindowAXNotificationPublisher(preferencesVM: preferencesVM)\n\n init(preferencesVM: PreferencesVM) {\n self.preferencesVM = preferencesVM\n appKind = .from(NSWorkspace.shared.frontmostApplication, preferencesVM: preferencesVM)\n\n activateAccessibilitiesForCurrentApp()\n watchApplicationChange()\n watchAppsDiffChange()\n }\n}\n\nextension ApplicationVM {\n private func watchApplicationChange() {\n let axNotification = windowAXNotificationPublisher.mapToVoid()\n\n let workspaceNotification = NSWorkspace.shared.notificationCenter\n .publisher(for: NSWorkspace.didActivateApplicationNotification, object: NSWorkspace.shared)\n .mapToVoid()\n\n Publishers\n .Merge(axNotification, workspaceNotification)\n .compactMap { [weak self] _ -> NSRunningApplication? in\n guard self?.preferencesVM.preferences.isEnhancedModeEnabled == true,\n let elm: UIElement = try? systemWideElement.attribute(.focusedApplication),\n let pid = try? elm.pid()\n else { return NSWorkspace.shared.frontmostApplication }\n return NSRunningApplication(processIdentifier: pid)\n }\n .removeDuplicates()\n .flatMapLatest { [weak self] (app: NSRunningApplication) -> AnyPublisher in\n guard let preferencesVM = self?.preferencesVM\n else { return Empty().eraseToAnyPublisher() }\n\n guard NSApplication.isBrowser(app)\n else { return Just(.from(app, preferencesVM: preferencesVM)).eraseToAnyPublisher() }\n\n return Timer\n .interval(seconds: 1)\n .prepend(Date())\n .compactMap { _ in app.focusedUIElement(preferencesVM: preferencesVM) }\n .first()\n .flatMapLatest { _ in\n app.watchAX([\n .focusedUIElementChanged,\n .titleChanged,\n .windowCreated,\n ], [.application, .window])\n .filter { $0.notification != .windowCreated }\n .map { event in event.runningApp }\n }\n .prepend(app)\n .compactMap { app -> AppKind? in .from(app, preferencesVM: preferencesVM) }\n .eraseToAnyPublisher()\n }\n .removeDuplicates(by: { $0.isSameAppOrWebsite(with: $1, detectAddressBar: true) })\n .sink { [weak self] in self?.appKind = $0 }\n .store(in: cancelBag)\n }\n}\n\nextension ApplicationVM {\n private func watchAppsDiffChange() {\n AppsDiff\n .publisher(preferencesVM: preferencesVM)\n .assign(to: &$appsDiff)\n }\n\n private func activateAccessibilitiesForCurrentApp() {\n $appKind\n .compactMap { $0 }\n .filter { [weak self] _ in self?.preferencesVM.preferences.isEnhancedModeEnabled == true }\n .filter { [weak self] in self?.preferencesVM.isHideIndicator($0) != true }\n .sink { $0.getApp().activateAccessibilities() }\n .store(in: cancelBag)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/KeyboardRestoreStrategy.swift", "import SwiftUI\n\nenum KeyboardRestoreStrategy: String, CaseIterable, Identifiable {\n case UseDefaultKeyboardInstead\n case RestorePreviouslyUsedOne\n\n var name: String {\n switch self {\n case .UseDefaultKeyboardInstead:\n return \"Use Default Keyboard Instead\".i18n()\n case .RestorePreviouslyUsedOne:\n return \"Restore Previously Used One\".i18n()\n }\n }\n\n var systemImageName: String {\n switch self {\n case .UseDefaultKeyboardInstead:\n return \"d.circle.fill\"\n case .RestorePreviouslyUsedOne:\n return \"arrow.uturn.left.circle.fill\"\n }\n }\n\n var id: Self { self }\n}\n"], ["/InputSourcePro/Input Source Pro/Persistence/BrowserRule.swift", "import Cocoa\n\nenum BrowserRuleType: Int32, CaseIterable {\n case domainSuffix = 0\n case domain = 1\n case urlRegex = 2\n\n var name: String {\n switch self {\n case .domainSuffix:\n return \"DOMAIN-SUFFIX\"\n case .domain:\n return \"DOMAIN\"\n case .urlRegex:\n return \"URL-REGEX\"\n }\n }\n\n var explanation: String {\n return \"\\(name) Explanation\".i18n()\n }\n}\n\nextension BrowserRule {\n @MainActor\n var forcedKeyboard: InputSource? {\n guard let inputSourceId = inputSourceId else { return nil }\n\n return InputSource.sources.first { $0.id == inputSourceId }\n }\n\n var type: BrowserRuleType {\n get {\n return BrowserRuleType(rawValue: typeValue) ?? .domainSuffix\n }\n\n set {\n typeValue = newValue.rawValue\n }\n }\n\n func validate(url: URL) -> Bool {\n return Self.validate(type: type, url: url, value: value)\n }\n\n func id() -> String {\n return \"\\(type.name)_\\(value ?? \"\")_\\(createdAt?.timeIntervalSince1970 ?? 0)\"\n }\n}\n\nextension BrowserRule {\n static func validate(type: BrowserRuleType, url: URL, value: String?) -> Bool {\n switch type {\n case .domainSuffix:\n if let suffix = value,\n let host = url.host,\n let regex = try? NSRegularExpression(pattern: \"\\(suffix)$\", options: .caseInsensitive)\n {\n return regex.matches(host)\n }\n return false\n case .domain:\n return url.host == value\n case .urlRegex:\n if let regex = try? NSRegularExpression(pattern: value ?? \"\", options: .caseInsensitive) {\n return regex.matches(url.absoluteString)\n }\n return false\n }\n }\n}\n\nextension BrowserRule {\n var keyboardRestoreStrategy: KeyboardRestoreStrategy? {\n guard let rawValue = keyboardRestoreStrategyRaw\n else { return nil }\n\n return KeyboardRestoreStrategy(rawValue: rawValue)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/BrowserRuleEditView.swift", "import SwiftUI\n\nstruct BrowserRuleEditView: View {\n @State var value: String = \"\"\n @State var sampleValue: String = \"\"\n @State var ruleType = BrowserRuleType.domainSuffix\n @State var inputSourceItem = PickerItem.empty\n @State var restoreStrategyItem = PickerItem.empty\n @State var hideIndicator = false\n\n @State var isPopover = false\n\n @State private var width = CGFloat.zero\n\n @Binding var isPresented: Bool\n\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n let rule: BrowserRule?\n\n var ruleTypes: [BrowserRuleType] {\n BrowserRuleType.allCases\n }\n\n var inputSourceItems: [PickerItem] {\n [PickerItem.empty]\n + InputSource.sources.map { PickerItem(id: $0.id, title: $0.name, toolTip: $0.id) }\n }\n\n var restoreStrategyItems: [PickerItem] {\n [PickerItem.empty]\n + KeyboardRestoreStrategy.allCases.map { PickerItem(id: $0.rawValue, title: $0.name, toolTip: nil) }\n }\n\n var sampleURL: URL? {\n guard !sampleValue.isEmpty else { return nil }\n\n if sampleValue.starts(with: \"http://\") || sampleValue.starts(with: \"https://\") {\n return URL(string: sampleValue)\n } else {\n return URL(string: \"http://\\(sampleValue)\")\n }\n }\n\n var body: some View {\n VStack(spacing: 0) {\n VStack(alignment: .leading, spacing: 5) {\n Text(\"Match\".i18n().uppercased())\n .font(.footnote)\n .fontWeight(.medium)\n .opacity(0.5)\n\n VStack {\n HStack {\n Text(\"Sample URL\".i18n() + \":\")\n .alignedView(width: $width, alignment: .trailing)\n TextField(\"https://www.twitter.com/runjuuu\", text: $sampleValue)\n }\n\n HStack {\n Text(\"Rule Type\".i18n() + \":\")\n .alignedView(width: $width, alignment: .trailing)\n HStack {\n PopUpButtonPicker(\n items: ruleTypes,\n isItemSelected: { $0 == ruleType },\n getTitle: { $0.name },\n getToolTip: { $0.explanation },\n onSelect: handleSelectRule\n )\n\n Button(action: { isPopover.toggle() }) {\n SwiftUI.Image(systemName: \"questionmark\")\n }\n .font(.system(size: 10).weight(.bold))\n .frame(width: 18, height: 18)\n .clipShape(RoundedRectangle(cornerRadius: 99))\n .popover(\n isPresented: self.$isPopover,\n arrowEdge: .bottom\n ) {\n VStack {\n Text(.init(ruleType.explanation))\n .lineSpacing(3)\n }\n .frame(width: 280)\n .padding()\n }\n }\n }\n\n HStack {\n Text(\"Domain\".i18n() + \":\")\n .alignedView(width: $width, alignment: .trailing)\n HStack {\n TextField(\"twitter.com\", text: $value)\n if let url = sampleURL, !value.isEmpty {\n if BrowserRule.validate(type: ruleType, url: url, value: value) {\n Image(systemName: \"checkmark.circle.fill\")\n .foregroundColor(.green)\n .frame(width: 18, height: 18)\n } else {\n Image(systemName: \"x.circle.fill\")\n .foregroundColor(.red)\n .frame(width: 18, height: 18)\n }\n }\n }\n }\n }\n .padding()\n .background(Color.gray.opacity(0.1))\n .clipShape(RoundedRectangle(cornerRadius: 8))\n .padding(.bottom)\n }\n\n VStack(alignment: .leading, spacing: 5) {\n Text(\"Keyboard\".i18n().uppercased())\n .font(.footnote)\n .fontWeight(.medium)\n .opacity(0.5)\n\n VStack {\n HStack {\n Text(\"Default Keyboard\".i18n() + \":\")\n .alignedView(width: $width, alignment: .trailing)\n PopUpButtonPicker(\n items: inputSourceItems,\n isItemSelected: { $0 == inputSourceItem },\n getTitle: { $0?.title ?? \"\" },\n getToolTip: { $0?.toolTip },\n onSelect: handleSelectInputSource\n )\n }\n\n HStack {\n Text(\"Restore Strategy\".i18n() + \":\")\n .alignedView(width: $width, alignment: .trailing)\n PopUpButtonPicker(\n items: restoreStrategyItems,\n isItemSelected: { $0 == restoreStrategyItem },\n getTitle: { $0?.title ?? \"\" },\n getToolTip: { $0?.toolTip },\n onSelect: handleRestoreStrategy\n )\n }\n }\n .padding()\n .background(Color.gray.opacity(0.1))\n .clipShape(RoundedRectangle(cornerRadius: 8))\n .padding(.bottom)\n }\n\n VStack(alignment: .leading, spacing: 5) {\n Text(\"Tooltip\".i18n().uppercased())\n .font(.footnote)\n .fontWeight(.medium)\n .opacity(0.5)\n\n VStack {\n HStack {\n HStack(spacing: 4) {\n Image(systemName: \"eye.slash.circle.fill\")\n .foregroundColor(.gray)\n Text(\"Hide Indicator\".i18n() + \":\")\n }\n .alignedView(width: $width, alignment: .trailing)\n\n Toggle(\"\", isOn: $hideIndicator)\n .toggleStyle(.switch)\n\n Spacer()\n }\n }\n .padding()\n .background(Color.gray.opacity(0.1))\n .clipShape(RoundedRectangle(cornerRadius: 8))\n .padding(.bottom)\n }\n\n HStack {\n Spacer()\n\n Button(\"Cancel\".i18n(), action: cancel)\n .keyboardShortcut(.cancelAction)\n\n Button(\"\\(rule == nil ? \"Add\" : \"Save\")\".i18n(), action: save)\n .disabled(value.isEmpty)\n .keyboardShortcut(.defaultAction)\n }\n .padding(.top, 6)\n }\n .padding()\n .frame(width: 480)\n .onAppear {\n value = rule?.value ?? \"\"\n sampleValue = rule?.sample ?? \"\"\n ruleType = rule?.type ?? .domainSuffix\n hideIndicator = rule?.hideIndicator ?? false\n\n if let inputSource = rule?.forcedKeyboard {\n inputSourceItem = PickerItem(id: inputSource.id, title: inputSource.name, toolTip: inputSource.id)\n }\n\n if let keyboardRestoreStrategy = rule?.keyboardRestoreStrategy {\n restoreStrategyItem = PickerItem(\n id: keyboardRestoreStrategy.rawValue,\n title: keyboardRestoreStrategy.name,\n toolTip: nil\n )\n }\n }\n }\n\n func handleSelectInputSource(_ index: Int) {\n inputSourceItem = inputSourceItems[index]\n }\n\n func handleRestoreStrategy(_ index: Int) {\n restoreStrategyItem = restoreStrategyItems[index]\n }\n\n func handleSelectRule(_ index: Int) {\n ruleType = ruleTypes[index]\n }\n\n func cancel() {\n isPresented = false\n }\n\n func save() {\n guard !value.isEmpty else { return }\n\n let keyboardRestoreStrategy = restoreStrategyItem == .empty ? nil : KeyboardRestoreStrategy(rawValue: restoreStrategyItem.id)\n\n if let rule = rule {\n preferencesVM.updateBrowserRule(\n rule,\n type: ruleType,\n value: value,\n sample: sampleValue,\n inputSourceId: inputSourceItem.id,\n hideIndicator: hideIndicator,\n keyboardRestoreStrategy: keyboardRestoreStrategy\n )\n } else {\n preferencesVM.addBrowserRule(\n type: ruleType,\n value: value,\n sample: sampleValue,\n inputSourceId: inputSourceItem.id,\n hideIndicator: hideIndicator,\n keyboardRestoreStrategy: keyboardRestoreStrategy\n )\n }\n\n isPresented = false\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/InputSourceVM.swift", "import AppKit\nimport AXSwift\nimport Carbon\nimport Combine\nimport Foundation\n\n@MainActor\nclass InputSourceVM: ObservableObject {\n let preferencesVM: PreferencesVM\n\n private var _isProgrammaticChange = false\n\n private var cancelBag = CancelBag()\n\n private let selectInputSourceSubject = PassthroughSubject()\n\n private let inputSourceChangesSubject = PassthroughSubject()\n\n let inputSourceChangesPublisher: AnyPublisher\n\n init(preferencesVM: PreferencesVM) {\n self.preferencesVM = preferencesVM\n inputSourceChangesPublisher = inputSourceChangesSubject.eraseToAnyPublisher()\n\n watchSystemNotification()\n\n selectInputSourceSubject\n .tap { [weak self] inputSource in\n guard let preferencesVM = self?.preferencesVM\n else { return }\n\n inputSource.select(useCJKVFix: preferencesVM.isUseCJKVFix())\n }\n .flatMapLatest { _ in\n Timer.interval(seconds: 0.2)\n .map { _ in InputSource.getCurrentInputSource() }\n .withPrevious()\n .filter { previous, current in\n guard let previous = previous else { return false }\n return previous.id == current.id\n }\n .map { _, current in current }\n .prefix(1)\n }\n .sink { [weak self] in\n self?.inputSourceChangesSubject.send($0)\n self?._isProgrammaticChange = false\n }\n .store(in: cancelBag)\n }\n\n func select(inputSource: InputSource) {\n _isProgrammaticChange = true\n selectInputSourceSubject.send(inputSource)\n }\n\n private func watchSystemNotification() {\n DistributedNotificationCenter.default()\n .publisher(for: Notification.Name(rawValue: kTISNotifySelectedKeyboardInputSourceChanged as String))\n .receive(on: DispatchQueue.main)\n .filter { [weak self] _ in self?._isProgrammaticChange == false }\n .map { _ in InputSource.getCurrentInputSource() }\n .sink { [weak self] in self?.inputSourceChangesSubject.send($0) }\n .store(in: cancelBag)\n }\n\n private func getInputSourceFromMenu() -> InputSource? {\n for app in NSWorkspace.shared.runningApplications {\n if app.bundleIdentifier == \"com.apple.TextInputMenuAgent\" {\n if let application = app.getApplication(preferencesVM: preferencesVM),\n let menuBar: UIElement = try? application.attribute(.extrasMenuBar)\n {\n for child in menuBar.children() ?? [] {\n if let description: String = try? child.attribute(.description),\n let inputSource = InputSource.sources.first(where: { $0.name == description })\n {\n return inputSource\n }\n }\n }\n\n return nil\n }\n }\n\n return nil\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/PreferencesVM+IndicatorPosition.swift", "import AppKit\nimport AXSwift\nimport Combine\nimport CombineExt\n\nextension PreferencesVM {\n func calcSpacing(minLength: CGFloat) -> CGFloat {\n guard let spacing = preferences.indicatorPositionSpacing else { return 0 }\n\n switch spacing {\n case .none:\n return 0\n case .xs:\n return minLength * 0.02\n case .s:\n return minLength * 0.05\n case .m:\n return minLength * 0.08\n case .l:\n return minLength * 0.13\n case .xl:\n return minLength * 0.21\n }\n }\n\n typealias IndicatorPositionInfo = (kind: IndicatorActuallyPositionKind, point: CGPoint)\n\n func getIndicatorPositionPublisher(\n appSize: CGSize,\n app: NSRunningApplication\n ) -> AnyPublisher {\n Just(preferences.indicatorPosition)\n .compactMap { $0 }\n .flatMapLatest { [weak self] position -> AnyPublisher in\n let DEFAULT = self?.getIndicatorBasePosition(\n appSize: appSize,\n app: app,\n position: position\n ) ?? Empty(completeImmediately: true).eraseToAnyPublisher()\n\n guard let self = self\n else { return DEFAULT }\n\n return self.getPositionAroundFloatingWindow(app, size: appSize)\n .flatMapLatest { positionForFloatingWindow -> AnyPublisher in\n if let positionForFloatingWindow = positionForFloatingWindow {\n return Just((.floatingApp, positionForFloatingWindow)).eraseToAnyPublisher()\n }\n\n if self.preferences.isEnhancedModeEnabled,\n self.preferences.tryToDisplayIndicatorNearCursor == true,\n self.isAbleToQueryLocation(app)\n {\n return self.getPositionAroundInputCursor(size: appSize)\n .map { cursorPosition -> AnyPublisher in\n guard let cursorPosition = cursorPosition else { return DEFAULT }\n\n return Just((cursorPosition.isContainer ? .inputRect : .inputCursor, cursorPosition.point))\n .eraseToAnyPublisher()\n }\n .switchToLatest()\n .eraseToAnyPublisher()\n }\n\n return DEFAULT\n }\n .eraseToAnyPublisher()\n }\n .eraseToAnyPublisher()\n }\n\n func getIndicatorBasePosition(\n appSize: CGSize,\n app: NSRunningApplication,\n position: IndicatorPosition\n ) -> AnyPublisher {\n Just(position)\n .flatMapLatest { [weak self] _ -> AnyPublisher in\n guard let self = self else { return Just(nil).eraseToAnyPublisher() }\n\n switch position {\n case .nearMouse:\n return self.getPositionNearMouse(size: appSize)\n .map {\n guard let position = $0 else { return nil }\n return (.nearMouse, position)\n }\n .eraseToAnyPublisher()\n case .windowCorner:\n return self.getPositionRelativeToAppWindow(size: appSize, app)\n .map {\n guard let position = $0 else { return nil }\n return (.windowCorner, position)\n }\n .eraseToAnyPublisher()\n case .screenCorner:\n return self.getPositionRelativeToScreen(size: appSize, app)\n .map {\n guard let position = $0 else { return nil }\n return (.screenCorner, position)\n }\n .eraseToAnyPublisher()\n }\n }\n .eraseToAnyPublisher()\n }\n}\n\nprivate extension PreferencesVM {\n func getPositionAroundInputCursor(\n size _: CGSize\n ) -> AnyPublisher<(point: CGPoint, isContainer: Bool)?, Never> {\n Future { promise in\n DispatchQueue.global().async {\n guard let rectInfo = systemWideElement.getCursorRectInfo(),\n let screen = NSScreen.getScreenInclude(rect: rectInfo.rect)\n else { return promise(.success(nil)) }\n\n if rectInfo.isContainer,\n rectInfo.rect.width / screen.frame.width > 0.7 &&\n rectInfo.rect.height / screen.frame.height > 0.7\n {\n return promise(.success(nil))\n }\n\n let offset: CGFloat = 6\n\n return promise(.success((\n CGPoint(x: rectInfo.rect.minX, y: rectInfo.rect.maxY + offset),\n rectInfo.isContainer\n )))\n }\n }\n .receive(on: DispatchQueue.main)\n .eraseToAnyPublisher()\n }\n\n func getPositionNearMouse(size: CGSize) -> AnyPublisher {\n AnyPublisher.create { observer in\n guard let screen = NSScreen.getScreenWithMouse() else { return AnyCancellable {} }\n\n let offset: CGFloat = 12\n let padding: CGFloat = 5\n let maxXPoint = screen.visibleFrame.origin.x + screen.visibleFrame.width\n\n var mousePoint = CGPoint(x: NSEvent.mouseLocation.x, y: NSEvent.mouseLocation.y)\n\n // default offset\n mousePoint.x += offset\n mousePoint.y -= offset\n\n // move app to cursor's right/bottom edge\n mousePoint.y -= size.height\n\n // avoid overflow\n mousePoint.x = min(maxXPoint - size.width - padding, mousePoint.x)\n mousePoint.y = max(padding, mousePoint.y)\n\n observer.send(mousePoint)\n observer.send(completion: .finished)\n\n return AnyCancellable {}\n }\n }\n\n func getPositionRelativeToAppWindow(\n size: CGSize,\n _ app: NSRunningApplication\n ) -> AnyPublisher {\n app.getWindowInfoPublisher()\n .map { [weak self] windowInfo -> CGPoint? in\n guard let self = self,\n let windowBounds = windowInfo?.bounds,\n let screen = NSScreen.getScreenInclude(rect: windowBounds)\n else { return nil }\n\n let rect = windowBounds.relativeTo(screen: screen)\n\n return self.getPositionWithin(\n rect: rect,\n size: size,\n alignment: self.preferences.indicatorPositionAlignment ?? .bottomRight\n )\n }\n .eraseToAnyPublisher()\n }\n\n func getPositionRelativeToScreen(\n size: CGSize,\n _ app: NSRunningApplication\n ) -> AnyPublisher {\n app.getWindowInfoPublisher()\n .map { [weak self] windowInfo -> CGPoint? in\n guard let self = self,\n let windowBounds = windowInfo?.bounds,\n let screen = NSScreen.getScreenInclude(rect: windowBounds) ??\n NSScreen.getScreenWithMouse() ??\n NSScreen.main\n else { return nil }\n\n return self.getPositionWithin(\n rect: screen.visibleFrame,\n size: size,\n alignment: self.preferences.indicatorPositionAlignment ?? .bottomRight\n )\n }\n .eraseToAnyPublisher()\n }\n\n func getPositionAround(rect: CGRect) -> (NSScreen, CGPoint)? {\n guard let screen = NSScreen.getScreenInclude(rect: rect) else { return nil }\n\n return (screen, rect.relativeTo(screen: screen).origin)\n }\n\n func getPositionAroundFloatingWindow(\n _ app: NSRunningApplication, size: CGSize\n ) -> AnyPublisher {\n guard NSApplication.isSpotlightLikeApp(app.bundleIdentifier) else { return Just(nil).eraseToAnyPublisher() }\n\n return app.getWindowInfoPublisher()\n .map { [weak self] windowInfo -> CGPoint? in\n guard let self = self,\n let rect = windowInfo?.bounds,\n let (screen, point) = self.getPositionAround(rect: rect)\n else { return nil }\n\n let offset: CGFloat = 6\n\n let position = CGPoint(\n x: point.x,\n y: point.y + rect.height + offset\n )\n\n if screen.frame.contains(CGRect(origin: position, size: size)) {\n return position\n } else {\n return nil\n }\n }\n .eraseToAnyPublisher()\n }\n\n func getPositionWithin(\n rect: NSRect,\n size: CGSize,\n alignment: IndicatorPosition.Alignment\n ) -> CGPoint {\n let spacing = calcSpacing(minLength: min(rect.width, rect.height))\n\n switch alignment {\n case .topLeft:\n return CGPoint(\n x: rect.minX + spacing,\n y: rect.maxY - size.height - spacing\n )\n case .topCenter:\n return CGPoint(\n x: rect.midX - size.width / 2,\n y: rect.maxY - size.height - spacing\n )\n case .topRight:\n return CGPoint(\n x: rect.maxX - size.width - spacing,\n y: rect.maxY - size.height - spacing\n )\n case .center:\n return CGPoint(\n x: rect.midX - size.width / 2,\n y: rect.midY + size.height / 2\n )\n case .centerLeft:\n return CGPoint(\n x: rect.minX + spacing,\n y: rect.midY - size.height / 2\n )\n case .centerRight:\n return CGPoint(\n x: rect.maxX - size.width - spacing,\n y: rect.midY - size.height / 2\n )\n case .bottomLeft:\n return CGPoint(\n x: rect.minX + spacing,\n y: rect.minY + spacing\n )\n case .bottomCenter:\n return CGPoint(\n x: rect.midX - size.width / 2,\n y: rect.minY + spacing\n )\n case .bottomRight:\n return CGPoint(\n x: rect.maxX - size.width - spacing,\n y: rect.minY + spacing\n )\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/BrowserRuleRow.swift", "import SwiftUI\n\nstruct BrowserRuleRow: View {\n @State var showModal = false\n \n var isSelected: Bool = false\n \n @ObservedObject var rule: BrowserRule\n\n let imgSize: CGFloat = 16\n\n var body: some View {\n HStack {\n Text(rule.value ?? \"\")\n\n Spacer()\n\n if rule.hideIndicator == true {\n Image(systemName: \"eye.slash.circle.fill\")\n .opacity(0.7)\n .frame(width: imgSize, height: imgSize)\n }\n\n if let keyboardRestoreStrategy = rule.keyboardRestoreStrategy {\n let symbolName = keyboardRestoreStrategy.systemImageName\n let color: Color = {\n switch symbolName {\n case \"d.circle.fill\", \"d.square.fill\":\n return isSelected ? .primary.opacity(0.7) : .green\n case \"arrow.uturn.left.circle.fill\":\n return isSelected ? .primary.opacity(0.7) : .blue\n default:\n return .primary\n }\n }()\n Image(systemName: symbolName)\n .foregroundColor(color)\n .frame(width: imgSize, height: imgSize)\n }\n\n if let forcedKeyboard = rule.forcedKeyboard {\n SwiftUI.Image(nsImage: forcedKeyboard.icon ?? NSImage())\n .resizable()\n .scaledToFit()\n .frame(width: imgSize, height: imgSize)\n .opacity(0.7)\n }\n\n Text(rule.type.name)\n .font(.footnote)\n .padding(.horizontal, 4)\n .padding(.vertical, 2)\n .foregroundColor(.white)\n .background(Color.accentColor)\n .clipShape(RoundedRectangle(cornerRadius: 2))\n\n Button(\"Edit\") {\n showModal = true\n }\n }\n .sheet(isPresented: $showModal, content: {\n BrowserRuleEditView(isPresented: $showModal, rule: rule)\n })\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSApplication.swift", "import AppKit\n\n// MARK: - isFloatingApp\n\nprivate let floatingAppIdentifier: [(\n identifier: String,\n maxWindowLayer: Int,\n isSpotlightLikeApp: Bool,\n isValid: (((windowLayer: Int?, windowBounds: CGRect?)) -> Bool)?\n)] = [\n (\"com.apple.Spotlight\", 30, true, nil),\n (\"com.runningwithcrayons.Alfred\", 30, true, nil),\n (\"at.obdev.LaunchBar\", 30, true, nil),\n (\"com.raycast.macos\", 30, true, nil),\n (\"com.googlecode.iterm2\", 30, false, nil),\n (\"com.xunyong.hapigo\", 30, true, nil),\n (\"com.hezongyidev.Bob\", 30, false, nil),\n (\"com.ripperhe.Bob\", 30, false, nil),\n (\"org.yuanli.utools\", 30, false, nil),\n (\"com.1password.1password\", 1000, true, nil),\n (\"com.eusoft.eudic.LightPeek\", 1000, true, nil),\n (\"com.contextsformac.Contexts\", 1000, true, { $0.windowLayer != 20 }),\n]\n\nextension NSApplication {\n static func isFloatingApp(_ bundleIdentifier: String?, windowLayer: Int? = nil, windowBounds: CGRect? = nil) -> Bool {\n guard let bundleIdentifier = bundleIdentifier else { return false }\n\n return floatingAppIdentifier.contains {\n guard $0.0 == bundleIdentifier else { return false }\n guard let windowLayer = windowLayer else { return true }\n guard windowLayer < $0.1, windowLayer > 0 else { return false }\n\n return $0.isValid?((windowLayer, windowBounds)) ?? true\n }\n }\n\n static func isSpotlightLikeApp(_ bundleIdentifier: String?) -> Bool {\n guard let bundleIdentifier = bundleIdentifier else { return false }\n\n return floatingAppIdentifier.contains(where: { $0.isSpotlightLikeApp && $0.identifier == bundleIdentifier })\n }\n\n static func isBrowser(_ app: NSRunningApplication) -> Bool {\n return getBrowser(app) != nil\n }\n\n static func getBrowser(_ app: NSRunningApplication) -> Browser? {\n if let bundleIdentifier = app.bundleIdentifier,\n let browser = Browser(rawValue: bundleIdentifier)\n {\n return browser\n } else {\n return nil\n }\n }\n}\n\n// MARK: - isBrowserApp\n\nprivate var browserAppIdentifier: Set = {\n let array1 = LSCopyAllRoleHandlersForContentType(\n \"public.html\" as CFString, .viewer\n )?.takeRetainedValue() as? [String] ?? []\n let array2 = LSCopyAllHandlersForURLScheme(\n \"https\" as CFString\n )?.takeRetainedValue() as? [String] ?? []\n\n let set1 = Set(array1)\n let set2 = Set(array2)\n\n return set1.intersection(set2)\n}()\n\nextension NSApplication {\n static func isBrowserApp(_ bundleIdentifier: String?) -> Bool {\n guard let bundleIdentifier = bundleIdentifier else { return false }\n\n return browserAppIdentifier.contains(bundleIdentifier)\n }\n\n static func isBrowserInstalled(_ bundleIdentifier: String) -> Bool {\n return isBrowserApp(bundleIdentifier)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/KeyboardCustomization.swift", "import SwiftUI\nimport VisualEffects\n\nstruct KeyboardCustomization: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n @State var textColor: Color = .clear\n @State var bgColor: Color = .clear\n\n let inputSource: InputSource\n\n let columns = [\n GridItem(.fixed(100), alignment: .trailing),\n GridItem(.flexible(minimum: 50, maximum: .infinity), alignment: .leading),\n ]\n\n let indicatorColumns = [\n GridItem(.flexible(minimum: 50, maximum: .infinity), alignment: .center),\n GridItem(.flexible(minimum: 50, maximum: .infinity), alignment: .center),\n ]\n\n var body: some View {\n let keyboardConfig = preferencesVM.getOrCreateKeyboardConfig(inputSource)\n\n VStack(alignment: .leading) {\n ZStack {\n LazyVGrid(columns: indicatorColumns) {\n DumpIndicatorView(config: IndicatorViewConfig(\n inputSource: inputSource,\n kind: .alwaysOn,\n size: preferencesVM.preferences.indicatorSize ?? .medium,\n bgColor: NSColor(bgColor),\n textColor: NSColor(textColor)\n ))\n\n DumpIndicatorView(config: IndicatorViewConfig(\n inputSource: inputSource,\n kind: preferencesVM.preferences.indicatorKind,\n size: preferencesVM.preferences.indicatorSize ?? .medium,\n bgColor: NSColor(bgColor),\n textColor: NSColor(textColor)\n ))\n\n Text(\"Always-On Indicator Style\")\n .font(.caption)\n .opacity(0.5)\n\n Text(\"Keyboard Indicator Style\")\n .font(.caption)\n .opacity(0.5)\n }\n .padding()\n .itemSectionStyle()\n\n VStack {\n Spacer()\n\n HStack {\n Spacer()\n Button(action: { reset(keyboardConfig) }) {\n Text(\"Reset\")\n }\n .buttonStyle(GhostButton(icon: Image(systemName: \"arrow.clockwise\")))\n }\n }\n .padding(.trailing, 4)\n .padding(.bottom, 4)\n }\n\n VStack(alignment: .center) {\n ColorBlocks(onSelectColor: {\n textColor = $0.a\n bgColor = $0.b\n })\n .padding(.vertical, 8)\n\n HStack {\n ColorPicker(\"Color\", selection: $textColor)\n\n Button(\n action: {\n let a = textColor\n let b = bgColor\n\n textColor = b\n bgColor = a\n },\n label: {\n Image(systemName: \"repeat\")\n }\n )\n\n ColorPicker(\"Background\", selection: $bgColor)\n }\n .labelsHidden()\n }\n .padding(.horizontal)\n }\n .padding()\n .onAppear {\n textColor = preferencesVM.getTextColor(inputSource)\n bgColor = preferencesVM.getBgColor(inputSource)\n }\n .onChange(of: bgColor, perform: { _ in save(keyboardConfig) })\n .onChange(of: textColor, perform: { _ in save(keyboardConfig) })\n .onDisappear {\n NSColorPanel.shared.close()\n }\n }\n\n func save(_ keyboardConfig: KeyboardConfig) {\n preferencesVM.update(keyboardConfig, textColor: textColor, bgColor: bgColor)\n }\n\n func reset(_: KeyboardConfig) {\n bgColor = preferencesVM.preferences.indicatorBackgroundColor\n textColor = preferencesVM.preferences.indicatorForgegroundColor\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSRunningApplication.swift", "import AppKit\nimport AXSwift\nimport Combine\n\nprivate func notify(\n _ observer: Observer?,\n _ validRoles: [Role],\n _ element: UIElement,\n _ notifications: [AXNotification],\n _ indetify: String?\n) -> AnyCancellable {\n guard let role = try? element.role(),\n validRoles.contains(role)\n else { return AnyCancellable {} }\n\n do {\n try notifications.forEach {\n try observer?.addNotification($0, forElement: element)\n }\n\n return AnyCancellable {\n for notification in notifications {\n try? observer?.removeNotification(notification, forElement: element)\n }\n }\n } catch {\n let role = role.rawValue\n let msg = \"\\(indetify ?? \"nil\"): Could not watch [\\(element)] with role \\(role): \\(error)\"\n\n #if DEBUG\n print(msg)\n #endif\n\n return AnyCancellable {}\n }\n}\n\nextension NSRunningApplication {\n typealias WatchAXOutput = (runningApp: NSRunningApplication, notification: AXNotification)\n\n func watchAX(\n elm: UIElement? = nil,\n _ notifications: [AXNotification],\n _ validRoles: [Role]\n ) -> AnyPublisher {\n return Timer.delay(seconds: 0.5)\n .receive(on: DispatchQueue.main)\n .flatMapLatest { _ -> AnyPublisher in\n AnyPublisher.create { [weak self] observer in\n let cancelBag = CancelBag()\n\n self?.activateAccessibilities()\n\n guard\n let runningApplication = self,\n let app = Application(runningApplication)\n else { return AnyCancellable {} }\n\n let appObserver = app.createObserver { (_ appObserver: Observer, _ element: UIElement, _ event: AXNotification) in\n // Watch events on new windows\n if event == .windowCreated {\n notify(\n appObserver,\n validRoles,\n element,\n notifications,\n runningApplication.bundleIdentifier\n )\n .store(in: cancelBag)\n }\n\n observer.send((runningApplication, event))\n }\n\n notify(\n appObserver,\n validRoles,\n elm ?? app,\n notifications,\n runningApplication.bundleIdentifier\n )\n .store(in: cancelBag)\n\n return AnyCancellable {\n cancelBag.cancel()\n appObserver?.stop()\n }\n }\n }\n .eraseToAnyPublisher()\n }\n}\n\nextension NSRunningApplication {\n func bundleId() -> String? {\n if let bundleIdentifier = bundleIdentifier {\n return bundleIdentifier\n }\n\n if let url = bundleURL ?? executableURL {\n return url.bundleId()\n }\n\n return nil\n }\n}\n\nextension NSRunningApplication {\n // For performance reasons Chromium only makes the webview accessible when there it detects voiceover through the `AXEnhancedUserInterface` attribute on the Chrome application itself:\n // http://dev.chromium.org/developers/design-documents/accessibility\n // Similarly, electron uses `AXManualAccessibility`:\n // https://electronjs.org/docs/tutorial/accessibility#assistive-technology\n func activateAccessibilities() {\n guard bundleIdentifier?.starts(with: \"com.apple.\") != true else { return }\n\n activateAccessibility(attribute: \"AXEnhancedUserInterface\")\n activateAccessibility(attribute: \"AXManualAccessibility\")\n }\n\n func activateAccessibility(attribute: String) {\n if let application = Application(self),\n let isSettable = try? application.attributeIsSettable(attribute),\n isSettable\n {\n if let rawValue: AnyObject = try? application.attribute(attribute),\n CFBooleanGetTypeID() == CFGetTypeID(rawValue),\n let enabled = rawValue as? Bool, enabled\n {\n return\n }\n\n try? application.setAttribute(attribute, value: true)\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/RulesSettingsView.swift", "import SwiftUI\n\nstruct RulesSettingsView: View {\n @State var selectedApp = Set()\n\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n var items: [PickerItem] {\n [PickerItem.empty]\n + InputSource.sources.map { PickerItem(id: $0.id, title: $0.name, toolTip: $0.id) }\n }\n\n var body: some View {\n VStack(alignment: .leading, spacing: 0) {\n HStack(spacing: 0) {\n VStack(alignment: .leading, spacing: 0) {\n ApplicationPicker(selectedApp: $selectedApp)\n .border(width: 1, edges: [.bottom], color: Color(NSColor.gridColor))\n\n HStack(spacing: 5) {\n Button(action: selectApp) {\n SwiftUI.Image(systemName: \"plus\")\n }\n\n Button(action: removeApp) {\n SwiftUI.Image(systemName: \"minus\")\n }\n .disabled(selectedApp.isEmpty)\n\n RunningApplicationsPicker(onSelect: selectRunningApp)\n }\n .padding(10)\n }\n .frame(width: 245)\n .border(width: 1, edges: [.trailing], color: Color(NSColor.gridColor))\n\n ApplicationDetail(selectedApp: $selectedApp)\n .padding()\n\n Spacer(minLength: 0)\n }\n }\n }\n\n func selectApp() {\n let panel = NSOpenPanel()\n\n panel.allowsMultipleSelection = true\n panel.canChooseDirectories = false\n panel.allowedContentTypes = [.application]\n\n if let applicationPath = NSSearchPathForDirectoriesInDomains(\n .applicationDirectory,\n .localDomainMask,\n true\n ).first {\n panel.directoryURL = URL(fileURLWithPath: applicationPath, isDirectory: true)\n }\n\n if panel.runModal() == .OK {\n selectedApp = Set(panel.urls.map {\n preferencesVM.addAppCustomization($0, bundleId: $0.bundleId())\n })\n }\n }\n\n func removeApp() {\n for app in selectedApp {\n preferencesVM.removeAppCustomization(app)\n }\n selectedApp.removeAll()\n }\n\n func selectRunningApp(_ app: NSRunningApplication) {\n if let appRule = preferencesVM.addAppCustomization(app) {\n selectedApp = Set([appRule])\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/InputSource/InputSource.swift", "import Carbon\nimport Cocoa\nimport Combine\nimport CoreGraphics\nimport CryptoKit\n\n@MainActor\nclass InputSource {\n static let logger = ISPLogger(\n category: \"🤖 \" + String(describing: InputSource.self),\n disabled: true\n )\n\n let tisInputSource: TISInputSource\n\n let icon: NSImage?\n\n var id: String { tisInputSource.id }\n var name: String { tisInputSource.name }\n\n var isCJKVR: Bool {\n guard let lang = tisInputSource.sourceLanguages.first else { return false }\n\n return lang == \"ru\" || lang == \"ko\" || lang == \"ja\" || lang == \"vi\" || lang.hasPrefix(\"zh\")\n }\n\n init(tisInputSource: TISInputSource) {\n self.tisInputSource = tisInputSource\n\n icon = { () -> NSImage? in\n if let imgName = Self.iconMap[String(tisInputSource.id.sha256().prefix(8))],\n let image = NSImage(named: imgName)\n {\n return image.markTemplateIfGrayScaleOrPdf()\n }\n\n guard let imageURL = tisInputSource.iconImageURL else {\n if #available(macOS 11.0, *) {\n return nil\n } else {\n if let iconRef = tisInputSource.iconRef {\n return NSImage(iconRef: iconRef).markTemplateIfGrayScaleOrPdf()\n } else {\n return nil\n }\n }\n }\n\n for url in [imageURL.retinaImageURL, imageURL.tiffImageURL, imageURL] {\n if let image = NSImage(contentsOf: url) {\n return image.markTemplateIfGrayScaleOrPdf(url: url)\n }\n }\n\n if let baseURL = imageURL.baseURL,\n baseURL.lastPathComponent.hasSuffix(\".app\")\n {\n return NSWorkspace.shared.icon(forFile: baseURL.relativePath)\n }\n\n return nil\n }()\n }\n\n func select(useCJKVFix: Bool) {\n Self.logger.debug { \"Select \\(id)\" }\n\n guard Self.getCurrentInputSource().id != id else {\n Self.logger.debug { \"Skip Select \\(id)\" }\n return\n }\n\n let updateStrategy: String = {\n if isCJKVR {\n // https://stackoverflow.com/a/60375569\n if useCJKVFix,\n PermissionsVM.checkAccessibility(prompt: false),\n let selectPreviousShortcut = Self.getSelectPreviousShortcut()\n {\n TISSelectInputSource(tisInputSource)\n\n // Workaround for TIS CJKV layout bug:\n // when it's CJKV, select nonCJKV input first and then return\n if let nonCJKV = Self.nonCJKVSource() {\n Self.logger.debug { \"S1: Start\" }\n TISSelectInputSource(nonCJKV.tisInputSource)\n Self.logger.debug { \"S1: selectPrevious\" }\n Self.selectPrevious(shortcut: selectPreviousShortcut)\n Self.logger.debug { \"S1: Done\" }\n }\n\n return \"S1\"\n } else {\n TISSelectInputSource(tisInputSource)\n return \"S0-2\"\n }\n } else {\n TISSelectInputSource(tisInputSource)\n\n return \"S0-2\"\n }\n }()\n\n Self.logger.debug { \"Select by \\(updateStrategy)\" }\n }\n}\n\nextension InputSource: @preconcurrency Equatable {\n static func == (lhs: InputSource, rhs: InputSource) -> Bool {\n return lhs.id == rhs.id\n }\n}\n\nextension InputSource {\n private static var cancelBag = CancelBag()\n\n @MainActor\n static func getCurrentInputSource() -> InputSource {\n return InputSource(tisInputSource: TISCopyCurrentKeyboardInputSource().takeRetainedValue())\n }\n}\n\nextension InputSource {\n static var sources: [InputSource] {\n let inputSourceNSArray = TISCreateInputSourceList(nil, false).takeRetainedValue() as NSArray\n let inputSourceList = inputSourceNSArray as! [TISInputSource]\n\n return inputSourceList\n .filter { $0.category == TISInputSource.Category.keyboardInputSource && $0.isSelectable }\n .map { InputSource(tisInputSource: $0) }\n }\n\n static func nonCJKVSource() -> InputSource? {\n return sources.first(where: { !$0.isCJKVR })\n }\n\n static func anotherCJKVSource(current: InputSource) -> InputSource? {\n return sources.first(where: { $0 != current && $0.isCJKVR })\n }\n\n static func selectPrevious(shortcut: (Int, UInt64)) {\n let src = CGEventSource(stateID: .hidSystemState)\n\n let key = CGKeyCode(shortcut.0)\n let flag = CGEventFlags(rawValue: shortcut.1)\n\n let down = CGEvent(keyboardEventSource: src, virtualKey: key, keyDown: true)!\n let up = CGEvent(keyboardEventSource: src, virtualKey: key, keyDown: false)!\n\n down.flags = flag\n up.flags = flag\n\n let ctrlDown = CGEvent(keyboardEventSource: nil, virtualKey: UInt16(kVK_Control), keyDown: true)\n let ctrlUp = CGEvent(keyboardEventSource: nil, virtualKey: UInt16(kVK_Control), keyDown: false)\n\n ctrlDown?.post(tap: .cghidEventTap)\n down.post(tap: .cghidEventTap)\n up.post(tap: .cghidEventTap)\n ctrlUp?.post(tap: .cghidEventTap)\n }\n\n // from read-symbolichotkeys script of Karabiner\n // github.com/tekezo/Karabiner/blob/master/src/util/read-symbolichotkeys/read-symbolichotkeys/main.m\n static func getSelectPreviousShortcut() -> (Int, UInt64)? {\n guard let dict = UserDefaults.standard.persistentDomain(forName: \"com.apple.symbolichotkeys\") else {\n return nil\n }\n guard let symbolichotkeys = dict[\"AppleSymbolicHotKeys\"] as! NSDictionary? else {\n return nil\n }\n guard let symbolichotkey = symbolichotkeys[\"60\"] as! NSDictionary? else {\n return nil\n }\n if (symbolichotkey[\"enabled\"] as! NSNumber).intValue != 1 {\n return nil\n }\n guard let value = symbolichotkey[\"value\"] as! NSDictionary? else {\n return nil\n }\n guard let parameters = value[\"parameters\"] as! NSArray? else {\n return nil\n }\n return (\n (parameters[1] as! NSNumber).intValue,\n (parameters[2] as! NSNumber).uint64Value\n )\n }\n}\n\nprivate extension URL {\n var retinaImageURL: URL {\n var components = pathComponents\n let filename: String = components.removeLast()\n let ext: String = pathExtension\n let retinaFilename = filename.replacingOccurrences(of: \".\" + ext, with: \"@2x.\" + ext)\n return NSURL.fileURL(withPathComponents: components + [retinaFilename])!\n }\n\n var tiffImageURL: URL {\n return deletingPathExtension().appendingPathExtension(\"tiff\")\n }\n}\n\nextension InputSource: @preconcurrency CustomStringConvertible {\n var description: String {\n id\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/NavigationVM.swift", "import SwiftUI\n\n@MainActor\nclass NavigationVM: ObservableObject {\n enum Nav: String, CaseIterable, Identifiable {\n var id: String { rawValue }\n\n case general = \"General\"\n\n case appRules = \"App Rules\"\n case browserRules = \"Browser Rules\"\n\n case position = \"Position\"\n case appearance = \"Appearance\"\n\n case inputSourcesColorScheme = \"Input Sources Color Scheme\"\n case keyboardShortcut = \"Hot Keys\"\n\n case troubleshooting = \"Troubleshooting\"\n\n static var grouped: [(id: String, title: String, nav: [Nav])] {\n [\n (\"general\", \"\", [.general]),\n (\"rule\", \"Rules\", [.appRules, .browserRules]),\n (\"theme\", \"Indicator\", [.position, .appearance]),\n (\"keyboard\", \"Keyboard\", [.inputSourcesColorScheme, .keyboardShortcut]),\n (\"others\", \"Others\", [.troubleshooting]),\n ]\n }\n }\n\n @Published var selection: Nav = .general\n}\n"], ["/InputSourcePro/Input Source Pro/Controllers/IndicatorWindowController+Indicator.swift", "import Foundation\n\nextension IndicatorWindowController {\n func getAppSize() -> CGSize? {\n return indicatorVC.fittingSize\n }\n\n func updateIndicator(event _: IndicatorVM.ActivateEvent, inputSource: InputSource) {\n let preferences = preferencesVM.preferences\n\n indicatorVC.prepare(config: IndicatorViewConfig(\n inputSource: inputSource,\n kind: preferences.indicatorKind,\n size: preferences.indicatorSize ?? .medium,\n bgColor: preferencesVM.getBgNSColor(inputSource),\n textColor: preferencesVM.getTextNSColor(inputSource)\n ))\n\n if isActive {\n indicatorVC.refresh()\n }\n }\n\n func moveIndicator(position: PreferencesVM.IndicatorPositionInfo) {\n indicatorVC.refresh()\n moveTo(point: position.point)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Persistence/MainStorage.swift", "import AppKit\nimport Combine\n\nclass MainStorage: NSObject {\n var keyboardConfigs = CurrentValueSubject<[KeyboardConfig], Never>([])\n\n let container: NSPersistentContainer\n\n private lazy var keyboardConfigsFRC: NSFetchedResultsController = {\n let fetchRequest = KeyboardConfig.fetchRequest()\n\n fetchRequest.sortDescriptors = [NSSortDescriptor(key: \"id\", ascending: true)]\n\n keyboardConfigsFRC = NSFetchedResultsController(\n fetchRequest: fetchRequest,\n managedObjectContext: container.viewContext,\n sectionNameKeyPath: nil,\n cacheName: nil\n )\n\n keyboardConfigsFRC.delegate = self\n\n return keyboardConfigsFRC\n }()\n\n init(container: NSPersistentContainer) {\n self.container = container\n\n super.init()\n }\n\n func refresh() {\n do {\n try keyboardConfigsFRC.performFetch()\n\n if let configs = keyboardConfigsFRC.fetchedObjects {\n keyboardConfigs.send(configs)\n }\n } catch {\n print(\"MainStorage refresh error: \\(error.localizedDescription)\")\n }\n }\n}\n\nextension MainStorage: NSFetchedResultsControllerDelegate {\n func controllerDidChangeContent(_ controller: NSFetchedResultsController) {\n if let configs = controller.fetchedObjects as? [KeyboardConfig] {\n keyboardConfigs.send(configs)\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Persistence/AppRule.swift", "import Cocoa\n\nextension AppRule {\n var image: NSImage? {\n guard let path = url else { return nil }\n\n return NSWorkspace.shared.icon(forFile: path.path)\n }\n}\n\nextension AppRule {\n @MainActor\n var forcedKeyboard: InputSource? {\n guard let inputSourceId = inputSourceId else { return nil }\n\n return InputSource.sources.first { $0.id == inputSourceId }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Indicator/IndicatorViewConfig.swift", "import AppKit\n\nenum IndicatorKind {\n case icon\n case title\n case iconAndTitle\n case alwaysOn\n}\n\n@MainActor\nstruct IndicatorViewConfig {\n let inputSource: InputSource\n let kind: IndicatorKind\n let size: IndicatorSize\n let bgColor: NSColor?\n let textColor: NSColor?\n\n func render() -> NSView? {\n switch kind {\n case .iconAndTitle:\n return renderWithLabel()\n case .icon:\n return renderWithoutLabel()\n case .title:\n return renderOnlyLabel()\n case .alwaysOn:\n return renderAlwaysOn()\n }\n }\n\n func renderAlwaysOn() -> NSView? {\n let containerView = getContainerView()\n\n containerView.layer?.cornerRadius = 8\n\n containerView.snp.makeConstraints {\n $0.width.height.equalTo(8)\n }\n\n return containerView\n }\n\n private func renderWithLabel() -> NSView? {\n guard let imageView = getImageView(inputSource)\n else { return renderOnlyLabel() }\n\n let containerView = getContainerView()\n let labelView = NSTextField(labelWithString: inputSource.name)\n let stackView = NSStackView(views: [imageView, labelView])\n\n switch size {\n case .small:\n containerView.layer?.cornerRadius = 3\n stackView.spacing = 3\n labelView.font = .systemFont(ofSize: 10)\n case .medium:\n containerView.layer?.cornerRadius = 4\n stackView.spacing = 5\n labelView.font = .systemFont(ofSize: 12.6)\n case .large:\n containerView.layer?.cornerRadius = 6\n stackView.spacing = 8\n labelView.font = .systemFont(ofSize: 20)\n }\n\n labelView.textColor = textColor\n stackView.alignment = .centerY\n containerView.addSubview(stackView)\n\n stackView.snp.makeConstraints { make in\n switch size {\n case .small:\n make.edges.equalToSuperview().inset(NSEdgeInsets(top: 3, left: 3, bottom: 3, right: 3))\n case .medium:\n make.edges.equalToSuperview().inset(NSEdgeInsets(top: 4, left: 4, bottom: 4, right: 4))\n case .large:\n make.edges.equalToSuperview().inset(NSEdgeInsets(top: 6, left: 6, bottom: 6, right: 6))\n }\n }\n\n return containerView\n }\n\n private func renderWithoutLabel() -> NSView? {\n guard let imageView = getImageView(inputSource)\n else { return renderOnlyLabel() }\n\n let containerView = getContainerView()\n let stackView = NSStackView(views: [imageView])\n\n containerView.layer?.cornerRadius = 4\n containerView.addSubview(stackView)\n\n stackView.snp.makeConstraints { make in\n make.edges.equalToSuperview().inset(NSEdgeInsets(top: 3, left: 3, bottom: 3, right: 3))\n }\n\n return containerView\n }\n\n private func renderOnlyLabel() -> NSView? {\n let containerView = getContainerView()\n let labelView = NSTextField(labelWithString: inputSource.name)\n let stackView = NSStackView(views: [labelView])\n\n switch size {\n case .small:\n containerView.layer?.cornerRadius = 3\n stackView.spacing = 3\n labelView.font = .systemFont(ofSize: 10)\n case .medium:\n containerView.layer?.cornerRadius = 4\n stackView.spacing = 5\n labelView.font = .systemFont(ofSize: 12.6)\n case .large:\n containerView.layer?.cornerRadius = 6\n stackView.spacing = 8\n labelView.font = .systemFont(ofSize: 20)\n }\n\n labelView.textColor = textColor\n stackView.alignment = .centerY\n containerView.addSubview(stackView)\n\n stackView.snp.makeConstraints { make in\n switch size {\n case .small:\n make.edges.equalToSuperview().inset(NSEdgeInsets(top: 3, left: 3, bottom: 3, right: 3))\n case .medium:\n make.edges.equalToSuperview().inset(NSEdgeInsets(top: 4, left: 4, bottom: 4, right: 4))\n case .large:\n make.edges.equalToSuperview().inset(NSEdgeInsets(top: 6, left: 6, bottom: 6, right: 6))\n }\n }\n\n return containerView\n }\n\n private func getImageView(_ inputSource: InputSource) -> NSView? {\n// if let textImage = getTextImageView(inputSource) { return textImage }\n\n guard let image = inputSource.icon\n else { return nil }\n\n let imageView = NSImageView(image: image)\n\n imageView.contentTintColor = textColor\n\n imageView.snp.makeConstraints { make in\n let size = imageView.image?.size ?? .zero\n let ratio = size.height / size.width\n let width: CGFloat = {\n switch self.size {\n case .small:\n return 12\n case .medium:\n return 16\n case .large:\n return 24\n }\n }()\n let height = ratio * width\n\n make.size.equalTo(CGSize(width: width, height: height))\n }\n\n return imageView\n }\n\n private func getTextImageView(_ inputSource: InputSource) -> NSView? {\n guard let labelName = inputSource.getSystemLabelName()\n else { return nil }\n\n let labelView = NSTextField(labelWithString: labelName)\n let view = NSView()\n\n view.addSubview(labelView)\n view.wantsLayer = true\n view.layer?.backgroundColor = textColor?.cgColor\n view.layer?.cornerRadius = 2\n\n labelView.snp.makeConstraints {\n $0.center.equalTo(view)\n }\n\n view.snp.makeConstraints {\n// $0.width.equalTo(22)\n $0.width.height.equalTo(16)\n }\n\n labelView.textColor = bgColor\n labelView.font = .systemFont(ofSize: labelName.count > 1 ? 10 : 11, weight: .regular)\n\n return view\n }\n\n private func getContainerView() -> NSView {\n let containerView = NSView()\n\n containerView.wantsLayer = true\n containerView.setValue(bgColor, forKey: \"backgroundColor\")\n\n containerView.layer?.borderWidth = 1\n containerView.layer?.borderColor = NSColor.black.withAlphaComponent(0.1 * (bgColor?.alphaComponent ?? 1)).cgColor\n\n return containerView\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Controllers/PreferencesWindowController+NSToolbar.swift", "import AppKit\n\nextension PreferencesWindowController: NSSharingServicePickerToolbarItemDelegate {\n func items(for _: NSSharingServicePickerToolbarItem) -> [Any] {\n // Compose an array of items that are sharable such as text, URLs, etc.\n // depending on the context of your application (i.e. what the user\n // current has selected in the app and/or they tab they're in).\n let sharableItems = [URL(string: \"https://inputsource.pro/\")!] as [Any]\n\n return sharableItems\n }\n}\n\nextension PreferencesWindowController: NSToolbarDelegate {\n func toolbarDefaultItemIdentifiers(_: NSToolbar) -> [NSToolbarItem.Identifier] {\n return []\n// return [.toolbarShareButtonItem]\n }\n\n func toolbarAllowedItemIdentifiers(_: NSToolbar) -> [NSToolbarItem.Identifier] {\n return [.toolbarShareButtonItem]\n }\n\n func toolbar(\n _: NSToolbar,\n itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier,\n willBeInsertedIntoToolbar _: Bool\n ) -> NSToolbarItem? {\n if itemIdentifier == NSToolbarItem.Identifier.toolbarShareButtonItem {\n let shareItem = NSSharingServicePickerToolbarItem(itemIdentifier: itemIdentifier)\n\n shareItem.toolTip = \"Share\"\n shareItem.delegate = self\n\n if #available(macOS 11.0, *) {\n shareItem.menuFormRepresentation?.image = NSImage(\n systemSymbolName: \"square.and.arrow.up\",\n accessibilityDescription: nil\n )\n }\n\n return shareItem\n }\n\n return nil\n }\n}\n\nextension PreferencesWindowController: NSToolbarItemValidation {\n func validateToolbarItem(_ item: NSToolbarItem) -> Bool {\n if item.itemIdentifier == .toolbarShareButtonItem {\n return true\n }\n\n return false\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/InputSource/TISInputSource+Extension.swift", "import Carbon\nimport Foundation\n\nextension TISInputSource {\n enum Category {\n static var keyboardInputSource: String {\n return kTISCategoryKeyboardInputSource as String\n }\n }\n\n private func getProperty(_ key: CFString) -> AnyObject? {\n let cfType = TISGetInputSourceProperty(self, key)\n if cfType != nil {\n return Unmanaged.fromOpaque(cfType!).takeUnretainedValue()\n } else {\n return nil\n }\n }\n\n var id: String {\n return getProperty(kTISPropertyInputSourceID) as! String\n }\n\n var name: String {\n return getProperty(kTISPropertyLocalizedName) as! String\n }\n\n var category: String? {\n return getProperty(kTISPropertyInputSourceCategory) as? String\n }\n\n var isSelectable: Bool {\n return getProperty(kTISPropertyInputSourceIsSelectCapable) as? Bool ?? false\n }\n\n var sourceLanguages: [String] {\n return getProperty(kTISPropertyInputSourceLanguages) as? [String] ?? []\n }\n\n var iconImageURL: URL? {\n return getProperty(kTISPropertyIconImageURL) as? URL\n }\n\n var iconRef: IconRef? {\n return OpaquePointer(TISGetInputSourceProperty(self, kTISPropertyIconRef))\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/PreferencesVM+BrowserAddress.swift", "import AppKit\nimport AXSwift\n\nprivate let chromiumSearchBarDescMap = [\n \"Aadressi- ja otsinguriba\": true,\n \"Address and search bar\": true,\n \"Address bar at bar sa paghahanap\": true,\n \"Adres ve arama çubuğu\": true,\n \"Adres- en soekbalk\": true,\n \"Adres- en zoekbalk\": true,\n \"Adreses un meklēšanas josla\": true,\n \"Adresna traka i traka za pretraživanje\": true,\n \"Adresní a vyhledávací řádek\": true,\n \"Adreso ir paieškos juosta\": true,\n \"Adress- och sökfält\": true,\n \"Adress- und Suchleiste\": true,\n \"Adresse og søgelinje\": true,\n \"Adresse- og søkefelt\": true,\n \"Bar alamat dan carian\": true,\n \"Bar cyfeiriad a chwilio\": true,\n \"Bara de adrese și de căutare\": true,\n \"Barra d'adreces i de cerca\": true,\n \"Barra de direcciones y de búsqueda\": true,\n \"Barra de direcciones y de búsqueda \": true,\n \"Barra de enderezos e de busca\": true,\n \"Barra de endereço e de pesquisa\": true,\n \"Barra de pesquisa e endereço\": true,\n \"Barra degli indirizzi e di ricerca\": true,\n \"Barre d'adresse et de recherche\": true,\n \"Bilah penelusuran dan alamat\": true,\n \"Cím- és keresősáv\": true,\n \"Helbide- eta bilaketa-barra\": true,\n \"Ikheli nebha yosesho\": true,\n \"Manzil va qidiruv paneli\": true,\n \"Naslovna in iskalna vrstica\": true,\n \"Osoite- ja hakupalkki\": true,\n \"Panel s adresou a vyhľadávací panel\": true,\n \"Pasek adresu i wyszukiwania\": true,\n \"Shiriti i adresës dhe i kërkimit\": true,\n \"Thanh địa chỉ và tìm kiếm\": true,\n \"Traka za adresu i pretragu\": true,\n \"Traka za adresu i pretraživanje\": true,\n \"Upau wa anwani na utafutaji\": true,\n \"Veffanga- og leitarstika\": true,\n \"Ünvan və axtarış paneli\": true,\n \"Γραμμή διευθύνσεων και αναζήτησης\": true,\n \"Адрасны радок і панэль пошуку\": true,\n \"Адресная строка и строка поиска\": true,\n \"Адресний і пошуковий рядок\": true,\n \"Дарек жана издөө тилкеси\": true,\n \"Лента за адреса и за пребарување\": true,\n \"Лента за адреси и за търсене\": true,\n \"Мекенжайы және іздеу жолағы\": true,\n \"Трака за адресу и претрагу\": true,\n \"Хаяг ба хайлтын цонх\": true,\n \"Հասցեագոտի և որոնման գոտի\": true,\n \"שורת חיפוש וכתובות אתרים\": true,\n \"شريط العناوين والبحث\": true,\n \"نوار جستجو و آدرس\": true,\n \"پتہ اور تلاش بار\": true,\n \"ठेगाना र खोज पट्टी\": true,\n \"पता और सर्च बार\": true,\n \"पत्ता आणि शोध बार\": true,\n \"ঠিকনা আৰু সন্ধানৰ বাৰ\": true,\n \"ঠিকানা এবং সার্চ দণ্ড\": true,\n \"ਪਤਾ ਅਤੇ ਖੋਜ ਬਾਰ\": true,\n \"સરનામું અને શોધ બાર\": true,\n \"ଠିକଣା ଏବଂ ସନ୍ଧାନ ବାର୍\": true,\n \"முகவரி மற்றும் தேடல் பட்டி\": true,\n \"అడ్రస్‌ మరియు శోధన బార్\": true,\n \"ವಿಳಾಸ ಹಾಗೂ ಹುಡುಕಾಟ ಪಟ್ಟಿ\": true,\n \"വിലാസവും തിരയൽ ബാറും\": true,\n \"ලිපිනය සහ සෙවීම් බාර් එක\": true,\n \"ที่อยู่และแถบค้นหา\": true,\n \"ແຖບ​ທີ່​ຢູ່​ ແລະ​ຄົ້ນ​ຫາ\": true,\n \"လိပ်စာ နှင့် ရှာဖွေရေး ဘား\": true,\n \"მისამართი და ძიების ზოლი\": true,\n \"የአድራሻ እና ፍለጋ አሞሌ\": true,\n \"អាសយដ្ឋាន និងរបាស្វែងរក\": true,\n \"アドレス検索バー\": true,\n \"地址和搜索栏\": true,\n \"網址與搜尋列\": true,\n \"주소창 및 검색창\": true,\n]\n\nenum BrowserThatCanWatchBrowserAddressFocus: CaseIterable {\n static var allBundleIdentifiers = allCases.map { $0.bundleIdentifier }\n\n static func createBy(bundleIdentifier: String?) -> BrowserThatCanWatchBrowserAddressFocus? {\n if let bundleIdentifier = bundleIdentifier {\n for item in allCases {\n if item.bundleIdentifier == bundleIdentifier {\n return item\n }\n }\n }\n\n return nil\n }\n\n case Safari, SafariTechnologyPreview, Chrome, Chromium, Brave, BraveBeta, BraveNightly, Edge, Vivaldi, Arc, Opera, Firefox, FirefoxNightly, FirefoxDeveloperEdition, Zen, Dia\n\n var bundleIdentifier: String {\n return browser.rawValue\n }\n\n var browser: Browser {\n switch self {\n case .Safari:\n return .Safari\n case .SafariTechnologyPreview:\n return .SafariTechnologyPreview\n case .Chrome:\n return .Chrome\n case .Chromium:\n return .Chromium\n case .Brave:\n return .Brave\n case .BraveBeta:\n return .BraveBeta\n case .BraveNightly:\n return .BraveNightly\n case .Edge:\n return .Edge\n case .Vivaldi:\n return .Vivaldi\n case .Arc:\n return .Arc\n case .Opera:\n return .Opera\n case .Firefox:\n return .Firefox\n case .FirefoxNightly:\n return .FirefoxNightly\n case .FirefoxDeveloperEdition:\n return .FirefoxDeveloperEdition\n case .Zen:\n return .Zen\n case .Dia:\n return .Dia\n }\n }\n\n func isFocusOnBrowserAddress(focusedElement: UIElement?) -> Bool {\n guard let focusedElement = focusedElement\n else { return false }\n\n switch self {\n case .Safari, .SafariTechnologyPreview:\n return focusedElement.domIdentifier() == \"WEB_BROWSER_ADDRESS_AND_SEARCH_FIELD\"\n\n case .Arc:\n return focusedElement.domIdentifier() == \"commandBarTextField\"\n\n case .Vivaldi:\n let classList = focusedElement.domClassList()\n return classList.contains(\"UrlBar-UrlField\") && classList.contains(\"vivaldi-addressfield\")\n\n case .Opera:\n return focusedElement.domClassList().contains(\"AddressTextfieldView\")\n\n case .Chromium, .Chrome, .Brave, .BraveBeta, .BraveNightly, .Edge, .Dia:\n if focusedElement.domClassList().contains(\"OmniboxViewViews\") {\n if let description = focusedElement.safeString(attribute: .description),\n chromiumSearchBarDescMap[description] == true\n {\n return true\n }\n\n if let title = focusedElement.safeString(attribute: .title),\n chromiumSearchBarDescMap[title] == true\n {\n return true\n }\n\n return false\n } else {\n return false\n }\n\n case .Firefox, .FirefoxNightly, .FirefoxDeveloperEdition, .Zen:\n return focusedElement.firefoxDomIdentifier() == \"urlbar-input\"\n }\n }\n}\n\nextension PreferencesVM {\n func isFocusOnBrowserAddress(app: NSRunningApplication?, focusedElement: UIElement?) -> Bool {\n return BrowserThatCanWatchBrowserAddressFocus\n .createBy(bundleIdentifier: app?.bundleIdentifier)?\n .isFocusOnBrowserAddress(focusedElement: focusedElement) ?? false\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSRunningApplication+WindowInfo.swift", "import AppKit\nimport Combine\nimport Foundation\n\nprivate func isValidWindow(windowAlpha: CGFloat, windowBounds: CGRect) -> Bool {\n // ----------------------------------------\n // Ignore windows.\n //\n // There are well known windows that we need ignore:\n // * Google Chrome has some transparent windows.\n // * Google Chrome's status bar which is shown when mouse cursor is on links.\n // * Karabiner's status message windows.\n //\n // Do not forget to treat this situations:\n // * Do not ignore menubar.\n // * Do not ignore popup menu.\n // * Do not ignore alert window on web browsers.\n // * Do not ignore iTunes's preferences window which has some special behavior.\n\n // Ignore transparent windows.\n let transparentThreshold: CGFloat = 0.001\n\n if windowAlpha < transparentThreshold {\n return false\n }\n\n // Ignore small windows. (For example, a status bar of Google Chrome.)\n let windowSizeThreshold: CGFloat = 40\n if windowBounds.size.width < windowSizeThreshold ||\n windowBounds.size.height < windowSizeThreshold\n {\n return false\n }\n\n // Xcode and some app have some invisable window at fullscreen mode\n if let screen = NSScreen.getScreenInclude(rect: windowBounds),\n windowBounds.width == screen.frame.width,\n windowBounds.height < 70\n {\n return false\n }\n\n return true\n}\n\nextension NSRunningApplication {\n static func getWindowInfoPublisher(processIdentifier: pid_t) -> AnyPublisher {\n AnyPublisher.create { observer in\n let thread = Thread(block: {\n observer.send(getWindowInfo(processIdentifier: processIdentifier))\n observer.send(completion: .finished)\n })\n\n thread.start()\n\n return AnyCancellable { thread.cancel() }\n }\n .receive(on: DispatchQueue.main)\n .eraseToAnyPublisher()\n }\n\n func getWindowInfoPublisher() -> AnyPublisher {\n return NSRunningApplication.getWindowInfoPublisher(processIdentifier: processIdentifier)\n }\n}\n\nstruct WindowInfo {\n let bounds: CGRect\n let layer: Int\n}\n\nprivate func getWindowInfo(processIdentifier: pid_t) -> WindowInfo? {\n guard let windows = CGWindowListCopyWindowInfo(.optionOnScreenAboveWindow, kCGNullWindowID) as? [[String: Any]]\n else { return nil }\n\n for window in windows {\n // Target windows:\n // * frontmostApplication\n // * loginwindow (shutdown dialog)\n // * Launchpad\n //\n // Limitations:\n // * There is not reliable way to judge whether Dashboard is shown.\n\n guard\n let windowOwnerPID = window[\"kCGWindowOwnerPID\"] as? pid_t,\n let windowLayer = window[\"kCGWindowLayer\"] as? Int,\n let windowAlpha = window[\"kCGWindowAlpha\"] as? CGFloat,\n let windowBounds = CGRect(dictionaryRepresentation: window[\"kCGWindowBounds\"] as! CFDictionary)\n else { continue }\n\n guard windowOwnerPID == processIdentifier\n else { continue }\n\n if isValidWindow(windowAlpha: windowAlpha, windowBounds: windowBounds) {\n return .init(bounds: windowBounds, layer: windowLayer)\n }\n }\n\n return nil\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSWorkspace.swift", "import AppKit\n\nextension NSWorkspace {\n func openAccessibilityPreferences() {\n open(\n URL(string: \"x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility\")!\n )\n }\n\n func openAutomationPreferences() {\n open(\n URL(string: \"x-apple.systempreferences:com.apple.preference.security?Privacy_Automation\")!\n )\n }\n\n func openKeyboardPreferences() {\n open(\n URL(fileURLWithPath: \"/System/Library/PreferencePanes/Keyboard.prefPane\")\n )\n }\n}\n\nextension NSWorkspace {\n func desktopImage() -> NSImage? {\n guard let mainScreen = NSScreen.main,\n let url = desktopImageURL(for: mainScreen),\n let image = NSImage(contentsOf: url)\n else { return nil }\n\n return image\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/CustomizedIndicatorView.swift", "import SwiftUI\n\nstruct CustomizedIndicatorView: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n let inputSource: InputSource\n\n init(inputSource: InputSource) {\n self.inputSource = inputSource\n }\n\n var body: some View {\n return Group {\n DumpIndicatorView(config: IndicatorViewConfig(\n inputSource: inputSource,\n kind: preferencesVM.preferences.indicatorKind,\n size: preferencesVM.preferences.indicatorSize ?? .medium,\n bgColor: NSColor(preferencesVM.getBgColor(inputSource)),\n textColor: NSColor(preferencesVM.getTextColor(inputSource))\n ))\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/RunningApplicationsPicker.swift", "import SwiftUI\n\nstruct RunningApplicationsPicker: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n let appIconSize: CGFloat = 18\n\n let onSelect: (NSRunningApplication) -> Void\n\n init(onSelect: @escaping (NSRunningApplication) -> Void) {\n self.onSelect = onSelect\n }\n\n var body: some View {\n Menu(\"Add Running Apps\") {\n ForEach(preferencesVM.filterApps(NSWorkspace.shared.runningApplications), id: \\.processIdentifier) { app in\n Button(action: { onSelect(app) }) {\n Text(app.localizedName ?? app.bundleId() ?? app.description)\n\n if let url = app.bundleURL {\n let image = NSWorkspace.shared.icon(forFile: url.path)\n\n SwiftUI.Image(nsImage: image)\n .resizable()\n .frame(width: appIconSize, height: appIconSize)\n } else {\n SwiftUI.Image(systemName: \"app.dashed\")\n .resizable()\n .frame(width: appIconSize, height: appIconSize)\n }\n }\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/IndicatorView.swift", "import SwiftUI\n\nstruct IndicatorView: NSViewControllerRepresentable {\n @EnvironmentObject var preferencesVM: PreferencesVM\n @EnvironmentObject var indicatorVM: IndicatorVM\n @EnvironmentObject var inputSourceVM: InputSourceVM\n\n func makeNSViewController(context _: Context) -> IndicatorViewController {\n return IndicatorViewController()\n }\n\n func updateNSViewController(_ indicatorViewController: IndicatorViewController, context _: Context) {\n indicatorViewController.prepare(config: IndicatorViewConfig(\n inputSource: indicatorVM.state.inputSource,\n kind: preferencesVM.preferences.indicatorKind,\n size: preferencesVM.preferences.indicatorSize ?? .medium,\n bgColor: NSColor(preferencesVM.preferences.indicatorBackgroundColor),\n textColor: NSColor(preferencesVM.preferences.indicatorForgegroundColor)\n ))\n\n indicatorViewController.refresh()\n }\n}\n\nstruct DumpIndicatorView: NSViewControllerRepresentable {\n let config: IndicatorViewConfig\n\n init(config: IndicatorViewConfig) {\n self.config = config\n }\n\n func makeNSViewController(context _: Context) -> IndicatorViewController {\n return IndicatorViewController()\n }\n\n func updateNSViewController(_ indicatorViewController: IndicatorViewController, context _: Context) {\n indicatorViewController.prepare(config: config)\n indicatorViewController.refresh()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/AddSwitchingGroupButton.swift", "import SwiftUI\n\nstruct AddSwitchingGroupButton: View {\n @State var isActive = false\n @State var selections = Set()\n\n let onSelect: ([InputSource]) -> Void\n\n var body: some View {\n Button(\"Add Switch Group\".i18n(), systemImage: \"plus.circle\") {\n isActive = true\n }\n .sheet(isPresented: $isActive, content: {\n VStack(alignment: .leading) {\n Text(\"Select Input Sources\".i18n())\n .font(.title)\n .padding(.bottom, 4)\n\n Text(\"Add a switch group to allow switching between multiple input sources using the same hotkey. Select at least two input sources.\".i18n())\n .lineLimit(nil)\n .multilineTextAlignment(.leading)\n .frame(width: 500)\n\n VStack(alignment: .leading) {\n ForEach(InputSource.sources, id: \\.id) { inputSource in\n VStack(alignment: .leading) {\n HStack(spacing: 6) {\n if selections.contains(inputSource.id) {\n Image(systemName: \"checkmark.circle.fill\")\n .foregroundColor(Color.accentColor)\n .font(.system(size: 16))\n } else {\n Image(systemName: \"circle\")\n .foregroundColor(.gray)\n .font(.system(size: 16))\n }\n\n Text(inputSource.name)\n }\n .frame(height: 12)\n\n Divider()\n }\n .contentShape(Rectangle())\n .onTapGesture {\n if selections.contains(inputSource.id) {\n selections.remove(inputSource.id)\n } else {\n selections.insert(inputSource.id)\n }\n }\n }\n }\n .padding(.vertical)\n\n HStack {\n Spacer()\n\n Button(\"Cancel\".i18n()) { hide() }\n .keyboardShortcut(.cancelAction)\n Button(\"Add\".i18n()) { add() }\n .keyboardShortcut(.defaultAction)\n .disabled(selections.count < 2)\n }\n }\n .padding()\n })\n }\n\n func add() {\n onSelect(InputSource.sources.filter { selections.contains($0.id) })\n hide()\n }\n\n func hide() {\n isActive = false\n selections.removeAll()\n }\n}\n\nstruct MultipleSelectionRow: View {\n var title: String\n var isSelected: Bool\n var action: () -> Void\n\n var body: some View {\n Button(action: action) {\n HStack {\n Text(self.title)\n if self.isSelected {\n Spacer()\n Image(systemName: \"checkmark\")\n }\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Accessibility/AXSwift.swift", "import AXSwift\nimport Cocoa\n\nextension UIElement {\n func getCursorRectInfo() -> (rect: CGRect, isContainer: Bool)? {\n guard let focusedElement: UIElement = try? attribute(.focusedUIElement),\n Self.isInputContainer(focusedElement),\n let inputAreaRect = Self.findInputAreaRect(focusedElement)\n else { return nil }\n\n if let cursorRect = Self.findCursorRect(focusedElement),\n inputAreaRect.contains(cursorRect)\n {\n return (rect: cursorRect, isContainer: false)\n } else {\n return (rect: inputAreaRect, isContainer: true)\n }\n }\n}\n\nextension UIElement {\n static func isInputContainer(_ elm: UIElement?) -> Bool {\n guard let elm = elm,\n let role = try? elm.role()\n else { return false }\n\n return role == .textArea || role == .textField || role == .comboBox\n }\n\n static func findInputAreaRect(_ focusedElement: UIElement) -> CGRect? {\n if let parent: UIElement = try? focusedElement.attribute(.parent),\n let role = try? parent.role(),\n role == .scrollArea,\n let origin: CGPoint = try? parent.attribute(.position),\n let size: CGSize = try? parent.attribute(.size)\n {\n return NSScreen.convertFromQuartz(CGRect(origin: origin, size: size))\n }\n\n if let origin: CGPoint = try? focusedElement.attribute(.position),\n let size: CGSize = try? focusedElement.attribute(.size)\n {\n return NSScreen.convertFromQuartz(CGRect(origin: origin, size: size))\n }\n\n return nil\n }\n}\n\nextension UIElement {\n static func findCursorRect(_ focusedElement: UIElement) -> CGRect? {\n return findWebAreaCursor(focusedElement) ?? findNativeInputAreaCursor(focusedElement)\n }\n\n static func findWebAreaCursor(_ focusedElement: UIElement) -> CGRect? {\n guard let range: AXTextMarkerRange = try? focusedElement.attribute(\"AXSelectedTextMarkerRange\"),\n let bounds: CGRect = try? focusedElement.parameterizedAttribute(\"AXBoundsForTextMarkerRange\", param: range)\n else { return nil }\n\n return NSScreen.convertFromQuartz(bounds)\n }\n\n static func findNativeInputAreaCursor(_ focusedElement: UIElement) -> CGRect? {\n guard let selectedRange: CFRange = try? focusedElement.attribute(.selectedTextRange),\n let visibleRange: CFRange = try? focusedElement.attribute(.visibleCharacterRange),\n let rawValue: AnyObject = try? focusedElement.attribute(.value),\n CFGetTypeID(rawValue) == CFStringGetTypeID(),\n let value = rawValue as? String\n else { return nil }\n\n func getBounds(cursor location: Int) -> CGRect? {\n return try? focusedElement.parameterizedAttribute(\n kAXBoundsForRangeParameterizedAttribute,\n param: AXValue.range(CFRange(location: max(location, 0), length: 1))\n )\n .flatMap(NSScreen.convertFromQuartz)\n }\n\n func getCursorBounds() -> CGRect? {\n let lastCursor = visibleRange.location + visibleRange.length\n // Notes 最后存在两个换行符时会有问题\n // let isLastCursor = selectedRange.location >= (lastCursor - 1)\n let isLastCursor = selectedRange.location >= lastCursor\n let location = selectedRange.location - (isLastCursor ? 1 : 0)\n\n guard let bounds = getBounds(cursor: location)\n else { return nil }\n\n if isLastCursor, value.string(at: location) == \"\\n\" {\n if location > 0 {\n for offsetDiff in 1 ... location {\n let offset = location - offsetDiff\n\n if value.string(at: offset + 1) == \"\\n\",\n let prevNewLineBounds = getBounds(cursor: offset)\n {\n return CGRect(\n origin: CGPoint(\n x: prevNewLineBounds.origin.x,\n y: prevNewLineBounds.minY - prevNewLineBounds.height\n ),\n size: bounds.size\n )\n }\n }\n\n return nil\n } else {\n return nil\n }\n } else {\n return bounds\n }\n }\n\n func getLineBounds() -> CGRect? {\n guard let cursorLine: Int = try? focusedElement.attribute(.insertionPointLineNumber),\n let lineRange: CFRange = try? focusedElement.parameterizedAttribute(\"AXRangeForLine\", param: cursorLine),\n let bounds: CGRect = try? focusedElement.parameterizedAttribute(\n kAXBoundsForRangeParameterizedAttribute,\n param: AXValue.range(lineRange)\n )\n else { return nil }\n\n return NSScreen.convertFromQuartz(bounds)\n }\n\n return getCursorBounds() ?? getLineBounds()\n }\n}\n\nextension UIElement {\n func children() -> [UIElement]? {\n guard let children: [AXUIElement] = try? attribute(.children)\n else { return nil }\n\n return children.map { .init($0) }\n }\n}\n\nextension Role {\n static let validInputElms: [Role] = [.comboBox, .textArea, .textField]\n\n static let allCases: [Role] = [\n .unknown,\n .button,\n .radioButton,\n .checkBox,\n .slider,\n .tabGroup,\n .textField,\n .staticText,\n .textArea,\n .scrollArea,\n .popUpButton,\n .menuButton,\n .table,\n .application,\n .group,\n .radioGroup,\n .list,\n .scrollBar,\n .valueIndicator,\n .image,\n .menuBar,\n .menu,\n .menuItem,\n .column,\n .row,\n .toolbar,\n .busyIndicator,\n .progressIndicator,\n .window,\n .drawer,\n .systemWide,\n .outline,\n .incrementor,\n .browser,\n .comboBox,\n .splitGroup,\n .splitter,\n .colorWell,\n .growArea,\n .sheet,\n .helpTag,\n .matte,\n .ruler,\n .rulerMarker,\n .link,\n .disclosureTriangle,\n .grid,\n .relevanceIndicator,\n .levelIndicator,\n .cell,\n .popover,\n .layoutArea,\n .layoutItem,\n .handle,\n ]\n}\n\nextension AXNotification {\n static let allCases: [AXNotification] = [\n .mainWindowChanged,\n .focusedWindowChanged,\n .focusedUIElementChanged,\n .applicationActivated,\n .applicationDeactivated,\n .applicationHidden,\n .applicationShown,\n .windowCreated,\n .windowMoved,\n .windowResized,\n .windowMiniaturized,\n .windowDeminiaturized,\n .drawerCreated,\n .sheetCreated,\n .uiElementDestroyed,\n .valueChanged,\n .titleChanged,\n .resized,\n .moved,\n .created,\n .layoutChanged,\n .helpTagCreated,\n .selectedTextChanged,\n .rowCountChanged,\n .selectedChildrenChanged,\n .selectedRowsChanged,\n .selectedColumnsChanged,\n .rowExpanded,\n .rowCollapsed,\n .selectedCellsChanged,\n .unitsChanged,\n .selectedChildrenMoved,\n .announcementRequested,\n ]\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Indicator/IndicatorPosition.swift", "import AppKit\n\nenum IndicatorActuallyPositionKind {\n case floatingApp\n case inputCursor\n case inputRect\n case nearMouse\n case windowCorner\n case screenCorner\n\n var isInputArea: Bool {\n self == .inputRect || self == .inputCursor\n }\n}\n\nenum IndicatorPosition: Int32, CaseIterable, Identifiable {\n case nearMouse = 0\n case windowCorner = 1\n case screenCorner = 2\n\n var id: Self { self }\n\n enum Alignment: Int32, CaseIterable {\n case topLeft = 0\n case topCenter = 5\n case topRight = 1\n case centerLeft = 7\n case center = 2\n case centerRight = 8\n case bottomLeft = 3\n case bottomCenter = 6\n case bottomRight = 4\n }\n\n enum Spacing: Int32, CaseIterable {\n case none = 0\n case xs = 1\n case s = 2\n case m = 3\n case l = 4\n case xl = 5\n }\n}\n\nextension IndicatorPosition {\n var name: String {\n switch self {\n case .nearMouse:\n return \"Follow Mouse\".i18n()\n case .windowCorner:\n return \"Relative to App\".i18n()\n case .screenCorner:\n return \"Relative to Screen\".i18n()\n }\n }\n}\n\nextension IndicatorPosition.Alignment {\n var name: String {\n switch self {\n case .topLeft:\n return \"Top-Left Corner\".i18n()\n case .topRight:\n return \"Top-Right Corner\".i18n()\n case .topCenter:\n return \"Top-Center\".i18n()\n case .center:\n return \"Center\".i18n()\n case .centerLeft:\n return \"Center-Left\".i18n()\n case .centerRight:\n return \"Center-Right\".i18n()\n case .bottomLeft:\n return \"Bottom-Left Corner\".i18n()\n case .bottomCenter:\n return \"Bottom-Center\".i18n()\n case .bottomRight:\n return \"Bottom-Right Corner\".i18n()\n }\n }\n}\n\nextension IndicatorPosition.Spacing {\n static func fromSlide(value: Double) -> Self {\n return .init(rawValue: Int32(value)) ?? .m\n }\n\n var name: String {\n switch self {\n case .none:\n return \"Nope\".i18n()\n case .xs:\n return \"XS\".i18n()\n case .s:\n return \"S\".i18n()\n case .m:\n return \"M\".i18n()\n case .l:\n return \"L\".i18n()\n case .xl:\n return \"XL\".i18n()\n }\n }\n}\n\nextension IndicatorPosition: Codable {\n private enum CodingKeys: String, CodingKey {\n case base\n }\n\n private enum Base: String, Codable {\n case nearMouse, windowCorner, screenCorner\n }\n\n func encode(to encoder: Encoder) throws {\n var container = encoder.container(keyedBy: CodingKeys.self)\n\n switch self {\n case .nearMouse:\n try container.encode(Base.nearMouse, forKey: .base)\n case .windowCorner:\n try container.encode(Base.windowCorner, forKey: .base)\n case .screenCorner:\n try container.encode(Base.screenCorner, forKey: .base)\n }\n }\n\n init(from decoder: Decoder) throws {\n let container = try decoder.container(keyedBy: CodingKeys.self)\n let base = try container.decode(Base.self, forKey: .base)\n\n switch base {\n case .nearMouse:\n self = .nearMouse\n case .windowCorner:\n self = .windowCorner\n case .screenCorner:\n self = .screenCorner\n }\n }\n}\n\nextension IndicatorPosition.Alignment: Codable {\n private enum CodingKeys: String, CodingKey {\n case base\n }\n\n func encode(to encoder: Encoder) throws {\n var container = encoder.container(keyedBy: CodingKeys.self)\n try container.encode(rawValue, forKey: .base)\n }\n\n init(from decoder: Decoder) throws {\n let container = try decoder.container(keyedBy: CodingKeys.self)\n let rawValue = try container.decode(Int32.self, forKey: .base)\n\n self = Self(rawValue: rawValue)!\n }\n}\n\nextension IndicatorPosition.Spacing: Codable {\n private enum CodingKeys: String, CodingKey {\n case base\n }\n\n func encode(to encoder: Encoder) throws {\n var container = encoder.container(keyedBy: CodingKeys.self)\n try container.encode(rawValue, forKey: .base)\n }\n\n init(from decoder: Decoder) throws {\n let container = try decoder.container(keyedBy: CodingKeys.self)\n let rawValue = try container.decode(Int32.self, forKey: .base)\n\n self = Self(rawValue: rawValue)!\n }\n}\n"], ["/InputSourcePro/Input Source Pro/System/AppDelegate.swift", "import Cocoa\nimport Combine\nimport SwiftUI\nimport Alamofire\nimport LaunchAtLogin\n\nclass AppDelegate: NSObject, NSApplicationDelegate {\n var navigationVM: NavigationVM!\n var indicatorVM: IndicatorVM!\n var preferencesVM: PreferencesVM!\n var permissionsVM: PermissionsVM!\n var applicationVM: ApplicationVM!\n var inputSourceVM: InputSourceVM!\n var feedbackVM: FeedbackVM!\n var indicatorWindowController: IndicatorWindowController!\n var statusItemController: StatusItemController!\n\n func applicationDidFinishLaunching(_: Notification) {\n feedbackVM = FeedbackVM()\n navigationVM = NavigationVM()\n permissionsVM = PermissionsVM()\n preferencesVM = PreferencesVM(permissionsVM: permissionsVM)\n applicationVM = ApplicationVM(preferencesVM: preferencesVM)\n inputSourceVM = InputSourceVM(preferencesVM: preferencesVM)\n indicatorVM = IndicatorVM(permissionsVM: permissionsVM, preferencesVM: preferencesVM, applicationVM: applicationVM, inputSourceVM: inputSourceVM)\n\n indicatorWindowController = IndicatorWindowController(\n permissionsVM: permissionsVM,\n preferencesVM: preferencesVM,\n indicatorVM: indicatorVM,\n applicationVM: applicationVM,\n inputSourceVM: inputSourceVM\n )\n\n statusItemController = StatusItemController(\n navigationVM: navigationVM,\n permissionsVM: permissionsVM,\n preferencesVM: preferencesVM,\n applicationVM: applicationVM,\n indicatorVM: indicatorVM,\n feedbackVM: feedbackVM,\n inputSourceVM: inputSourceVM\n )\n \n LaunchAtLogin.migrateIfNeeded()\n openPreferencesAtFirstLaunch()\n sendLaunchPing()\n updateInstallVersionInfo()\n }\n\n func applicationDidBecomeActive(_: Notification) {\n statusItemController.openPreferences()\n }\n\n @MainActor\n func openPreferencesAtFirstLaunch() {\n if preferencesVM.preferences.prevInstalledBuildVersion != preferencesVM.preferences.buildVersion {\n statusItemController.openPreferences()\n }\n }\n\n @MainActor\n func updateInstallVersionInfo() {\n preferencesVM.preferences.prevInstalledBuildVersion = preferencesVM.preferences.buildVersion\n }\n \n @MainActor\n func sendLaunchPing() {\n let url = \"https://inputsource.pro/api/launch\"\n let launchData: [String: String] = [\n \"prevInstalledBuildVersion\": \"\\(preferencesVM.preferences.prevInstalledBuildVersion)\",\n \"shortVersion\": Bundle.main.shortVersion,\n \"buildVersion\": \"\\(Bundle.main.buildVersion)\",\n \"osVersion\": ProcessInfo.processInfo.operatingSystemVersionString\n ]\n \n AF.request(\n url,\n method: .post,\n parameters: launchData,\n encoding: JSONEncoding.default\n )\n .response { response in\n switch response.result {\n case .success:\n print(\"Launch ping sent successfully.\")\n case let .failure(error):\n print(\"Failed to send launch ping:\", error)\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/BrowserURL.swift", "import AppKit\nimport AXSwift\n\n// Update BrowserThatCanWatchBrowserAddressFocus as well\nenum Browser: String, CaseIterable {\n case Safari = \"com.apple.Safari\"\n case SafariTechnologyPreview = \"com.apple.SafariTechnologyPreview\"\n case Chrome = \"com.google.Chrome\"\n case Chromium = \"org.chromium.Chromium\"\n case Arc = \"company.thebrowser.Browser\"\n case Edge = \"com.microsoft.edgemac\"\n case Brave = \"com.brave.Browser\"\n case BraveBeta = \"com.brave.Browser.beta\"\n case BraveNightly = \"com.brave.Browser.nightly\"\n case Vivaldi = \"com.vivaldi.Vivaldi\"\n case Opera = \"com.operasoftware.Opera\"\n case Thorium = \"org.chromium.Thorium\"\n case Firefox = \"org.mozilla.firefox\"\n case FirefoxDeveloperEdition = \"org.mozilla.firefoxdeveloperedition\"\n case FirefoxNightly = \"org.mozilla.nightly\"\n case Zen = \"app.zen-browser.zen\"\n case Dia = \"company.thebrowser.dia\"\n\n var displayName: String {\n switch self {\n case .Safari:\n return \"Safari\"\n case .SafariTechnologyPreview:\n return \"Safari Technology Preview\"\n case .Chrome:\n return \"Chrome\"\n case .Chromium:\n return \"Chromium\"\n case .Arc:\n return \"Arc\"\n case .Edge:\n return \"Edge\"\n case .Brave:\n return \"Brave\"\n case .BraveBeta:\n return \"Brave Beta\"\n case .BraveNightly:\n return \"Brave Nightly\"\n case .Vivaldi:\n return \"Vivaldi\"\n case .Opera:\n return \"Opera\"\n case .Thorium:\n return \"Thorium\"\n case .Firefox:\n return \"Firefox\"\n case .FirefoxDeveloperEdition:\n return \"Firefox Developer Edition\"\n case .FirefoxNightly:\n return \"Firefox Nightly\"\n case .Zen:\n return \"Zen\"\n case .Dia:\n return \"Dia\"\n }\n }\n}\n\nextension Browser {\n func getCurrentTabURL(focusedWindow: UIElement) -> URL? {\n guard let windowElement = Element.initialize(rawElement: focusedWindow.element),\n let webArea = (try? QueryWebAreaService(windowElement: windowElement).perform()),\n let url = webArea.url\n else { return nil }\n\n if [\n \"favorites://\",\n \"edge://newtab/\",\n \"chrome://newtab/\",\n \"chrome://new-tab-page/\",\n \"chrome://vivaldi-webui/\",\n \"about:newtab\", // Firefox\n ].contains(where: { url.absoluteString.contains($0) }) {\n return .newtab\n } else {\n return url\n }\n }\n}\n\nextension Browser {\n static func isSupportedBrowser(bundleId: String) -> Bool {\n return allCases.contains { $0.rawValue == bundleId }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/CodableUserDefault.swift", "import Cocoa\nimport Combine\n\n@propertyWrapper\nfinal class CodableUserDefault: NSObject {\n var wrappedValue: T? {\n get {\n guard let data = userDefaults.data(forKey: key) else { return nil }\n return try? JSONDecoder().decode(T.self, from: data)\n }\n\n set {\n do {\n let data = try JSONEncoder().encode(newValue)\n\n userDefaults.setValue(data, forKey: key)\n } catch {\n print(\"Unable to Encode (\\(error))\")\n }\n }\n }\n\n private let key: String\n private let userDefaults: UserDefaults\n private var observerContext = 0\n private let subject: CurrentValueSubject\n\n init(wrappedValue defaultValue: T, _ key: String, userDefaults: UserDefaults = .standard) {\n self.key = key\n self.userDefaults = userDefaults\n subject = CurrentValueSubject(defaultValue)\n\n super.init()\n\n do {\n try userDefaults.register(defaults: [key: JSONEncoder().encode(defaultValue)])\n // This fulfills requirement 4. Some implementations use NSUserDefaultsDidChangeNotification\n // but that is sent every time any value is updated in UserDefaults.\n userDefaults.addObserver(self, forKeyPath: key, options: .new, context: &observerContext)\n } catch {\n print(\"Unable to register (\\(error))\")\n }\n\n subject.value = wrappedValue\n }\n\n override func observeValue(\n forKeyPath keyPath: String?,\n of object: Any?,\n change: [NSKeyValueChangeKey: Any]?,\n context: UnsafeMutableRawPointer?\n ) {\n if context == &observerContext {\n subject.value = wrappedValue\n } else {\n super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)\n }\n }\n\n deinit {\n userDefaults.removeObserver(self, forKeyPath: key, context: &observerContext)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/PreferencesView.swift", "import SwiftUI\nimport VisualEffects\n\nstruct PreferencesView: View {\n @EnvironmentObject var navigationVM: NavigationVM\n @EnvironmentObject var preferencesVM: PreferencesVM\n @EnvironmentObject var indicatorVM: IndicatorVM\n\n @State private var asyncSelection: NavigationVM.Nav = .general\n\n var body: some View {\n return HStack(spacing: 0) {\n ZStack {\n VisualEffectBlur(material: .sidebar, blendingMode: .behindWindow, state: .followsWindowActiveState)\n\n HStack {\n VStack {\n Button(action: {}) {\n // Trap default focus ring\n Text(\"Input Source Pro\")\n }\n\n Spacer()\n }\n Spacer()\n }\n .opacity(0)\n\n VStack(spacing: 12) {\n ForEach(NavigationVM.Nav.grouped, id: \\.id) { group in\n VStack(spacing: 2) {\n if !group.title.isEmpty {\n HStack {\n Text(group.title.i18n())\n .font(.system(size: 10))\n .opacity(0.6)\n Spacer()\n }\n .padding(.leading, 20)\n .padding(.bottom, 2)\n }\n\n ForEach(group.nav) { nav in\n let onSelect = { navigationVM.selection = nav }\n\n Button(action: onSelect) {\n Text(nav.displayName)\n }\n .buttonStyle(\n NavButtonStyle(\n icon: nav.icon,\n isActive: navigationVM.selection == nav\n )\n )\n }\n }\n }\n\n Spacer()\n\n Text(\" \\(preferencesVM.versionStr) (\\(preferencesVM.buildStr))\")\n .opacity(0.5)\n .font(.system(size: 12))\n }\n .padding(.top, 40)\n .padding(.vertical)\n }\n .frame(width: 200)\n\n HStack {\n VStack(spacing: 0) {\n HStack {\n SwiftUI.Image(systemName: asyncSelection.icon)\n .font(.system(size: 18, weight: .medium))\n .opacity(0.8)\n .frame(width: 20)\n\n VStack(alignment: .leading, spacing: 0) {\n Text(\"Input Source Pro\")\n .font(.system(size: 12, weight: .semibold))\n .opacity(0.8)\n\n Text(asyncSelection.displayName)\n .font(.system(size: 11))\n .opacity(0.6)\n }\n\n Spacer()\n }\n .frame(height: 52)\n .padding(.horizontal)\n .border(width: 1, edges: [.bottom], color: NSColor.border.color)\n\n asyncSelection.getView()\n Spacer(minLength: 0)\n }\n\n Spacer(minLength: 0)\n }\n .border(width: 1, edges: [.leading], color: NSColor.border.color)\n }\n .frame(minWidth: 780, minHeight: 620)\n .background(NSColor.background.color)\n .environment(\\.managedObjectContext, preferencesVM.container.viewContext)\n .onChange(of: navigationVM.selection) { _ in\n asyncSelection = navigationVM.selection\n }\n .onAppear {\n asyncSelection = navigationVM.selection\n }\n .edgesIgnoringSafeArea(.top)\n .modifier(FeedbackModal())\n }\n}\n\nextension NavigationVM.Nav {\n var icon: String {\n switch self {\n case .general:\n return \"slider.horizontal.3\"\n\n case .appRules:\n return \"square.grid.2x2\"\n\n case .browserRules:\n return \"safari\"\n\n case .position:\n return \"arrow.up.and.down.and.arrow.left.and.right\"\n\n case .appearance:\n return \"paintbrush\"\n\n case .inputSourcesColorScheme:\n return \"paintpalette\"\n\n case .keyboardShortcut:\n return \"command\"\n\n case .troubleshooting:\n return \"ladybug\"\n }\n }\n\n var displayName: String {\n switch self {\n case .inputSourcesColorScheme:\n return \"Color Scheme\".i18n()\n default:\n return rawValue.i18n()\n }\n }\n\n @ViewBuilder\n func getView() -> some View {\n switch self {\n case .general:\n GeneralSettingsView()\n\n case .appRules:\n RulesSettingsView()\n\n case .browserRules:\n BrowserRulesSettingsView()\n\n case .position:\n PositionSettingsView()\n\n case .appearance:\n AppearanceSettingsView()\n\n case .inputSourcesColorScheme:\n InputSourcesAppearanceSettingsView()\n\n case .keyboardShortcut:\n KeyboardsSettingsView()\n\n case .troubleshooting:\n TroubleshootingSettingsView()\n }\n }\n}\n\nstruct NavButtonStyle: ButtonStyle {\n let icon: String\n\n let isActive: Bool\n\n func makeBody(configuration: Self.Configuration) -> some View {\n HStack {\n VStack {\n SwiftUI.Image(systemName: icon)\n .font(.system(size: 15, weight: .medium))\n .frame(width: 15, height: 15)\n .opacity(0.9)\n }\n\n configuration.label\n .lineLimit(1)\n\n Spacer()\n }\n .padding(.leading, 10)\n .padding(.trailing, 5)\n .padding(.vertical, 8)\n .frame(maxWidth: .infinity)\n .background(isActive ? Color.gray.opacity(0.2) : Color.clear)\n .background(configuration.isPressed ? Color.gray.opacity(0.1) : Color.clear)\n .foregroundColor(Color.primary)\n .clipShape(RoundedRectangle(cornerRadius: 6))\n .contentShape(Rectangle())\n .padding(.horizontal, 10)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/TroubleshootingSettingsView.swift", "import SwiftUI\n\nstruct TroubleshootingSettingsView: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n @State var isShowCJKVFixEnableFailedView = false\n\n var body: some View {\n let isCJKVFixEnabledBinding = Binding(\n get: { preferencesVM.preferences.isCJKVFixEnabled },\n set: { onToggleCJKVFix($0) }\n )\n\n ScrollView {\n VStack(spacing: 18) {\n SettingsSection(title: \"\") {\n VStack(alignment: .leading) {\n HStack {\n Toggle(\"\", isOn: isCJKVFixEnabledBinding)\n .disabled(!preferencesVM.preferences.isEnhancedModeEnabled)\n .toggleStyle(.switch)\n .labelsHidden()\n\n Text(\"Enabled CJKV Fix\".i18n())\n .font(.headline)\n\n Spacer()\n\n EnhancedModeRequiredBadge()\n }\n\n Text(.init(\"Enabled CJKV Fix Description\".i18n()))\n .font(.system(size: 12))\n .opacity(0.8)\n }\n .padding()\n }\n \n SettingsSection(title: \"\") {\n CursorLagFixView()\n }\n\n SettingsSection(title: \"\") {\n FeedbackButton()\n }\n }\n .padding()\n }\n .background(NSColor.background1.color)\n .sheet(isPresented: $isShowCJKVFixEnableFailedView) {\n CJKVFixEnableFailedView(isPresented: $isShowCJKVFixEnableFailedView)\n }\n }\n\n func onToggleCJKVFix(_ isCJKVFixEnabled: Bool) {\n if isCJKVFixEnabled {\n if InputSource.getSelectPreviousShortcut() == nil {\n isShowCJKVFixEnableFailedView = true\n } else {\n preferencesVM.update {\n $0.isCJKVFixEnabled = true\n }\n }\n } else {\n preferencesVM.update {\n $0.isCJKVFixEnabled = false\n }\n }\n }\n}\n\nenum CursorSettingStatus {\n case enabled\n case disabled\n case undefined\n case unknown\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSImage+Extension.swift", "import AppKit\n\nextension NSImage {\n func markTemplateIfGrayScaleOrPdf(url: URL? = nil) -> NSImage {\n let image = copy() as! NSImage\n\n if url?.pathExtension == \"pdf\" || isGrayScale() {\n image.isTemplate = true\n }\n\n return image\n }\n\n func isGrayScale() -> Bool {\n guard let imageRef = cgImage(),\n let colorSpace = imageRef.colorSpace\n else { return false }\n\n if colorSpace.model == .monochrome {\n return true\n }\n\n guard let imageData = imageRef.dataProvider?.data,\n let rawData = CFDataGetBytePtr(imageData)\n else { return false }\n\n var byteIndex = 0\n\n for _ in 0 ..< imageRef.width * imageRef.height {\n let r = rawData[byteIndex]\n let g = rawData[byteIndex + 1]\n let b = rawData[byteIndex + 2]\n\n if r == g && g == b {\n byteIndex += 4\n } else {\n return false\n }\n }\n\n return true\n }\n\n func cgImage() -> CGImage? {\n var rect = CGRect(origin: .zero, size: size)\n return cgImage(forProposedRect: &rect, context: nil, hints: nil)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/CJKVFixEnableFailedView.swift", "import SwiftUI\n\nstruct CJKVFixEnableFailedView: View {\n @Binding var isPresented: Bool\n\n @State var isOpened = false\n\n var body: some View {\n VStack(spacing: 0) {\n Text(\"Enabled CJKV Fix Failed Desc\")\n\n Image(\"Enabled CJKV Fix Shortcut Img\".i18n())\n .resizable()\n .aspectRatio(contentMode: .fit)\n .shadow(color: .black.opacity(0.26), radius: 8)\n .padding(20)\n\n HStack {\n Spacer()\n\n if isOpened {\n Button(\"Close\", action: { isPresented = false })\n .keyboardShortcut(.defaultAction)\n } else {\n Button(\"Cancel\", action: { isPresented = false })\n .keyboardShortcut(.cancelAction)\n\n Button(\"Open Keyboard Settings\", action: {\n NSWorkspace.shared.openKeyboardPreferences()\n isOpened = true\n })\n .keyboardShortcut(.defaultAction)\n }\n }\n }\n .padding()\n .frame(width: 480)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Controllers/PreferencesWindowController.swift", "import AppKit\nimport SwiftUI\n\n@MainActor\nclass PreferencesWindowController: NSWindowController {\n let navigationVM: NavigationVM\n let permissionsVM: PermissionsVM\n let preferencesVM: PreferencesVM\n let indicatorVM: IndicatorVM\n let feedbackVM: FeedbackVM\n let inputSourceVM: InputSourceVM\n\n init(\n navigationVM: NavigationVM,\n permissionsVM: PermissionsVM,\n preferencesVM: PreferencesVM,\n indicatorVM: IndicatorVM,\n feedbackVM: FeedbackVM,\n inputSourceVM: InputSourceVM\n ) {\n self.navigationVM = navigationVM\n self.permissionsVM = permissionsVM\n self.preferencesVM = preferencesVM\n self.indicatorVM = indicatorVM\n self.feedbackVM = feedbackVM\n self.inputSourceVM = inputSourceVM\n\n let window = NSWindow(\n contentViewController: NSHostingController(\n rootView: PreferencesView()\n .environmentObject(navigationVM)\n .environmentObject(preferencesVM)\n .environmentObject(indicatorVM)\n .environmentObject(permissionsVM)\n .environmentObject(feedbackVM)\n .environmentObject(inputSourceVM)\n )\n )\n\n super.init(window: window)\n\n window.delegate = self\n\n configureWindow()\n }\n\n @available(*, unavailable)\n required init?(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n\n private func configureWindow() {\n window?.standardWindowButton(NSWindow.ButtonType.zoomButton)?.isEnabled = false\n window?.standardWindowButton(NSWindow.ButtonType.miniaturizeButton)?.isEnabled = false\n\n window?.title = \"Input Source Pro\"\n window?.titleVisibility = .hidden\n window?.titlebarAppearsTransparent = true\n window?.styleMask.insert(.fullSizeContentView)\n }\n}\n\nextension PreferencesWindowController: NSWindowDelegate {\n func windowWillClose(_: Notification) {\n NSApp.setActivationPolicy(.accessory)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Accessibility/AXSwift+Browser.swift", "import AXSwift\nimport Cocoa\n\nextension UIElement {\n func domIdentifier() -> String? {\n return safeString(attribute: .identifier)\n }\n\n func firefoxDomIdentifier() -> String? {\n return safeString(attribute: \"AXDOMIdentifier\")\n }\n\n func safeString(attribute attr: Attribute) -> String? {\n if let anyObject: AnyObject = try? attribute(attr),\n CFGetTypeID(anyObject) == CFStringGetTypeID()\n {\n return anyObject as? String\n } else {\n return nil\n }\n }\n\n func safeString(attribute attr: String) -> String? {\n if let anyObject: AnyObject = try? attribute(attr),\n CFGetTypeID(anyObject) == CFStringGetTypeID()\n {\n return anyObject as? String\n } else {\n return nil\n }\n }\n\n func domClassList() -> [String] {\n if let rawDOMClassList: AnyObject = try? attribute(\"AXDOMClassList\"),\n CFGetTypeID(rawDOMClassList) == CFArrayGetTypeID(),\n let domClassList1 = rawDOMClassList as? [AnyObject],\n let rawDOMClass = domClassList1.first,\n CFGetTypeID(rawDOMClass) == CFStringGetTypeID(),\n let domClassList = domClassList1 as? [String]\n {\n return domClassList\n } else {\n return []\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/UserDefault.swift", "// https://gist.github.com/simonbs/61c8269e1b0550feab606ee9890fa72b\nimport Cocoa\nimport Combine\n\n@propertyWrapper\nfinal class UserDefault: NSObject {\n // This ensures requirement 1 is fulfilled. The wrapped value is stored in user defaults.\n var wrappedValue: T {\n get {\n return userDefaults.object(forKey: key) as! T\n }\n set {\n userDefaults.setValue(newValue, forKey: key)\n }\n }\n\n var projectedValue: AnyPublisher {\n return subject.eraseToAnyPublisher()\n }\n\n private let key: String\n private let userDefaults: UserDefaults\n private var observerContext = 0\n private let subject: CurrentValueSubject\n\n init(wrappedValue defaultValue: T, _ key: String, userDefaults: UserDefaults = .standard) {\n self.key = key\n self.userDefaults = userDefaults\n subject = CurrentValueSubject(defaultValue)\n super.init()\n userDefaults.register(defaults: [key: defaultValue])\n // This fulfills requirement 4. Some implementations use NSUserDefaultsDidChangeNotification\n // but that is sent every time any value is updated in UserDefaults.\n userDefaults.addObserver(self, forKeyPath: key, options: .new, context: &observerContext)\n subject.value = wrappedValue\n }\n\n override func observeValue(\n forKeyPath keyPath: String?,\n of object: Any?,\n change: [NSKeyValueChangeKey: Any]?,\n context: UnsafeMutableRawPointer?\n ) {\n if context == &observerContext {\n subject.value = wrappedValue\n } else {\n super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)\n }\n }\n\n deinit {\n userDefaults.removeObserver(self, forKeyPath: key, context: &observerContext)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/PreferencesVM+HotKeyGroup.swift", "import AppKit\nimport AXSwift\nimport Foundation\n\nextension PreferencesVM {\n func addHotKeyGroup(\n inputSources: [InputSource]\n ) {\n let rule = HotKeyGroup(context: container.viewContext)\n\n rule.createdAt = Date()\n rule.id = UUID().uuidString\n rule.inputSources = inputSources\n\n saveContext()\n }\n\n func deleteHotKeyGroup(_ group: HotKeyGroup) {\n container.viewContext.delete(group)\n saveContext()\n }\n\n func updateHotKeyGroup(\n _ group: HotKeyGroup,\n inputSources: [InputSource]\n ) {\n saveContext {\n group.inputSources = inputSources\n }\n }\n\n func getHotKeyGroups() -> [HotKeyGroup] {\n let request = NSFetchRequest(entityName: \"HotKeyGroup\")\n\n do {\n return try container.viewContext.fetch(request)\n } catch {\n print(\"getHotKeyGroups() error: \\(error.localizedDescription)\")\n return []\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSRunningApplication+FocusedElement.swift", "import AXSwift\nimport Cocoa\n\nextension NSRunningApplication {\n @MainActor\n func focusedUIElement(preferencesVM: PreferencesVM?) -> UIElement? {\n return focuedUIElement(application: getApplication(preferencesVM: preferencesVM))\n }\n\n @MainActor\n func focuedUIElement(application: Application?) -> UIElement? {\n if let application = application {\n return try? application.attribute(.focusedUIElement)\n } else {\n return nil\n }\n }\n\n @MainActor\n func getApplication(preferencesVM: PreferencesVM?) -> Application? {\n if let preferencesVM = preferencesVM,\n preferencesVM.preferences.isEnhancedModeEnabled,\n !NSApplication.isFloatingApp(bundleIdentifier)\n {\n return Application(self)\n } else {\n return nil\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/IndicatorPositionEditor.swift", "import SwiftUI\nimport VisualEffects\n\nstruct IndicatorPositionEditor: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n let columns = Array(repeating: GridItem(.flexible(), spacing: 0), count: 3)\n\n @State var hoveredAlignment: IndicatorPosition.Alignment? = nil\n\n let height: CGFloat = 230\n let windowHPadding: CGFloat = 30\n let windowVPadding: CGFloat = 15\n\n var selectedAlignment: IndicatorPosition.Alignment {\n preferencesVM.preferences.indicatorPositionAlignment ?? .bottomRight\n }\n\n var position: IndicatorPosition {\n preferencesVM.preferences.indicatorPosition ?? .nearMouse\n }\n\n var alignmentHPadding: CGFloat {\n let offset = position == .windowCorner ? windowHPadding : 0\n let minLength = position == .windowCorner ? height - offset * 2 : height\n let spacing = preferencesVM.calcSpacing(minLength: minLength)\n\n return spacing + offset\n }\n\n var alignmentVPadding: CGFloat {\n let offset = position == .windowCorner ? windowVPadding : 0\n let minLength = position == .windowCorner ? height - offset * 2 : height\n let spacing = preferencesVM.calcSpacing(minLength: minLength)\n\n return spacing + offset\n }\n\n let items: [IndicatorPosition.Alignment] = [\n .topLeft, .topCenter, .topRight,\n .centerLeft, .center, .centerRight,\n .bottomLeft, .bottomCenter, .bottomRight,\n ]\n\n var body: some View {\n LazyVGrid(columns: columns, spacing: 0) {\n ForEach(items, id: \\.self) { (alignment: IndicatorPosition.Alignment) in\n IndicatorAlignmentItem(\n alignment: alignment,\n position: position,\n isSelected: selectedAlignment == alignment,\n content: {\n let offset = offset(alignment: alignment)\n\n alignment.indicator()\n .rotationEffect(alignment.rotate)\n .offset(x: offset.x, y: offset.y)\n .foregroundColor(Color.primary)\n }\n )\n .frame(height: height / 3)\n .onTapGesture {\n withAnimation {\n preferencesVM.update {\n $0.indicatorPositionAlignment = alignment\n }\n }\n }\n }\n .opacity(position == .nearMouse ? 0 : 1)\n }\n .background(\n IndicatorAlignmentView(\n alignment: position == .nearMouse ? .center : selectedAlignment\n ) {\n IndicatorView()\n .fixedSize()\n .padding(.horizontal, alignmentHPadding)\n .padding(.vertical, alignmentVPadding)\n }\n )\n .background(\n windowIndicator()\n )\n .background(\n Image(\"FakeDesktop\")\n .resizable()\n .aspectRatio(contentMode: .fill)\n .scaledToFill()\n )\n }\n\n @ViewBuilder\n func windowIndicator() -> some View {\n MockWindowView()\n .padding(.horizontal, windowHPadding)\n .padding(.vertical, windowVPadding)\n .frame(height: height)\n .opacity(position == .windowCorner ? 1 : 0)\n .offset(x: 0, y: position == .windowCorner ? 0 : height)\n }\n\n func offset(alignment: IndicatorPosition.Alignment) -> (x: Double, y: Double) {\n switch alignment {\n case .center:\n return (0, 0)\n case .centerLeft:\n return (alignmentHPadding, 0)\n case .centerRight:\n return (-alignmentHPadding, 0)\n case .topLeft:\n return (alignmentHPadding, alignmentVPadding)\n case .topCenter:\n return (0, alignmentVPadding)\n case .topRight:\n return (-alignmentHPadding, alignmentVPadding)\n case .bottomLeft:\n return (alignmentHPadding, -alignmentVPadding)\n case .bottomCenter:\n return (0, -alignmentVPadding)\n case .bottomRight:\n return (-alignmentHPadding, -alignmentVPadding)\n }\n }\n}\n\nstruct IndicatorAlignmentItem: View {\n let alignment: IndicatorPosition.Alignment\n\n let position: IndicatorPosition\n\n let isSelected: Bool\n\n let content: Content\n\n @State var isHovered: Bool = false\n\n init(alignment: IndicatorPosition.Alignment, position: IndicatorPosition, isSelected: Bool, @ViewBuilder content: () -> Content) {\n self.alignment = alignment\n self.position = position\n self.isSelected = isSelected\n self.content = content()\n }\n\n var body: some View {\n IndicatorAlignmentView(alignment: alignment) {\n content\n }\n .frame(maxWidth: .infinity, maxHeight: .infinity)\n .contentShape(Rectangle())\n .opacity(isSelected ? 0 : 1)\n .opacity(isHovered ? 0.9 : 0.3)\n .animation(.default, value: isSelected)\n .animation(.default, value: isHovered)\n .onHover(perform: { isHovered = $0 })\n }\n}\n\nprivate extension IndicatorPosition.Alignment {\n var rotate: Angle {\n switch self {\n case .topLeft:\n return .degrees(-90)\n case .topRight:\n return .zero\n case .bottomLeft:\n return .degrees(180)\n case .bottomRight:\n return .degrees(90)\n case .center:\n return .degrees(45)\n case .centerLeft:\n return .zero\n case .centerRight:\n return .zero\n case .topCenter:\n return .zero\n case .bottomCenter:\n return .zero\n }\n }\n\n @ViewBuilder\n func indicator() -> some View {\n switch self {\n case .center:\n RoundedRectangle(cornerRadius: 3)\n .frame(width: 30, height: 30)\n case .topCenter, .bottomCenter:\n RoundedRectangle(cornerRadius: 2)\n .frame(width: 44, height: 8)\n case .centerLeft, .centerRight:\n RoundedRectangle(cornerRadius: 2)\n .frame(width: 8, height: 30)\n default:\n Image(nsImage: .triangle)\n .resizable()\n .scaledToFit()\n .frame(width: 30)\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/KeyboardsSettingsView.swift", "import KeyboardShortcuts\nimport SwiftUI\n\nstruct KeyboardsSettingsView: View {\n @FetchRequest(sortDescriptors: [NSSortDescriptor(key: \"createdAt\", ascending: true)])\n var hotKeyGroups: FetchedResults\n\n @EnvironmentObject var preferencesVM: PreferencesVM\n @EnvironmentObject var indicatorVM: IndicatorVM\n\n let imgSize: CGFloat = 16\n\n var body: some View {\n ScrollView {\n VStack(spacing: 0) {\n normalSection\n groupSection\n AddSwitchingGroupButton(onSelect: preferencesVM.addHotKeyGroup)\n }\n .padding()\n }\n .background(NSColor.background1.color)\n }\n\n var normalSection: some View {\n ForEach(InputSource.sources, id: \\.id) { inputSource in\n SettingsSection(title: \"\") {\n HStack {\n CustomizedIndicatorView(inputSource: inputSource)\n .help(inputSource.id)\n\n Spacer()\n\n KeyboardShortcuts.Recorder(for: .init(inputSource.id), onChange: { _ in\n indicatorVM.refreshShortcut()\n })\n }\n .padding()\n }\n .padding(.bottom)\n }\n }\n\n var groupSection: some View {\n ForEach(hotKeyGroups, id: \\.self) { group in\n SettingsSection(title: \"\") {\n HStack(alignment: .top) {\n VStack(alignment: .leading) {\n ForEach(group.inputSources, id: \\.id) { inputSource in\n CustomizedIndicatorView(inputSource: inputSource)\n .help(inputSource.id)\n }\n }\n\n Spacer()\n\n VStack(alignment: .trailing) {\n KeyboardShortcuts.Recorder(for: .init(group.id!), onChange: { _ in\n indicatorVM.refreshShortcut()\n })\n\n HStack {\n Button(\"Delete\".i18n()) {\n deleteGroup(group: group)\n }\n }\n }\n }\n .padding()\n }\n .padding(.bottom)\n }\n }\n\n func deleteGroup(group: HotKeyGroup) {\n KeyboardShortcuts.reset([.init(group.id!)])\n preferencesVM.deleteHotKeyGroup(group)\n indicatorVM.refreshShortcut()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/PopUpButtonPicker.swift", "import AppKit\nimport SwiftUI\n\nstruct PickerItem: Equatable, Identifiable {\n static let mixed = PickerItem(id: \"mixed\", title: \"Mixed\", toolTip: nil)\n static let empty = PickerItem(id: \"\", title: \"\", toolTip: nil)\n\n let id: String\n let title: String\n let toolTip: String?\n}\n\nstruct PopUpButtonPicker: NSViewRepresentable {\n final class Coordinator: NSObject {\n private let parent: PopUpButtonPicker\n\n init(parent: PopUpButtonPicker) {\n self.parent = parent\n }\n\n @IBAction\n func selectItem(_ sender: NSPopUpButton) {\n parent.onSelect(sender.indexOfSelectedItem)\n }\n }\n\n let items: [Item]\n var width: CGFloat? = nil\n var isItemEnabled: (Item) -> Bool = { _ in true }\n let isItemSelected: (Item) -> Bool\n let getTitle: (Item) -> String\n let getToolTip: (Item) -> String?\n let onSelect: (Int) -> Void\n\n func makeCoordinator() -> Coordinator {\n Coordinator(parent: self)\n }\n\n func makeNSView(context: Self.Context) -> NSPopUpButton {\n let popUpButton = NSPopUpButton(frame: .zero, pullsDown: false)\n popUpButton.autoenablesItems = false\n popUpButton.target = context.coordinator\n popUpButton.action = #selector(Coordinator.selectItem(_:))\n\n if let width = width {\n popUpButton.snp.makeConstraints { make in\n make.width.equalTo(width)\n }\n }\n\n return popUpButton\n }\n\n func updateNSView(_ popUpButton: NSPopUpButton, context _: Self.Context) {\n popUpButton.removeAllItems()\n\n for item in items {\n let menuItem = NSMenuItem()\n\n // in order for this to work, autoenablesItems must be set to false\n menuItem.isEnabled = isItemEnabled(item)\n menuItem.title = getTitle(item)\n menuItem.toolTip = getToolTip(item)\n\n popUpButton.menu?.addItem(menuItem)\n }\n\n if let selectedIndex = items.firstIndex(where: isItemSelected) {\n popUpButton.selectItem(at: selectedIndex)\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/InputSourcesAppearanceSettingsView.swift", "import SwiftUI\n\nstruct InputSourcesAppearanceSettingsView: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n let imgSize: CGFloat = 16\n\n var body: some View {\n ScrollView {\n VStack(spacing: 18) {\n ForEach(InputSource.sources, id: \\.id) { inputSource in\n SettingsSection(title: inputSource.name, noI18N: true) {\n KeyboardCustomization(inputSource: inputSource)\n }\n }\n }\n .padding()\n .padding(.bottom)\n }\n .background(NSColor.background1.color)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/URL.swift", "import AppKit\n\nextension URL {\n static let newtab = URL(string: \"isp://newtab\")!\n\n func open() {\n NSWorkspace.shared.open(self)\n }\n\n func bundleId() -> String {\n Bundle(url: self)?.bundleIdentifier ?? dataRepresentation.md5()\n }\n\n func removeFragment() -> URL {\n var components = URLComponents(url: self, resolvingAgainstBaseURL: false)\n\n components?.fragment = nil\n\n return components?.url ?? self\n }\n}\n\nextension URL {\n static let website = URL(\n string: \"https://inputsource.pro\"\n )!\n\n static let purchase = URL(\n string: \"https://inputsource.pro/purchase\"\n )!\n\n static let twitter = URL(\n string: \"https://twitter.com/runjuuu\"\n )!\n\n static let emailString = \"support@inputsource.pro\"\n\n static let email = URL(string: \"mailto:\\(emailString)\")!\n\n static let howToEnableAccessbility = URL(\n string: \"https://inputsource.pro/help/enable-spotlight-like-apps-support\"\n )!\n\n static let howToEnableBrowserRule = URL(\n string: \"https://inputsource.pro/help/enable-browser-rule\"\n )!\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Indicator/IndicatorColor.swift", "import SwiftUI\n\nstruct IndicatorColor {\n let light: Color\n let dark: Color\n}\n\nextension IndicatorColor {\n var dynamicColor: NSColor {\n return NSColor(name: nil) { appearance in\n switch appearance.bestMatch(from: [.darkAqua]) {\n case .darkAqua?:\n return NSColor(self.dark)\n default:\n return NSColor(self.light)\n }\n }\n }\n}\n\nextension IndicatorColor {\n static let background = IndicatorColor(\n light: .white.opacity(0.95),\n dark: .black\n )\n\n static let forgeground = IndicatorColor(\n light: .black,\n dark: .white\n )\n}\n\nextension IndicatorColor: Codable {\n private enum CodingKeys: String, CodingKey { case light, dark }\n\n init(from decoder: Decoder) throws {\n let container = try decoder.container(keyedBy: CodingKeys.self)\n let lightStr = try container.decode(String.self, forKey: .light)\n let darkStr = try container.decode(String.self, forKey: .dark)\n\n light = Color(hex: lightStr)\n dark = Color(hex: darkStr)\n }\n\n func encode(to encoder: Encoder) throws {\n var container = encoder.container(keyedBy: CodingKeys.self)\n try container.encode(light.hexWithAlpha, forKey: .light)\n try container.encode(dark.hexWithAlpha, forKey: .dark)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/NSToggleView.swift", "import AppKit\nimport SwiftUI\n\nenum NSToggleViewState {\n case on, off, mixed\n\n var controlState: NSControl.StateValue {\n switch self {\n case .on:\n return .on\n case .mixed:\n return .mixed\n case .off:\n return .off\n }\n }\n}\n\nstruct NSToggleView: NSViewRepresentable {\n let label: String\n let state: NSToggleViewState\n let onStateUpdate: () -> NSControl.StateValue\n\n func makeCoordinator() -> Coordinator {\n Coordinator(parent: self)\n }\n\n func makeNSView(context: Self.Context) -> NSButton {\n let button = NSButton()\n\n button.title = label\n button.allowsMixedState = true\n button.setButtonType(.switch)\n button.target = context.coordinator\n button.action = #selector(Coordinator.onClick(_:))\n\n return button\n }\n\n func updateNSView(_ button: NSButton, context _: Self.Context) {\n button.title = label\n button.state = state.controlState\n }\n}\n\nextension NSToggleView {\n final class Coordinator: NSObject {\n private let parent: NSToggleView\n\n init(parent: NSToggleView) {\n self.parent = parent\n }\n\n @IBAction\n func onClick(_ sender: NSButton) {\n sender.state = parent.onStateUpdate()\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Persistence/HotKeyGroup.swift", "import Cocoa\n\nextension HotKeyGroup {\n private static let separator = \"∆\"\n\n private var ids: [String] {\n return inputSourceIds?.components(separatedBy: Self.separator) ?? []\n }\n\n @MainActor\n var inputSources: [InputSource] {\n get {\n return InputSource.sources\n .filter { ids.contains($0.id) }\n }\n set {\n inputSourceIds = newValue.map { $0.id }.joined(separator: Self.separator)\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSString.swift", "import Foundation\n\nextension String {\n func string(at atIndex: Int) -> String {\n guard !isEmpty else { return self }\n\n let offset = max(min(count - 1, atIndex), 0)\n\n return String(self[index(startIndex, offsetBy: offset)])\n }\n}\n\nextension String {\n func runCommand(\n requireSudo: Bool,\n completion: @escaping (_ output: String, _ errorOutput: String, _ exitCode: Int32) -> Void\n ) {\n let process = Process()\n let stdoutPipe = Pipe()\n let stderrPipe = Pipe()\n\n if requireSudo {\n let appleScript = \"\"\"\n do shell script \"\\(self.replacingOccurrences(of: \"\\\"\", with: \"\\\\\\\"\"))\" with administrator privileges\n \"\"\"\n process.launchPath = \"/usr/bin/osascript\"\n process.arguments = [\"-e\", appleScript]\n } else {\n process.launchPath = \"/bin/bash\"\n process.arguments = [\"-c\", self]\n }\n\n process.standardOutput = stdoutPipe\n process.standardError = stderrPipe\n\n process.terminationHandler = { proc in\n let outputData = stdoutPipe.fileHandleForReading.readDataToEndOfFile()\n let errorData = stderrPipe.fileHandleForReading.readDataToEndOfFile()\n \n let output = String(data: outputData, encoding: .utf8) ?? \"\"\n let errorOutput = String(data: errorData, encoding: .utf8) ?? \"\"\n let exitCode = proc.terminationStatus\n\n DispatchQueue.main.async {\n completion(output, errorOutput, exitCode)\n }\n }\n\n do {\n try process.run()\n } catch {\n DispatchQueue.main.async {\n completion(\"\", \"Process failed to start: \\(error)\", -1)\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/ApplicationVM+AXNotification.swift", "import AppKit\nimport AXSwift\nimport Combine\nimport Foundation\n\nextension ApplicationVM {\n static func createWindowAXNotificationPublisher(\n preferencesVM: PreferencesVM\n ) -> AnyPublisher {\n return preferencesVM.$preferences\n .flatMapLatest { preferences -> AnyPublisher in\n guard preferences.isEnhancedModeEnabled\n else { return Empty().eraseToAnyPublisher() }\n\n return NSWorkspace.shared\n .publisher(for: \\.runningApplications)\n .map { $0.filter { NSApplication.isFloatingApp($0.bundleIdentifier) } }\n .removeDuplicates()\n .flatMapLatest { apps in\n Publishers.MergeMany(apps\n .map {\n $0.watchAX(\n [.windowCreated, .uiElementDestroyed],\n [.application, .window]\n )\n }\n )\n }\n .eraseToAnyPublisher()\n }\n .share()\n .eraseToAnyPublisher()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Accessibility/QueryWebAreaService.swift", "import AXSwift\nimport Cocoa\nimport RxSwift\n\nclass QueryWebAreaService {\n let windowElement: Element\n\n init(windowElement: Element) {\n self.windowElement = windowElement\n }\n\n func perform() throws -> Element? {\n try fetchScrollArea()\n }\n\n private func fetchScrollArea() throws -> Element? {\n var stack: [Element] = [windowElement]\n\n while stack.count > 0 {\n let element = stack.popLast()!\n\n if element.role == \"AXWebArea\",\n element.url?.scheme != \"chrome-extension\"\n {\n return element\n }\n\n let children = try fetchChildren(element) ?? []\n for child in children {\n stack.append(child)\n }\n }\n\n return nil\n }\n\n private func fetchChildren(_ element: Element) throws -> [Element]? {\n let rawElementsOptional: [AXUIElement]? = try {\n if element.role == \"AXTable\" || element.role == \"AXOutline\" {\n return try UIElement(element.rawElement).attribute(.visibleRows)\n }\n return try UIElement(element.rawElement).attribute(.children)\n }()\n\n guard let rawElements = rawElementsOptional else {\n return nil\n }\n\n return rawElements\n .map { Element.initialize(rawElement: $0) }\n .compactMap { $0 }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/EnhancedModeToggle.swift", "import SwiftUI\n\nstruct EnhancedModeToggle: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n @EnvironmentObject var permissionsVM: PermissionsVM\n\n @State var isShowAccessibilityRequest = false\n\n var body: some View {\n let isDetectSpotlightLikeAppBinding = Binding(\n get: { preferencesVM.preferences.isEnhancedModeEnabled },\n set: { onNeedDetectSpotlightLikeApp($0) }\n )\n\n VStack(alignment: .leading) {\n HStack {\n Toggle(\"\", isOn: isDetectSpotlightLikeAppBinding)\n .sheet(isPresented: $isShowAccessibilityRequest) {\n AccessibilityPermissionRequestView(isPresented: $isShowAccessibilityRequest)\n }\n\n Text(\"Enhanced Mode\".i18n())\n\n Spacer()\n }\n\n Text(.init(\"Enhanced Mode Description\".i18n()))\n .font(.system(size: 12))\n .opacity(0.8)\n }\n .padding()\n }\n\n func onNeedDetectSpotlightLikeApp(_ isDetectSpotlightLikeApp: Bool) {\n preferencesVM.update {\n if isDetectSpotlightLikeApp {\n if permissionsVM.isAccessibilityEnabled {\n $0.isEnhancedModeEnabled = true\n } else {\n isShowAccessibilityRequest = true\n }\n } else {\n $0.isEnhancedModeEnabled = false\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Combine/Combine.swift", "import AppKit\nimport Combine\n\nextension Publisher {\n func tap(_ receiveOutput: @escaping (Output) -> Void) -> AnyPublisher {\n handleEvents(receiveOutput: { output in\n receiveOutput(output)\n })\n .eraseToAnyPublisher()\n }\n}\n\nextension Publisher {\n func mapTo(_ value: T) -> AnyPublisher {\n map { _ in value }\n .eraseToAnyPublisher()\n }\n}\n\nextension Publisher {\n typealias WithPrevious = (previous: T?, current: T)\n\n /// Includes the current element as well as the previous element from the upstream publisher in a tuple where the previous element is optional.\n /// The first time the upstream publisher emits an element, the previous element will be `nil`.\n ///\n /// ```\n /// let range = (1...5)\n /// let subscription = range.publisher\n /// .pairwise()\n /// .sink { print(\"(\\($0.previous), \\($0.current))\", terminator: \" \") }\n /// ```\n /// Prints: \"(nil, 1) (Optional(1), 2) (Optional(2), 3) (Optional(3), 4) (Optional(4), 5)\".\n ///\n /// - Returns: A publisher of a tuple of the previous and current elements from the upstream publisher.\n ///\n /// - Note: Based on .\n func withPrevious() -> AnyPublisher, Failure> {\n // `scan()` needs an initial value, which is `nil` in our case.\n // Therefore we have to return an optional here and use `compactMap()` below the remove the optional type.\n scan(nil) { previousPair, currentElement -> WithPrevious? in\n WithPrevious(previous: previousPair?.current, current: currentElement)\n }\n .compactMap { $0 }\n .eraseToAnyPublisher()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/LoopingPlayerNSView.swift", "import AppKit\nimport AVFoundation\nimport SwiftUI\n\nstruct PlayerView: NSViewRepresentable {\n let url: URL\n\n func updateNSView(_: NSViewType, context _: Context) {}\n\n func makeNSView(context _: Context) -> some NSView {\n return LoopingPlayerUIView(url: url)\n }\n}\n\nclass LoopingPlayerUIView: NSView {\n private let playerLayer = AVPlayerLayer()\n\n @available(*, unavailable)\n required init?(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n\n init(url: URL) {\n super.init(frame: .zero)\n\n // Setup the player\n let player = AVPlayer(url: url)\n playerLayer.player = player\n playerLayer.videoGravity = .resizeAspectFill\n\n wantsLayer = true\n layer?.addSublayer(playerLayer)\n\n // Setup looping\n player.actionAtItemEnd = .none\n NotificationCenter.default.addObserver(\n self,\n selector: #selector(playerItemDidReachEnd(notification:)),\n name: .AVPlayerItemDidPlayToEndTime,\n object: player.currentItem\n )\n\n // Start the movie\n player.play()\n }\n \n deinit {\n NotificationCenter.default.removeObserver(self)\n }\n\n @objc\n func playerItemDidReachEnd(notification _: Notification) {\n playerLayer.player?.seek(to: CMTime.zero)\n }\n\n override func layout() {\n super.layout()\n playerLayer.frame = bounds\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Indicator/IndicatorInfo.swift", "import Foundation\n\nenum IndicatorInfo: Int32, CaseIterable, Identifiable {\n case iconAndTitle = 0\n case iconOnly = 1\n case titleOnly = 2\n\n var id: Self { self }\n\n var name: String {\n switch self {\n case .iconAndTitle: return \"Icon and Title\".i18n()\n case .iconOnly: return \"Icon\".i18n()\n case .titleOnly: return \"Title\".i18n()\n }\n }\n}\n\nextension IndicatorInfo: Codable {\n private enum CodingKeys: String, CodingKey {\n case base\n }\n\n private enum Base: String, Codable {\n case iconAndTitle, iconOnly, titleOnly\n }\n\n func encode(to encoder: Encoder) throws {\n var container = encoder.container(keyedBy: CodingKeys.self)\n\n switch self {\n case .iconAndTitle:\n try container.encode(Base.iconAndTitle, forKey: .base)\n case .iconOnly:\n try container.encode(Base.iconOnly, forKey: .base)\n case .titleOnly:\n try container.encode(Base.titleOnly, forKey: .base)\n }\n }\n\n init(from decoder: Decoder) throws {\n let container = try decoder.container(keyedBy: CodingKeys.self)\n let base = try container.decode(Base.self, forKey: .base)\n\n switch base {\n case .iconAndTitle:\n self = .iconAndTitle\n case .iconOnly:\n self = .iconOnly\n case .titleOnly:\n self = .titleOnly\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Controllers/IndicatorViewController.swift", "import AppKit\nimport SnapKit\n\n@MainActor\nclass IndicatorViewController: NSViewController {\n let hoverableView = NSViewHoverable(frame: .zero)\n\n private(set) var config: IndicatorViewConfig? = nil {\n didSet {\n nextAlwaysOnView = config?.renderAlwaysOn()\n nextNormalView = config?.render()\n\n if normalView == nil || alwaysOnView == nil {\n refresh()\n }\n }\n }\n\n var fittingSize: CGSize? {\n nextNormalView?.fittingSize ?? normalView?.fittingSize\n }\n\n private(set) var nextNormalView: NSView? = nil\n private(set) var nextAlwaysOnView: NSView? = nil\n\n private(set) var normalView: NSView? = nil {\n didSet {\n oldValue?.removeFromSuperview()\n\n if let normalView = normalView {\n view.addSubview(normalView)\n\n normalView.snp.makeConstraints { make in\n let size = normalView.fittingSize\n\n make.edges.equalToSuperview()\n make.width.equalTo(size.width)\n make.height.equalTo(size.height)\n }\n }\n }\n }\n\n private(set) var alwaysOnView: NSView? = nil {\n didSet {\n oldValue?.removeFromSuperview()\n\n if let alwaysOnView = alwaysOnView {\n alwaysOnView.alphaValue = 0\n view.addSubview(alwaysOnView)\n\n alwaysOnView.snp.makeConstraints { make in\n make.leading.bottom.equalToSuperview()\n }\n }\n }\n }\n\n init() {\n super.init(nibName: nil, bundle: nil)\n }\n\n @available(*, unavailable)\n required init?(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n\n func prepare(config: IndicatorViewConfig) {\n self.config = config\n }\n\n func refresh() {\n if let nextNormalView = nextNormalView {\n normalView = nextNormalView\n self.nextNormalView = nil\n }\n\n if let nextAlwaysOnView = nextAlwaysOnView {\n alwaysOnView = nextAlwaysOnView\n self.nextAlwaysOnView = nil\n }\n }\n\n func showAlwaysOnView() {\n normalView?.animator().alphaValue = 0\n alwaysOnView?.animator().alphaValue = 1\n }\n\n override func loadView() {\n view = hoverableView\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/FeedbackVM.swift", "import Alamofire\nimport SwiftUI\n\n@MainActor\nfinal class FeedbackVM: ObservableObject {\n enum Status {\n case hided, editing, sending, sent\n }\n\n var isSent: Bool { status == .sent }\n\n var isSending: Bool { status == .sending }\n\n var isPresented: Bool { status != .hided }\n\n @Published private(set) var status = Status.hided\n\n @Published var message = \"\"\n\n @Published var email = \"\"\n\n func show() {\n if status == .hided {\n status = .editing\n }\n }\n\n func hide() {\n if status != .sending {\n status = .hided\n }\n }\n\n func sendFeedback() async {\n withAnimation {\n status = .sending\n }\n\n let _ = await AF\n .request(\n \"https://inputsource.pro/api/feedback\",\n method: .post,\n parameters: [\n \"message\": message,\n \"email\": email,\n \"version\": \"\\(Bundle.main.shortVersion) \\(Bundle.main.buildVersion)\",\n \"osVersion\": ProcessInfo.processInfo.operatingSystemVersionString,\n ],\n encoder: .json\n )\n .serializingDecodable(Alamofire.Empty.self, emptyResponseCodes: [200])\n .response\n\n message = \"\"\n email = \"\"\n\n withAnimation {\n status = .sent\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSScreen.swift", "import AppKit\n\nextension NSScreen {\n static func getScreenWithMouse() -> NSScreen? {\n let mouseLocation = NSEvent.mouseLocation\n let screens = NSScreen.screens\n\n return screens.first(where: { NSMouseInRect(mouseLocation, $0.frame, false) })\n }\n\n static func getScreenInclude(rect: CGRect) -> NSScreen? {\n return NSScreen.screens\n .map { screen in (screen, screen.frame.intersection(rect)) }\n .filter { _, intersect in !intersect.isNull }\n .map { screen, intersect in (screen, intersect.size.width * intersect.size.height) }\n .max { lhs, rhs in lhs.1 < rhs.1 }?.0\n }\n}\n\nextension NSScreen {\n /// The screen whose bottom left is at (0, 0).\n static var primary: NSScreen? {\n return NSScreen.screens.first\n }\n\n /// Converts the rectangle from Quartz \"display space\" to Cocoa \"screen space\".\n /// \n static func convertFromQuartz(_ rect: CGRect) -> CGRect? {\n return NSScreen.primary.map { screen in\n var result = rect\n result.origin.y = screen.frame.maxY - result.maxY\n return result\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppsDiff.swift", "import AppKit\nimport Combine\n\n@MainActor\nstruct AppsDiff {\n let removed: Set\n let added: Set\n let all: Set\n\n func diff(_ runningApps: Set) -> AppsDiff {\n let removedApps = all.subtracting(runningApps)\n let addedApps = runningApps.subtracting(all)\n\n return AppsDiff(removed: removedApps, added: addedApps, all: runningApps)\n }\n}\n\nextension AppsDiff {\n static var empty = AppsDiff(removed: [], added: [], all: [])\n\n static func publisher(preferencesVM: PreferencesVM) -> AnyPublisher {\n NSWorkspace.shared\n .publisher(for: \\.runningApplications)\n .map { apps in Set(preferencesVM.filterApps(apps)) }\n .scan(.empty) { appsDiff, runningApps -> AppsDiff in\n appsDiff.diff(runningApps)\n }\n .replaceError(with: .empty)\n .eraseToAnyPublisher()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/BrowserPermissionRequestView.swift", "import Combine\nimport SwiftUI\n\nstruct BrowserPermissionRequestView: View {\n @EnvironmentObject var permissionsVM: PermissionsVM\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n @Binding var isPresented: Bool\n\n @State var isDisableTips: Bool = true\n\n var onSuccess: () -> Void\n\n let timer = Timer\n .interval(seconds: 1)\n .mapToVoid()\n .ignoreFailure()\n .eraseToAnyPublisher()\n\n let fakeTimer = Empty(outputType: Void.self, failureType: Never.self)\n .eraseToAnyPublisher()\n\n var body: some View {\n VStack {\n Text(\"Permission Required\")\n .font(.title)\n .fontWeight(.medium)\n .padding(.vertical, 10)\n\n VStack(alignment: .leading) {\n Text(\"Browser Rules Accessibility Permission Description\")\n\n HStack {\n Spacer()\n\n if permissionsVM.isAccessibilityEnabled {\n SwiftUI.Image(systemName: \"checkmark.circle.fill\")\n .resizable()\n .frame(width: 16, height: 16)\n .foregroundColor(.green)\n\n Button(\"Authorized\", action: openAccessibilityPreferences)\n .disabled(true)\n } else {\n Button(\"Open Accessibility Preferences\", action: openAccessibilityPreferences)\n .keyboardShortcut(.defaultAction)\n }\n }\n .padding(.top, 5)\n }\n\n Divider()\n .padding(.vertical, 10)\n\n HStack {\n Button(action: URL.howToEnableBrowserRule.open) {\n SwiftUI.Image(systemName: \"questionmark\")\n }\n .font(.system(size: 10).weight(.bold))\n .frame(width: 18, height: 18)\n .clipShape(RoundedRectangle(cornerRadius: 99))\n .disabled(isDisableTips)\n\n Spacer()\n\n Button(\"Close\", action: close)\n .keyboardShortcut(.cancelAction)\n }\n }\n .lineLimit(nil)\n .fixedSize(horizontal: false, vertical: true)\n .padding()\n .frame(width: 400)\n .onAppear {\n DispatchQueue.main.async {\n isDisableTips = false\n }\n }\n .onChange(of: permissionsVM.isAccessibilityEnabled) { _ in\n onAuthorizeSuccess()\n }\n }\n\n func close() {\n isPresented = false\n }\n\n func openAccessibilityPreferences() {\n NSWorkspace.shared.openAccessibilityPreferences()\n }\n\n func openAutomationPreferences() {\n NSWorkspace.shared.openAutomationPreferences()\n }\n\n func onAuthorizeSuccess() {\n onSuccess()\n close()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Indicator/IndicatorSize.swift", "import AppKit\n\nenum IndicatorSize: Int32, CaseIterable, Identifiable {\n case small = 1\n case medium = 2\n case large = 3\n\n var displayName: String {\n switch self {\n case .small:\n return \"Small\".i18n()\n case .medium:\n return \"Medium\".i18n()\n case .large:\n return \"Large\".i18n()\n }\n }\n\n var id: Self { self }\n}\n\nextension IndicatorSize: Codable {\n private enum CodingKeys: String, CodingKey {\n case base\n }\n\n func encode(to encoder: Encoder) throws {\n var container = encoder.container(keyedBy: CodingKeys.self)\n try container.encode(rawValue, forKey: .base)\n }\n\n init(from decoder: Decoder) throws {\n let container = try decoder.container(keyedBy: CodingKeys.self)\n let rawValue = try container.decode(Int32.self, forKey: .base)\n\n self = Self(rawValue: rawValue)!\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/PositionSettingsView.swift", "import AVKit\nimport SwiftUI\n\nstruct PositionSettingsView: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n @EnvironmentObject var navigationVM: NavigationVM\n\n @Environment(\\.colorScheme) var colorScheme: ColorScheme\n\n @State var displayIndicatorNearCursorTips = false\n @State var displayAlwaysOnIndicatorTips = false\n @State private var width = CGFloat.zero\n\n var body: some View {\n let sliderBinding = Binding(\n get: {\n Double(preferencesVM.preferences.indicatorPositionSpacing?.rawValue ?? 3)\n },\n set: { newValue in\n withAnimation(.easeInOut(duration: 0.2)) {\n preferencesVM.update {\n $0.indicatorPositionSpacing = .fromSlide(value: newValue)\n }\n }\n }\n )\n\n let positionBinding = Binding(\n get: {\n preferencesVM.preferences.indicatorPosition ?? .nearMouse\n },\n set: { newValue in\n withAnimation(.easeInOut(duration: 0.3)) {\n preferencesVM.update {\n $0.indicatorPosition = newValue\n }\n }\n }\n )\n\n ScrollView {\n VStack(spacing: 18) {\n SettingsSection(title: \"Position\") {\n VStack(spacing: 0) {\n IndicatorPositionEditor()\n .clipShape(RoundedRectangle(cornerRadius: 6))\n .padding(.horizontal)\n .padding(.top)\n\n Picker(\"Position\", selection: positionBinding) {\n ForEach(IndicatorPosition.allCases) { item in\n Text(item.name).tag(item)\n }\n }\n .labelsHidden()\n .pickerStyle(.segmented)\n .padding()\n\n if preferencesVM.preferences.indicatorPosition != .nearMouse {\n HStack {\n Text(\"Spacing\".i18n() + \":\")\n .alignedView(width: $width, alignment: .leading)\n\n HStack {\n Slider(value: sliderBinding, in: 0 ... 5, step: 1)\n\n if let name = preferencesVM.preferences.indicatorPositionSpacing?.name {\n Text(name)\n .foregroundColor(.primary)\n .frame(width: 50, height: 25)\n .background(Color.primary.opacity(0.05))\n .clipShape(RoundedRectangle(cornerRadius: 6))\n .noAnimation()\n }\n }\n }\n .padding()\n .border(width: 1, edges: [.top, .bottom], color: NSColor.border2.color)\n\n HStack {\n Text(\"Alignment\".i18n() + \":\")\n .alignedView(width: $width, alignment: .leading)\n\n HStack {\n PopUpButtonPicker(\n items: IndicatorPosition.Alignment.allCases,\n isItemSelected: { $0 == preferencesVM.preferences.indicatorPositionAlignment },\n getTitle: { $0.name },\n getToolTip: { $0.name },\n onSelect: { index in\n withAnimation(.easeInOut(duration: 0.3)) {\n preferencesVM.update {\n let value = IndicatorPosition.Alignment.allCases[index]\n $0.indicatorPositionAlignment = value\n }\n }\n }\n )\n }\n }\n .padding()\n }\n }\n }\n\n SettingsSection(title: \"Advanced\", tips: EnhancedModeRequiredBadge()) {\n VStack(spacing: 0) {\n HStack {\n Toggle(isOn: $preferencesVM.preferences.tryToDisplayIndicatorNearCursor) {}\n .toggleStyle(.switch)\n .disabled(!preferencesVM.preferences.isEnhancedModeEnabled)\n\n Text(\"tryToDisplayIndicatorNearCursor\".i18n())\n\n Spacer()\n\n QuestionButton(\n content: {\n SwiftUI.Image(systemName: \"video\")\n .font(.system(size: 11, weight: .bold))\n .padding(6)\n },\n popover: {\n PlayerView(url: Bundle.main.url(\n forResource: \"Indicator-Near-Cursor-Demo-\\($0 == .dark ? \"Dark\" : \"Light\")\",\n withExtension: \"mp4\"\n )!)\n .frame(height: 118)\n\n Text(\"Enhanced Mode Required Tips\".i18n())\n .font(.footnote)\n .opacity(0.6)\n .padding(.vertical, 10)\n }\n )\n }\n .padding(.horizontal)\n .padding(.vertical, 10)\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n\n VStack {\n let needDisableAlwaysOnIndicator = !preferencesVM.preferences.isEnhancedModeEnabled || !preferencesVM.preferences.tryToDisplayIndicatorNearCursor\n\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.isEnableAlwaysOnIndicator)\n .disabled(needDisableAlwaysOnIndicator)\n .toggleStyle(.switch)\n .labelsHidden()\n\n Text(\"isEnableAlwaysOnIndicator\".i18n())\n\n Spacer()\n\n QuestionButton(\n content: {\n SwiftUI.Image(systemName: \"video\")\n .font(.system(size: 11, weight: .bold))\n .padding(6)\n },\n popover: {\n PlayerView(url: Bundle.main.url(\n forResource: \"Always-On-Indicator-Demo-\\($0 == .dark ? \"Dark\" : \"Light\")\",\n withExtension: \"mp4\"\n )!)\n .frame(height: 118)\n\n Text(\"alwaysOnIndicatorTips\".i18n())\n .font(.footnote)\n .padding(.vertical, 10)\n .opacity(0.6)\n }\n )\n }\n }\n .padding(.horizontal)\n .padding(.vertical, 10)\n }\n }\n }\n .padding()\n .padding(.bottom)\n }\n .onAppear(perform: updatePreviewModeOnAppear)\n .background(NSColor.background1.color)\n }\n\n func updatePreviewModeOnAppear() {\n if preferencesVM.preferences.isAutoAppearanceMode {\n preferencesVM.preferences.appearanceMode = colorScheme == .dark ? .dark : .light\n }\n }\n\n func resetColors() {\n if preferencesVM.preferences.appearanceMode == .light {\n preferencesVM.preferences.indicatorForgegroundColor = IndicatorColor.forgeground.light\n preferencesVM.preferences.indicatorBackgroundColor = IndicatorColor.background.light\n }\n\n if preferencesVM.preferences.appearanceMode == .dark {\n preferencesVM.preferences.indicatorForgegroundColor = IndicatorColor.forgeground.dark\n preferencesVM.preferences.indicatorBackgroundColor = IndicatorColor.background.dark\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/Color.swift", "// https://github.com/nbasham/BlackLabsSwiftUIColor/blob/main/Sources/BlackLabsSwiftUIColor/BlackLabsSwiftUIColor.swift\n\nimport SwiftUI\n\npublic extension Color {\n var hex: String { NSColor(self).hex }\n var hexWithAlpha: String { NSColor(self).hexWithAlpha }\n\n func hexDescription(_ includeAlpha: Bool = false) -> String {\n NSColor(self).hexDescription(includeAlpha)\n }\n}\n\npublic extension Color {\n /**\n Creates an immuatble `Color` instance specified by a hex string, CSS color name, or nil.\n\n - parameter hex: A case insensitive `String`? representing a hex or CSS value e.g.\n\n - **\"abc\"**\n - **\"abc7\"**\n - **\"#abc7\"**\n - **\"00FFFF\"**\n - **\"#00FFFF\"**\n - **\"00FFFF77\"**\n - **\"Orange\", \"Azure\", \"Tomato\"** Modern browsers support 140 color names ()\n - **\"Clear\"** [NSColor clearColor]\n - **\"Transparent\"** [NSColor clearColor]\n - **nil** [NSColor clearColor]\n - **empty string** [NSColor clearColor]\n */\n init(hex: String?) {\n self.init(NSColor(hex: hex))\n }\n}\n\nextension NSColor {\n /**\n Creates an immuatble `NSColor` instance specified by a hex string, CSS color name, or nil.\n\n - parameter hex: A case insensitive `String`? representing a hex or CSS value e.g.\n\n - **\"abc\"**\n - **\"abc7\"**\n - **\"#abc7\"**\n - **\"00FFFF\"**\n - **\"#00FFFF\"**\n - **\"00FFFF77\"**\n - **\"Orange\", \"Azure\", \"Tomato\"** Modern browsers support 140 color names ()\n - **\"Clear\"** [NSColor clearColor]\n - **\"Transparent\"** [NSColor clearColor]\n - **nil** [NSColor clearColor]\n - **empty string** [NSColor clearColor]\n */\n convenience init(hex: String?) {\n let normalizedHexString: String = NSColor.normalize(hex)\n var c: UInt64 = 0\n Scanner(string: normalizedHexString).scanHexInt64(&c)\n\n let cc = CUnsignedInt(c)\n\n self.init(\n red: NSColorMasks.redValue(cc),\n green: NSColorMasks.greenValue(cc),\n blue: NSColorMasks.blueValue(cc),\n alpha: NSColorMasks.alphaValue(cc)\n )\n }\n\n var hex: String { hexDescription(false) }\n var hexWithAlpha: String { hexDescription(true) }\n\n /**\n Returns a hex equivalent of this `NSColor`.\n\n - Parameter includeAlpha: Optional parameter to include the alpha hex, defaults to `false`.\n\n `color.hexDescription() -> \"ff0000\"`\n\n `color.hexDescription(true) -> \"ff0000aa\"`\n\n - Returns: A new string with `String` with the color's hexidecimal value.\n */\n func hexDescription(_ includeAlpha: Bool = false) -> String {\n guard cgColor.numberOfComponents == 4,\n let a = cgColor.components?.map({ Int($0 * CGFloat(255)) })\n else { return \"Color not RGB.\" }\n\n let color = String(format: \"%02x%02x%02x\", a[0], a[1], a[2])\n\n if includeAlpha {\n let alpha = String(format: \"%02x\", a[3])\n return \"\\(color)\\(alpha)\"\n }\n\n return color\n }\n\n fileprivate enum NSColorMasks: CUnsignedInt {\n case redMask = 0xFF00_0000\n case greenMask = 0x00FF_0000\n case blueMask = 0x0000_FF00\n case alphaMask = 0x0000_00FF\n\n static func redValue(_ value: CUnsignedInt) -> CGFloat {\n return CGFloat((value & redMask.rawValue) >> 24) / 255.0\n }\n\n static func greenValue(_ value: CUnsignedInt) -> CGFloat {\n return CGFloat((value & greenMask.rawValue) >> 16) / 255.0\n }\n\n static func blueValue(_ value: CUnsignedInt) -> CGFloat {\n return CGFloat((value & blueMask.rawValue) >> 8) / 255.0\n }\n\n static func alphaValue(_ value: CUnsignedInt) -> CGFloat {\n return CGFloat(value & alphaMask.rawValue) / 255.0\n }\n }\n\n fileprivate static func normalize(_ hex: String?) -> String {\n guard var hexString = hex else {\n return \"00000000\"\n }\n if let cssColor = cssToHexDictionary[hexString.uppercased()] {\n return cssColor.count == 8 ? cssColor : cssColor + \"ff\"\n }\n if hexString.hasPrefix(\"#\") {\n hexString = String(hexString.dropFirst())\n }\n if hexString.count == 3 || hexString.count == 4 {\n hexString = hexString.map { \"\\($0)\\($0)\" }.joined()\n }\n let hasAlpha = hexString.count > 7\n if !hasAlpha {\n hexString += \"ff\"\n }\n return hexString\n }\n\n /**\n All modern browsers support the following 140 color names (see http://www.w3schools.com/cssref/css_colornames.asp)\n */\n fileprivate static func hexFromCssName(_ cssName: String) -> String {\n let key = cssName.uppercased()\n if let hex = cssToHexDictionary[key] {\n return hex\n }\n return cssName\n }\n\n static let cssToHexDictionary: [String: String] = [\n \"CLEAR\": \"00000000\",\n \"TRANSPARENT\": \"00000000\",\n \"\": \"00000000\",\n \"ALICEBLUE\": \"F0F8FF\",\n \"ANTIQUEWHITE\": \"FAEBD7\",\n \"AQUA\": \"00FFFF\",\n \"AQUAMARINE\": \"7FFFD4\",\n \"AZURE\": \"F0FFFF\",\n \"BEIGE\": \"F5F5DC\",\n \"BISQUE\": \"FFE4C4\",\n \"BLACK\": \"000000\",\n \"BLANCHEDALMOND\": \"FFEBCD\",\n \"BLUE\": \"0000FF\",\n \"BLUEVIOLET\": \"8A2BE2\",\n \"BROWN\": \"A52A2A\",\n \"BURLYWOOD\": \"DEB887\",\n \"CADETBLUE\": \"5F9EA0\",\n \"CHARTREUSE\": \"7FFF00\",\n \"CHOCOLATE\": \"D2691E\",\n \"CORAL\": \"FF7F50\",\n \"CORNFLOWERBLUE\": \"6495ED\",\n \"CORNSILK\": \"FFF8DC\",\n \"CRIMSON\": \"DC143C\",\n \"CYAN\": \"00FFFF\",\n \"DARKBLUE\": \"00008B\",\n \"DARKCYAN\": \"008B8B\",\n \"DARKGOLDENROD\": \"B8860B\",\n \"DARKGRAY\": \"A9A9A9\",\n \"DARKGREY\": \"A9A9A9\",\n \"DARKGREEN\": \"006400\",\n \"DARKKHAKI\": \"BDB76B\",\n \"DARKMAGENTA\": \"8B008B\",\n \"DARKOLIVEGREEN\": \"556B2F\",\n \"DARKORANGE\": \"FF8C00\",\n \"DARKORCHID\": \"9932CC\",\n \"DARKRED\": \"8B0000\",\n \"DARKSALMON\": \"E9967A\",\n \"DARKSEAGREEN\": \"8FBC8F\",\n \"DARKSLATEBLUE\": \"483D8B\",\n \"DARKSLATEGRAY\": \"2F4F4F\",\n \"DARKSLATEGREY\": \"2F4F4F\",\n \"DARKTURQUOISE\": \"00CED1\",\n \"DARKVIOLET\": \"9400D3\",\n \"DEEPPINK\": \"FF1493\",\n \"DEEPSKYBLUE\": \"00BFFF\",\n \"DIMGRAY\": \"696969\",\n \"DIMGREY\": \"696969\",\n \"DODGERBLUE\": \"1E90FF\",\n \"FIREBRICK\": \"B22222\",\n \"FLORALWHITE\": \"FFFAF0\",\n \"FORESTGREEN\": \"228B22\",\n \"FUCHSIA\": \"FF00FF\",\n \"GAINSBORO\": \"DCDCDC\",\n \"GHOSTWHITE\": \"F8F8FF\",\n \"GOLD\": \"FFD700\",\n \"GOLDENROD\": \"DAA520\",\n \"GRAY\": \"808080\",\n \"GREY\": \"808080\",\n \"GREEN\": \"008000\",\n \"GREENYELLOW\": \"ADFF2F\",\n \"HONEYDEW\": \"F0FFF0\",\n \"HOTPINK\": \"FF69B4\",\n \"INDIANRED\": \"CD5C5C\",\n \"INDIGO\": \"4B0082\",\n \"IVORY\": \"FFFFF0\",\n \"KHAKI\": \"F0E68C\",\n \"LAVENDER\": \"E6E6FA\",\n \"LAVENDERBLUSH\": \"FFF0F5\",\n \"LAWNGREEN\": \"7CFC00\",\n \"LEMONCHIFFON\": \"FFFACD\",\n \"LIGHTBLUE\": \"ADD8E6\",\n \"LIGHTCORAL\": \"F08080\",\n \"LIGHTCYAN\": \"E0FFFF\",\n \"LIGHTGOLDENRODYELLOW\": \"FAFAD2\",\n \"LIGHTGRAY\": \"D3D3D3\",\n \"LIGHTGREY\": \"D3D3D3\",\n \"LIGHTGREEN\": \"90EE90\",\n \"LIGHTPINK\": \"FFB6C1\",\n \"LIGHTSALMON\": \"FFA07A\",\n \"LIGHTSEAGREEN\": \"20B2AA\",\n \"LIGHTSKYBLUE\": \"87CEFA\",\n \"LIGHTSLATEGRAY\": \"778899\",\n \"LIGHTSLATEGREY\": \"778899\",\n \"LIGHTSTEELBLUE\": \"B0C4DE\",\n \"LIGHTYELLOW\": \"FFFFE0\",\n \"LIME\": \"00FF00\",\n \"LIMEGREEN\": \"32CD32\",\n \"LINEN\": \"FAF0E6\",\n \"MAGENTA\": \"FF00FF\",\n \"MAROON\": \"800000\",\n \"MEDIUMAQUAMARINE\": \"66CDAA\",\n \"MEDIUMBLUE\": \"0000CD\",\n \"MEDIUMORCHID\": \"BA55D3\",\n \"MEDIUMPURPLE\": \"9370DB\",\n \"MEDIUMSEAGREEN\": \"3CB371\",\n \"MEDIUMSLATEBLUE\": \"7B68EE\",\n \"MEDIUMSPRINGGREEN\": \"00FA9A\",\n \"MEDIUMTURQUOISE\": \"48D1CC\",\n \"MEDIUMVIOLETRED\": \"C71585\",\n \"MIDNIGHTBLUE\": \"191970\",\n \"MINTCREAM\": \"F5FFFA\",\n \"MISTYROSE\": \"FFE4E1\",\n \"MOCCASIN\": \"FFE4B5\",\n \"NAVAJOWHITE\": \"FFDEAD\",\n \"NAVY\": \"000080\",\n \"OLDLACE\": \"FDF5E6\",\n \"OLIVE\": \"808000\",\n \"OLIVEDRAB\": \"6B8E23\",\n \"ORANGE\": \"FFA500\",\n \"ORANGERED\": \"FF4500\",\n \"ORCHID\": \"DA70D6\",\n \"PALEGOLDENROD\": \"EEE8AA\",\n \"PALEGREEN\": \"98FB98\",\n \"PALETURQUOISE\": \"AFEEEE\",\n \"PALEVIOLETRED\": \"DB7093\",\n \"PAPAYAWHIP\": \"FFEFD5\",\n \"PEACHPUFF\": \"FFDAB9\",\n \"PERU\": \"CD853F\",\n \"PINK\": \"FFC0CB\",\n \"PLUM\": \"DDA0DD\",\n \"POWDERBLUE\": \"B0E0E6\",\n \"PURPLE\": \"800080\",\n \"RED\": \"FF0000\",\n \"ROSYBROWN\": \"BC8F8F\",\n \"ROYALBLUE\": \"4169E1\",\n \"SADDLEBROWN\": \"8B4513\",\n \"SALMON\": \"FA8072\",\n \"SANDYBROWN\": \"F4A460\",\n \"SEAGREEN\": \"2E8B57\",\n \"SEASHELL\": \"FFF5EE\",\n \"SIENNA\": \"A0522D\",\n \"SILVER\": \"C0C0C0\",\n \"SKYBLUE\": \"87CEEB\",\n \"SLATEBLUE\": \"6A5ACD\",\n \"SLATEGRAY\": \"708090\",\n \"SLATEGREY\": \"708090\",\n \"SNOW\": \"FFFAFA\",\n \"SPRINGGREEN\": \"00FF7F\",\n \"STEELBLUE\": \"4682B4\",\n \"TAN\": \"D2B48C\",\n \"TEAL\": \"008080\",\n \"THISTLE\": \"D8BFD8\",\n \"TOMATO\": \"FF6347\",\n \"TURQUOISE\": \"40E0D0\",\n \"VIOLET\": \"EE82EE\",\n \"WHEAT\": \"F5DEB3\",\n \"WHITE\": \"FFFFFF\",\n \"WHITESMOKE\": \"F5F5F5\",\n \"YELLOW\": \"FFFF00\",\n \"YELLOWGREEN\": \"9ACD32\",\n ]\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/AppearanceSettingsView.swift", "import AVKit\nimport SwiftUI\n\nstruct AppearanceSettingsView: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n @EnvironmentObject var navigationVM: NavigationVM\n\n @Environment(\\.colorScheme) var colorScheme: ColorScheme\n\n @State private var width = CGFloat.zero\n\n var body: some View {\n let infoBinding = Binding(\n get: {\n preferencesVM.preferences.indicatorInfo ?? .iconAndTitle\n },\n set: { newValue in\n withAnimation(.easeInOut(duration: 0.3)) {\n preferencesVM.update {\n $0.indicatorInfo = newValue\n }\n }\n }\n )\n\n let sizeBinding = Binding(\n get: {\n preferencesVM.preferences.indicatorSize ?? .medium\n },\n set: { newValue in\n withAnimation(.easeInOut(duration: 0.3)) {\n preferencesVM.update {\n $0.indicatorSize = newValue\n }\n }\n }\n )\n\n ScrollView {\n VStack(alignment: .leading, spacing: 18) {\n SettingsSection(title: \"Indicator Info\") {\n VStack(spacing: 0) {\n ItemSection {\n IndicatorView()\n }\n .frame(height: 100)\n .padding(.horizontal)\n .padding(.top)\n\n Picker(\"Position\", selection: infoBinding) {\n ForEach(IndicatorInfo.allCases) { item in\n Text(item.name).tag(item)\n }\n }\n .labelsHidden()\n .pickerStyle(.segmented)\n .padding()\n }\n }\n\n SettingsSection(title: \"Indicator Size\") {\n Picker(\"Size\", selection: sizeBinding) {\n ForEach(IndicatorSize.allCases) { item in\n Text(item.displayName).tag(item)\n }\n }\n .labelsHidden()\n .pickerStyle(.segmented)\n .padding()\n }\n\n SettingsSection(title: \"Color Scheme\") {\n VStack(spacing: 0) {\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.isAutoAppearanceMode)\n .toggleStyle(.switch)\n .labelsHidden()\n\n Text(\"Sync with OS\".i18n())\n\n Spacer()\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n\n VStack(spacing: 16) {\n Picker(\"\", selection: $preferencesVM.preferences.appearanceMode) {\n Text(\"In Light Mode\".i18n()).tag(Optional(Preferences.AppearanceMode.light))\n Text(\"In Dark Mode\".i18n()).tag(Optional(Preferences.AppearanceMode.dark))\n }\n .labelsHidden()\n .pickerStyle(.segmented)\n\n ColorBlocks(\n onSelectColor: { scheme in\n preferencesVM.update {\n $0.indicatorForgegroundColor = scheme.a\n $0.indicatorBackgroundColor = scheme.b\n }\n }\n )\n\n ItemSection {\n IndicatorView()\n\n HStack {\n ColorPicker(\n \"Color\",\n selection: $preferencesVM.preferences.indicatorForgegroundColor\n )\n .labelsHidden()\n\n Button(\n action: {\n preferencesVM.update {\n let a = $0.indicatorForgegroundColor\n let b = $0.indicatorBackgroundColor\n\n $0.indicatorForgegroundColor = b\n $0.indicatorBackgroundColor = a\n }\n },\n label: {\n Image(systemName: \"repeat\")\n }\n )\n\n ColorPicker(\n \"Background\",\n selection: $preferencesVM.preferences.indicatorBackgroundColor\n )\n .labelsHidden()\n }\n }\n .frame(height: 130)\n }\n .padding()\n }\n }\n }\n .padding()\n .padding(.bottom)\n }\n .background(NSColor.background1.color)\n .onAppear(perform: updatePreviewModeOnAppear)\n .onDisappear {\n NSColorPanel.shared.close()\n }\n }\n\n func updatePreviewModeOnAppear() {\n if preferencesVM.preferences.isAutoAppearanceMode {\n preferencesVM.preferences.appearanceMode = colorScheme == .dark ? .dark : .light\n }\n }\n\n func resetColors() {\n if preferencesVM.preferences.appearanceMode == .light {\n preferencesVM.preferences.indicatorForgegroundColor = IndicatorColor.forgeground.light\n preferencesVM.preferences.indicatorBackgroundColor = IndicatorColor.background.light\n }\n\n if preferencesVM.preferences.appearanceMode == .dark {\n preferencesVM.preferences.indicatorForgegroundColor = IndicatorColor.forgeground.dark\n preferencesVM.preferences.indicatorBackgroundColor = IndicatorColor.background.dark\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Log/ISPLogger.swift", "import AppKit\nimport os\n\nclass ISPLogger {\n let category: String\n\n var disabled: Bool\n\n init(category: String, disabled: Bool = false) {\n self.category = category\n self.disabled = disabled\n }\n\n func debug(_ getString: () -> String) {\n if disabled { return }\n // TODO: - Add toggle\n #if DEBUG\n let str = getString()\n let formatter = DateFormatter()\n formatter.dateFormat = \"H:mm:ss.SSSS\"\n print(formatter.string(from: Date()), \"[\\(category)]\", str)\n #endif\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/PermissionsVM.swift", "import AppKit\nimport Combine\n\n@MainActor\nfinal class PermissionsVM: ObservableObject {\n @discardableResult\n static func checkAccessibility(prompt: Bool) -> Bool {\n let checkOptPrompt = kAXTrustedCheckOptionPrompt.takeUnretainedValue() as NSString\n return AXIsProcessTrustedWithOptions([checkOptPrompt: prompt] as CFDictionary?)\n }\n\n @Published var isAccessibilityEnabled = PermissionsVM.checkAccessibility(prompt: false)\n\n init() {\n watchAccessibilityChange()\n }\n\n private func watchAccessibilityChange() {\n guard !isAccessibilityEnabled else { return }\n\n Timer\n .interval(seconds: 1)\n .map { _ in Self.checkAccessibility(prompt: false) }\n .filter { $0 }\n .first()\n .assign(to: &$isAccessibilityEnabled)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/CursorLagFixView.swift", "import SwiftUI\n\nstruct CursorLagFixView: View {\n @State private var isCursorLagFixEnabled = false\n @State private var isRunningCommand = false\n @State private var isRebootRequired = false\n \n var body: some View {\n let toggleBinding = Binding(\n get: { isCursorLagFixEnabled },\n set: {\n isCursorLagFixEnabled = $0\n toggleRedesignedTextCursor(disable: $0)\n }\n )\n \n VStack(alignment: .leading, spacing: 12) {\n HStack {\n Toggle(\"\", isOn: toggleBinding)\n .disabled(isRunningCommand)\n .toggleStyle(.switch)\n .labelsHidden()\n \n Text(\"Cursor Lag Fix\".i18n())\n .font(.headline)\n \n Spacer()\n \n RebootRequiredBadge(isRequired: isRebootRequired)\n }\n \n Text(.init(\"Cursor Lag Fix Description\".i18n()))\n .font(.system(size: 12))\n .opacity(0.8)\n }\n .padding()\n .onAppear(perform: checkCursorSetting)\n }\n \n func toggleRedesignedTextCursor(disable: Bool) {\n guard !isRunningCommand else { return }\n \n let command = \"sudo defaults write /Library/Preferences/FeatureFlags/Domain/UIKit.plist redesigned_text_cursor -dict-add Enabled -bool \\(disable ? \"NO\" : \"YES\")\"\n \n isRunningCommand = true\n \n command.runCommand(\n requireSudo: true,\n completion: { _, _, _ in\n isRunningCommand = false\n isRebootRequired = true\n checkCursorSetting()\n }\n )\n }\n \n func checkCursorSetting() {\n guard !isRunningCommand else { return }\n \n let command = \"defaults read /Library/Preferences/FeatureFlags/Domain/UIKit.plist redesigned_text_cursor\"\n \n isRunningCommand = true\n \n command.runCommand(\n requireSudo: false,\n completion: { output, _, _ in\n isRunningCommand = false\n isCursorLagFixEnabled = output.contains(\"Enabled = 0\")\n }\n )\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Accessibility/Accessibility.swift", "import AppKit\nimport ApplicationServices\n\nextension AXValue {\n private func get(_ type: AXValueType, initial: T) -> T? {\n var result = initial\n return AXValueGetValue(self, type, &result) ? result : nil\n }\n\n var asPoint: CGPoint? { return get(.cgPoint, initial: .zero) }\n var asSize: CGSize? { return get(.cgSize, initial: .zero) }\n var asRect: CGRect? { return get(.cgRect, initial: .zero) }\n var asRange: CFRange? { return get(.cfRange, initial: CFRange()) }\n var asError: AXError? { return get(.axError, initial: .success) }\n\n private static func create(_ type: AXValueType, _ value: T) -> AXValue {\n var value = value\n return AXValueCreate(type, &value)!\n }\n\n static func point(_ v: CGPoint) -> AXValue { return create(.cgPoint, v) }\n static func size(_ v: CGSize) -> AXValue { return create(.cgSize, v) }\n static func rect(_ v: CGRect) -> AXValue { return create(.cgRect, v) }\n static func range(_ v: CFRange) -> AXValue { return create(.cfRange, v) }\n static func error(_ v: AXError) -> AXValue { return create(.axError, v) }\n}\n"], ["/InputSourcePro/Input Source Pro/Persistence/KeyboardConfig.swift", "import Cocoa\nimport SwiftUI\n\nextension KeyboardConfig {\n var textColor: Color? {\n get {\n if let hex = textColorHex {\n return Color(hex: hex)\n } else {\n return nil\n }\n }\n\n set {\n textColorHex = newValue?.hexWithAlpha\n }\n }\n\n var bgColor: Color? {\n get {\n if let hex = bgColorHex {\n return Color(hex: hex)\n } else {\n return nil\n }\n }\n\n set {\n bgColorHex = newValue?.hexWithAlpha\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/Data+SHA256.swift", "import CommonCrypto\nimport Foundation\n\nextension Data {\n public func sha256() -> String {\n return hexStringFromData(input: digest(input: self as NSData))\n }\n\n private func digest(input: NSData) -> NSData {\n let digestLength = Int(CC_SHA256_DIGEST_LENGTH)\n var hash = [UInt8](repeating: 0, count: digestLength)\n CC_SHA256(input.bytes, UInt32(input.length), &hash)\n return NSData(bytes: hash, length: digestLength)\n }\n\n private func hexStringFromData(input: NSData) -> String {\n var bytes = [UInt8](repeating: 0, count: input.length)\n input.getBytes(&bytes, length: input.length)\n\n var hexString = \"\"\n for byte in bytes {\n hexString += String(format: \"%02x\", UInt8(byte))\n }\n\n return hexString\n }\n}\n\npublic extension String {\n func sha256() -> String {\n if let stringData = data(using: String.Encoding.utf8) {\n return stringData.sha256()\n }\n return \"\"\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Window/FloatWindow.swift", "import AppKit\n\nclass FloatWindow: NSPanel {\n private let _canBecomeKey: Bool\n\n override var canBecomeKey: Bool {\n return _canBecomeKey\n }\n\n init(\n canBecomeKey: Bool,\n contentRect: CGRect,\n styleMask style: NSWindow.StyleMask,\n backing backingStoreType: NSWindow.BackingStoreType,\n defer flag: Bool\n ) {\n _canBecomeKey = canBecomeKey\n\n super.init(\n contentRect: contentRect,\n styleMask: style,\n backing: backingStoreType,\n defer: flag\n )\n\n level = .screenSaver\n\n hasShadow = false\n isOpaque = false\n backgroundColor = .clear\n isMovableByWindowBackground = true\n hidesOnDeactivate = false\n\n titleVisibility = .hidden\n titlebarAppearsTransparent = true\n\n styleMask.insert(.nonactivatingPanel)\n\n collectionBehavior = [\n .moveToActiveSpace,\n .fullScreenAuxiliary,\n .stationary,\n .ignoresCycle,\n ]\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Window/FloatWindowController.swift", "import AppKit\n\nclass FloatWindowController: NSWindowController, NSWindowDelegate {\n init(canBecomeKey: Bool = false) {\n super.init(window: FloatWindow(\n canBecomeKey: canBecomeKey,\n contentRect: CGRect(origin: .zero, size: .zero),\n styleMask: [.borderless, .fullSizeContentView, .nonactivatingPanel],\n backing: .buffered,\n defer: false\n ))\n\n window?.delegate = self\n window?.ignoresMouseEvents = true\n window?.standardWindowButton(.zoomButton)?.isEnabled = false\n window?.standardWindowButton(.miniaturizeButton)?.isEnabled = false\n }\n\n @available(*, unavailable)\n required init?(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n}\n\nextension FloatWindowController {\n func active() {\n window?.orderFront(nil)\n }\n\n func deactive() {\n window?.orderOut(nil)\n }\n\n func moveTo(point: CGPoint) {\n window?.setFrameOrigin(point)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Utilities/Border.swift", "import SwiftUI\n\nprivate struct EdgeBorder: Shape {\n var width: CGFloat\n var edges: [Edge]\n\n func path(in rect: CGRect) -> Path {\n var path = Path()\n for edge in edges {\n var x: CGFloat {\n switch edge {\n case .top, .bottom, .leading: return rect.minX\n case .trailing: return rect.maxX - width\n }\n }\n\n var y: CGFloat {\n switch edge {\n case .top, .leading, .trailing: return rect.minY\n case .bottom: return rect.maxY - width\n }\n }\n\n var w: CGFloat {\n switch edge {\n case .top, .bottom: return rect.width\n case .leading, .trailing: return width\n }\n }\n\n var h: CGFloat {\n switch edge {\n case .top, .bottom: return width\n case .leading, .trailing: return rect.height\n }\n }\n path.addPath(Path(CGRect(x: x, y: y, width: w, height: h)))\n }\n return path\n }\n}\n\nextension View {\n func border(width: CGFloat, edges: [Edge], color: Color) -> some View {\n overlay(EdgeBorder(width: width, edges: edges).foregroundColor(color))\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/AccessibilityPermissionRequestView.swift", "import SwiftUI\n\nstruct AccessibilityPermissionRequestView: View {\n @EnvironmentObject var permissionsVM: PermissionsVM\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n @Binding var isPresented: Bool\n\n @State var isDisableTips: Bool = true\n\n var body: some View {\n VStack(alignment: .leading) {\n Text(.init(\"Enhanced Mode Permission Description\".i18n()))\n .lineSpacing(4)\n\n HStack {\n Button(action: URL.howToEnableAccessbility.open) {\n SwiftUI.Image(systemName: \"questionmark\")\n }\n .font(.system(size: 10).weight(.bold))\n .frame(width: 18, height: 18)\n .clipShape(RoundedRectangle(cornerRadius: 99))\n .disabled(isDisableTips)\n\n Spacer()\n\n Button(\"Open Accessibility Preferences\") {\n NSWorkspace.shared.openAccessibilityPreferences()\n }\n .keyboardShortcut(.defaultAction)\n\n Button(\"Cancel\", action: cancel)\n .keyboardShortcut(.cancelAction)\n }\n .padding(.top)\n }\n .padding()\n .lineLimit(nil)\n .frame(width: 400)\n .onChange(of: permissionsVM.isAccessibilityEnabled, perform: whenAccessibilityEnabled)\n .onAppear {\n DispatchQueue.main.async {\n isDisableTips = false\n }\n }\n }\n\n func cancel() {\n isPresented = false\n }\n\n func whenAccessibilityEnabled(_ isAccessibilityEnabled: Bool) {\n if isAccessibilityEnabled {\n isPresented = false\n preferencesVM.update {\n $0.isEnhancedModeEnabled = true\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/SettingsSection.swift", "import SwiftUI\n\nstruct SettingsSection: View {\n let title: String\n\n let tips: Tips?\n\n let noI18N: Bool\n\n let content: Content\n\n init(title: String, noI18N: Bool = false, tips: Tips? = nil, @ViewBuilder _ content: () -> Content) {\n self.title = title\n self.noI18N = noI18N\n self.tips = tips\n self.content = content()\n }\n\n var body: some View {\n VStack(alignment: .leading) {\n if !title.isEmpty || tips != nil {\n HStack {\n if !title.isEmpty {\n Text(noI18N ? title : title.i18n())\n .opacity(0.8)\n }\n\n tips\n }\n .padding(.horizontal)\n }\n\n VStack(alignment: .leading, spacing: 0) {\n content\n }\n .frame(maxWidth: .infinity)\n .background(NSColor.background2.color)\n .clipShape(RoundedRectangle(cornerRadius: 8))\n .overlay(\n RoundedRectangle(cornerRadius: 8)\n .stroke(NSColor.border2.color, lineWidth: 1)\n )\n }\n }\n}\n\n// Support optional footer\nextension SettingsSection where Tips == EmptyView {\n init(title: String, noI18N: Bool = false, @ViewBuilder _ content: () -> Content) {\n self.title = title\n self.noI18N = noI18N\n tips = nil\n self.content = content()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Combine/Timer.swift", "import AppKit\nimport Combine\n\nextension Timer {\n static func delay(\n seconds: TimeInterval,\n tolerance _: TimeInterval? = nil,\n options _: RunLoop.SchedulerOptions? = nil\n ) -> AnyPublisher {\n return Timer.interval(seconds: seconds)\n .first()\n .eraseToAnyPublisher()\n }\n\n static func interval(\n seconds: TimeInterval\n ) -> AnyPublisher {\n return Timer.publish(every: seconds, on: .main, in: .common)\n .autoconnect()\n .ignoreFailure()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Accessibility/Element.swift", "import AXSwift\nimport Cocoa\n\nclass Element {\n let rawElement: AXUIElement\n let role: String\n let url: URL?\n\n var clippedFrame: NSRect?\n\n static func initialize(rawElement: AXUIElement) -> Element? {\n let uiElement = UIElement(rawElement)\n let valuesOptional = try? uiElement.getMultipleAttributes([.role, .url])\n\n guard let values = valuesOptional else { return nil }\n guard let role: String = values[Attribute.role] as! String? else { return nil }\n\n return Element(rawElement: rawElement, role: role, url: values[Attribute.url] as? URL)\n }\n\n init(rawElement: AXUIElement, role: String, url: URL?) {\n self.rawElement = rawElement\n self.role = role\n self.url = url\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSEvent.swift", "import AppKit\nimport Combine\n\nextension NSEvent {\n static func watch(matching: NSEvent.EventTypeMask) -> AnyPublisher {\n AnyPublisher\n .create { observer in\n let monitor = self.addGlobalMonitorForEvents(\n matching: matching,\n handler: { observer.send($0) }\n )\n\n return AnyCancellable { NSEvent.removeMonitor(monitor!) }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/FeedbackButton.swift", "import SwiftUI\n\nstruct FeedbackButton: View {\n @EnvironmentObject var feedbackVM: FeedbackVM\n\n var body: some View {\n Button(\n action: feedbackVM.show,\n label: {\n HStack {\n Text(\"Send Feedback\".i18n() + \"...\")\n Spacer()\n }\n }\n )\n .buttonStyle(SectionButtonStyle())\n }\n}\n\nstruct FeedbackModal: ViewModifier {\n @EnvironmentObject var feedbackVM: FeedbackVM\n\n func body(content: Content) -> some View {\n content\n .sheet(isPresented: .constant(feedbackVM.isPresented), content: {\n LoadingView(isShowing: feedbackVM.isSending) {\n VStack(alignment: .leading) {\n if feedbackVM.isSent {\n HStack {\n Spacer()\n\n VStack {\n Text(\"FeedbackSuccessTips\".i18n())\n .multilineTextAlignment(.center)\n .font(.system(size: 16))\n .padding(.horizontal)\n .padding(.vertical, 30)\n\n Button(\"Close\".i18n()) {\n feedbackVM.hide()\n }\n .keyboardShortcut(.defaultAction)\n .padding(.bottom)\n }\n\n Spacer()\n }\n } else {\n Text(\"FeedbackTips\".i18n())\n .foregroundColor(.primary.opacity(0.8))\n .padding(.vertical, 8)\n\n Text(\"FeedbackMessageTitle\".i18n() + \":\")\n\n ISPTextEditor(text: $feedbackVM.message, placeholder: \"FeedbackMessagePlaceholder\".i18n(), minHeight: 80)\n\n Text(\"FeedbackEmailTitle\".i18n() + \":\")\n .padding(.top, 8)\n\n ISPTextEditor(text: $feedbackVM.email, placeholder: \"support@inputsource.pro\", minHeight: 0)\n\n HStack {\n Spacer()\n\n Button(\"Cancel\".i18n()) {\n feedbackVM.hide()\n }\n .keyboardShortcut(.cancelAction)\n\n Button(\"Send Feedback\".i18n()) {\n Task {\n await feedbackVM.sendFeedback()\n }\n }\n .keyboardShortcut(.defaultAction)\n .disabled(feedbackVM.message.isEmpty)\n }\n .padding(.top)\n }\n }\n .lineLimit(nil)\n .padding()\n .fixedSize(horizontal: false, vertical: true)\n .frame(width: 450)\n .disabled(feedbackVM.isSending)\n }\n .background(NSColor.background.color)\n })\n }\n}\n"], ["/InputSourcePro/Input Source Pro/System/AppMenu.swift", "import Cocoa\n\nclass AppMenu: NSMenu {\n private lazy var applicationName = ProcessInfo.processInfo.processName\n\n override init(title: String) {\n super.init(title: title)\n\n let mainMenu = NSMenuItem()\n mainMenu.submenu = NSMenu(title: \"MainMenu\")\n mainMenu.submenu?.items = [\n NSMenuItem(title: \"About \\(applicationName)\", action: #selector(NSApplication.orderFrontStandardAboutPanel(_:)), keyEquivalent: \"\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Preferences...\", action: nil, keyEquivalent: \",\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Hide \\(applicationName)\", action: #selector(NSApplication.hide(_:)), keyEquivalent: \"h\"),\n NSMenuItem(title: \"Hide Others\", target: self, action: #selector(NSApplication.hideOtherApplications(_:)), keyEquivalent: \"h\", modifier: .init(arrayLiteral: [.command, .option])),\n NSMenuItem(title: \"Show All\", action: #selector(NSApplication.unhideAllApplications(_:)), keyEquivalent: \"\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Quit \\(applicationName)\", action: #selector(NSApplication.shared.terminate(_:)), keyEquivalent: \"q\"),\n ]\n\n let fileMenu = NSMenuItem()\n fileMenu.submenu = NSMenu(title: \"File\")\n fileMenu.submenu?.items = [\n NSMenuItem(title: \"New\", action: #selector(NSDocumentController.newDocument(_:)), keyEquivalent: \"n\"),\n NSMenuItem(title: \"Open\", action: #selector(NSDocumentController.openDocument(_:)), keyEquivalent: \"o\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Close\", action: #selector(NSWindow.performClose(_:)), keyEquivalent: \"w\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Save\", action: #selector(NSDocument.save(_:)), keyEquivalent: \"s\"),\n NSMenuItem(title: \"Save As...\", action: #selector(NSDocument.saveAs(_:)), keyEquivalent: \"S\"),\n NSMenuItem(title: \"Revert to Saved...\", action: #selector(NSDocument.revertToSaved(_:)), keyEquivalent: \"\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Export\", action: nil, keyEquivalent: \"\"),\n ]\n\n let editMenu = NSMenuItem()\n editMenu.submenu = NSMenu(title: \"Edit\")\n editMenu.submenu?.items = [\n NSMenuItem(title: \"Undo\", action: #selector(UndoManager.undo), keyEquivalent: \"z\"),\n NSMenuItem(title: \"Redo\", action: #selector(UndoManager.redo), keyEquivalent: \"Z\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Cut\", action: #selector(NSText.cut(_:)), keyEquivalent: \"x\"),\n NSMenuItem(title: \"Copy\", action: #selector(NSText.copy(_:)), keyEquivalent: \"c\"),\n NSMenuItem(title: \"Paste\", action: #selector(NSText.paste(_:)), keyEquivalent: \"v\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Select All\", action: #selector(NSText.selectAll(_:)), keyEquivalent: \"a\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Delete\", target: self, action: nil, keyEquivalent: \"⌫\", modifier: .init()),\n NSMenuItem(title: \"Duplicate\", action: #selector(NSApplication.copy), keyEquivalent: \"d\"),\n ]\n\n let windowMenu = NSMenuItem()\n windowMenu.submenu = NSMenu(title: \"Window\")\n windowMenu.submenu?.items = [\n NSMenuItem(title: \"Minimize\", action: #selector(NSWindow.miniaturize(_:)), keyEquivalent: \"m\"),\n NSMenuItem(title: \"Zoom\", action: #selector(NSWindow.performZoom(_:)), keyEquivalent: \"\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Show All\", action: #selector(NSApplication.arrangeInFront(_:)), keyEquivalent: \"m\"),\n ]\n\n let viewMenu = NSMenuItem()\n viewMenu.submenu = NSMenu(title: \"View\")\n viewMenu.submenu?.items = []\n\n let helpMenu = NSMenuItem()\n let helpMenuSearch = NSMenuItem()\n helpMenuSearch.view = NSTextField()\n helpMenu.submenu = NSMenu(title: \"Help\")\n helpMenu.submenu?.items = [\n helpMenuSearch,\n ]\n\n items = [mainMenu, fileMenu, editMenu, viewMenu, windowMenu, helpMenu]\n }\n\n @available(*, unavailable)\n required init(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/FileManager+Ext.swift", "import Foundation\n\nextension FileManager {\n func isDirectory(atPath path: String) -> Bool {\n let fileManager = FileManager.default\n var isDir: ObjCBool = false\n\n if fileManager.fileExists(atPath: path, isDirectory: &isDir) {\n return isDir.boolValue\n } else {\n return false\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/QuestionButton.swift", "import SwiftUI\n\nstruct QuestionButton: View {\n @State var displayTips = false\n\n @Environment(\\.colorScheme) var colorScheme: ColorScheme\n\n let content: () -> Content\n let popover: (ColorScheme) -> Popover\n\n init(\n @ViewBuilder content: @escaping () -> Content,\n @ViewBuilder popover: @escaping (ColorScheme) -> Popover\n ) {\n self.content = content\n self.popover = popover\n }\n\n var body: some View {\n Button(action: { displayTips.toggle() }) {\n content()\n .font(.body.bold())\n }\n .buttonStyle(QuestionButtonStyle())\n .popover(isPresented: $displayTips, arrowEdge: .top) {\n VStack(spacing: 0) {\n popover(colorScheme)\n }\n .frame(width: 280)\n }\n }\n}\n\nstruct QuestionButtonStyle: ButtonStyle {\n @State var isHover = false\n\n func makeBody(configuration: Configuration) -> some View {\n configuration.label\n .opacity(isHover ? 1 : 0.8)\n .background(Color.gray.opacity(configuration.isPressed ? 0.6 : isHover ? 0.3 : 0.15))\n .clipShape(Circle())\n .animation(.easeOut(duration: 0.2), value: configuration.isPressed)\n .onHover { hover in\n withAnimation {\n isHover = hover\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/NSViewHoverable.swift", "import AppKit\nimport Combine\n\nclass NSViewHoverable: NSView {\n private let hoverdSubject: PassthroughSubject\n\n let hoverdPublisher: AnyPublisher\n\n override init(frame frameRect: NSRect) {\n hoverdSubject = PassthroughSubject()\n hoverdPublisher = hoverdSubject.eraseToAnyPublisher()\n\n super.init(frame: frameRect)\n }\n\n @available(*, unavailable)\n required init?(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n\n override func updateTrackingAreas() {\n trackingAreas.forEach { removeTrackingArea($0) }\n\n addTrackingArea(\n NSTrackingArea(\n rect: bounds,\n options: [.activeAlways, .mouseMoved, .mouseEnteredAndExited],\n owner: self,\n userInfo: nil\n )\n )\n }\n\n override func mouseMoved(with _: NSEvent) {\n hoverdSubject.send(true)\n }\n\n override func mouseExited(with _: NSEvent) {\n hoverdSubject.send(false)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Utilities/ButtonStyle.swift", "import SwiftUI\n\nstruct GhostButton: ButtonStyle {\n @State var isHover = false\n\n let icon: Icon\n\n func makeBody(configuration: Configuration) -> some View {\n HStack(spacing: 4) {\n icon\n\n if isHover {\n configuration.label\n .scaleEffect(0.9)\n }\n }\n .padding(.vertical, 4)\n .padding(.horizontal, 6)\n .opacity(isHover ? 1 : 0.6)\n .background(Color.gray.opacity(configuration.isPressed ? 0.6 : isHover ? 0.3 : 0))\n .clipShape(Capsule())\n .animation(.easeOut(duration: 0.2), value: configuration.isPressed)\n .onHover { hover in\n withAnimation {\n isHover = hover\n }\n }\n }\n}\n\nstruct SectionButtonStyle: ButtonStyle {\n func makeBody(configuration: Self.Configuration) -> some View {\n configuration.label\n .padding()\n .frame(maxWidth: .infinity)\n .background(configuration.isPressed ? Color.gray.opacity(0.05) : Color.clear)\n .foregroundColor(Color.accentColor)\n .clipShape(RoundedRectangle(cornerRadius: 6))\n .contentShape(Rectangle())\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/i18n.swift", "import Foundation\n\nextension String {\n func i18n(\n comment: String = \"\",\n tableName: String = \"Localizable\"\n ) -> String {\n #if DEBUG\n let fallback = \"**\\(self)**\"\n #else\n let fallback = self\n #endif\n\n return NSLocalizedString(\n self,\n tableName: tableName,\n value: fallback,\n comment: comment\n )\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/PromotionBadge.swift", "import SwiftUI\n\nstruct PromotionBadge: View {\n var body: some View {\n VStack(alignment: .leading) {\n Text(\"Promotion\".i18n())\n \n Spacer(minLength: 10)\n \n HStack {\n Spacer()\n \n if #available(macOS 13, *) {\n ShareLink(item: .website) {\n Label {\n Text(\"Share with friends\".i18n())\n } icon: {\n Image(systemName: \"square.and.arrow.up.fill\")\n .foregroundColor(.blue)\n }\n }\n } else {\n Button(action: {\n URL.website.open()\n }) {\n Label {\n Text(\"Share with friends\".i18n())\n } icon: {\n Image(systemName: \"square.and.arrow.up.fill\")\n .foregroundColor(.blue)\n }\n }\n }\n \n \n Button(action: {\n URL(string: \"https://github.com/runjuu/InputSourcePro\")?.open()\n }) {\n Label {\n Text(\"Star on GitHub\".i18n())\n } icon: {\n Image(systemName: \"star.fill\")\n .foregroundColor(Color(red: 1.0, green: 0.84, blue: 0.0))\n }\n }\n \n Button(action: {\n URL(string: \"https://github.com/sponsors/runjuu\")?.open()\n }) {\n Label {\n Text(\"Sponsor\".i18n())\n } icon: {\n Image(systemName: \"heart.fill\")\n .foregroundColor(.pink)\n }\n }\n }\n }\n .padding()\n }\n}\n\n// add support for Canvas Preview\nstruct PromotionBadge_Previews: PreviewProvider {\n static var previews: some View {\n PromotionBadge()\n .frame(width: 635, height: 95)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/IndicatorAlignmentView.swift", "import SwiftUI\n\nstruct IndicatorAlignmentView: View {\n let content: Content\n\n let alignment: IndicatorPosition.Alignment\n\n init(\n alignment: IndicatorPosition.Alignment,\n @ViewBuilder content: () -> Content\n ) {\n self.content = content()\n self.alignment = alignment\n }\n\n var body: some View {\n VStack {\n if [.bottomLeft, .bottomRight, .bottomCenter].contains(alignment) {\n Spacer(minLength: 0)\n }\n\n HStack {\n if [.topRight, .bottomRight, .centerRight].contains(alignment) {\n Spacer(minLength: 0)\n }\n\n content\n\n if [.topLeft, .bottomLeft, .centerLeft].contains(alignment) {\n Spacer(minLength: 0)\n }\n }\n\n if [.topRight, .topLeft, .topCenter].contains(alignment) {\n Spacer(minLength: 0)\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/PreferenceSection.swift", "import SwiftUI\n\nstruct PreferenceSection: View {\n let title: String\n\n let content: Content\n\n let hideDivider: Bool\n\n init(title: String, hideDivider: Bool = false, @ViewBuilder _ content: () -> Content) {\n self.title = title\n self.hideDivider = hideDivider\n self.content = content()\n }\n\n var body: some View {\n VStack(alignment: .leading, spacing: 0) {\n HStack(alignment: .firstTextBaseline) {\n VStack {\n Text(title.isEmpty ? title : \"\\(title.i18n()):\")\n .fontWeight(.bold)\n .tracking(0.2)\n .frame(width: 100, alignment: .leading)\n }\n\n VStack(alignment: .leading) {\n content\n }\n\n Spacer(minLength: 0)\n }\n\n if !hideDivider {\n Divider()\n .padding(.vertical)\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Utilities/AlignedWidth.swift", "import SwiftUI\n\n// https://stackoverflow.com/a/63997630\n\n// The preference key used to advise parent views of a change in value.\nstruct AlignedWidthPreferenceKey: PreferenceKey {\n static var defaultValue: CGFloat = .zero\n\n static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {\n value = max(value, nextValue())\n }\n}\n\nextension View {\n func alignedView(width: Binding, alignment: Alignment = .trailing) -> some View {\n modifier(AlignedWidthView(width: width, alignment: alignment))\n }\n}\n\nstruct AlignedWidthView: ViewModifier {\n @Binding var width: CGFloat\n\n var alignment: Alignment\n\n func body(content: Content) -> some View {\n content\n .background(GeometryReader {\n Color.clear.preference(\n key: AlignedWidthPreferenceKey.self,\n value: $0.frame(in: .local).size.width\n )\n })\n .onPreferenceChange(AlignedWidthPreferenceKey.self) {\n if $0 > self.width {\n self.width = $0\n }\n }\n .frame(minWidth: width, alignment: alignment)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSRegularExpression.swift", "import Foundation\n\nextension NSRegularExpression {\n func matches(_ string: String) -> Bool {\n let range = NSRange(location: 0, length: string.utf16.count)\n return firstMatch(in: string, options: [], range: range) != nil\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSMenuItem.swift", "import AppKit\n\nextension NSMenuItem {\n convenience init(\n title string: String,\n target: AnyObject = NSMenuItem.self as AnyObject,\n action selector: Selector?,\n keyEquivalent charCode: String,\n modifier: NSEvent.ModifierFlags = .command\n ) {\n self.init(title: string, action: selector, keyEquivalent: charCode)\n keyEquivalentModifierMask = modifier\n self.target = target\n }\n\n convenience init(title string: String, submenuItems: [NSMenuItem]) {\n self.init(title: string, action: nil, keyEquivalent: \"\")\n submenu = NSMenu()\n submenu?.items = submenuItems\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/CGRect.swift", "import AppKit\nimport Foundation\n\nextension CGRect {\n func relativeTo(screen: NSScreen) -> CGRect {\n let point = CGPoint(x: minX, y: screen.frame.maxY - maxY)\n\n return CGRect(origin: point, size: size)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSTableView+RemoveBG.swift", "import AppKit\n\n// Removes background from List in SwiftUI\nextension NSTableView {\n override open func viewDidMoveToWindow() {\n super.viewDidMoveToWindow()\n\n backgroundColor = NSColor.clear\n if let esv = enclosingScrollView {\n esv.drawsBackground = false\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSCFRange.swift", "import Foundation\n\nextension CFRange {\n init(range: NSRange) {\n self = CFRangeMake(range.location == NSNotFound ? kCFNotFound : range.location, range.length)\n }\n\n func cursorRange(offset: Int, value: String) -> NSRange {\n return NSRange(location: max(min(location + offset, value.count - 1), 0), length: 1)\n }\n}\n\nextension NSRange {\n init(range: CFRange) {\n self = NSMakeRange(range.location == kCFNotFound ? NSNotFound : range.location, range.length)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/FocusAwareTextField.swift", "import AppKit\nimport RxRelay\n\nclass FocusAwareTextField: NSTextField {\n let focus$ = PublishRelay()\n\n override func becomeFirstResponder() -> Bool {\n focus$.accept(true)\n return super.becomeFirstResponder()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/ItemSection.swift", "import SwiftUI\n\nstruct ItemSection: View {\n let content: Content\n\n init(@ViewBuilder _ content: () -> Content) {\n self.content = content()\n }\n\n var body: some View {\n HStack {\n Spacer()\n VStack {\n Spacer()\n content\n Spacer()\n }\n Spacer()\n }\n .itemSectionStyle()\n }\n}\n\nstruct ItemSectionStyle: ViewModifier {\n func body(content: Content) -> some View {\n content\n .background(NSColor.background1.color)\n .clipShape(RoundedRectangle(cornerRadius: 6))\n .overlay(\n RoundedRectangle(cornerRadius: 6)\n .stroke(NSColor.border2.color, lineWidth: 1)\n )\n }\n}\n\nextension View {\n func itemSectionStyle() -> some View {\n modifier(ItemSectionStyle())\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/QuestionMark.swift", "import SwiftUI\n\nstruct QuestionMark: View {\n @State var isPresented: Bool = false\n\n let content: Content\n\n init(@ViewBuilder content: () -> Content) {\n self.content = content()\n }\n\n var body: some View {\n Button(action: { isPresented.toggle() }) {\n SwiftUI.Image(systemName: \"questionmark\")\n }\n .font(.system(size: 10).weight(.bold))\n .frame(width: 18, height: 18)\n .clipShape(RoundedRectangle(cornerRadius: 99))\n .popover(isPresented: $isPresented, arrowEdge: .top) {\n content\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/InputSource/InputSource+Name.swift", "import Carbon\nimport Cocoa\nimport Combine\nimport CoreGraphics\n\nprivate let nameMap = [\n \"com.apple.inputmethod.Korean.2SetKorean\": \"한\",\n \"com.apple.inputmethod.Korean.3SetKorean\": \"한\",\n \"com.apple.inputmethod.Korean.390Sebulshik\": \"한\",\n \"com.apple.inputmethod.Korean.GongjinCheongRomaja\": \"한\",\n \"com.apple.inputmethod.Korean.HNCRomaja\": \"한\",\n\n \"com.apple.inputmethod.Kotoeri.RomajiTyping.Japanese\": \"あ\",\n \"com.apple.inputmethod.Kotoeri.KanaTyping.Japanese\": \"あ\",\n\n \"com.apple.keylayout.Irish\": \"IE\",\n \"com.apple.keylayout.Dvorak-Right\": \"DV\",\n \"com.apple.keylayout.DVORAK-QWERTYCMD\": \"DV\",\n \"com.apple.keylayout.Dvorak-Left\": \"DV\",\n \"com.apple.keylayout.Dvorak\": \"DV\",\n \"com.apple.keylayout.Colemak\": \"CO\",\n \"com.apple.keylayout.British-PC\": \"GB\",\n \"com.apple.keylayout.British\": \"GB\",\n \"com.apple.keylayout.Australian\": \"AU\",\n \"com.apple.keylayout.ABC-India\": \"IN\",\n \"com.apple.keylayout.USInternational-PC\": \"US\",\n \"com.apple.keylayout.US\": \"US\",\n \"com.apple.keylayout.USExtended\": \"A\",\n \"com.apple.keylayout.ABC\": \"A\",\n \"com.apple.keylayout.Canadian\": \"CA\",\n\n \"com.apple.inputmethod.TCIM.Cangjie\": \"倉\",\n \"com.apple.inputmethod.TCIM.Pinyin\": \"繁拼\",\n \"com.apple.inputmethod.TCIM.Shuangpin\": \"雙\",\n \"com.apple.inputmethod.TCIM.WBH\": \"畫\",\n \"com.apple.inputmethod.TCIM.Jianyi\": \"速\",\n \"com.apple.inputmethod.TCIM.Zhuyin\": \"注\",\n \"com.apple.inputmethod.TCIM.ZhuyinEten\": \"注\",\n\n \"com.apple.inputmethod.TYIM.Sucheng\": \"速\",\n \"com.apple.inputmethod.TYIM.Stroke\": \"畫\",\n \"com.apple.inputmethod.TYIM.Phonetic\": \"粤拼\",\n \"com.apple.inputmethod.TYIM.Cangjie\": \"倉\",\n\n \"com.apple.inputmethod.SCIM.WBX\": \"五\",\n \"com.apple.inputmethod.SCIM.WBH\": \"画\",\n \"com.apple.inputmethod.SCIM.Shuangpin\": \"双\",\n \"com.apple.inputmethod.SCIM.ITABC\": \"拼\",\n]\n\nextension InputSource {\n func getSystemLabelName() -> String? {\n return nameMap[id]\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/EnhancedModeRequiredBadge.swift", "import SwiftUI\n\nstruct EnhancedModeRequiredBadge: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n var body: some View {\n Button(action: {}) {\n Text(\"Enhanced Mode Required\".i18n())\n }\n .buttonStyle(EnhanceModeRequiredButtonStyle())\n .opacity(preferencesVM.preferences.isEnhancedModeEnabled ? 0 : 1)\n .animation(.easeInOut, value: preferencesVM.preferences.isEnhancedModeEnabled)\n }\n}\n\nstruct EnhanceModeRequiredButtonStyle: ButtonStyle {\n func makeBody(configuration: Self.Configuration) -> some View {\n configuration.label\n .font(.system(size: 10))\n .padding(.horizontal, 4)\n .padding(.vertical, 3)\n .background(Color.yellow)\n .foregroundColor(Color.black)\n .clipShape(RoundedRectangle(cornerRadius: 4))\n .contentShape(Rectangle())\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/Bundle+Version.swift", "import AppKit\n\nextension Bundle {\n var shortVersion: String {\n infoDictionary?[\"CFBundleShortVersionString\"] as? String ?? \"unknown\"\n }\n\n var buildVersion: Int {\n Int(infoDictionary?[\"CFBundleVersion\"] as? String ?? \"0\") ?? 0\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSRunningApplication+FloatingApp.swift", "import AppKit\nimport Foundation\n\nextension NSRunningApplication {\n // FIXME: check window info\n var isFloatingApp: Bool {\n NSApplication.isFloatingApp(bundleIdentifier)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/ISPTextEditor.swift", "//\n// ISPTextEditor.swift\n// Input Source Pro\n//\n// Created by runjuu on 2023-03-05.\n//\n\nimport SwiftUI\n\nstruct ISPTextEditor: View {\n @Binding var text: String\n\n var placeholder: String\n\n let minHeight: CGFloat\n\n var body: some View {\n ZStack(alignment: .topLeading) {\n TextEditor(text: $text)\n .padding(.vertical, 7)\n .padding(.horizontal, 2)\n .frame(minHeight: minHeight, maxHeight: 500, alignment: .leading)\n .foregroundColor(Color(.labelColor))\n .multilineTextAlignment(.leading)\n .background(Color(NSColor.textBackgroundColor))\n .clipShape(RoundedRectangle(cornerRadius: 6))\n .overlay(\n RoundedRectangle(cornerRadius: 6)\n .stroke(Color.primary.opacity(0.3), lineWidth: 1)\n )\n\n Text(placeholder)\n .padding(.vertical, 7)\n .padding(.horizontal, 7)\n .foregroundColor(Color(.placeholderTextColor))\n .opacity(text.isEmpty ? 1 : 0)\n .allowsHitTesting(false)\n }\n .font(.body)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/ColorBlock.swift", "import SwiftUI\n\nstruct ColorBlocks: View {\n typealias Scheme = (a: Color, b: Color)\n\n let onSelectColor: (Scheme) -> Void\n\n let colors: [Scheme] = [\n (.init(hex: \"#FFF\"), .init(hex: \"#000\")),\n (.init(hex: \"#FFF\"), .init(hex: \"#ef233c\")),\n (.init(hex: \"#FFF\"), .init(hex: \"#f77f00\")),\n (.init(hex: \"#000\"), .init(hex: \"#F6CB56\")),\n (.init(hex: \"#FFF\"), .init(hex: \"#2c6e49\")),\n (.init(hex: \"#FFF\"), .init(hex: \"#0c7489\")),\n (.init(hex: \"#FFF\"), .init(hex: \"#023e8a\")),\n (.init(hex: \"#FFF\"), .init(hex: \"#7209b7\")),\n ]\n\n var body: some View {\n HStack {\n ForEach(Array(zip(colors.indices, colors)), id: \\.0) { _, scheme in\n Spacer()\n ColorBlock(colorA: scheme.a, colorB: scheme.b)\n .onTapGesture {\n onSelectColor(scheme)\n }\n Spacer()\n }\n }\n }\n}\n\nstruct ColorBlock: View {\n let colorA: Color\n\n let colorB: Color\n\n var body: some View {\n RoundedRectangle(cornerRadius: 4)\n .fill(colorB)\n .overlay(\n SwiftUI.Image(systemName: \"textformat\")\n .foregroundColor(colorA)\n .font(.system(size: 12, weight: .semibold))\n )\n .frame(width: 28, height: 20)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/RebootRequiredBadge.swift", "import SwiftUI\n\nstruct RebootRequiredBadge: View {\n let isRequired: Bool\n \n var body: some View {\n Button(action: {}) {\n Text(\"System Reboot Required\".i18n())\n }\n .buttonStyle(RebootRequiredButtonStyle())\n .opacity(isRequired ? 1 : 0)\n .animation(.easeInOut, value: isRequired)\n }\n}\n\nstruct RebootRequiredButtonStyle: ButtonStyle {\n func makeBody(configuration: Self.Configuration) -> some View {\n configuration.label\n .font(.system(size: 10))\n .padding(.horizontal, 4)\n .padding(.vertical, 3)\n .background(Color.gray)\n .foregroundColor(Color.white)\n .clipShape(RoundedRectangle(cornerRadius: 4))\n .contentShape(Rectangle())\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/Data+MD5.swift", "import CryptoKit\nimport Foundation\n\nextension Data {\n func md5() -> String {\n Insecure.MD5\n .hash(data: self)\n .map { String(format: \"%02hhx\", $0) }\n .joined()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Utilities/NoAnimation.swift", "import SwiftUI\n\nstruct NoAnimation: ViewModifier {\n func body(content: Content) -> some View {\n content\n .transaction { transaction in\n transaction.animation = nil\n }\n }\n}\n\nextension View {\n func noAnimation() -> some View {\n modifier(NoAnimation())\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/MockWindowView.swift", "import SwiftUI\nimport VisualEffects\n\nstruct MockWindowView: View {\n var body: some View {\n ZStack {\n VisualEffectBlur(\n material: .windowBackground,\n blendingMode: .withinWindow,\n state: .active\n )\n\n VStack {\n HStack {\n Circle()\n .frame(width: 10, height: 10)\n .foregroundColor(Color(NSColor.close))\n\n Circle()\n .frame(width: 10, height: 10)\n .foregroundColor(Color(NSColor.minimise))\n\n Circle()\n .frame(width: 10, height: 10)\n .foregroundColor(Color(NSColor.maximise))\n Spacer()\n }\n Spacer()\n }\n .padding(10)\n }\n .clipShape(RoundedRectangle(cornerRadius: 9))\n .shadow(color: Color.black.opacity(0.2), radius: 5, x: 3, y: 3)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/LoadingView.swift", "import SwiftUI\n\nstruct LoadingView: View where Content: View {\n var isShowing: Bool\n\n var content: () -> Content\n\n var body: some View {\n ZStack(alignment: .center) {\n self.content()\n .disabled(isShowing)\n .opacity(isShowing ? 0.5 : 1)\n\n VStack {\n ProgressView()\n .frame(width: 30, height: 30)\n }\n .opacity(isShowing ? 1 : 0)\n .animation(.easeOut, value: isShowing)\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSToolbarItem+Identifier.swift", "import AppKit\n\nextension NSToolbar.Identifier {\n static let preferencesWindowToolbarIdentifier = NSToolbar.Identifier(\"PreferencesWindowToolbar\")\n}\n\nextension NSToolbarItem.Identifier {\n static let toolbarShareButtonItem = NSToolbarItem.Identifier(rawValue: \"ToolbarShareButtonItem\")\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSColor.swift", "import AppKit\nimport SwiftUI\n\nextension NSColor {\n var color: Color {\n Color(self)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/System/main.swift", "import Cocoa\n\nlet delegate = AppDelegate()\nlet menu = AppMenu()\n\nNSApplication.shared.delegate = delegate\nNSApplication.shared.mainMenu = menu\n\n_ = NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv)\n"], ["/InputSourcePro/Input Source Pro/Utilities/CancelBag.swift", "import Combine\n\nfinal class CancelBag {\n fileprivate(set) var subscriptions = Set()\n\n func cancel() {\n subscriptions.removeAll()\n }\n}\n\nextension AnyCancellable {\n func store(in cancelBag: CancelBag) {\n cancelBag.subscriptions.insert(self)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/InputSource/IconMap.swift", "import Foundation\n\nextension InputSource {\n static let iconMap = [\n \"12234107\": \"62E0CC7B-901A-411D-818A-0AFC810B0532\",\n \"19304143\": \"A479A7C2-F39C-4374-AE69-C8C181374291\",\n \"27026352\": \"4117A20B-DF89-4304-88FA-D96B8237F822\",\n \"28098003\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"30160324\": \"671AD248-E86D-4294-B01C-6D40E2D19BFF\",\n \"71800932\": \"42A0793D-A1F0-4633-956C-6C24C4770D5A\",\n \"86338706\": \"3A6F6B79-D429-4602-8AE8-0AF37175355A\",\n \"94679192\": \"C9301AC0-A972-4DEB-81AD-9EAB0C71E2B1\",\n \"b1ce8378\": \"47101D70-F7EC-4CAF-9E79-EE417ED6D70F\",\n \"a2293646\": \"9722A832-91F4-4A67-B406-E2FC59074563\",\n \"db454877\": \"99529B6C-0A4D-440E-9A64-911D2515EAFE\",\n \"cbce68ac\": \"45FE4808-C8D9-4C20-9395-38ADC56EED6F\",\n \"e1761b42\": \"0BDE5D8A-61C4-4970-9CFD-A57FECCD0F06\",\n \"33d33781\": \"41F3F960-D979-43E9-ABD9-6F9697A99B9B\",\n \"e40293fa\": \"14005E12-0506-4BF2-9666-8211AFD754D5\",\n \"1ce2f0f3\": \"24B1B420-B287-4BB0-969C-8BFCC678B866\",\n \"8309b9ec\": \"9AC7481F-9AAD-4ED6-A0A2-7C0AFE5B2BE5\",\n \"89da7463\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"a4939376\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"867457f1\": \"BE86C109-31F8-4C1D-9578-F46DF1DEF2B7\",\n \"3899e9a3\": \"40599FAA-AFB1-4C6C-815D-13E6B6BB1E7B\",\n \"698bfbc3\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"e20e8a42\": \"7A47F327-58BA-4B48-AF85-BDBB8BACFA3A\",\n \"f4877994\": \"2DE6399A-0326-4D57-ACE8-6183305BBB28\",\n \"d815cf37\": \"ABA144C9-F007-44C1-82B9-1EC79B30DEA7\",\n \"43754cd2\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"400ffcd6\": \"63249E4A-3105-4D59-B641-458B1B8F9F4F\",\n \"07ab0602\": \"0BDE5D8A-61C4-4970-9CFD-A57FECCD0F06\",\n \"93c001bf\": \"DEF03A5D-FBDA-44FE-9903-1BA349C70742\",\n \"e744f5fc\": \"8D2979B6-7689-4EA6-866D-17210B2A5D5C\",\n \"f17ec27f\": \"F2E5DCED-0628-4491-A683-BAD29FBAE546\",\n \"315a0635\": \"6318A437-3962-4957-8F00-17BDE8292C9A\",\n \"86e12f79\": \"EFD62836-76A2-4B24-A9E4-A29CADCAA1D8\",\n \"b6715cbf\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"9d104945\": \"0BDE5D8A-61C4-4970-9CFD-A57FECCD0F06\",\n \"bbdae7cc\": \"D6DD6280-34D5-4A09-8406-913055E80D4F\",\n \"266d37f0\": \"E93D2928-BB12-4B7A-B148-023FE368F768\",\n \"1c41d885\": \"1544DF19-FC49-4EB9-BB59-E6ED8C57A272\",\n \"eec3fd6f\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"6e03fe80\": \"ABA144C9-F007-44C1-82B9-1EC79B30DEA7\",\n \"29006a72\": \"7BB5DD15-393B-4879-BA2E-45B6E1E1761F\",\n \"2b70ad68\": \"F592A155-59CD-4590-8840-7726FC215730\",\n \"5c63cc7b\": \"1150F661-C12C-49B5-9DD3-51C5C942277C\",\n \"cb0d578c\": \"671AD248-E86D-4294-B01C-6D40E2D19BFF\",\n \"4090640c\": \"DC3DA07D-A07D-425D-A817-FEFABFDB711A\",\n \"7079724c\": \"F0AF7FDB-DE37-4A76-92ED-88AB988A003A\",\n \"719ce030\": \"8C320B5A-772D-4DF3-A34F-2EC07B6D054D\",\n \"ea17e573\": \"12D06541-2675-4160-8827-7E5A32D23627\",\n \"c8e12572\": \"614A664B-068F-4B5B-AD3F-CE72AF912B48\",\n \"d87c5553\": \"0BDE5D8A-61C4-4970-9CFD-A57FECCD0F06\",\n \"1998ce3c\": \"94E6C24D-05D3-401A-9463-F8CDCBB6DFAE\",\n \"5c739cd8\": \"7EF95678-BCA9-4FD0-AD73-6F2EC0C3BA58\",\n \"02a8a069\": \"9BC01780-5C89-49BF-B2C7-B799A0FE317E\",\n \"86f29ad0\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"ad4f3484\": \"4AEC0DCA-2F80-4A63-B23A-6D505B4C55F3\",\n \"8ad2e816\": \"854BCE43-D01E-485B-A3E9-0D0F518B4A86\",\n \"a6b5c89c\": \"F0AF7FDB-DE37-4A76-92ED-88AB988A003A\",\n \"4869720f\": \"E45828A1-28C1-4EB2-B744-C0AFFD49B3D5\",\n \"d60e5c94\": \"D7B94935-4BF7-4A08-ABB7-5816817137B5\",\n \"dc1c63c0\": \"E4E1A898-4128-459D-89C7-D6B7867C0C08\",\n \"df6450c9\": \"2CE658AC-E8B0-4D4C-A893-B9C2A891E846\",\n \"d8bf107e\": \"9AC7481F-9AAD-4ED6-A0A2-7C0AFE5B2BE5\",\n \"a9b362f7\": \"2CC5AE74-F920-4D34-B5E4-F4AEF09D7F9C\",\n \"b89471aa\": \"381071E4-417A-4002-9699-8B8645DEFF4C\",\n \"9ff686a8\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"fc7e017e\": \"DEF03A5D-FBDA-44FE-9903-1BA349C70742\",\n \"3be0b38a\": \"47E931D1-7440-43D0-AB56-49794D42A628\",\n \"0e5acd60\": \"DE5AAF98-BC8F-4BE7-A4F8-80BCD7259C3E\",\n \"ee376a01\": \"85412A26-63FA-4936-B552-0F6065E7E6FB\",\n \"cfc23f4d\": \"1D9651C9-1D1D-47B9-95C0-C2A66EB4198C\",\n \"09ffadd1\": \"5AFD3681-A38F-43A9-A635-0356419453BA\",\n \"5851afb9\": \"8C320B5A-772D-4DF3-A34F-2EC07B6D054D\",\n \"fa478f42\": \"32D98AFC-7792-4F71-91F3-F83013A0A941\",\n \"d3b8669e\": \"1728813A-8FB3-43DF-B3A8-01F0E440004F\",\n \"2b467b65\": \"5D7B1D1A-612A-4FDC-9F55-FAE62A4DF863\",\n \"db9a7d9a\": \"E8BCEBD3-C407-4C02-AF7D-915F0B61E1E2\",\n \"2616d538\": \"4117A20B-DF89-4304-88FA-D96B8237F822\",\n \"63591e06\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"a7c2d310\": \"B7746411-299F-46CE-AD31-6BD27E8F6AC8\",\n \"0c0e3e33\": \"0BDE5D8A-61C4-4970-9CFD-A57FECCD0F06\",\n \"0b92667b\": \"D1BF4948-15E4-4EE3-9133-A417B13B742A\",\n \"a85e0f12\": \"59B13CD3-BF1C-4688-A7D8-DED5DA7AD503\",\n \"1baf6530\": \"1D54967C-A538-43EF-B14F-E6999261915C\",\n \"a86dbf81\": \"9EB423B4-42BD-414D-9863-B424C4C1C7A2\",\n \"2829274f\": \"418EAD09-94C8-442F-A1EB-22610C8D0F22\",\n \"b179bb4a\": \"E4E1A898-4128-459D-89C7-D6B7867C0C08\",\n \"d4769388\": \"B6DF802E-3059-49AC-8B46-C5D138CEEF09\",\n \"9495c4e2\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"c189531b\": \"22B821CC-B495-4D04-8D0C-99A9F5009B91\",\n \"a6a891b5\": \"2F1B18A2-1F6E-47F2-AAE9-1683A7D7E3DD\",\n \"247cf24e\": \"2F367878-36F4-4ACA-A74A-3B3FBD1B2DB7\",\n \"400f17c4\": \"0FAF403B-67A6-49F5-B1CF-CCD72D3CFC77\",\n \"668a30d6\": \"CA58FF15-8944-48BD-8B13-85C62A3032E7\",\n \"27a63ca6\": \"48911C5C-2BDF-4625-B3FC-D6042D485FDC\",\n \"7d054a33\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"bc781ecf\": \"0A1E7B88-A30E-47FD-AA31-0EEF8D7B308D\",\n \"18b0c1bf\": \"A685B482-A0AB-4E5F-9D98-B657D2579A02\",\n \"888f7d7e\": \"44A7B552-951C-439D-9B66-E481025CDA3D\",\n \"eb0b34fc\": \"555C454B-E3D5-4D4B-A4FA-04BE776A18E3\",\n \"3bde5571\": \"EE3B4F8F-EDB9-4906-BBD5-55572518E589\",\n \"d29022b7\": \"24B1B420-B287-4BB0-969C-8BFCC678B866\",\n \"50dcc406\": \"9798FD62-3724-4EBB-BF08-C2BA9CDBD051\",\n \"de55325e\": \"AD82741E-E3E0-457F-944D-4089589FAA74\",\n \"a616c527\": \"1544DF19-FC49-4EB9-BB59-E6ED8C57A272\",\n \"be2451e3\": \"64E0097C-D022-4AD1-B1F8-8179AF922347\",\n \"b547c79f\": \"F1FB3965-B448-4281-B88E-797CCB5E1CB9\",\n \"8929985c\": \"2F367878-36F4-4ACA-A74A-3B3FBD1B2DB7\",\n \"004ed606\": \"7CAE6A9D-6A41-4E35-A00D-EB026314432B\",\n \"1a4118ec\": \"726FFB0C-D838-4634-B815-C1120AC2EB1A\",\n \"f7b1c48f\": \"95D21DA5-73D7-466A-9FBA-21B5D3EAF44C\",\n \"e0b93787\": \"F6BBAA30-D51C-4393-9319-BC3DA549B474\",\n \"bf9de7ac\": \"0D015644-FE01-4E47-BC69-211D3907596E\",\n \"ea497b29\": \"B2D3048B-1F94-4A61-B270-F29DDE09A508\",\n \"b9f2f630\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"a09dca9f\": \"1D9651C9-1D1D-47B9-95C0-C2A66EB4198C\",\n \"cc2855c4\": \"726FFB0C-D838-4634-B815-C1120AC2EB1A\",\n \"69436caa\": \"47720907-47A7-43F0-A7A6-1C3D45FF6E82\",\n \"e30f5f53\": \"22B821CC-B495-4D04-8D0C-99A9F5009B91\",\n \"61aab9c3\": \"E45828A1-28C1-4EB2-B744-C0AFFD49B3D5\",\n \"ce5bb9ee\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"07619740\": \"D6DD6280-34D5-4A09-8406-913055E80D4F\",\n \"3d317f9f\": \"24B1B420-B287-4BB0-969C-8BFCC678B866\",\n \"e3a30f0e\": \"D7699CD3-4A59-49A5-AF99-F1A3A3B2373E\",\n \"0c148ae3\": \"AE4C2970-F3F8-45EE-AF18-39904D636ACE\",\n \"27179b5f\": \"8B90F012-4A1A-4E85-BACC-0401F1865A90\",\n \"3e04932f\": \"84684E50-4D01-4EB5-A087-A9C7B9BC9D17\",\n \"a10ee111\": \"2A96FBC0-D2D5-411F-9B6B-F24BD6104BF7\",\n \"25bcbcdb\": \"48911C5C-2BDF-4625-B3FC-D6042D485FDC\",\n \"c9d00a71\": \"94E6C24D-05D3-401A-9463-F8CDCBB6DFAE\",\n \"4feb8e48\": \"7C65C690-0665-4A7A-9864-36428242789C\",\n \"c7aded35\": \"7498631E-1C04-4207-9407-CA1F02E5C7D5\",\n \"d18ebad8\": \"BDA09217-C081-4FC8-BBE3-B2FF3BA7EC52\",\n \"dc04c9bf\": \"288281B7-EAC6-4F63-9D09-E7A2E2D67D30\",\n \"963f1da1\": \"BEB80FC2-E80D-494B-B718-E3CBED7BB533\",\n \"b97f77dc\": \"D9E09252-5C10-481B-9F33-773669D889BA\",\n \"6e9e1330\": \"8C320B5A-772D-4DF3-A34F-2EC07B6D054D\",\n \"ad812fc8\": \"24B1B420-B287-4BB0-969C-8BFCC678B866\",\n \"74bcc5c7\": \"1C5CAE31-7AAB-4F7E-9ECD-CD34DAC44D35\",\n \"c70f027b\": \"887279DC-0339-4C84-A8C9-C1FBC1D06050\",\n \"b98bc34d\": \"6D7B8A06-FE11-4A7F-9F02-E0E070556E44\",\n \"1ea92671\": \"D9E09252-5C10-481B-9F33-773669D889BA\",\n \"c92c8bf8\": \"9DBF63D5-5CC1-4D83-8C3D-861C3C894C6D\",\n \"7f29e426\": \"04C19F60-EDE3-481D-828F-5542A5FC38D4\",\n \"ea34a8c9\": \"FDC80D50-AF7B-449D-A560-D3AD2EE1D038\",\n \"adf9f70b\": \"41F3F960-D979-43E9-ABD9-6F9697A99B9B\",\n \"4186b088\": \"F0AF7FDB-DE37-4A76-92ED-88AB988A003A\",\n \"2d2388fb\": \"6870AC38-D7B5-4209-B086-3C23ECBBDC13\",\n \"97aba18b\": \"5D7B1D1A-612A-4FDC-9F55-FAE62A4DF863\",\n \"12a8787d\": \"41AB5B71-C470-4F5F-994C-B4FEB8C27A38\",\n \"7ecb03b0\": \"BD82C314-90FF-4966-B5FB-671432C60B14\",\n \"7065b10a\": \"0A420457-A462-4857-A114-EFB4C6E2A402\",\n \"7ed9e71c\": \"06391E5F-D86B-4F73-A9AF-5206A7D2092C\",\n \"786d39b4\": \"B581ADA5-4D62-4680-ACEF-A7ABBA85A9D7\",\n \"a405ec7f\": \"DE5AAF98-BC8F-4BE7-A4F8-80BCD7259C3E\",\n \"3c8f642e\": \"FDC80D50-AF7B-449D-A560-D3AD2EE1D038\",\n \"58455c57\": \"E45828A1-28C1-4EB2-B744-C0AFFD49B3D5\",\n \"235dd000\": \"997494BF-9144-4987-BB62-D70FDD0270A2\",\n \"6510e391\": \"7F227C36-226B-4465-80C4-3BA4AE270A95\",\n \"0d796371\": \"9AC7481F-9AAD-4ED6-A0A2-7C0AFE5B2BE5\",\n \"7abf92cc\": \"555C454B-E3D5-4D4B-A4FA-04BE776A18E3\",\n \"0f6c2128\": \"84684E50-4D01-4EB5-A087-A9C7B9BC9D17\",\n \"1c6dfb89\": \"7F280C1A-8742-424F-8E69-E7CA50810C0E\",\n \"6738fbef\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"f85cad76\": \"F2E5DCED-0628-4491-A683-BAD29FBAE546\",\n \"e8a7b7ac\": \"525E9E05-97C9-4198-AEB1-D159ED6BEFFE\",\n \"998008af\": \"9A8AAAA9-FDE9-46DD-9344-B25CCF79400A\",\n \"a9223b6b\": \"80AB9670-E6EE-4C30-A31C-AC3E6752F42D\",\n \"85fdb832\": \"6D594AFC-54B9-41AE-861E-FE6640176F0F\",\n \"985b9c1c\": \"47101D70-F7EC-4CAF-9E79-EE417ED6D70F\",\n \"b3fd6e15\": \"47101D70-F7EC-4CAF-9E79-EE417ED6D70F\",\n \"e9c087a5\": \"B7746411-299F-46CE-AD31-6BD27E8F6AC8\",\n \"b2ff3df1\": \"2A96FBC0-D2D5-411F-9B6B-F24BD6104BF7\",\n \"cac39a88\": \"7D3DA8CA-D663-4D76-9F2F-61AD2E8C474F\",\n \"cf08c795\": \"7C913FED-1E33-4B8D-AF83-EF9ADD8BF7ED\",\n \"62a32f72\": \"8D2979B6-7689-4EA6-866D-17210B2A5D5C\",\n \"69d17de6\": \"43D1D1FE-193A-4730-89B6-01EBF3F9D6CA\",\n \"f5f80979\": \"DAC2C56F-DC3C-40F9-A468-EFB72BE78E5E\",\n \"2c08766a\": \"E45828A1-28C1-4EB2-B744-C0AFFD49B3D5\",\n \"6c663dfe\": \"85412A26-63FA-4936-B552-0F6065E7E6FB\",\n \"4877037d\": \"0291D80B-1C39-4ECD-8ADB-570D2FAF3204\",\n \"9214334f\": \"C65B1C88-A254-4A3E-9A31-FF63C3579140\",\n \"6f37b707\": \"80AB9670-E6EE-4C30-A31C-AC3E6752F42D\",\n \"5510f56b\": \"24B1B420-B287-4BB0-969C-8BFCC678B866\",\n \"978271a2\": \"8B90F012-4A1A-4E85-BACC-0401F1865A90\",\n \"eee37628\": \"9AC7481F-9AAD-4ED6-A0A2-7C0AFE5B2BE5\",\n \"c635e696\": \"DAC92286-021D-4E7C-8064-9172E53FD37C\",\n \"ffbdd714\": \"49176BD9-5A86-437A-AA07-B027198B21A4\",\n \"6e1e6064\": \"E45828A1-28C1-4EB2-B744-C0AFFD49B3D5\",\n \"cd43b6a4\": \"588AAF70-3342-4DEB-ACC4-18C6DAAF070B\",\n \"83ce500f\": \"515356B7-FCE0-46A7-B6E6-EA1E20F9440A\",\n \"8b62fd42\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"b91b29e1\": \"D7699CD3-4A59-49A5-AF99-F1A3A3B2373E\",\n \"aad82b0e\": \"341AF28C-8140-4BF5-BBD2-DE48ED54B52E\",\n \"359130dd\": \"9AC7481F-9AAD-4ED6-A0A2-7C0AFE5B2BE5\",\n \"208de7e6\": \"ABA144C9-F007-44C1-82B9-1EC79B30DEA7\",\n \"16e15af7\": \"70419D3C-491D-446F-810F-34B656695F84\",\n \"0dee34a1\": \"1BF82110-8702-414B-BBE7-0D4AEBC8CE59\",\n \"fd60e6e1\": \"E76B0F98-61EF-4BB4-A174-33C636778D2D\",\n \"4b1fc25e\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"fb856728\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"c498db0d\": \"42A17026-B747-43FE-856F-08E5E1F3B375\",\n \"58e42a83\": \"88F0C365-5336-4C6E-97B4-C849412B2AFE\",\n \"97270e25\": \"7F227C36-226B-4465-80C4-3BA4AE270A95\",\n \"d46bd534\": \"2F367878-36F4-4ACA-A74A-3B3FBD1B2DB7\",\n \"525f4b59\": \"D7B64293-CCFC-478D-838D-25CEECE1D581\",\n \"c58e71bf\": \"5D7B1D1A-612A-4FDC-9F55-FAE62A4DF863\",\n \"3296bbf9\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"539a2414\": \"6D594AFC-54B9-41AE-861E-FE6640176F0F\",\n \"d05ecc0e\": \"2C36545F-B948-45CA-8814-6AA884AF4414\",\n \"234f9818\": \"DAC92286-021D-4E7C-8064-9172E53FD37C\",\n \"49a2fe1e\": \"0EB6F607-10E3-4310-9476-14BD0CDCDB00\",\n \"18dbea05\": \"F6BBAA30-D51C-4393-9319-BC3DA549B474\",\n \"2ff577b6\": \"49176BD9-5A86-437A-AA07-B027198B21A4\",\n \"d2d2113d\": \"7757DA96-25F6-4BD0-B2AD-3C5192C1B8CA\",\n \"3479a4e7\": \"0BDE5D8A-61C4-4970-9CFD-A57FECCD0F06\",\n \"bbf248dc\": \"CC364542-2678-46FE-8841-19EE238CDB36\",\n \"4b361b85\": \"457ED6AA-4EE9-4F5B-85CB-234415406853\",\n \"be426c78\": \"001359CD-55CF-49FA-A3A6-8A5E018A3CBB\",\n \"73e81f14\": \"5AFD3681-A38F-43A9-A635-0356419453BA\",\n \"218762fe\": \"45B52BCC-ED70-4BD2-9B8C-B2A2E64AC8E4\",\n \"4e49cac1\": \"BE86C109-31F8-4C1D-9578-F46DF1DEF2B7\",\n \"da5bb098\": \"5B2F9F82-2ACF-4608-A138-93B67AFEC8B5\",\n \"9f25876a\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"62b0a598\": \"8D2979B6-7689-4EA6-866D-17210B2A5D5C\",\n \"6e278b38\": \"BA1AA637-942E-40FD-A754-61953BC423B5\",\n \"e95c1507\": \"43D1D1FE-193A-4730-89B6-01EBF3F9D6CA\",\n \"75317e2c\": \"3F8CAF4E-01C7-4CCC-A3AB-C2041CCF678A\",\n \"bfab0f6e\": \"8D2979B6-7689-4EA6-866D-17210B2A5D5C\",\n \"154bf45a\": \"1265ADE8-35CA-4D70-9945-4CAE0D2A2FAD\",\n \"0569f839\": \"DEF03A5D-FBDA-44FE-9903-1BA349C70742\",\n \"3b22c4c6\": \"47720907-47A7-43F0-A7A6-1C3D45FF6E82\",\n \"0167a31d\": \"32B9FF3C-8D94-4B10-AD4F-1A70341C2E73\",\n \"3f1989f1\": \"744B5137-BB36-48C2-A4D1-08C186443ADD\",\n \"7ffc9c42\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"624655b7\": \"5AFD3681-A38F-43A9-A635-0356419453BA\",\n \"4e4f177f\": \"06391E5F-D86B-4F73-A9AF-5206A7D2092C\",\n \"9b527cbb\": \"F0297169-B077-4E67-B95C-F7F8F94D196A\",\n \"8969ae38\": \"ABA144C9-F007-44C1-82B9-1EC79B30DEA7\",\n \"d674736c\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"fbeafd09\": \"1C5CAE31-7AAB-4F7E-9ECD-CD34DAC44D35\",\n \"b586d8a0\": \"00773942-1BE4-49ED-8655-6FC675F6C949\",\n \"c914ede2\": \"0A420457-A462-4857-A114-EFB4C6E2A402\",\n \"a589f266\": \"BBA79BC5-78A5-4EA0-A8F0-9D12A54FDAB4\",\n \"47ed8329\": \"E489417D-13AA-4ED6-B1C7-735A2520F7F9\",\n \"2472b4bc\": \"A685B482-A0AB-4E5F-9D98-B657D2579A02\",\n \"754b228a\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"bd098872\": \"7D09137D-C942-427E-90E0-2C8A33CE4917\",\n \"1526f53f\": \"9AC7481F-9AAD-4ED6-A0A2-7C0AFE5B2BE5\",\n \"36fec563\": \"1265ADE8-35CA-4D70-9945-4CAE0D2A2FAD\",\n \"9ba7f97f\": \"2F1B18A2-1F6E-47F2-AAE9-1683A7D7E3DD\",\n \"b2576fc4\": \"7C913FED-1E33-4B8D-AF83-EF9ADD8BF7ED\",\n \"9bc85978\": \"7EEE2901-804F-4A11-BC7E-97277587428C\",\n \"9c8b76e3\": \"5B2F9F82-2ACF-4608-A138-93B67AFEC8B5\",\n \"451243b4\": \"0E555052-1D93-4F25-98F3-99D2E1300929\",\n \"429c3811\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"128ff90c\": \"4DA12B48-8B78-40BD-A705-F16816B17077\",\n \"58beffc7\": \"77B325ED-16B1-4468-B936-FB71DCC547CD\",\n \"a97f103b\": \"BA1AA637-942E-40FD-A754-61953BC423B5\",\n \"da8f20e9\": \"ABA144C9-F007-44C1-82B9-1EC79B30DEA7\",\n \"bf974976\": \"8C320B5A-772D-4DF3-A34F-2EC07B6D054D\",\n \"6b8fe3f8\": \"88F0C365-5336-4C6E-97B4-C849412B2AFE\",\n \"f85be9a9\": \"8D2979B6-7689-4EA6-866D-17210B2A5D5C\",\n \"ac660083\": \"588B83A7-540C-4329-9DCF-FA4F15EB2A29\",\n \"0edede09\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"1875dff7\": \"9722A832-91F4-4A67-B406-E2FC59074563\",\n \"41c01b9d\": \"3AE73689-3E55-4681-A0F4-25FED9B6F7DE\",\n \"3880c1ab\": \"2C36545F-B948-45CA-8814-6AA884AF4414\",\n \"46923cf2\": \"0BDE5D8A-61C4-4970-9CFD-A57FECCD0F06\",\n \"13d24b22\": \"C5E4C22D-6421-4823-9327-513CFD5F89B9\",\n \"fd2528e3\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n ]\n}\n"]], "task_instance_info": {"created_time": "2025-08-21 03:17:35", "created_task_model": "DeepSeek-R1", "function_skeleton": "func getAppDefaultKeyboard ( _ appKind: AppKind ) -> InputSource? { }", "code_description": "This code segment functions to: Determine the appropriate default keyboard configuration for an application by sequentially evaluating address bar focus status, browser-specific rules, application customization preferences, and finally falling back to system-wide defaults."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```swift\n[TASK_BEGIN]\n func getAppDefaultKeyboard(_ appKind: AppKind) -> InputSource? {\n let app = appKind.getApp()\n let appRule = getAppCustomization(app: app)\n \n if let defaultKeyboardId = appRule?.defaultKeyboardId {\n return inputSourceManager.findById(defaultKeyboardId)\n }\n \n return nil\n }\n[TASK_END]\n```", "inference_time": "2025-08-21 03-17-49"}, "editdistance_info": {"edit_distance": 33.3333, "calculate_time": "2025-08-21 03:17:49", "true_code_clean": "func getAppDefaultKeyboard(_ appKind: AppKind) -> InputSource? {\n if appKind.getBrowserInfo()?.isFocusedOnAddressBar == true,\n let browserAddressKeyboard = browserAddressDefaultKeyboard\n {\n return browserAddressKeyboard\n }\n if let inputSource = appKind.getBrowserInfo()?.rule?.forcedKeyboard {\n return inputSource\n }\n return getAppCustomization(app: appKind.getApp())?.forcedKeyboard ?? systemWideDefaultKeyboard\n }", "predict_code_clean": "func getAppDefaultKeyboard(_ appKind: AppKind) -> InputSource? {\n let app = appKind.getApp()\n let appRule = getAppCustomization(app: app)\n if let defaultKeyboardId = appRule?.defaultKeyboardId {\n return inputSourceManager.findById(defaultKeyboardId)\n }\n return nil\n }"}} +{"repo_name": "InputSourcePro", "file_name": "/InputSourcePro/Input Source Pro/Utilities/i18n.swift", "inference_info": {"prefix_code": "import Foundation\n\nextension String {\n ", "suffix_code": "\n}\n", "middle_code": "func i18n(\n comment: String = \"\",\n tableName: String = \"Localizable\"\n ) -> String {\n #if DEBUG\n let fallback = \"**\\(self)**\"\n #else\n let fallback = self\n #endif\n return NSLocalizedString(\n self,\n tableName: tableName,\n value: fallback,\n comment: comment\n )\n }", "code_description": null, "fill_type": "FUNCTION_TYPE", "language_type": "swift", "sub_task_type": null}, "context_code": [["/InputSourcePro/Input Source Pro/Utilities/Log/ISPLogger.swift", "import AppKit\nimport os\n\nclass ISPLogger {\n let category: String\n\n var disabled: Bool\n\n init(category: String, disabled: Bool = false) {\n self.category = category\n self.disabled = disabled\n }\n\n func debug(_ getString: () -> String) {\n if disabled { return }\n // TODO: - Add toggle\n #if DEBUG\n let str = getString()\n let formatter = DateFormatter()\n formatter.dateFormat = \"H:mm:ss.SSSS\"\n print(formatter.string(from: Date()), \"[\\(category)]\", str)\n #endif\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSRunningApplication.swift", "import AppKit\nimport AXSwift\nimport Combine\n\nprivate func notify(\n _ observer: Observer?,\n _ validRoles: [Role],\n _ element: UIElement,\n _ notifications: [AXNotification],\n _ indetify: String?\n) -> AnyCancellable {\n guard let role = try? element.role(),\n validRoles.contains(role)\n else { return AnyCancellable {} }\n\n do {\n try notifications.forEach {\n try observer?.addNotification($0, forElement: element)\n }\n\n return AnyCancellable {\n for notification in notifications {\n try? observer?.removeNotification(notification, forElement: element)\n }\n }\n } catch {\n let role = role.rawValue\n let msg = \"\\(indetify ?? \"nil\"): Could not watch [\\(element)] with role \\(role): \\(error)\"\n\n #if DEBUG\n print(msg)\n #endif\n\n return AnyCancellable {}\n }\n}\n\nextension NSRunningApplication {\n typealias WatchAXOutput = (runningApp: NSRunningApplication, notification: AXNotification)\n\n func watchAX(\n elm: UIElement? = nil,\n _ notifications: [AXNotification],\n _ validRoles: [Role]\n ) -> AnyPublisher {\n return Timer.delay(seconds: 0.5)\n .receive(on: DispatchQueue.main)\n .flatMapLatest { _ -> AnyPublisher in\n AnyPublisher.create { [weak self] observer in\n let cancelBag = CancelBag()\n\n self?.activateAccessibilities()\n\n guard\n let runningApplication = self,\n let app = Application(runningApplication)\n else { return AnyCancellable {} }\n\n let appObserver = app.createObserver { (_ appObserver: Observer, _ element: UIElement, _ event: AXNotification) in\n // Watch events on new windows\n if event == .windowCreated {\n notify(\n appObserver,\n validRoles,\n element,\n notifications,\n runningApplication.bundleIdentifier\n )\n .store(in: cancelBag)\n }\n\n observer.send((runningApplication, event))\n }\n\n notify(\n appObserver,\n validRoles,\n elm ?? app,\n notifications,\n runningApplication.bundleIdentifier\n )\n .store(in: cancelBag)\n\n return AnyCancellable {\n cancelBag.cancel()\n appObserver?.stop()\n }\n }\n }\n .eraseToAnyPublisher()\n }\n}\n\nextension NSRunningApplication {\n func bundleId() -> String? {\n if let bundleIdentifier = bundleIdentifier {\n return bundleIdentifier\n }\n\n if let url = bundleURL ?? executableURL {\n return url.bundleId()\n }\n\n return nil\n }\n}\n\nextension NSRunningApplication {\n // For performance reasons Chromium only makes the webview accessible when there it detects voiceover through the `AXEnhancedUserInterface` attribute on the Chrome application itself:\n // http://dev.chromium.org/developers/design-documents/accessibility\n // Similarly, electron uses `AXManualAccessibility`:\n // https://electronjs.org/docs/tutorial/accessibility#assistive-technology\n func activateAccessibilities() {\n guard bundleIdentifier?.starts(with: \"com.apple.\") != true else { return }\n\n activateAccessibility(attribute: \"AXEnhancedUserInterface\")\n activateAccessibility(attribute: \"AXManualAccessibility\")\n }\n\n func activateAccessibility(attribute: String) {\n if let application = Application(self),\n let isSettable = try? application.attributeIsSettable(attribute),\n isSettable\n {\n if let rawValue: AnyObject = try? application.attribute(attribute),\n CFBooleanGetTypeID() == CFGetTypeID(rawValue),\n let enabled = rawValue as? Bool, enabled\n {\n return\n }\n\n try? application.setAttribute(attribute, value: true)\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Controllers/StatusItemController.swift", "import Cocoa\nimport Combine\n\n@MainActor\nclass StatusItemController {\n let navigationVM: NavigationVM\n let permissionsVM: PermissionsVM\n let preferencesVM: PreferencesVM\n let applicationVM: ApplicationVM\n let indicatorVM: IndicatorVM\n let feedbackVM: FeedbackVM\n let inputSourceVM: InputSourceVM\n\n let cancelBag = CancelBag()\n\n var statusItem: NSStatusItem?\n var hasPreferencesShown = false\n\n var addRuleMenu: NSMenuItem? {\n guard let app = applicationVM.appKind?.getApp() else { return nil }\n\n var items: [NSMenuItem] = [\n AppRuleMenuItem(app: app, preferencesVM: preferencesVM, inputSource: nil),\n NSMenuItem.separator(),\n ]\n\n items[0].toolTip = \"Default Keyboard Tooltip\".i18n()\n\n items += InputSource.sources.map {\n AppRuleMenuItem(app: app, preferencesVM: preferencesVM, inputSource: $0)\n }\n\n items\n .filter { (($0 as? AppRuleMenuItem) != nil) ? true : false }\n .enumerated()\n .forEach { index, item in\n if index < 10 {\n item.keyEquivalent = \"\\(index)\"\n item.keyEquivalentModifierMask = .command\n }\n }\n\n let menu = NSMenuItem(\n title: String(format: \"Default Keyboard for %@\".i18n(), app.localizedName ?? \"Current App\".i18n()),\n submenuItems: items\n )\n\n menu.toolTip = app.bundleIdentifier\n\n return menu\n }\n\n var addBrowserRuleMenu: NSMenuItem? {\n guard let browserInfo = applicationVM.appKind?.getBrowserInfo(),\n let host = browserInfo.url.host\n else { return nil }\n\n var items: [NSMenuItem] = [\n BrowserRuleMenuItem(url: browserInfo.url, preferencesVM: preferencesVM, inputSource: nil),\n NSMenuItem.separator(),\n ]\n\n items[0].toolTip = \"Default Keyboard Tooltip\".i18n()\n\n items += InputSource.sources.map {\n BrowserRuleMenuItem(url: browserInfo.url, preferencesVM: preferencesVM, inputSource: $0)\n }\n\n items\n .filter { (($0 as? BrowserRuleMenuItem) != nil) ? true : false }\n .enumerated()\n .forEach { index, item in\n if index < 10 {\n item.keyEquivalent = \"\\(index)\"\n item.keyEquivalentModifierMask = .command\n }\n }\n\n return NSMenuItem(\n title: String(format: \"Default Keyboard for %@\".i18n(), host),\n submenuItems: items\n )\n }\n\n var settingsMenu: NSMenuItem? {\n NSMenuItem(\n title: \"Preferences\".i18n() + \"...\",\n target: self,\n action: #selector(openPreferences),\n keyEquivalent: \",\"\n )\n }\n\n var changelogMenu: NSMenuItem? {\n NSMenuItem(\n title: \"Changelog\".i18n(),\n target: self,\n action: #selector(openChangelog),\n keyEquivalent: \"\"\n )\n }\n\n var checkUpdatesMenu: NSMenuItem? {\n NSMenuItem(\n title: \"Check for Updates\".i18n() + \"...\",\n target: self,\n action: #selector(checkForUpdates),\n keyEquivalent: \"\"\n )\n }\n\n var menu: NSMenu {\n let menu = NSMenu()\n\n let items = [\n NSMenuItem(title: \"Input Source Pro\".i18n(), action: nil, keyEquivalent: \"\"),\n addBrowserRuleMenu ?? addRuleMenu,\n NSMenuItem.separator(),\n changelogMenu,\n checkUpdatesMenu,\n settingsMenu,\n NSMenuItem.separator(),\n NSMenuItem(\n title: \"Quit\".i18n(),\n action: #selector(NSApplication.shared.terminate(_:)),\n keyEquivalent: \"q\"\n ),\n ]\n .compactMap { $0 }\n\n items.forEach { menu.addItem($0) }\n\n return menu\n }\n\n lazy var preferencesWindowController = PreferencesWindowController(\n navigationVM: self.navigationVM,\n permissionsVM: self.permissionsVM,\n preferencesVM: self.preferencesVM,\n indicatorVM: self.indicatorVM,\n feedbackVM: self.feedbackVM,\n inputSourceVM: self.inputSourceVM\n )\n\n init(\n navigationVM: NavigationVM,\n permissionsVM: PermissionsVM,\n preferencesVM: PreferencesVM,\n applicationVM: ApplicationVM,\n indicatorVM: IndicatorVM,\n feedbackVM: FeedbackVM,\n inputSourceVM: InputSourceVM\n ) {\n self.navigationVM = navigationVM\n self.permissionsVM = permissionsVM\n self.preferencesVM = preferencesVM\n self.applicationVM = applicationVM\n self.indicatorVM = indicatorVM\n self.feedbackVM = feedbackVM\n self.inputSourceVM = inputSourceVM\n\n preferencesVM.$preferences\n .map(\\.isShowIconInMenuBar)\n .removeDuplicates()\n .map { isShow -> AnyPublisher in\n if isShow {\n return AnyPublisher.create { [unowned self] _ in\n statusItem = NSStatusBar.system.statusItem(\n withLength: NSStatusItem.squareLength\n )\n\n statusItem?.button?.image = NSImage(named: \"MenuBarIcon\")\n statusItem?.button?.image?.size = NSSize(width: 16, height: 16)\n statusItem?.button?.image?.isTemplate = true\n statusItem?.button?.target = self\n statusItem?.button?.action = #selector(self.displayMenu)\n\n return AnyCancellable { [unowned self] in\n self.statusItem = nil\n }\n }\n } else {\n return Empty().eraseToAnyPublisher()\n }\n }\n .switchToLatest()\n .sink {}\n .store(in: cancelBag)\n }\n\n @objc func displayMenu() {\n // https://stackoverflow.com/a/57612963\n statusItem?.menu = menu\n statusItem?.button?.performClick(nil)\n statusItem?.menu = nil\n }\n\n @objc func openPreferences() {\n NSApp.setActivationPolicy(.regular)\n NSApplication.shared.activate(ignoringOtherApps: true)\n if let window = preferencesWindowController.window {\n DispatchQueue.main.async {\n if !self.hasPreferencesShown {\n self.hasPreferencesShown = true\n window.center()\n }\n \n window.makeKeyAndOrderFront(nil)\n }\n }\n }\n\n @objc func openChangelog() {\n if let url = URL(string: \"https://inputsource.pro/changelog\") {\n NSWorkspace.shared.open(url)\n }\n }\n\n @objc func checkForUpdates() {\n preferencesVM.checkUpdates()\n }\n\n @objc func openFeedback() {\n feedbackVM.show()\n navigationVM.selection = .troubleshooting\n openPreferences()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Persistence/BrowserRule.swift", "import Cocoa\n\nenum BrowserRuleType: Int32, CaseIterable {\n case domainSuffix = 0\n case domain = 1\n case urlRegex = 2\n\n var name: String {\n switch self {\n case .domainSuffix:\n return \"DOMAIN-SUFFIX\"\n case .domain:\n return \"DOMAIN\"\n case .urlRegex:\n return \"URL-REGEX\"\n }\n }\n\n var explanation: String {\n return \"\\(name) Explanation\".i18n()\n }\n}\n\nextension BrowserRule {\n @MainActor\n var forcedKeyboard: InputSource? {\n guard let inputSourceId = inputSourceId else { return nil }\n\n return InputSource.sources.first { $0.id == inputSourceId }\n }\n\n var type: BrowserRuleType {\n get {\n return BrowserRuleType(rawValue: typeValue) ?? .domainSuffix\n }\n\n set {\n typeValue = newValue.rawValue\n }\n }\n\n func validate(url: URL) -> Bool {\n return Self.validate(type: type, url: url, value: value)\n }\n\n func id() -> String {\n return \"\\(type.name)_\\(value ?? \"\")_\\(createdAt?.timeIntervalSince1970 ?? 0)\"\n }\n}\n\nextension BrowserRule {\n static func validate(type: BrowserRuleType, url: URL, value: String?) -> Bool {\n switch type {\n case .domainSuffix:\n if let suffix = value,\n let host = url.host,\n let regex = try? NSRegularExpression(pattern: \"\\(suffix)$\", options: .caseInsensitive)\n {\n return regex.matches(host)\n }\n return false\n case .domain:\n return url.host == value\n case .urlRegex:\n if let regex = try? NSRegularExpression(pattern: value ?? \"\", options: .caseInsensitive) {\n return regex.matches(url.absoluteString)\n }\n return false\n }\n }\n}\n\nextension BrowserRule {\n var keyboardRestoreStrategy: KeyboardRestoreStrategy? {\n guard let rawValue = keyboardRestoreStrategyRaw\n else { return nil }\n\n return KeyboardRestoreStrategy(rawValue: rawValue)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSString.swift", "import Foundation\n\nextension String {\n func string(at atIndex: Int) -> String {\n guard !isEmpty else { return self }\n\n let offset = max(min(count - 1, atIndex), 0)\n\n return String(self[index(startIndex, offsetBy: offset)])\n }\n}\n\nextension String {\n func runCommand(\n requireSudo: Bool,\n completion: @escaping (_ output: String, _ errorOutput: String, _ exitCode: Int32) -> Void\n ) {\n let process = Process()\n let stdoutPipe = Pipe()\n let stderrPipe = Pipe()\n\n if requireSudo {\n let appleScript = \"\"\"\n do shell script \"\\(self.replacingOccurrences(of: \"\\\"\", with: \"\\\\\\\"\"))\" with administrator privileges\n \"\"\"\n process.launchPath = \"/usr/bin/osascript\"\n process.arguments = [\"-e\", appleScript]\n } else {\n process.launchPath = \"/bin/bash\"\n process.arguments = [\"-c\", self]\n }\n\n process.standardOutput = stdoutPipe\n process.standardError = stderrPipe\n\n process.terminationHandler = { proc in\n let outputData = stdoutPipe.fileHandleForReading.readDataToEndOfFile()\n let errorData = stderrPipe.fileHandleForReading.readDataToEndOfFile()\n \n let output = String(data: outputData, encoding: .utf8) ?? \"\"\n let errorOutput = String(data: errorData, encoding: .utf8) ?? \"\"\n let exitCode = proc.terminationStatus\n\n DispatchQueue.main.async {\n completion(output, errorOutput, exitCode)\n }\n }\n\n do {\n try process.run()\n } catch {\n DispatchQueue.main.async {\n completion(\"\", \"Process failed to start: \\(error)\", -1)\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Controllers/PreferencesWindowController+NSToolbar.swift", "import AppKit\n\nextension PreferencesWindowController: NSSharingServicePickerToolbarItemDelegate {\n func items(for _: NSSharingServicePickerToolbarItem) -> [Any] {\n // Compose an array of items that are sharable such as text, URLs, etc.\n // depending on the context of your application (i.e. what the user\n // current has selected in the app and/or they tab they're in).\n let sharableItems = [URL(string: \"https://inputsource.pro/\")!] as [Any]\n\n return sharableItems\n }\n}\n\nextension PreferencesWindowController: NSToolbarDelegate {\n func toolbarDefaultItemIdentifiers(_: NSToolbar) -> [NSToolbarItem.Identifier] {\n return []\n// return [.toolbarShareButtonItem]\n }\n\n func toolbarAllowedItemIdentifiers(_: NSToolbar) -> [NSToolbarItem.Identifier] {\n return [.toolbarShareButtonItem]\n }\n\n func toolbar(\n _: NSToolbar,\n itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier,\n willBeInsertedIntoToolbar _: Bool\n ) -> NSToolbarItem? {\n if itemIdentifier == NSToolbarItem.Identifier.toolbarShareButtonItem {\n let shareItem = NSSharingServicePickerToolbarItem(itemIdentifier: itemIdentifier)\n\n shareItem.toolTip = \"Share\"\n shareItem.delegate = self\n\n if #available(macOS 11.0, *) {\n shareItem.menuFormRepresentation?.image = NSImage(\n systemSymbolName: \"square.and.arrow.up\",\n accessibilityDescription: nil\n )\n }\n\n return shareItem\n }\n\n return nil\n }\n}\n\nextension PreferencesWindowController: NSToolbarItemValidation {\n func validateToolbarItem(_ item: NSToolbarItem) -> Bool {\n if item.itemIdentifier == .toolbarShareButtonItem {\n return true\n }\n\n return false\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/InputSource/InputSource.swift", "import Carbon\nimport Cocoa\nimport Combine\nimport CoreGraphics\nimport CryptoKit\n\n@MainActor\nclass InputSource {\n static let logger = ISPLogger(\n category: \"🤖 \" + String(describing: InputSource.self),\n disabled: true\n )\n\n let tisInputSource: TISInputSource\n\n let icon: NSImage?\n\n var id: String { tisInputSource.id }\n var name: String { tisInputSource.name }\n\n var isCJKVR: Bool {\n guard let lang = tisInputSource.sourceLanguages.first else { return false }\n\n return lang == \"ru\" || lang == \"ko\" || lang == \"ja\" || lang == \"vi\" || lang.hasPrefix(\"zh\")\n }\n\n init(tisInputSource: TISInputSource) {\n self.tisInputSource = tisInputSource\n\n icon = { () -> NSImage? in\n if let imgName = Self.iconMap[String(tisInputSource.id.sha256().prefix(8))],\n let image = NSImage(named: imgName)\n {\n return image.markTemplateIfGrayScaleOrPdf()\n }\n\n guard let imageURL = tisInputSource.iconImageURL else {\n if #available(macOS 11.0, *) {\n return nil\n } else {\n if let iconRef = tisInputSource.iconRef {\n return NSImage(iconRef: iconRef).markTemplateIfGrayScaleOrPdf()\n } else {\n return nil\n }\n }\n }\n\n for url in [imageURL.retinaImageURL, imageURL.tiffImageURL, imageURL] {\n if let image = NSImage(contentsOf: url) {\n return image.markTemplateIfGrayScaleOrPdf(url: url)\n }\n }\n\n if let baseURL = imageURL.baseURL,\n baseURL.lastPathComponent.hasSuffix(\".app\")\n {\n return NSWorkspace.shared.icon(forFile: baseURL.relativePath)\n }\n\n return nil\n }()\n }\n\n func select(useCJKVFix: Bool) {\n Self.logger.debug { \"Select \\(id)\" }\n\n guard Self.getCurrentInputSource().id != id else {\n Self.logger.debug { \"Skip Select \\(id)\" }\n return\n }\n\n let updateStrategy: String = {\n if isCJKVR {\n // https://stackoverflow.com/a/60375569\n if useCJKVFix,\n PermissionsVM.checkAccessibility(prompt: false),\n let selectPreviousShortcut = Self.getSelectPreviousShortcut()\n {\n TISSelectInputSource(tisInputSource)\n\n // Workaround for TIS CJKV layout bug:\n // when it's CJKV, select nonCJKV input first and then return\n if let nonCJKV = Self.nonCJKVSource() {\n Self.logger.debug { \"S1: Start\" }\n TISSelectInputSource(nonCJKV.tisInputSource)\n Self.logger.debug { \"S1: selectPrevious\" }\n Self.selectPrevious(shortcut: selectPreviousShortcut)\n Self.logger.debug { \"S1: Done\" }\n }\n\n return \"S1\"\n } else {\n TISSelectInputSource(tisInputSource)\n return \"S0-2\"\n }\n } else {\n TISSelectInputSource(tisInputSource)\n\n return \"S0-2\"\n }\n }()\n\n Self.logger.debug { \"Select by \\(updateStrategy)\" }\n }\n}\n\nextension InputSource: @preconcurrency Equatable {\n static func == (lhs: InputSource, rhs: InputSource) -> Bool {\n return lhs.id == rhs.id\n }\n}\n\nextension InputSource {\n private static var cancelBag = CancelBag()\n\n @MainActor\n static func getCurrentInputSource() -> InputSource {\n return InputSource(tisInputSource: TISCopyCurrentKeyboardInputSource().takeRetainedValue())\n }\n}\n\nextension InputSource {\n static var sources: [InputSource] {\n let inputSourceNSArray = TISCreateInputSourceList(nil, false).takeRetainedValue() as NSArray\n let inputSourceList = inputSourceNSArray as! [TISInputSource]\n\n return inputSourceList\n .filter { $0.category == TISInputSource.Category.keyboardInputSource && $0.isSelectable }\n .map { InputSource(tisInputSource: $0) }\n }\n\n static func nonCJKVSource() -> InputSource? {\n return sources.first(where: { !$0.isCJKVR })\n }\n\n static func anotherCJKVSource(current: InputSource) -> InputSource? {\n return sources.first(where: { $0 != current && $0.isCJKVR })\n }\n\n static func selectPrevious(shortcut: (Int, UInt64)) {\n let src = CGEventSource(stateID: .hidSystemState)\n\n let key = CGKeyCode(shortcut.0)\n let flag = CGEventFlags(rawValue: shortcut.1)\n\n let down = CGEvent(keyboardEventSource: src, virtualKey: key, keyDown: true)!\n let up = CGEvent(keyboardEventSource: src, virtualKey: key, keyDown: false)!\n\n down.flags = flag\n up.flags = flag\n\n let ctrlDown = CGEvent(keyboardEventSource: nil, virtualKey: UInt16(kVK_Control), keyDown: true)\n let ctrlUp = CGEvent(keyboardEventSource: nil, virtualKey: UInt16(kVK_Control), keyDown: false)\n\n ctrlDown?.post(tap: .cghidEventTap)\n down.post(tap: .cghidEventTap)\n up.post(tap: .cghidEventTap)\n ctrlUp?.post(tap: .cghidEventTap)\n }\n\n // from read-symbolichotkeys script of Karabiner\n // github.com/tekezo/Karabiner/blob/master/src/util/read-symbolichotkeys/read-symbolichotkeys/main.m\n static func getSelectPreviousShortcut() -> (Int, UInt64)? {\n guard let dict = UserDefaults.standard.persistentDomain(forName: \"com.apple.symbolichotkeys\") else {\n return nil\n }\n guard let symbolichotkeys = dict[\"AppleSymbolicHotKeys\"] as! NSDictionary? else {\n return nil\n }\n guard let symbolichotkey = symbolichotkeys[\"60\"] as! NSDictionary? else {\n return nil\n }\n if (symbolichotkey[\"enabled\"] as! NSNumber).intValue != 1 {\n return nil\n }\n guard let value = symbolichotkey[\"value\"] as! NSDictionary? else {\n return nil\n }\n guard let parameters = value[\"parameters\"] as! NSArray? else {\n return nil\n }\n return (\n (parameters[1] as! NSNumber).intValue,\n (parameters[2] as! NSNumber).uint64Value\n )\n }\n}\n\nprivate extension URL {\n var retinaImageURL: URL {\n var components = pathComponents\n let filename: String = components.removeLast()\n let ext: String = pathExtension\n let retinaFilename = filename.replacingOccurrences(of: \".\" + ext, with: \"@2x.\" + ext)\n return NSURL.fileURL(withPathComponents: components + [retinaFilename])!\n }\n\n var tiffImageURL: URL {\n return deletingPathExtension().appendingPathExtension(\"tiff\")\n }\n}\n\nextension InputSource: @preconcurrency CustomStringConvertible {\n var description: String {\n id\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKeyboardCache.swift", "import AppKit\nimport Foundation\nimport os\n\n@MainActor\nclass AppKeyboardCache {\n private var cache = [String: String]()\n\n let logger = ISPLogger(category: String(describing: AppKeyboardCache.self))\n\n func remove(_ kind: AppKind) {\n if let id = kind.getId(), cache[id] != nil {\n logger.debug { \"Remove #\\(id)\" }\n cache[id] = nil\n }\n }\n\n func save(_ kind: AppKind, keyboard: InputSource?) {\n guard let id = kind.getId() else { return }\n\n if let keyboardId = keyboard?.id {\n logger.debug { \"Save \\(id)#\\(keyboardId)\" }\n cache[id] = keyboardId\n }\n }\n\n func retrieve(_ kind: AppKind) -> InputSource? {\n guard let id = kind.getId(),\n let keyboardId = cache[id]\n else { return nil }\n\n logger.debug { \"Retrieve \\(id)#\\(keyboardId)\" }\n\n return InputSource.sources.first { $0.id == keyboardId }\n }\n\n func clear() {\n // FIXME: - Some apps/websites where 'restore' is selected should be ignored\n logger.debug { \"Clear All\" }\n cache.removeAll()\n }\n\n func remove(byBundleId bundleId: String) {\n for key in cache.keys {\n if key.starts(with: \"\\(bundleId)_\") {\n logger.debug { \"Remove \\(bundleId)#\\(key)\" }\n cache[key] = nil\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/BrowserRuleEditView.swift", "import SwiftUI\n\nstruct BrowserRuleEditView: View {\n @State var value: String = \"\"\n @State var sampleValue: String = \"\"\n @State var ruleType = BrowserRuleType.domainSuffix\n @State var inputSourceItem = PickerItem.empty\n @State var restoreStrategyItem = PickerItem.empty\n @State var hideIndicator = false\n\n @State var isPopover = false\n\n @State private var width = CGFloat.zero\n\n @Binding var isPresented: Bool\n\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n let rule: BrowserRule?\n\n var ruleTypes: [BrowserRuleType] {\n BrowserRuleType.allCases\n }\n\n var inputSourceItems: [PickerItem] {\n [PickerItem.empty]\n + InputSource.sources.map { PickerItem(id: $0.id, title: $0.name, toolTip: $0.id) }\n }\n\n var restoreStrategyItems: [PickerItem] {\n [PickerItem.empty]\n + KeyboardRestoreStrategy.allCases.map { PickerItem(id: $0.rawValue, title: $0.name, toolTip: nil) }\n }\n\n var sampleURL: URL? {\n guard !sampleValue.isEmpty else { return nil }\n\n if sampleValue.starts(with: \"http://\") || sampleValue.starts(with: \"https://\") {\n return URL(string: sampleValue)\n } else {\n return URL(string: \"http://\\(sampleValue)\")\n }\n }\n\n var body: some View {\n VStack(spacing: 0) {\n VStack(alignment: .leading, spacing: 5) {\n Text(\"Match\".i18n().uppercased())\n .font(.footnote)\n .fontWeight(.medium)\n .opacity(0.5)\n\n VStack {\n HStack {\n Text(\"Sample URL\".i18n() + \":\")\n .alignedView(width: $width, alignment: .trailing)\n TextField(\"https://www.twitter.com/runjuuu\", text: $sampleValue)\n }\n\n HStack {\n Text(\"Rule Type\".i18n() + \":\")\n .alignedView(width: $width, alignment: .trailing)\n HStack {\n PopUpButtonPicker(\n items: ruleTypes,\n isItemSelected: { $0 == ruleType },\n getTitle: { $0.name },\n getToolTip: { $0.explanation },\n onSelect: handleSelectRule\n )\n\n Button(action: { isPopover.toggle() }) {\n SwiftUI.Image(systemName: \"questionmark\")\n }\n .font(.system(size: 10).weight(.bold))\n .frame(width: 18, height: 18)\n .clipShape(RoundedRectangle(cornerRadius: 99))\n .popover(\n isPresented: self.$isPopover,\n arrowEdge: .bottom\n ) {\n VStack {\n Text(.init(ruleType.explanation))\n .lineSpacing(3)\n }\n .frame(width: 280)\n .padding()\n }\n }\n }\n\n HStack {\n Text(\"Domain\".i18n() + \":\")\n .alignedView(width: $width, alignment: .trailing)\n HStack {\n TextField(\"twitter.com\", text: $value)\n if let url = sampleURL, !value.isEmpty {\n if BrowserRule.validate(type: ruleType, url: url, value: value) {\n Image(systemName: \"checkmark.circle.fill\")\n .foregroundColor(.green)\n .frame(width: 18, height: 18)\n } else {\n Image(systemName: \"x.circle.fill\")\n .foregroundColor(.red)\n .frame(width: 18, height: 18)\n }\n }\n }\n }\n }\n .padding()\n .background(Color.gray.opacity(0.1))\n .clipShape(RoundedRectangle(cornerRadius: 8))\n .padding(.bottom)\n }\n\n VStack(alignment: .leading, spacing: 5) {\n Text(\"Keyboard\".i18n().uppercased())\n .font(.footnote)\n .fontWeight(.medium)\n .opacity(0.5)\n\n VStack {\n HStack {\n Text(\"Default Keyboard\".i18n() + \":\")\n .alignedView(width: $width, alignment: .trailing)\n PopUpButtonPicker(\n items: inputSourceItems,\n isItemSelected: { $0 == inputSourceItem },\n getTitle: { $0?.title ?? \"\" },\n getToolTip: { $0?.toolTip },\n onSelect: handleSelectInputSource\n )\n }\n\n HStack {\n Text(\"Restore Strategy\".i18n() + \":\")\n .alignedView(width: $width, alignment: .trailing)\n PopUpButtonPicker(\n items: restoreStrategyItems,\n isItemSelected: { $0 == restoreStrategyItem },\n getTitle: { $0?.title ?? \"\" },\n getToolTip: { $0?.toolTip },\n onSelect: handleRestoreStrategy\n )\n }\n }\n .padding()\n .background(Color.gray.opacity(0.1))\n .clipShape(RoundedRectangle(cornerRadius: 8))\n .padding(.bottom)\n }\n\n VStack(alignment: .leading, spacing: 5) {\n Text(\"Tooltip\".i18n().uppercased())\n .font(.footnote)\n .fontWeight(.medium)\n .opacity(0.5)\n\n VStack {\n HStack {\n HStack(spacing: 4) {\n Image(systemName: \"eye.slash.circle.fill\")\n .foregroundColor(.gray)\n Text(\"Hide Indicator\".i18n() + \":\")\n }\n .alignedView(width: $width, alignment: .trailing)\n\n Toggle(\"\", isOn: $hideIndicator)\n .toggleStyle(.switch)\n\n Spacer()\n }\n }\n .padding()\n .background(Color.gray.opacity(0.1))\n .clipShape(RoundedRectangle(cornerRadius: 8))\n .padding(.bottom)\n }\n\n HStack {\n Spacer()\n\n Button(\"Cancel\".i18n(), action: cancel)\n .keyboardShortcut(.cancelAction)\n\n Button(\"\\(rule == nil ? \"Add\" : \"Save\")\".i18n(), action: save)\n .disabled(value.isEmpty)\n .keyboardShortcut(.defaultAction)\n }\n .padding(.top, 6)\n }\n .padding()\n .frame(width: 480)\n .onAppear {\n value = rule?.value ?? \"\"\n sampleValue = rule?.sample ?? \"\"\n ruleType = rule?.type ?? .domainSuffix\n hideIndicator = rule?.hideIndicator ?? false\n\n if let inputSource = rule?.forcedKeyboard {\n inputSourceItem = PickerItem(id: inputSource.id, title: inputSource.name, toolTip: inputSource.id)\n }\n\n if let keyboardRestoreStrategy = rule?.keyboardRestoreStrategy {\n restoreStrategyItem = PickerItem(\n id: keyboardRestoreStrategy.rawValue,\n title: keyboardRestoreStrategy.name,\n toolTip: nil\n )\n }\n }\n }\n\n func handleSelectInputSource(_ index: Int) {\n inputSourceItem = inputSourceItems[index]\n }\n\n func handleRestoreStrategy(_ index: Int) {\n restoreStrategyItem = restoreStrategyItems[index]\n }\n\n func handleSelectRule(_ index: Int) {\n ruleType = ruleTypes[index]\n }\n\n func cancel() {\n isPresented = false\n }\n\n func save() {\n guard !value.isEmpty else { return }\n\n let keyboardRestoreStrategy = restoreStrategyItem == .empty ? nil : KeyboardRestoreStrategy(rawValue: restoreStrategyItem.id)\n\n if let rule = rule {\n preferencesVM.updateBrowserRule(\n rule,\n type: ruleType,\n value: value,\n sample: sampleValue,\n inputSourceId: inputSourceItem.id,\n hideIndicator: hideIndicator,\n keyboardRestoreStrategy: keyboardRestoreStrategy\n )\n } else {\n preferencesVM.addBrowserRule(\n type: ruleType,\n value: value,\n sample: sampleValue,\n inputSourceId: inputSourceItem.id,\n hideIndicator: hideIndicator,\n keyboardRestoreStrategy: keyboardRestoreStrategy\n )\n }\n\n isPresented = false\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/URL.swift", "import AppKit\n\nextension URL {\n static let newtab = URL(string: \"isp://newtab\")!\n\n func open() {\n NSWorkspace.shared.open(self)\n }\n\n func bundleId() -> String {\n Bundle(url: self)?.bundleIdentifier ?? dataRepresentation.md5()\n }\n\n func removeFragment() -> URL {\n var components = URLComponents(url: self, resolvingAgainstBaseURL: false)\n\n components?.fragment = nil\n\n return components?.url ?? self\n }\n}\n\nextension URL {\n static let website = URL(\n string: \"https://inputsource.pro\"\n )!\n\n static let purchase = URL(\n string: \"https://inputsource.pro/purchase\"\n )!\n\n static let twitter = URL(\n string: \"https://twitter.com/runjuuu\"\n )!\n\n static let emailString = \"support@inputsource.pro\"\n\n static let email = URL(string: \"mailto:\\(emailString)\")!\n\n static let howToEnableAccessbility = URL(\n string: \"https://inputsource.pro/help/enable-spotlight-like-apps-support\"\n )!\n\n static let howToEnableBrowserRule = URL(\n string: \"https://inputsource.pro/help/enable-browser-rule\"\n )!\n}\n"], ["/InputSourcePro/Input Source Pro/Models/PreferencesVM.swift", "import AppKit\nimport AXSwift\nimport Combine\nimport CombineExt\nimport LaunchAtLogin\nimport Sparkle\nimport SwiftUI\n\nprivate enum UpdateFeed {\n static let stable = URL(string: \"https://inputsource.pro/stable/appcast.xml\")!\n static let beta = URL(string: \"https://inputsource.pro/beta/appcast.xml\")!\n}\n\n@MainActor\nfinal class PreferencesVM: NSObject, ObservableObject {\n @Published\n var preferences = Preferences()\n\n @Published\n var keyboardConfigs: [KeyboardConfig] = []\n\n var permissionsVM: PermissionsVM\n\n var updaterController: SPUStandardUpdaterController?\n\n var cancelBag = CancelBag()\n\n var appKeyboardCache = AppKeyboardCache()\n\n let container: NSPersistentContainer\n let mainStorage: MainStorage\n\n let versionStr = \"\\(Bundle.main.infoDictionary?[\"CFBundleShortVersionString\"] as? String ?? \"unknown\")\"\n\n let buildStr = \"\\(Bundle.main.infoDictionary?[\"CFBundleVersion\"] as? String ?? \"unknown\")\"\n\n @Published\n var automaticallyChecksForUpdates = false\n\n @Published\n var canChecksForUpdates = false\n\n init(permissionsVM: PermissionsVM) {\n self.permissionsVM = permissionsVM\n container = NSPersistentContainer(name: \"Main\")\n mainStorage = MainStorage(container: container)\n \n super.init();\n \n setupAutoUpdate()\n\n // TODO: - Move to MainStorage\n container.loadPersistentStores { _, error in\n if let error = error {\n print(\"Core Data 'Main' failed to load: \\(error.localizedDescription)\")\n } else {\n self.mainStorage.refresh()\n }\n }\n\n if preferences.prevInstalledBuildVersion == 0 {\n for filterApp in filterApps(NSWorkspace.shared.runningApplications) {\n addAppCustomization(filterApp)\n }\n }\n\n cleanRemovedAppCustomizationIfNeed()\n migratePreferncesIfNeed()\n migrateBoutiqueIfNeed()\n watchKeyboardConfigsChange()\n watchPreferenceChanges()\n }\n\n func update(_ change: (inout Preferences) -> Void) {\n var draft = preferences\n\n change(&draft)\n\n preferences = draft\n }\n\n func saveContext(_ callback: (() -> Void)? = nil) {\n if let callback = callback {\n container.viewContext.performAndWait {\n callback()\n save()\n }\n } else {\n save()\n }\n\n func save() {\n do {\n try container.viewContext.save()\n } catch {\n print(\"saveAppCustomization error: \\(error.localizedDescription)\")\n }\n }\n }\n}\n\nextension PreferencesVM {\n private func watchPreferenceChanges() {\n $preferences\n .map(\\.isLaunchAtLogin)\n .removeDuplicates()\n .sink { LaunchAtLogin.isEnabled = $0 }\n .store(in: cancelBag)\n }\n \n private func watchKeyboardConfigsChange() {\n mainStorage.keyboardConfigs\n .assign(to: &$keyboardConfigs)\n }\n}\n\nextension PreferencesVM: @preconcurrency SPUUpdaterDelegate {\n private func setupAutoUpdate() {\n updaterController = SPUStandardUpdaterController(\n startingUpdater: true,\n updaterDelegate: self,\n userDriverDelegate: nil\n )\n\n updaterController?.updater\n .publisher(for: \\.automaticallyChecksForUpdates)\n .removeDuplicates()\n .assign(to: &$automaticallyChecksForUpdates)\n\n $automaticallyChecksForUpdates\n .dropFirst()\n .sink { [weak self] in self?.updaterController?.updater.automaticallyChecksForUpdates = $0 }\n .store(in: cancelBag)\n\n updaterController?.updater\n .publisher(for: \\.canCheckForUpdates)\n .debounce(for: 0.5, scheduler: DispatchQueue.main)\n .assign(to: &$canChecksForUpdates)\n }\n\n func checkUpdates() {\n updaterController?.updater.checkForUpdates()\n }\n \n func feedURLString(for updater: SPUUpdater) -> String? {\n let url = preferences.receiveBetaUpdates ? UpdateFeed.beta : UpdateFeed.stable\n return url.absoluteString\n }\n}\n\nextension PreferencesVM {\n func getBrowserURL(_ bundleIdentifier: String?, application: Application?) -> URL? {\n guard\n permissionsVM.isAccessibilityEnabled,\n let bundleIdentifier = bundleIdentifier,\n let browser = Browser(rawValue: bundleIdentifier)\n else { return nil }\n\n switch browser {\n case .Safari:\n guard preferences.isEnableURLSwitchForSafari else { return nil }\n case .SafariTechnologyPreview:\n guard preferences.isEnableURLSwitchForSafariTechnologyPreview else { return nil }\n case .Chrome:\n guard preferences.isEnableURLSwitchForChrome else { return nil }\n case .Chromium:\n guard preferences.isEnableURLSwitchForChromium else { return nil }\n case .Arc:\n guard preferences.isEnableURLSwitchForArc else { return nil }\n case .Edge:\n guard preferences.isEnableURLSwitchForEdge else { return nil }\n case .Brave:\n guard preferences.isEnableURLSwitchForBrave else { return nil }\n case .BraveBeta:\n guard preferences.isEnableURLSwitchForBraveBeta else { return nil }\n case .BraveNightly:\n guard preferences.isEnableURLSwitchForBraveNightly else { return nil }\n case .Vivaldi:\n guard preferences.isEnableURLSwitchForVivaldi else { return nil }\n case .Opera:\n guard preferences.isEnableURLSwitchForOpera else { return nil }\n case .Thorium:\n guard preferences.isEnableURLSwitchForThorium else { return nil }\n case .Firefox:\n guard preferences.isEnableURLSwitchForFirefox else { return nil }\n case .FirefoxDeveloperEdition:\n guard preferences.isEnableURLSwitchForFirefoxDeveloperEdition else { return nil }\n case .FirefoxNightly:\n guard preferences.isEnableURLSwitchForFirefoxNightly else { return nil }\n case .Zen:\n guard preferences.isEnableURLSwitchForZen else { return nil }\n case .Dia:\n guard preferences.isEnableURLSwitchForDia else { return nil }\n }\n\n if let application = application,\n let focusedWindow: UIElement = try? application.attribute(.focusedWindow),\n let url = browser.getCurrentTabURL(focusedWindow: focusedWindow)\n {\n return url\n } else {\n if browser == .Safari || browser == .SafariTechnologyPreview {\n return .newtab\n } else {\n return nil\n }\n }\n }\n\n func filterApps(_ apps: [NSRunningApplication]) -> [NSRunningApplication] {\n let isDetectSpotlightLikeApp = preferences.isEnhancedModeEnabled\n\n return apps.filter { app in\n (isDetectSpotlightLikeApp && NSApplication.isFloatingApp(app.bundleIdentifier))\n || app.activationPolicy == .regular\n }\n }\n}\n\nstruct Preferences {\n enum AppearanceMode: String, CaseIterable, Codable, Equatable {\n case dark = \"Dark\"\n case light = \"Light\"\n }\n\n private enum Key {\n static let prevInstalledBuildVersion = \"prevInstalledBuildVersion\"\n\n static let isLaunchAtLogin = \"isLaunchAtLogin\"\n static let isShowIconInMenuBar = \"isShowIconInMenuBar\"\n static let isEnhancedModeEnabled = \"isDetectSpotlightLikeApp\"\n static let isCJKVFixEnabled = \"isCJKVFixEnabled\"\n\n static let systemWideDefaultKeyboardId = \"systemWideDefaultKeyboardId\"\n\n static let browserAddressDefaultKeyboardId = \"browserAddressDefaultKeyboardId\"\n static let isActiveWhenLongpressLeftMouse = \"isActiveWhenLongpressLeftMouse\"\n static let isActiveWhenFocusedElementChanges = \"isActiveWhenFocusedElementChanges\"\n static let isActiveWhenSwitchApp = \"isActiveWhenSwitchApp\"\n static let isHideWhenSwitchAppWithForceKeyboard = \"isHideWhenSwitchAppWithForceKeyboard\"\n static let isActiveWhenSwitchInputSource = \"isActiveWhenSwitchInputSource\"\n\n static let isRestorePreviouslyUsedInputSource = \"isRestorePreviouslyUsedInputSource\"\n\n static let isEnableURLSwitchForSafari = \"isEnableURLSwitchForSafari\"\n static let isEnableURLSwitchForSafariTechnologyPreview = \"isEnableURLSwitchForSafariTechnologyPreview\"\n static let isEnableURLSwitchForChrome = \"isEnableURLSwitchForChrome\"\n static let isEnableURLSwitchForChromium = \"isEnableURLSwitchForChromium\"\n static let isEnableURLSwitchForArc = \"isEnableURLSwitchForArc\"\n static let isEnableURLSwitchForEdge = \"isEnableURLSwitchForEdge\"\n static let isEnableURLSwitchForBrave = \"isEnableURLSwitchForBrave\"\n static let isEnableURLSwitchForBraveBeta = \"isEnableURLSwitchForBraveBeta\"\n static let isEnableURLSwitchForBraveNightly = \"isEnableURLSwitchForBraveNightly\"\n static let isEnableURLSwitchForVivaldi = \"isEnableURLSwitchForVivaldi\"\n static let isEnableURLSwitchForOpera = \"isEnableURLSwitchForOpera\"\n static let isEnableURLSwitchForThorium = \"isEnableURLSwitchForThorium\"\n static let isEnableURLSwitchForFirefox = \"isEnableURLSwitchForFirefox\"\n static let isEnableURLSwitchForFirefoxDeveloperEdition = \"isEnableURLSwitchForFirefoxDeveloperEdition\"\n static let isEnableURLSwitchForFirefoxNightly = \"isEnableURLSwitchForFirefoxNightly\"\n static let isEnableURLSwitchForZen = \"isEnableURLSwitchForZen\"\n static let isEnableURLSwitchForDia = \"isEnableURLSwitchForDia\"\n\n static let isAutoAppearanceMode = \"isAutoAppearanceMode\"\n static let appearanceMode = \"appearanceMode\"\n static let isShowInputSourcesLabel = \"isShowInputSourcesLabel\"\n static let indicatorBackground = \"indicatorBackground\"\n static let indicatorForgeground = \"indicatorForgeground\"\n\n static let tryToDisplayIndicatorNearCursor = \"tryToDisplayIndicatorNearCursor\"\n static let isEnableAlwaysOnIndicator = \"isEnableAlwaysOnIndicator\"\n\n static let indicatorPosition = \"indicatorPosition\"\n static let indicatorPositionAlignment = \"indicatorPositionAlignment\"\n static let indicatorPositionSpacing = \"indicatorPositionSpacing\"\n\n static let indicatorSize = \"indicatorSize\"\n static let indicatorInfo = \"indicatorInfo\"\n \n static let receiveBetaUpdates = \"receiveBetaUpdates\"\n }\n\n fileprivate init() {}\n\n @UserDefault(Preferences.Key.prevInstalledBuildVersion)\n var prevInstalledBuildVersion = 0\n\n // MARK: - General\n\n @UserDefault(Preferences.Key.isLaunchAtLogin)\n var isLaunchAtLogin = LaunchAtLogin.isEnabled\n\n @UserDefault(Preferences.Key.isShowIconInMenuBar)\n var isShowIconInMenuBar = true\n\n @UserDefault(Preferences.Key.isEnhancedModeEnabled)\n var isEnhancedModeEnabled = false\n\n @UserDefault(Preferences.Key.isCJKVFixEnabled)\n var isCJKVFixEnabled = false\n \n @UserDefault(Preferences.Key.receiveBetaUpdates)\n var receiveBetaUpdates = false\n\n // MARK: - Triggers\n\n @UserDefault(Preferences.Key.isActiveWhenLongpressLeftMouse)\n var isActiveWhenLongpressLeftMouse = true\n\n @UserDefault(Preferences.Key.isActiveWhenSwitchApp)\n var isActiveWhenSwitchApp = true\n\n @UserDefault(Preferences.Key.isHideWhenSwitchAppWithForceKeyboard)\n var isHideWhenSwitchAppWithForceKeyboard = false\n\n @UserDefault(Preferences.Key.isActiveWhenSwitchInputSource)\n var isActiveWhenSwitchInputSource = true\n\n @UserDefault(Preferences.Key.isActiveWhenFocusedElementChanges)\n var isActiveWhenFocusedElementChanges = true\n\n // MARK: - Input Source\n\n @UserDefault(Preferences.Key.isRestorePreviouslyUsedInputSource)\n var isRestorePreviouslyUsedInputSource = false\n\n // MARK: - App Rules\n\n @UserDefault(Preferences.Key.systemWideDefaultKeyboardId)\n var systemWideDefaultKeyboardId = \"\"\n\n // MARK: - Browser Rules\n\n @UserDefault(Preferences.Key.browserAddressDefaultKeyboardId)\n var browserAddressDefaultKeyboardId = \"\"\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForSafari)\n var isEnableURLSwitchForSafari = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForSafariTechnologyPreview)\n var isEnableURLSwitchForSafariTechnologyPreview = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForChrome)\n var isEnableURLSwitchForChrome = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForChromium)\n var isEnableURLSwitchForChromium = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForArc)\n var isEnableURLSwitchForArc = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForEdge)\n var isEnableURLSwitchForEdge = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForBrave)\n var isEnableURLSwitchForBrave = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForBraveBeta)\n var isEnableURLSwitchForBraveBeta = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForBraveNightly)\n var isEnableURLSwitchForBraveNightly = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForVivaldi)\n var isEnableURLSwitchForVivaldi = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForOpera)\n var isEnableURLSwitchForOpera = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForThorium)\n var isEnableURLSwitchForThorium = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForFirefox)\n var isEnableURLSwitchForFirefox = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForFirefoxDeveloperEdition)\n var isEnableURLSwitchForFirefoxDeveloperEdition = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForFirefoxNightly)\n var isEnableURLSwitchForFirefoxNightly = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForZen)\n var isEnableURLSwitchForZen = false\n \n @UserDefault(Preferences.Key.isEnableURLSwitchForDia)\n var isEnableURLSwitchForDia = false\n\n // MARK: - Appearance\n\n @available(*, deprecated, message: \"Use indicatorInfo instead\")\n @UserDefault(Preferences.Key.isShowInputSourcesLabel)\n var isShowInputSourcesLabel = true\n\n @CodableUserDefault(Preferences.Key.indicatorInfo)\n var indicatorInfo = IndicatorInfo.iconAndTitle\n\n @CodableUserDefault(Preferences.Key.indicatorSize)\n var indicatorSize = IndicatorSize.medium\n\n @UserDefault(Preferences.Key.isAutoAppearanceMode)\n var isAutoAppearanceMode = true\n\n @CodableUserDefault(Preferences.Key.appearanceMode)\n var appearanceMode = AppearanceMode.dark\n\n @CodableUserDefault(Preferences.Key.indicatorBackground)\n var indicatorBackground = IndicatorColor.background\n\n @CodableUserDefault(Preferences.Key.indicatorForgeground)\n var indicatorForgeground = IndicatorColor.forgeground\n\n @UserDefault(Preferences.Key.tryToDisplayIndicatorNearCursor)\n var tryToDisplayIndicatorNearCursor = true\n\n @UserDefault(Preferences.Key.isEnableAlwaysOnIndicator)\n var isEnableAlwaysOnIndicator = false\n\n @CodableUserDefault(Preferences.Key.indicatorPosition)\n var indicatorPosition = IndicatorPosition.nearMouse\n\n @CodableUserDefault(Preferences.Key.indicatorPositionAlignment)\n var indicatorPositionAlignment = IndicatorPosition.Alignment.bottomRight\n\n @CodableUserDefault(Preferences.Key.indicatorPositionSpacing)\n var indicatorPositionSpacing = IndicatorPosition.Spacing.s\n}\n\nextension Preferences {\n var shortVersion: String {\n Bundle.main.shortVersion\n }\n\n var buildVersion: Int {\n Bundle.main.buildVersion\n }\n\n var isActiveWhenFocusedElementChangesEnabled: Bool {\n return isEnhancedModeEnabled && isActiveWhenFocusedElementChanges\n }\n\n var indicatorKind: IndicatorKind {\n guard let indicatorInfo = indicatorInfo else { return .iconAndTitle }\n\n switch indicatorInfo {\n case .iconAndTitle:\n return .iconAndTitle\n case .iconOnly:\n return .icon\n case .titleOnly:\n return .title\n }\n }\n\n var indicatorBackgroundColor: Color {\n get {\n switch appearanceMode {\n case .dark?:\n return indicatorBackground?.dark ?? IndicatorColor.background.dark\n default:\n return indicatorBackground?.light ?? IndicatorColor.background.light\n }\n }\n\n set {\n guard let appearanceMode = appearanceMode,\n let indicatorBackground = indicatorBackground\n else { return }\n\n switch appearanceMode {\n case .dark:\n self.indicatorBackground = IndicatorColor(\n light: indicatorBackground.light,\n dark: newValue\n )\n case .light:\n self.indicatorBackground = IndicatorColor(\n light: newValue,\n dark: indicatorBackground.dark\n )\n }\n }\n }\n\n var indicatorForgegroundColor: Color {\n get {\n switch appearanceMode {\n case .dark?:\n return indicatorForgeground?.dark ?? IndicatorColor.forgeground.dark\n default:\n return indicatorForgeground?.light ?? IndicatorColor.forgeground.light\n }\n }\n\n set {\n guard let appearanceMode = appearanceMode,\n let indicatorForgeground = indicatorForgeground\n else { return }\n\n switch appearanceMode {\n case .dark:\n self.indicatorForgeground = IndicatorColor(\n light: indicatorForgeground.light,\n dark: newValue\n )\n case .light:\n self.indicatorForgeground = IndicatorColor(\n light: newValue,\n dark: indicatorForgeground.dark\n )\n }\n }\n }\n}\n\nextension PreferencesVM {\n var systemWideDefaultKeyboard: InputSource? {\n return InputSource.sources.first { $0.id == preferences.systemWideDefaultKeyboardId }\n }\n\n var browserAddressDefaultKeyboard: InputSource? {\n return InputSource.sources.first { $0.id == preferences.browserAddressDefaultKeyboardId }\n }\n}\n\nextension PreferencesVM {\n func isUseCJKVFix() -> Bool {\n return preferences.isEnhancedModeEnabled && preferences.isCJKVFixEnabled\n }\n\n func isAbleToQueryLocation(_ app: NSRunningApplication) -> Bool {\n if app.bundleIdentifier == \"com.tencent.WeWorkMac\" {\n return false\n } else {\n return true\n }\n }\n\n func isShowAlwaysOnIndicator(app: NSRunningApplication) -> Bool {\n if preferences.isEnableAlwaysOnIndicator,\n isAbleToQueryLocation(app)\n {\n return true\n } else {\n return false\n }\n }\n\n func needDetectFocusedFieldChanges(app: NSRunningApplication) -> Bool {\n if preferences.isActiveWhenFocusedElementChangesEnabled,\n isAbleToQueryLocation(app)\n {\n return true\n } else {\n return false\n }\n }\n\n func isHideIndicator(_ appKind: AppKind) -> Bool {\n if let browserRule = appKind.getBrowserInfo()?.rule,\n browserRule.hideIndicator\n {\n return true\n }\n\n return getAppCustomization(app: appKind.getApp())?.hideIndicator == true\n }\n\n func needDisplayEnhancedModePrompt(bundleIdentifier: String?) -> Bool {\n NSApplication.isFloatingApp(bundleIdentifier) && !preferences.isEnhancedModeEnabled\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/PreferencesVM+BrowserRule.swift", "import AppKit\nimport AXSwift\nimport Foundation\n\nextension PreferencesVM {\n func addBrowserRule(\n type: BrowserRuleType,\n value: String,\n sample: String,\n inputSourceId: String,\n hideIndicator: Bool,\n keyboardRestoreStrategy: KeyboardRestoreStrategy?\n ) {\n let rule = BrowserRule(context: container.viewContext)\n\n rule.createdAt = Date()\n rule.type = type\n rule.value = value\n rule.sample = sample\n rule.inputSourceId = inputSourceId\n rule.keyboardRestoreStrategyRaw = keyboardRestoreStrategy?.rawValue\n rule.hideIndicator = hideIndicator\n rule.disabled = false\n\n saveContext()\n }\n\n func deleteBrowserRule(_ rule: BrowserRule) {\n container.viewContext.delete(rule)\n saveContext()\n }\n\n func updateBrowserRule(\n _ rule: BrowserRule,\n type: BrowserRuleType,\n value: String,\n sample: String,\n inputSourceId: String,\n hideIndicator: Bool,\n keyboardRestoreStrategy: KeyboardRestoreStrategy?\n ) {\n saveContext {\n rule.type = type\n rule.value = value\n rule.sample = sample\n rule.inputSourceId = inputSourceId\n rule.hideIndicator = hideIndicator\n rule.keyboardRestoreStrategyRaw = keyboardRestoreStrategy?.rawValue\n }\n }\n\n func toggleBrowserRule(_ rule: BrowserRule) {\n saveContext {\n rule.disabled.toggle()\n }\n }\n\n private func getBrowserRules() -> [BrowserRule] {\n let request = NSFetchRequest(entityName: \"BrowserRule\")\n\n do {\n return try container.viewContext.fetch(request)\n } catch {\n print(\"getBrowserRules() error: \\(error.localizedDescription)\")\n return []\n }\n }\n\n func getBrowserRule(url: URL) -> BrowserRule? {\n return getBrowserRules().first { $0.validate(url: url) }\n }\n}\n\nextension PreferencesVM {\n var isNeedToDetectBrowserTabChanges: Bool {\n guard preferences.isEnhancedModeEnabled else { return false }\n\n return Browser.allCases.contains(where: isBrowserEnabled)\n }\n\n func isBrowserAndEnabled(_ app: NSRunningApplication) -> Bool {\n guard let browser = NSApplication.getBrowser(app)\n else { return false }\n\n return isBrowserEnabled(browser)\n }\n\n func isBrowserEnabled(_ browser: Browser) -> Bool {\n switch browser {\n case .Safari:\n return preferences.isEnableURLSwitchForSafari\n case .SafariTechnologyPreview:\n return preferences.isEnableURLSwitchForSafariTechnologyPreview\n case .Chrome:\n return preferences.isEnableURLSwitchForChrome\n case .Chromium:\n return preferences.isEnableURLSwitchForChromium\n case .Arc:\n return preferences.isEnableURLSwitchForArc\n case .Edge:\n return preferences.isEnableURLSwitchForEdge\n case .Brave:\n return preferences.isEnableURLSwitchForBrave\n case .BraveBeta:\n return preferences.isEnableURLSwitchForBraveBeta\n case .BraveNightly:\n return preferences.isEnableURLSwitchForBraveNightly\n case .Vivaldi:\n return preferences.isEnableURLSwitchForVivaldi\n case .Opera:\n return preferences.isEnableURLSwitchForOpera\n case .Thorium:\n return preferences.isEnableURLSwitchForThorium\n case .Firefox:\n return preferences.isEnableURLSwitchForFirefox\n case .FirefoxDeveloperEdition:\n return preferences.isEnableURLSwitchForFirefoxDeveloperEdition\n case .FirefoxNightly:\n return preferences.isEnableURLSwitchForFirefoxNightly\n case .Zen:\n return preferences.isEnableURLSwitchForZen\n case .Dia:\n return preferences.isEnableURLSwitchForDia\n }\n }\n\n func getBrowserInfo(app: NSRunningApplication) -> (url: URL, rule: BrowserRule?)? {\n guard let url = getBrowserURL(app.bundleIdentifier, application: Application(app)) else { return nil }\n\n return (url, getBrowserRule(url: url))\n }\n}\n"], ["/InputSourcePro/Input Source Pro/System/AppMenu.swift", "import Cocoa\n\nclass AppMenu: NSMenu {\n private lazy var applicationName = ProcessInfo.processInfo.processName\n\n override init(title: String) {\n super.init(title: title)\n\n let mainMenu = NSMenuItem()\n mainMenu.submenu = NSMenu(title: \"MainMenu\")\n mainMenu.submenu?.items = [\n NSMenuItem(title: \"About \\(applicationName)\", action: #selector(NSApplication.orderFrontStandardAboutPanel(_:)), keyEquivalent: \"\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Preferences...\", action: nil, keyEquivalent: \",\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Hide \\(applicationName)\", action: #selector(NSApplication.hide(_:)), keyEquivalent: \"h\"),\n NSMenuItem(title: \"Hide Others\", target: self, action: #selector(NSApplication.hideOtherApplications(_:)), keyEquivalent: \"h\", modifier: .init(arrayLiteral: [.command, .option])),\n NSMenuItem(title: \"Show All\", action: #selector(NSApplication.unhideAllApplications(_:)), keyEquivalent: \"\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Quit \\(applicationName)\", action: #selector(NSApplication.shared.terminate(_:)), keyEquivalent: \"q\"),\n ]\n\n let fileMenu = NSMenuItem()\n fileMenu.submenu = NSMenu(title: \"File\")\n fileMenu.submenu?.items = [\n NSMenuItem(title: \"New\", action: #selector(NSDocumentController.newDocument(_:)), keyEquivalent: \"n\"),\n NSMenuItem(title: \"Open\", action: #selector(NSDocumentController.openDocument(_:)), keyEquivalent: \"o\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Close\", action: #selector(NSWindow.performClose(_:)), keyEquivalent: \"w\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Save\", action: #selector(NSDocument.save(_:)), keyEquivalent: \"s\"),\n NSMenuItem(title: \"Save As...\", action: #selector(NSDocument.saveAs(_:)), keyEquivalent: \"S\"),\n NSMenuItem(title: \"Revert to Saved...\", action: #selector(NSDocument.revertToSaved(_:)), keyEquivalent: \"\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Export\", action: nil, keyEquivalent: \"\"),\n ]\n\n let editMenu = NSMenuItem()\n editMenu.submenu = NSMenu(title: \"Edit\")\n editMenu.submenu?.items = [\n NSMenuItem(title: \"Undo\", action: #selector(UndoManager.undo), keyEquivalent: \"z\"),\n NSMenuItem(title: \"Redo\", action: #selector(UndoManager.redo), keyEquivalent: \"Z\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Cut\", action: #selector(NSText.cut(_:)), keyEquivalent: \"x\"),\n NSMenuItem(title: \"Copy\", action: #selector(NSText.copy(_:)), keyEquivalent: \"c\"),\n NSMenuItem(title: \"Paste\", action: #selector(NSText.paste(_:)), keyEquivalent: \"v\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Select All\", action: #selector(NSText.selectAll(_:)), keyEquivalent: \"a\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Delete\", target: self, action: nil, keyEquivalent: \"⌫\", modifier: .init()),\n NSMenuItem(title: \"Duplicate\", action: #selector(NSApplication.copy), keyEquivalent: \"d\"),\n ]\n\n let windowMenu = NSMenuItem()\n windowMenu.submenu = NSMenu(title: \"Window\")\n windowMenu.submenu?.items = [\n NSMenuItem(title: \"Minimize\", action: #selector(NSWindow.miniaturize(_:)), keyEquivalent: \"m\"),\n NSMenuItem(title: \"Zoom\", action: #selector(NSWindow.performZoom(_:)), keyEquivalent: \"\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Show All\", action: #selector(NSApplication.arrangeInFront(_:)), keyEquivalent: \"m\"),\n ]\n\n let viewMenu = NSMenuItem()\n viewMenu.submenu = NSMenu(title: \"View\")\n viewMenu.submenu?.items = []\n\n let helpMenu = NSMenuItem()\n let helpMenuSearch = NSMenuItem()\n helpMenuSearch.view = NSTextField()\n helpMenu.submenu = NSMenu(title: \"Help\")\n helpMenu.submenu?.items = [\n helpMenuSearch,\n ]\n\n items = [mainMenu, fileMenu, editMenu, viewMenu, windowMenu, helpMenu]\n }\n\n @available(*, unavailable)\n required init(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/BrowserRuleMenuItem.swift", "import AppKit\n\n@MainActor\nclass BrowserRuleMenuItem: NSMenuItem {\n let url: URL\n let preferencesVM: PreferencesVM\n let inputSource: InputSource?\n\n var cancelBag = CancelBag()\n\n var browserRule: BrowserRule? {\n preferencesVM.getBrowserRule(url: url)\n }\n\n init(url: URL, preferencesVM: PreferencesVM, inputSource: InputSource?) {\n self.url = url\n self.preferencesVM = preferencesVM\n self.inputSource = inputSource\n\n super.init(title: inputSource?.name ?? \"\", action: #selector(forceKeyboard(_:)), keyEquivalent: \"\")\n\n target = self\n\n updateState()\n watchChanges()\n }\n\n @available(*, unavailable)\n required init(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n\n @objc func forceKeyboard(_: Any) {\n let inputSourceId = inputSource?.id ?? \"\"\n let host = url.host ?? \"\"\n\n if let browserRule = browserRule {\n preferencesVM.updateBrowserRule(\n browserRule,\n type: .domain,\n value: host,\n sample: url.absoluteString,\n inputSourceId: inputSourceId,\n hideIndicator: browserRule.hideIndicator,\n keyboardRestoreStrategy: browserRule.keyboardRestoreStrategy\n )\n } else {\n preferencesVM.addBrowserRule(\n type: .domain,\n value: host,\n sample: url.absoluteString,\n inputSourceId: inputSourceId,\n hideIndicator: false,\n keyboardRestoreStrategy: nil\n )\n }\n\n inputSource?.select(useCJKVFix: preferencesVM.isUseCJKVFix())\n\n watchChanges()\n }\n\n func watchChanges() {\n cancelBag.cancel()\n\n browserRule?.publisher(for: \\.inputSourceId)\n .sink { [weak self] _ in self?.updateState() }\n .store(in: cancelBag)\n }\n\n func updateState() {\n state = browserRule?.inputSourceId == inputSource?.id ? .on : .off\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/KeyboardRestoreStrategy.swift", "import SwiftUI\n\nenum KeyboardRestoreStrategy: String, CaseIterable, Identifiable {\n case UseDefaultKeyboardInstead\n case RestorePreviouslyUsedOne\n\n var name: String {\n switch self {\n case .UseDefaultKeyboardInstead:\n return \"Use Default Keyboard Instead\".i18n()\n case .RestorePreviouslyUsedOne:\n return \"Restore Previously Used One\".i18n()\n }\n }\n\n var systemImageName: String {\n switch self {\n case .UseDefaultKeyboardInstead:\n return \"d.circle.fill\"\n case .RestorePreviouslyUsedOne:\n return \"arrow.uturn.left.circle.fill\"\n }\n }\n\n var id: Self { self }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/IndicatorPositionEditor.swift", "import SwiftUI\nimport VisualEffects\n\nstruct IndicatorPositionEditor: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n let columns = Array(repeating: GridItem(.flexible(), spacing: 0), count: 3)\n\n @State var hoveredAlignment: IndicatorPosition.Alignment? = nil\n\n let height: CGFloat = 230\n let windowHPadding: CGFloat = 30\n let windowVPadding: CGFloat = 15\n\n var selectedAlignment: IndicatorPosition.Alignment {\n preferencesVM.preferences.indicatorPositionAlignment ?? .bottomRight\n }\n\n var position: IndicatorPosition {\n preferencesVM.preferences.indicatorPosition ?? .nearMouse\n }\n\n var alignmentHPadding: CGFloat {\n let offset = position == .windowCorner ? windowHPadding : 0\n let minLength = position == .windowCorner ? height - offset * 2 : height\n let spacing = preferencesVM.calcSpacing(minLength: minLength)\n\n return spacing + offset\n }\n\n var alignmentVPadding: CGFloat {\n let offset = position == .windowCorner ? windowVPadding : 0\n let minLength = position == .windowCorner ? height - offset * 2 : height\n let spacing = preferencesVM.calcSpacing(minLength: minLength)\n\n return spacing + offset\n }\n\n let items: [IndicatorPosition.Alignment] = [\n .topLeft, .topCenter, .topRight,\n .centerLeft, .center, .centerRight,\n .bottomLeft, .bottomCenter, .bottomRight,\n ]\n\n var body: some View {\n LazyVGrid(columns: columns, spacing: 0) {\n ForEach(items, id: \\.self) { (alignment: IndicatorPosition.Alignment) in\n IndicatorAlignmentItem(\n alignment: alignment,\n position: position,\n isSelected: selectedAlignment == alignment,\n content: {\n let offset = offset(alignment: alignment)\n\n alignment.indicator()\n .rotationEffect(alignment.rotate)\n .offset(x: offset.x, y: offset.y)\n .foregroundColor(Color.primary)\n }\n )\n .frame(height: height / 3)\n .onTapGesture {\n withAnimation {\n preferencesVM.update {\n $0.indicatorPositionAlignment = alignment\n }\n }\n }\n }\n .opacity(position == .nearMouse ? 0 : 1)\n }\n .background(\n IndicatorAlignmentView(\n alignment: position == .nearMouse ? .center : selectedAlignment\n ) {\n IndicatorView()\n .fixedSize()\n .padding(.horizontal, alignmentHPadding)\n .padding(.vertical, alignmentVPadding)\n }\n )\n .background(\n windowIndicator()\n )\n .background(\n Image(\"FakeDesktop\")\n .resizable()\n .aspectRatio(contentMode: .fill)\n .scaledToFill()\n )\n }\n\n @ViewBuilder\n func windowIndicator() -> some View {\n MockWindowView()\n .padding(.horizontal, windowHPadding)\n .padding(.vertical, windowVPadding)\n .frame(height: height)\n .opacity(position == .windowCorner ? 1 : 0)\n .offset(x: 0, y: position == .windowCorner ? 0 : height)\n }\n\n func offset(alignment: IndicatorPosition.Alignment) -> (x: Double, y: Double) {\n switch alignment {\n case .center:\n return (0, 0)\n case .centerLeft:\n return (alignmentHPadding, 0)\n case .centerRight:\n return (-alignmentHPadding, 0)\n case .topLeft:\n return (alignmentHPadding, alignmentVPadding)\n case .topCenter:\n return (0, alignmentVPadding)\n case .topRight:\n return (-alignmentHPadding, alignmentVPadding)\n case .bottomLeft:\n return (alignmentHPadding, -alignmentVPadding)\n case .bottomCenter:\n return (0, -alignmentVPadding)\n case .bottomRight:\n return (-alignmentHPadding, -alignmentVPadding)\n }\n }\n}\n\nstruct IndicatorAlignmentItem: View {\n let alignment: IndicatorPosition.Alignment\n\n let position: IndicatorPosition\n\n let isSelected: Bool\n\n let content: Content\n\n @State var isHovered: Bool = false\n\n init(alignment: IndicatorPosition.Alignment, position: IndicatorPosition, isSelected: Bool, @ViewBuilder content: () -> Content) {\n self.alignment = alignment\n self.position = position\n self.isSelected = isSelected\n self.content = content()\n }\n\n var body: some View {\n IndicatorAlignmentView(alignment: alignment) {\n content\n }\n .frame(maxWidth: .infinity, maxHeight: .infinity)\n .contentShape(Rectangle())\n .opacity(isSelected ? 0 : 1)\n .opacity(isHovered ? 0.9 : 0.3)\n .animation(.default, value: isSelected)\n .animation(.default, value: isHovered)\n .onHover(perform: { isHovered = $0 })\n }\n}\n\nprivate extension IndicatorPosition.Alignment {\n var rotate: Angle {\n switch self {\n case .topLeft:\n return .degrees(-90)\n case .topRight:\n return .zero\n case .bottomLeft:\n return .degrees(180)\n case .bottomRight:\n return .degrees(90)\n case .center:\n return .degrees(45)\n case .centerLeft:\n return .zero\n case .centerRight:\n return .zero\n case .topCenter:\n return .zero\n case .bottomCenter:\n return .zero\n }\n }\n\n @ViewBuilder\n func indicator() -> some View {\n switch self {\n case .center:\n RoundedRectangle(cornerRadius: 3)\n .frame(width: 30, height: 30)\n case .topCenter, .bottomCenter:\n RoundedRectangle(cornerRadius: 2)\n .frame(width: 44, height: 8)\n case .centerLeft, .centerRight:\n RoundedRectangle(cornerRadius: 2)\n .frame(width: 8, height: 30)\n default:\n Image(nsImage: .triangle)\n .resizable()\n .scaledToFit()\n .frame(width: 30)\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKind.swift", "import AppKit\nimport AXSwift\nimport Combine\nimport Foundation\n\n@MainActor\nenum AppKind {\n typealias BrowserInfo = (\n focusedElement: UIElement?,\n isFocusOnInputContainer: Bool,\n\n url: URL,\n rule: BrowserRule?,\n isFocusedOnAddressBar: Bool\n )\n\n typealias NormalInfo = (\n focusedElement: UIElement?,\n isFocusOnInputContainer: Bool\n )\n\n case normal(app: NSRunningApplication, info: NormalInfo)\n case browser(app: NSRunningApplication, info: BrowserInfo)\n\n func getId() -> String? {\n switch self {\n case let .normal(app, _):\n return app.bundleId()\n case let .browser(app, info):\n if !info.isFocusedOnAddressBar,\n info.url != .newtab,\n let bundleId = app.bundleId(),\n let addressId = info.rule?.id() ?? info.url.host\n {\n return \"\\(bundleId)_\\(addressId)\"\n } else {\n return nil\n }\n }\n }\n\n func getApp() -> NSRunningApplication {\n switch self {\n case let .normal(app, _):\n return app\n case let .browser(app, _):\n return app\n }\n }\n\n func getBrowserInfo() -> BrowserInfo? {\n switch self {\n case .normal:\n return nil\n case let .browser(_, info):\n return info\n }\n }\n\n func isFocusOnInputContainer() -> Bool {\n switch self {\n case let .normal(_, info):\n return info.isFocusOnInputContainer\n case let .browser(_, info):\n return info.isFocusOnInputContainer\n }\n }\n\n func getFocusedElement() -> UIElement? {\n switch self {\n case let .normal(_, info):\n return info.focusedElement\n case let .browser(_, info):\n return info.focusedElement\n }\n }\n\n func isSameAppOrWebsite(with otherKind: AppKind?, detectAddressBar: Bool = false) -> Bool {\n guard let otherKind = otherKind else { return false }\n guard getApp() == otherKind.getApp() else { return false }\n\n let isSameAddress = getBrowserInfo()?.url == otherKind.getBrowserInfo()?.url\n let isSameAddressBar = getBrowserInfo()?.isFocusedOnAddressBar == otherKind.getBrowserInfo()?.isFocusedOnAddressBar\n\n return detectAddressBar ? (isSameAddressBar && isSameAddress) : isSameAddress\n }\n}\n\n// MARK: - From\n\nextension AppKind {\n static func from(_ app: NSRunningApplication?, preferencesVM: PreferencesVM) -> AppKind? {\n if let app = app {\n return .from(app, preferencesVM: preferencesVM)\n } else {\n return nil\n }\n }\n\n static func from(_ app: NSRunningApplication, preferencesVM: PreferencesVM) -> AppKind {\n let application = app.getApplication(preferencesVM: preferencesVM)\n let focusedElement = app.focuedUIElement(application: application)\n let isFocusOnInputContainer = UIElement.isInputContainer(focusedElement)\n\n if let url = preferencesVM.getBrowserURL(app.bundleIdentifier, application: application)?.removeFragment() {\n let rule = preferencesVM.getBrowserRule(url: url)\n let isFocusOnBrowserAddress = preferencesVM.isFocusOnBrowserAddress(app: app, focusedElement: focusedElement)\n\n return .browser(\n app: app,\n info: (\n focusedElement,\n isFocusOnInputContainer,\n url,\n rule,\n isFocusOnBrowserAddress\n )\n )\n } else {\n return .normal(\n app: app,\n info: (\n focusedElement,\n isFocusOnInputContainer\n )\n )\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/PreferencesView.swift", "import SwiftUI\nimport VisualEffects\n\nstruct PreferencesView: View {\n @EnvironmentObject var navigationVM: NavigationVM\n @EnvironmentObject var preferencesVM: PreferencesVM\n @EnvironmentObject var indicatorVM: IndicatorVM\n\n @State private var asyncSelection: NavigationVM.Nav = .general\n\n var body: some View {\n return HStack(spacing: 0) {\n ZStack {\n VisualEffectBlur(material: .sidebar, blendingMode: .behindWindow, state: .followsWindowActiveState)\n\n HStack {\n VStack {\n Button(action: {}) {\n // Trap default focus ring\n Text(\"Input Source Pro\")\n }\n\n Spacer()\n }\n Spacer()\n }\n .opacity(0)\n\n VStack(spacing: 12) {\n ForEach(NavigationVM.Nav.grouped, id: \\.id) { group in\n VStack(spacing: 2) {\n if !group.title.isEmpty {\n HStack {\n Text(group.title.i18n())\n .font(.system(size: 10))\n .opacity(0.6)\n Spacer()\n }\n .padding(.leading, 20)\n .padding(.bottom, 2)\n }\n\n ForEach(group.nav) { nav in\n let onSelect = { navigationVM.selection = nav }\n\n Button(action: onSelect) {\n Text(nav.displayName)\n }\n .buttonStyle(\n NavButtonStyle(\n icon: nav.icon,\n isActive: navigationVM.selection == nav\n )\n )\n }\n }\n }\n\n Spacer()\n\n Text(\" \\(preferencesVM.versionStr) (\\(preferencesVM.buildStr))\")\n .opacity(0.5)\n .font(.system(size: 12))\n }\n .padding(.top, 40)\n .padding(.vertical)\n }\n .frame(width: 200)\n\n HStack {\n VStack(spacing: 0) {\n HStack {\n SwiftUI.Image(systemName: asyncSelection.icon)\n .font(.system(size: 18, weight: .medium))\n .opacity(0.8)\n .frame(width: 20)\n\n VStack(alignment: .leading, spacing: 0) {\n Text(\"Input Source Pro\")\n .font(.system(size: 12, weight: .semibold))\n .opacity(0.8)\n\n Text(asyncSelection.displayName)\n .font(.system(size: 11))\n .opacity(0.6)\n }\n\n Spacer()\n }\n .frame(height: 52)\n .padding(.horizontal)\n .border(width: 1, edges: [.bottom], color: NSColor.border.color)\n\n asyncSelection.getView()\n Spacer(minLength: 0)\n }\n\n Spacer(minLength: 0)\n }\n .border(width: 1, edges: [.leading], color: NSColor.border.color)\n }\n .frame(minWidth: 780, minHeight: 620)\n .background(NSColor.background.color)\n .environment(\\.managedObjectContext, preferencesVM.container.viewContext)\n .onChange(of: navigationVM.selection) { _ in\n asyncSelection = navigationVM.selection\n }\n .onAppear {\n asyncSelection = navigationVM.selection\n }\n .edgesIgnoringSafeArea(.top)\n .modifier(FeedbackModal())\n }\n}\n\nextension NavigationVM.Nav {\n var icon: String {\n switch self {\n case .general:\n return \"slider.horizontal.3\"\n\n case .appRules:\n return \"square.grid.2x2\"\n\n case .browserRules:\n return \"safari\"\n\n case .position:\n return \"arrow.up.and.down.and.arrow.left.and.right\"\n\n case .appearance:\n return \"paintbrush\"\n\n case .inputSourcesColorScheme:\n return \"paintpalette\"\n\n case .keyboardShortcut:\n return \"command\"\n\n case .troubleshooting:\n return \"ladybug\"\n }\n }\n\n var displayName: String {\n switch self {\n case .inputSourcesColorScheme:\n return \"Color Scheme\".i18n()\n default:\n return rawValue.i18n()\n }\n }\n\n @ViewBuilder\n func getView() -> some View {\n switch self {\n case .general:\n GeneralSettingsView()\n\n case .appRules:\n RulesSettingsView()\n\n case .browserRules:\n BrowserRulesSettingsView()\n\n case .position:\n PositionSettingsView()\n\n case .appearance:\n AppearanceSettingsView()\n\n case .inputSourcesColorScheme:\n InputSourcesAppearanceSettingsView()\n\n case .keyboardShortcut:\n KeyboardsSettingsView()\n\n case .troubleshooting:\n TroubleshootingSettingsView()\n }\n }\n}\n\nstruct NavButtonStyle: ButtonStyle {\n let icon: String\n\n let isActive: Bool\n\n func makeBody(configuration: Self.Configuration) -> some View {\n HStack {\n VStack {\n SwiftUI.Image(systemName: icon)\n .font(.system(size: 15, weight: .medium))\n .frame(width: 15, height: 15)\n .opacity(0.9)\n }\n\n configuration.label\n .lineLimit(1)\n\n Spacer()\n }\n .padding(.leading, 10)\n .padding(.trailing, 5)\n .padding(.vertical, 8)\n .frame(maxWidth: .infinity)\n .background(isActive ? Color.gray.opacity(0.2) : Color.clear)\n .background(configuration.isPressed ? Color.gray.opacity(0.1) : Color.clear)\n .foregroundColor(Color.primary)\n .clipShape(RoundedRectangle(cornerRadius: 6))\n .contentShape(Rectangle())\n .padding(.horizontal, 10)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/CursorLagFixView.swift", "import SwiftUI\n\nstruct CursorLagFixView: View {\n @State private var isCursorLagFixEnabled = false\n @State private var isRunningCommand = false\n @State private var isRebootRequired = false\n \n var body: some View {\n let toggleBinding = Binding(\n get: { isCursorLagFixEnabled },\n set: {\n isCursorLagFixEnabled = $0\n toggleRedesignedTextCursor(disable: $0)\n }\n )\n \n VStack(alignment: .leading, spacing: 12) {\n HStack {\n Toggle(\"\", isOn: toggleBinding)\n .disabled(isRunningCommand)\n .toggleStyle(.switch)\n .labelsHidden()\n \n Text(\"Cursor Lag Fix\".i18n())\n .font(.headline)\n \n Spacer()\n \n RebootRequiredBadge(isRequired: isRebootRequired)\n }\n \n Text(.init(\"Cursor Lag Fix Description\".i18n()))\n .font(.system(size: 12))\n .opacity(0.8)\n }\n .padding()\n .onAppear(perform: checkCursorSetting)\n }\n \n func toggleRedesignedTextCursor(disable: Bool) {\n guard !isRunningCommand else { return }\n \n let command = \"sudo defaults write /Library/Preferences/FeatureFlags/Domain/UIKit.plist redesigned_text_cursor -dict-add Enabled -bool \\(disable ? \"NO\" : \"YES\")\"\n \n isRunningCommand = true\n \n command.runCommand(\n requireSudo: true,\n completion: { _, _, _ in\n isRunningCommand = false\n isRebootRequired = true\n checkCursorSetting()\n }\n )\n }\n \n func checkCursorSetting() {\n guard !isRunningCommand else { return }\n \n let command = \"defaults read /Library/Preferences/FeatureFlags/Domain/UIKit.plist redesigned_text_cursor\"\n \n isRunningCommand = true\n \n command.runCommand(\n requireSudo: false,\n completion: { output, _, _ in\n isRunningCommand = false\n isCursorLagFixEnabled = output.contains(\"Enabled = 0\")\n }\n )\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Indicator/IndicatorPosition.swift", "import AppKit\n\nenum IndicatorActuallyPositionKind {\n case floatingApp\n case inputCursor\n case inputRect\n case nearMouse\n case windowCorner\n case screenCorner\n\n var isInputArea: Bool {\n self == .inputRect || self == .inputCursor\n }\n}\n\nenum IndicatorPosition: Int32, CaseIterable, Identifiable {\n case nearMouse = 0\n case windowCorner = 1\n case screenCorner = 2\n\n var id: Self { self }\n\n enum Alignment: Int32, CaseIterable {\n case topLeft = 0\n case topCenter = 5\n case topRight = 1\n case centerLeft = 7\n case center = 2\n case centerRight = 8\n case bottomLeft = 3\n case bottomCenter = 6\n case bottomRight = 4\n }\n\n enum Spacing: Int32, CaseIterable {\n case none = 0\n case xs = 1\n case s = 2\n case m = 3\n case l = 4\n case xl = 5\n }\n}\n\nextension IndicatorPosition {\n var name: String {\n switch self {\n case .nearMouse:\n return \"Follow Mouse\".i18n()\n case .windowCorner:\n return \"Relative to App\".i18n()\n case .screenCorner:\n return \"Relative to Screen\".i18n()\n }\n }\n}\n\nextension IndicatorPosition.Alignment {\n var name: String {\n switch self {\n case .topLeft:\n return \"Top-Left Corner\".i18n()\n case .topRight:\n return \"Top-Right Corner\".i18n()\n case .topCenter:\n return \"Top-Center\".i18n()\n case .center:\n return \"Center\".i18n()\n case .centerLeft:\n return \"Center-Left\".i18n()\n case .centerRight:\n return \"Center-Right\".i18n()\n case .bottomLeft:\n return \"Bottom-Left Corner\".i18n()\n case .bottomCenter:\n return \"Bottom-Center\".i18n()\n case .bottomRight:\n return \"Bottom-Right Corner\".i18n()\n }\n }\n}\n\nextension IndicatorPosition.Spacing {\n static func fromSlide(value: Double) -> Self {\n return .init(rawValue: Int32(value)) ?? .m\n }\n\n var name: String {\n switch self {\n case .none:\n return \"Nope\".i18n()\n case .xs:\n return \"XS\".i18n()\n case .s:\n return \"S\".i18n()\n case .m:\n return \"M\".i18n()\n case .l:\n return \"L\".i18n()\n case .xl:\n return \"XL\".i18n()\n }\n }\n}\n\nextension IndicatorPosition: Codable {\n private enum CodingKeys: String, CodingKey {\n case base\n }\n\n private enum Base: String, Codable {\n case nearMouse, windowCorner, screenCorner\n }\n\n func encode(to encoder: Encoder) throws {\n var container = encoder.container(keyedBy: CodingKeys.self)\n\n switch self {\n case .nearMouse:\n try container.encode(Base.nearMouse, forKey: .base)\n case .windowCorner:\n try container.encode(Base.windowCorner, forKey: .base)\n case .screenCorner:\n try container.encode(Base.screenCorner, forKey: .base)\n }\n }\n\n init(from decoder: Decoder) throws {\n let container = try decoder.container(keyedBy: CodingKeys.self)\n let base = try container.decode(Base.self, forKey: .base)\n\n switch base {\n case .nearMouse:\n self = .nearMouse\n case .windowCorner:\n self = .windowCorner\n case .screenCorner:\n self = .screenCorner\n }\n }\n}\n\nextension IndicatorPosition.Alignment: Codable {\n private enum CodingKeys: String, CodingKey {\n case base\n }\n\n func encode(to encoder: Encoder) throws {\n var container = encoder.container(keyedBy: CodingKeys.self)\n try container.encode(rawValue, forKey: .base)\n }\n\n init(from decoder: Decoder) throws {\n let container = try decoder.container(keyedBy: CodingKeys.self)\n let rawValue = try container.decode(Int32.self, forKey: .base)\n\n self = Self(rawValue: rawValue)!\n }\n}\n\nextension IndicatorPosition.Spacing: Codable {\n private enum CodingKeys: String, CodingKey {\n case base\n }\n\n func encode(to encoder: Encoder) throws {\n var container = encoder.container(keyedBy: CodingKeys.self)\n try container.encode(rawValue, forKey: .base)\n }\n\n init(from decoder: Decoder) throws {\n let container = try decoder.container(keyedBy: CodingKeys.self)\n let rawValue = try container.decode(Int32.self, forKey: .base)\n\n self = Self(rawValue: rawValue)!\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Indicator/IndicatorInfo.swift", "import Foundation\n\nenum IndicatorInfo: Int32, CaseIterable, Identifiable {\n case iconAndTitle = 0\n case iconOnly = 1\n case titleOnly = 2\n\n var id: Self { self }\n\n var name: String {\n switch self {\n case .iconAndTitle: return \"Icon and Title\".i18n()\n case .iconOnly: return \"Icon\".i18n()\n case .titleOnly: return \"Title\".i18n()\n }\n }\n}\n\nextension IndicatorInfo: Codable {\n private enum CodingKeys: String, CodingKey {\n case base\n }\n\n private enum Base: String, Codable {\n case iconAndTitle, iconOnly, titleOnly\n }\n\n func encode(to encoder: Encoder) throws {\n var container = encoder.container(keyedBy: CodingKeys.self)\n\n switch self {\n case .iconAndTitle:\n try container.encode(Base.iconAndTitle, forKey: .base)\n case .iconOnly:\n try container.encode(Base.iconOnly, forKey: .base)\n case .titleOnly:\n try container.encode(Base.titleOnly, forKey: .base)\n }\n }\n\n init(from decoder: Decoder) throws {\n let container = try decoder.container(keyedBy: CodingKeys.self)\n let base = try container.decode(Base.self, forKey: .base)\n\n switch base {\n case .iconAndTitle:\n self = .iconAndTitle\n case .iconOnly:\n self = .iconOnly\n case .titleOnly:\n self = .titleOnly\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/PreferencesVM+AppKeyboardCache.swift", "import AppKit\n\nextension PreferencesVM {\n func appNeedCacheKeyboard(_ appKind: AppKind) -> Bool {\n if let browserRule = appKind.getBrowserInfo()?.rule,\n let keyboardRestoreStrategy = browserRule.keyboardRestoreStrategy\n {\n switch keyboardRestoreStrategy {\n case .RestorePreviouslyUsedOne:\n return true\n case .UseDefaultKeyboardInstead:\n return false\n }\n }\n\n let appRule = getAppCustomization(app: appKind.getApp())\n\n if preferences.isRestorePreviouslyUsedInputSource,\n appRule?.doNotRestoreKeyboard != true\n {\n return true\n }\n\n if !preferences.isRestorePreviouslyUsedInputSource,\n appRule?.doRestoreKeyboard == true\n {\n return true\n }\n\n return false\n }\n\n func cacheKeyboardFor(_ appKind: AppKind, keyboard: InputSource) {\n let defaultKeyboard = getAppDefaultKeyboard(appKind)\n\n if appNeedCacheKeyboard(appKind),\n defaultKeyboard?.id != keyboard.id\n {\n appKeyboardCache.save(appKind, keyboard: keyboard)\n } else {\n appKeyboardCache.remove(appKind)\n }\n }\n\n func removeKeyboardCacheFor(bundleId: String) {\n appKeyboardCache.remove(byBundleId: bundleId)\n }\n\n func clearKeyboardCache() {\n appKeyboardCache.clear()\n }\n\n enum AppAutoSwitchKeyboardStatus {\n case cached(InputSource), specified(InputSource)\n\n var inputSource: InputSource {\n switch self {\n case let .cached(i): return i\n case let .specified(i): return i\n }\n }\n }\n\n func getAppAutoSwitchKeyboard(\n _ appKind: AppKind\n ) -> AppAutoSwitchKeyboardStatus? {\n if let cachedKeyboard = getAppCachedKeyboard(appKind) {\n return .cached(cachedKeyboard)\n }\n\n if let defaultKeyboard = getAppDefaultKeyboard(appKind) {\n return .specified(defaultKeyboard)\n }\n\n // Fallback to system-wide default keyboard to prevent input method getting stuck\n // This ensures that apps without specific keyboard configuration will always\n // switch to the system default, resolving issues like ChatGPT → Terminal switching\n if let systemDefaultKeyboard = systemWideDefaultKeyboard {\n return .specified(systemDefaultKeyboard)\n }\n\n return nil\n }\n\n func getAppCachedKeyboard(_ appKind: AppKind) -> InputSource? {\n guard appNeedCacheKeyboard(appKind) else { return nil }\n return appKeyboardCache.retrieve(appKind)\n }\n\n func getAppDefaultKeyboard(_ appKind: AppKind) -> InputSource? {\n if appKind.getBrowserInfo()?.isFocusedOnAddressBar == true,\n let browserAddressKeyboard = browserAddressDefaultKeyboard\n {\n return browserAddressKeyboard\n }\n\n if let inputSource = appKind.getBrowserInfo()?.rule?.forcedKeyboard {\n return inputSource\n }\n\n return getAppCustomization(app: appKind.getApp())?.forcedKeyboard ?? systemWideDefaultKeyboard\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/PreferencesVM+IndicatorPosition.swift", "import AppKit\nimport AXSwift\nimport Combine\nimport CombineExt\n\nextension PreferencesVM {\n func calcSpacing(minLength: CGFloat) -> CGFloat {\n guard let spacing = preferences.indicatorPositionSpacing else { return 0 }\n\n switch spacing {\n case .none:\n return 0\n case .xs:\n return minLength * 0.02\n case .s:\n return minLength * 0.05\n case .m:\n return minLength * 0.08\n case .l:\n return minLength * 0.13\n case .xl:\n return minLength * 0.21\n }\n }\n\n typealias IndicatorPositionInfo = (kind: IndicatorActuallyPositionKind, point: CGPoint)\n\n func getIndicatorPositionPublisher(\n appSize: CGSize,\n app: NSRunningApplication\n ) -> AnyPublisher {\n Just(preferences.indicatorPosition)\n .compactMap { $0 }\n .flatMapLatest { [weak self] position -> AnyPublisher in\n let DEFAULT = self?.getIndicatorBasePosition(\n appSize: appSize,\n app: app,\n position: position\n ) ?? Empty(completeImmediately: true).eraseToAnyPublisher()\n\n guard let self = self\n else { return DEFAULT }\n\n return self.getPositionAroundFloatingWindow(app, size: appSize)\n .flatMapLatest { positionForFloatingWindow -> AnyPublisher in\n if let positionForFloatingWindow = positionForFloatingWindow {\n return Just((.floatingApp, positionForFloatingWindow)).eraseToAnyPublisher()\n }\n\n if self.preferences.isEnhancedModeEnabled,\n self.preferences.tryToDisplayIndicatorNearCursor == true,\n self.isAbleToQueryLocation(app)\n {\n return self.getPositionAroundInputCursor(size: appSize)\n .map { cursorPosition -> AnyPublisher in\n guard let cursorPosition = cursorPosition else { return DEFAULT }\n\n return Just((cursorPosition.isContainer ? .inputRect : .inputCursor, cursorPosition.point))\n .eraseToAnyPublisher()\n }\n .switchToLatest()\n .eraseToAnyPublisher()\n }\n\n return DEFAULT\n }\n .eraseToAnyPublisher()\n }\n .eraseToAnyPublisher()\n }\n\n func getIndicatorBasePosition(\n appSize: CGSize,\n app: NSRunningApplication,\n position: IndicatorPosition\n ) -> AnyPublisher {\n Just(position)\n .flatMapLatest { [weak self] _ -> AnyPublisher in\n guard let self = self else { return Just(nil).eraseToAnyPublisher() }\n\n switch position {\n case .nearMouse:\n return self.getPositionNearMouse(size: appSize)\n .map {\n guard let position = $0 else { return nil }\n return (.nearMouse, position)\n }\n .eraseToAnyPublisher()\n case .windowCorner:\n return self.getPositionRelativeToAppWindow(size: appSize, app)\n .map {\n guard let position = $0 else { return nil }\n return (.windowCorner, position)\n }\n .eraseToAnyPublisher()\n case .screenCorner:\n return self.getPositionRelativeToScreen(size: appSize, app)\n .map {\n guard let position = $0 else { return nil }\n return (.screenCorner, position)\n }\n .eraseToAnyPublisher()\n }\n }\n .eraseToAnyPublisher()\n }\n}\n\nprivate extension PreferencesVM {\n func getPositionAroundInputCursor(\n size _: CGSize\n ) -> AnyPublisher<(point: CGPoint, isContainer: Bool)?, Never> {\n Future { promise in\n DispatchQueue.global().async {\n guard let rectInfo = systemWideElement.getCursorRectInfo(),\n let screen = NSScreen.getScreenInclude(rect: rectInfo.rect)\n else { return promise(.success(nil)) }\n\n if rectInfo.isContainer,\n rectInfo.rect.width / screen.frame.width > 0.7 &&\n rectInfo.rect.height / screen.frame.height > 0.7\n {\n return promise(.success(nil))\n }\n\n let offset: CGFloat = 6\n\n return promise(.success((\n CGPoint(x: rectInfo.rect.minX, y: rectInfo.rect.maxY + offset),\n rectInfo.isContainer\n )))\n }\n }\n .receive(on: DispatchQueue.main)\n .eraseToAnyPublisher()\n }\n\n func getPositionNearMouse(size: CGSize) -> AnyPublisher {\n AnyPublisher.create { observer in\n guard let screen = NSScreen.getScreenWithMouse() else { return AnyCancellable {} }\n\n let offset: CGFloat = 12\n let padding: CGFloat = 5\n let maxXPoint = screen.visibleFrame.origin.x + screen.visibleFrame.width\n\n var mousePoint = CGPoint(x: NSEvent.mouseLocation.x, y: NSEvent.mouseLocation.y)\n\n // default offset\n mousePoint.x += offset\n mousePoint.y -= offset\n\n // move app to cursor's right/bottom edge\n mousePoint.y -= size.height\n\n // avoid overflow\n mousePoint.x = min(maxXPoint - size.width - padding, mousePoint.x)\n mousePoint.y = max(padding, mousePoint.y)\n\n observer.send(mousePoint)\n observer.send(completion: .finished)\n\n return AnyCancellable {}\n }\n }\n\n func getPositionRelativeToAppWindow(\n size: CGSize,\n _ app: NSRunningApplication\n ) -> AnyPublisher {\n app.getWindowInfoPublisher()\n .map { [weak self] windowInfo -> CGPoint? in\n guard let self = self,\n let windowBounds = windowInfo?.bounds,\n let screen = NSScreen.getScreenInclude(rect: windowBounds)\n else { return nil }\n\n let rect = windowBounds.relativeTo(screen: screen)\n\n return self.getPositionWithin(\n rect: rect,\n size: size,\n alignment: self.preferences.indicatorPositionAlignment ?? .bottomRight\n )\n }\n .eraseToAnyPublisher()\n }\n\n func getPositionRelativeToScreen(\n size: CGSize,\n _ app: NSRunningApplication\n ) -> AnyPublisher {\n app.getWindowInfoPublisher()\n .map { [weak self] windowInfo -> CGPoint? in\n guard let self = self,\n let windowBounds = windowInfo?.bounds,\n let screen = NSScreen.getScreenInclude(rect: windowBounds) ??\n NSScreen.getScreenWithMouse() ??\n NSScreen.main\n else { return nil }\n\n return self.getPositionWithin(\n rect: screen.visibleFrame,\n size: size,\n alignment: self.preferences.indicatorPositionAlignment ?? .bottomRight\n )\n }\n .eraseToAnyPublisher()\n }\n\n func getPositionAround(rect: CGRect) -> (NSScreen, CGPoint)? {\n guard let screen = NSScreen.getScreenInclude(rect: rect) else { return nil }\n\n return (screen, rect.relativeTo(screen: screen).origin)\n }\n\n func getPositionAroundFloatingWindow(\n _ app: NSRunningApplication, size: CGSize\n ) -> AnyPublisher {\n guard NSApplication.isSpotlightLikeApp(app.bundleIdentifier) else { return Just(nil).eraseToAnyPublisher() }\n\n return app.getWindowInfoPublisher()\n .map { [weak self] windowInfo -> CGPoint? in\n guard let self = self,\n let rect = windowInfo?.bounds,\n let (screen, point) = self.getPositionAround(rect: rect)\n else { return nil }\n\n let offset: CGFloat = 6\n\n let position = CGPoint(\n x: point.x,\n y: point.y + rect.height + offset\n )\n\n if screen.frame.contains(CGRect(origin: position, size: size)) {\n return position\n } else {\n return nil\n }\n }\n .eraseToAnyPublisher()\n }\n\n func getPositionWithin(\n rect: NSRect,\n size: CGSize,\n alignment: IndicatorPosition.Alignment\n ) -> CGPoint {\n let spacing = calcSpacing(minLength: min(rect.width, rect.height))\n\n switch alignment {\n case .topLeft:\n return CGPoint(\n x: rect.minX + spacing,\n y: rect.maxY - size.height - spacing\n )\n case .topCenter:\n return CGPoint(\n x: rect.midX - size.width / 2,\n y: rect.maxY - size.height - spacing\n )\n case .topRight:\n return CGPoint(\n x: rect.maxX - size.width - spacing,\n y: rect.maxY - size.height - spacing\n )\n case .center:\n return CGPoint(\n x: rect.midX - size.width / 2,\n y: rect.midY + size.height / 2\n )\n case .centerLeft:\n return CGPoint(\n x: rect.minX + spacing,\n y: rect.midY - size.height / 2\n )\n case .centerRight:\n return CGPoint(\n x: rect.maxX - size.width - spacing,\n y: rect.midY - size.height / 2\n )\n case .bottomLeft:\n return CGPoint(\n x: rect.minX + spacing,\n y: rect.minY + spacing\n )\n case .bottomCenter:\n return CGPoint(\n x: rect.midX - size.width / 2,\n y: rect.minY + spacing\n )\n case .bottomRight:\n return CGPoint(\n x: rect.maxX - size.width - spacing,\n y: rect.minY + spacing\n )\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/RulesApplicationDetail.swift", "import SwiftUI\n\n// 新增 ToggleLabel 组件\nstruct ToggleLabel: View {\n let systemImageName: String\n let text: String\n var body: some View {\n HStack(spacing: 6) {\n Image(systemName: systemImageName)\n Text(text)\n }\n }\n}\n\nstruct ApplicationDetail: View {\n @Binding var selectedApp: Set\n\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n @State var forceKeyboard: PickerItem?\n @State var doRestoreKeyboardState = NSToggleViewState.off\n @State var doNotRestoreKeyboardState = NSToggleViewState.off\n @State var hideIndicator = NSToggleViewState.off\n\n var mixed: Bool {\n Set(selectedApp.map { $0.forcedKeyboard?.id }).count > 1\n }\n\n var items: [PickerItem] {\n [mixed ? PickerItem.mixed : nil, PickerItem.empty].compactMap { $0 }\n + InputSource.sources.map { PickerItem(id: $0.id, title: $0.name, toolTip: $0.id) }\n }\n\n var body: some View {\n VStack(alignment: .leading) {\n Text(String(format: \"%@ App(s) Selected\".i18n(), \"\\(selectedApp.count)\"))\n .font(.subheadline.monospacedDigit())\n .opacity(0.5)\n .padding(.bottom, 5)\n\n VStack(alignment: .leading) {\n Text(\"Default Keyboard\".i18n())\n .fontWeight(.medium)\n\n PopUpButtonPicker(\n items: items,\n isItemEnabled: { $0?.id != \"mixed\" },\n isItemSelected: { $0 == forceKeyboard },\n getTitle: { $0?.title ?? \"\" },\n getToolTip: { $0?.toolTip },\n onSelect: handleSelect\n )\n }\n\n Divider()\n .padding(.vertical, 4)\n\n VStack(alignment: .leading) {\n Text(\"Keyboard Restore Strategy\".i18n())\n .fontWeight(.medium)\n\n HStack {\n Image(systemName: \"d.circle.fill\")\n .foregroundColor(.green)\n NSToggleView(\n label: restoreStrategyName(strategy: .UseDefaultKeyboardInstead),\n state: preferencesVM.preferences.isRestorePreviouslyUsedInputSource\n ? doNotRestoreKeyboardState\n : .on,\n onStateUpdate: handleToggleDoNotRestoreKeyboard\n )\n .fixedSize()\n .disabled(!preferencesVM.preferences.isRestorePreviouslyUsedInputSource)\n }\n\n HStack {\n Image(systemName: \"arrow.uturn.left.circle.fill\")\n .foregroundColor(.blue)\n NSToggleView(\n label: restoreStrategyName(strategy: .RestorePreviouslyUsedOne),\n state: preferencesVM.preferences.isRestorePreviouslyUsedInputSource\n ? .on\n : doRestoreKeyboardState,\n onStateUpdate: handleToggleDoRestoreKeyboard\n )\n .fixedSize()\n .disabled(preferencesVM.preferences.isRestorePreviouslyUsedInputSource)\n }\n }\n\n Divider()\n .padding(.vertical, 4)\n\n VStack(alignment: .leading) {\n Text(\"Indicator\".i18n())\n .fontWeight(.medium)\n HStack {\n Image(systemName: \"eye.slash.circle.fill\")\n .foregroundColor(.gray)\n NSToggleView(\n label: \"Hide Indicator\".i18n(),\n state: hideIndicator,\n onStateUpdate: handleToggleHideIndicator\n )\n .fixedSize()\n }\n }\n\n if selectedApp.contains(where: { preferencesVM.needDisplayEnhancedModePrompt(bundleIdentifier: $0.bundleId) }) {\n Divider().padding(.vertical, 4)\n\n EnhancedModeRequiredBadge()\n }\n\n Spacer()\n }\n .disabled(selectedApp.isEmpty)\n .onChange(of: selectedApp) { _ in\n updateForceKeyboardId()\n updateDoRestoreKeyboardState()\n updateDoNotRestoreKeyboardState()\n updateHideIndicatorState()\n }\n }\n\n func updateForceKeyboardId() {\n if mixed {\n forceKeyboard = PickerItem.mixed\n } else if let keyboard = selectedApp.first?.forcedKeyboard {\n forceKeyboard = PickerItem(id: keyboard.id, title: keyboard.name, toolTip: keyboard.id)\n } else {\n forceKeyboard = PickerItem.empty\n }\n }\n\n func updateDoRestoreKeyboardState() {\n let stateSet = Set(selectedApp.map { $0.doRestoreKeyboard })\n\n if stateSet.count > 1 {\n doRestoreKeyboardState = .mixed\n } else {\n doRestoreKeyboardState = stateSet.first == true ? .on : .off\n }\n }\n\n func updateDoNotRestoreKeyboardState() {\n let stateSet = Set(selectedApp.map { $0.doNotRestoreKeyboard })\n\n if stateSet.count > 1 {\n doNotRestoreKeyboardState = .mixed\n } else {\n doNotRestoreKeyboardState = stateSet.first == true ? .on : .off\n }\n }\n\n func updateHideIndicatorState() {\n let stateSet = Set(selectedApp.map { $0.hideIndicator })\n\n if stateSet.count > 1 {\n hideIndicator = .mixed\n } else {\n hideIndicator = stateSet.first == true ? .on : .off\n }\n }\n\n func handleSelect(_ index: Int) {\n forceKeyboard = items[index]\n\n for app in selectedApp {\n preferencesVM.setForceKeyboard(app, forceKeyboard?.id)\n }\n }\n\n func handleToggleDoNotRestoreKeyboard() -> NSControl.StateValue {\n switch doNotRestoreKeyboardState {\n case .on:\n selectedApp.forEach { preferencesVM.setDoNotRestoreKeyboard($0, false) }\n doNotRestoreKeyboardState = .off\n return .off\n case .off, .mixed:\n selectedApp.forEach { preferencesVM.setDoNotRestoreKeyboard($0, true) }\n doNotRestoreKeyboardState = .on\n return .on\n }\n }\n\n func handleToggleDoRestoreKeyboard() -> NSControl.StateValue {\n switch doRestoreKeyboardState {\n case .on:\n selectedApp.forEach { preferencesVM.setDoRestoreKeyboard($0, false) }\n doRestoreKeyboardState = .off\n return .off\n case .off, .mixed:\n selectedApp.forEach { preferencesVM.setDoRestoreKeyboard($0, true) }\n doRestoreKeyboardState = .on\n return .on\n }\n }\n\n func handleToggleHideIndicator() -> NSControl.StateValue {\n switch hideIndicator {\n case .on:\n selectedApp.forEach { preferencesVM.setHideIndicator($0, false) }\n hideIndicator = .off\n return .off\n case .off, .mixed:\n selectedApp.forEach { preferencesVM.setHideIndicator($0, true) }\n hideIndicator = .on\n return .on\n }\n }\n\n func restoreStrategyName(strategy: KeyboardRestoreStrategy) -> String {\n strategy.name + restoreStrategyTips(strategy: strategy)\n }\n\n func restoreStrategyTips(strategy: KeyboardRestoreStrategy) -> String {\n switch strategy {\n case .RestorePreviouslyUsedOne:\n return preferencesVM.preferences.isRestorePreviouslyUsedInputSource ? \" (\\(\"Default\".i18n()))\" : \"\"\n case .UseDefaultKeyboardInstead:\n return !preferencesVM.preferences.isRestorePreviouslyUsedInputSource ? \" (\\(\"Default\".i18n()))\" : \"\"\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/IndicatorVM.swift", "import AppKit\nimport AXSwift\nimport Carbon\nimport Combine\nimport CombineExt\nimport KeyboardShortcuts\nimport os\n\n@MainActor\nfinal class IndicatorVM: ObservableObject {\n private var cancelBag = CancelBag()\n\n let applicationVM: ApplicationVM\n let preferencesVM: PreferencesVM\n let inputSourceVM: InputSourceVM\n let permissionsVM: PermissionsVM\n\n let logger = ISPLogger(category: String(describing: IndicatorVM.self))\n\n @Published\n private(set) var state: State\n\n var actionSubject = PassthroughSubject()\n\n var refreshShortcutSubject = PassthroughSubject()\n\n private(set) lazy var activateEventPublisher = Publishers.MergeMany([\n longMouseDownPublisher(),\n stateChangesPublisher(),\n ])\n .share()\n\n private(set) lazy var screenIsLockedPublisher = Publishers.MergeMany([\n DistributedNotificationCenter.default()\n .publisher(for: Notification.Name(rawValue: \"com.apple.screenIsLocked\"))\n .mapTo(true),\n\n DistributedNotificationCenter.default()\n .publisher(for: NSWorkspace.willSleepNotification)\n .mapTo(true),\n\n DistributedNotificationCenter.default()\n .publisher(for: Notification.Name(rawValue: \"com.apple.screenIsUnlocked\"))\n .mapTo(false),\n\n DistributedNotificationCenter.default()\n .publisher(for: NSWorkspace.didWakeNotification)\n .mapTo(false),\n ])\n .receive(on: DispatchQueue.main)\n .prepend(false)\n .removeDuplicates()\n .share()\n\n init(\n permissionsVM: PermissionsVM,\n preferencesVM: PreferencesVM,\n applicationVM: ApplicationVM,\n inputSourceVM: InputSourceVM\n ) {\n self.permissionsVM = permissionsVM\n self.preferencesVM = preferencesVM\n self.applicationVM = applicationVM\n self.inputSourceVM = inputSourceVM\n state = .from(\n preferencesVM: preferencesVM,\n inputSourceChangeReason: .system,\n applicationVM.appKind,\n InputSource.getCurrentInputSource()\n )\n\n clearAppKeyboardCacheIfNeed()\n watchState()\n }\n\n private func clearAppKeyboardCacheIfNeed() {\n applicationVM.$appsDiff\n .sink { [weak self] appsDiff in\n appsDiff.removed\n .compactMap { $0.bundleIdentifier }\n .forEach { bundleId in\n self?.preferencesVM.removeKeyboardCacheFor(bundleId: bundleId)\n }\n }\n .store(in: cancelBag)\n\n preferencesVM.$preferences\n .map(\\.isRestorePreviouslyUsedInputSource)\n .filter { $0 == false }\n .sink { [weak self] _ in\n self?.preferencesVM.clearKeyboardCache()\n }\n .store(in: cancelBag)\n }\n}\n\nextension IndicatorVM {\n enum InputSourceChangeReason {\n case noChanges, system, shortcut, appSpecified(PreferencesVM.AppAutoSwitchKeyboardStatus)\n }\n\n @MainActor\n struct State {\n let appKind: AppKind?\n let inputSource: InputSource\n let inputSourceChangeReason: InputSourceChangeReason\n\n func isSame(with other: State) -> Bool {\n return State.isSame(self, other)\n }\n\n static func isSame(_ lhs: IndicatorVM.State, _ rhs: IndicatorVM.State) -> Bool {\n guard let appKind1 = lhs.appKind, let appKind2 = rhs.appKind\n else { return lhs.appKind == nil && rhs.appKind == nil }\n\n guard appKind1.isSameAppOrWebsite(with: appKind2, detectAddressBar: true)\n else { return false }\n\n guard lhs.inputSource.id == rhs.inputSource.id\n else { return false }\n\n return true\n }\n\n static func from(\n preferencesVM _: PreferencesVM,\n inputSourceChangeReason: InputSourceChangeReason,\n _ appKind: AppKind?,\n _ inputSource: InputSource\n ) -> State {\n return .init(\n appKind: appKind,\n inputSource: inputSource,\n inputSourceChangeReason: inputSourceChangeReason\n )\n }\n }\n\n enum Action {\n case start\n case appChanged(AppKind)\n case switchInputSourceByShortcut(InputSource)\n case inputSourceChanged(InputSource)\n }\n\n func send(_ action: Action) {\n actionSubject.send(action)\n }\n\n func refreshShortcut() {\n refreshShortcutSubject.send(())\n }\n\n func watchState() {\n actionSubject\n .scan(state) { [weak self] state, action -> State in\n guard let preferencesVM = self?.preferencesVM,\n let inputSourceVM = self?.inputSourceVM\n else { return state }\n\n @MainActor\n func updateState(appKind: AppKind?, inputSource: InputSource, inputSourceChangeReason: InputSourceChangeReason) -> State {\n // TODO: Move to outside\n if let appKind = appKind {\n preferencesVM.cacheKeyboardFor(appKind, keyboard: inputSource)\n }\n\n return .from(\n preferencesVM: preferencesVM,\n inputSourceChangeReason: inputSourceChangeReason,\n appKind,\n inputSource\n )\n }\n\n switch action {\n case .start:\n return state\n case let .appChanged(appKind):\n if let status = preferencesVM.getAppAutoSwitchKeyboard(appKind) {\n inputSourceVM.select(inputSource: status.inputSource)\n\n return updateState(\n appKind: appKind,\n inputSource: status.inputSource,\n inputSourceChangeReason: .appSpecified(status)\n )\n } else {\n return updateState(\n appKind: appKind,\n inputSource: state.inputSource,\n inputSourceChangeReason: .noChanges\n )\n }\n case let .inputSourceChanged(inputSource):\n guard inputSource.id != state.inputSource.id else { return state }\n\n return updateState(appKind: state.appKind, inputSource: inputSource, inputSourceChangeReason: .system)\n case let .switchInputSourceByShortcut(inputSource):\n inputSourceVM.select(inputSource: inputSource)\n\n return updateState(appKind: state.appKind, inputSource: inputSource, inputSourceChangeReason: .shortcut)\n }\n }\n .removeDuplicates(by: { $0.isSame(with: $1) })\n .assign(to: &$state)\n\n applicationVM.$appKind\n .compactMap { $0 }\n .sink(receiveValue: { [weak self] in self?.send(.appChanged($0)) })\n .store(in: cancelBag)\n\n inputSourceVM.inputSourceChangesPublisher\n .sink(receiveValue: { [weak self] in self?.send(.inputSourceChanged($0)) })\n .store(in: cancelBag)\n\n refreshShortcutSubject\n .sink { [weak self] _ in\n KeyboardShortcuts.removeAllHandlers()\n\n for inputSource in InputSource.sources {\n KeyboardShortcuts.onKeyUp(for: .init(inputSource.id)) {\n self?.send(.switchInputSourceByShortcut(inputSource))\n }\n }\n\n self?.preferencesVM.getHotKeyGroups().forEach { group in\n KeyboardShortcuts.onKeyUp(for: .init(group.id!)) {\n guard group.inputSources.count > 0 else { return }\n\n let currIps = InputSource.getCurrentInputSource()\n let nextIdx = (\n (group.inputSources.firstIndex(where: { currIps.id == $0.id }) ?? -1) + 1\n ) % group.inputSources.count\n\n self?.send(.switchInputSourceByShortcut(group.inputSources[nextIdx]))\n }\n }\n }\n .store(in: cancelBag)\n\n refreshShortcut()\n send(.start)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSApplication.swift", "import AppKit\n\n// MARK: - isFloatingApp\n\nprivate let floatingAppIdentifier: [(\n identifier: String,\n maxWindowLayer: Int,\n isSpotlightLikeApp: Bool,\n isValid: (((windowLayer: Int?, windowBounds: CGRect?)) -> Bool)?\n)] = [\n (\"com.apple.Spotlight\", 30, true, nil),\n (\"com.runningwithcrayons.Alfred\", 30, true, nil),\n (\"at.obdev.LaunchBar\", 30, true, nil),\n (\"com.raycast.macos\", 30, true, nil),\n (\"com.googlecode.iterm2\", 30, false, nil),\n (\"com.xunyong.hapigo\", 30, true, nil),\n (\"com.hezongyidev.Bob\", 30, false, nil),\n (\"com.ripperhe.Bob\", 30, false, nil),\n (\"org.yuanli.utools\", 30, false, nil),\n (\"com.1password.1password\", 1000, true, nil),\n (\"com.eusoft.eudic.LightPeek\", 1000, true, nil),\n (\"com.contextsformac.Contexts\", 1000, true, { $0.windowLayer != 20 }),\n]\n\nextension NSApplication {\n static func isFloatingApp(_ bundleIdentifier: String?, windowLayer: Int? = nil, windowBounds: CGRect? = nil) -> Bool {\n guard let bundleIdentifier = bundleIdentifier else { return false }\n\n return floatingAppIdentifier.contains {\n guard $0.0 == bundleIdentifier else { return false }\n guard let windowLayer = windowLayer else { return true }\n guard windowLayer < $0.1, windowLayer > 0 else { return false }\n\n return $0.isValid?((windowLayer, windowBounds)) ?? true\n }\n }\n\n static func isSpotlightLikeApp(_ bundleIdentifier: String?) -> Bool {\n guard let bundleIdentifier = bundleIdentifier else { return false }\n\n return floatingAppIdentifier.contains(where: { $0.isSpotlightLikeApp && $0.identifier == bundleIdentifier })\n }\n\n static func isBrowser(_ app: NSRunningApplication) -> Bool {\n return getBrowser(app) != nil\n }\n\n static func getBrowser(_ app: NSRunningApplication) -> Browser? {\n if let bundleIdentifier = app.bundleIdentifier,\n let browser = Browser(rawValue: bundleIdentifier)\n {\n return browser\n } else {\n return nil\n }\n }\n}\n\n// MARK: - isBrowserApp\n\nprivate var browserAppIdentifier: Set = {\n let array1 = LSCopyAllRoleHandlersForContentType(\n \"public.html\" as CFString, .viewer\n )?.takeRetainedValue() as? [String] ?? []\n let array2 = LSCopyAllHandlersForURLScheme(\n \"https\" as CFString\n )?.takeRetainedValue() as? [String] ?? []\n\n let set1 = Set(array1)\n let set2 = Set(array2)\n\n return set1.intersection(set2)\n}()\n\nextension NSApplication {\n static func isBrowserApp(_ bundleIdentifier: String?) -> Bool {\n guard let bundleIdentifier = bundleIdentifier else { return false }\n\n return browserAppIdentifier.contains(bundleIdentifier)\n }\n\n static func isBrowserInstalled(_ bundleIdentifier: String) -> Bool {\n return isBrowserApp(bundleIdentifier)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/SettingsSection.swift", "import SwiftUI\n\nstruct SettingsSection: View {\n let title: String\n\n let tips: Tips?\n\n let noI18N: Bool\n\n let content: Content\n\n init(title: String, noI18N: Bool = false, tips: Tips? = nil, @ViewBuilder _ content: () -> Content) {\n self.title = title\n self.noI18N = noI18N\n self.tips = tips\n self.content = content()\n }\n\n var body: some View {\n VStack(alignment: .leading) {\n if !title.isEmpty || tips != nil {\n HStack {\n if !title.isEmpty {\n Text(noI18N ? title : title.i18n())\n .opacity(0.8)\n }\n\n tips\n }\n .padding(.horizontal)\n }\n\n VStack(alignment: .leading, spacing: 0) {\n content\n }\n .frame(maxWidth: .infinity)\n .background(NSColor.background2.color)\n .clipShape(RoundedRectangle(cornerRadius: 8))\n .overlay(\n RoundedRectangle(cornerRadius: 8)\n .stroke(NSColor.border2.color, lineWidth: 1)\n )\n }\n }\n}\n\n// Support optional footer\nextension SettingsSection where Tips == EmptyView {\n init(title: String, noI18N: Bool = false, @ViewBuilder _ content: () -> Content) {\n self.title = title\n self.noI18N = noI18N\n tips = nil\n self.content = content()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/Color.swift", "// https://github.com/nbasham/BlackLabsSwiftUIColor/blob/main/Sources/BlackLabsSwiftUIColor/BlackLabsSwiftUIColor.swift\n\nimport SwiftUI\n\npublic extension Color {\n var hex: String { NSColor(self).hex }\n var hexWithAlpha: String { NSColor(self).hexWithAlpha }\n\n func hexDescription(_ includeAlpha: Bool = false) -> String {\n NSColor(self).hexDescription(includeAlpha)\n }\n}\n\npublic extension Color {\n /**\n Creates an immuatble `Color` instance specified by a hex string, CSS color name, or nil.\n\n - parameter hex: A case insensitive `String`? representing a hex or CSS value e.g.\n\n - **\"abc\"**\n - **\"abc7\"**\n - **\"#abc7\"**\n - **\"00FFFF\"**\n - **\"#00FFFF\"**\n - **\"00FFFF77\"**\n - **\"Orange\", \"Azure\", \"Tomato\"** Modern browsers support 140 color names ()\n - **\"Clear\"** [NSColor clearColor]\n - **\"Transparent\"** [NSColor clearColor]\n - **nil** [NSColor clearColor]\n - **empty string** [NSColor clearColor]\n */\n init(hex: String?) {\n self.init(NSColor(hex: hex))\n }\n}\n\nextension NSColor {\n /**\n Creates an immuatble `NSColor` instance specified by a hex string, CSS color name, or nil.\n\n - parameter hex: A case insensitive `String`? representing a hex or CSS value e.g.\n\n - **\"abc\"**\n - **\"abc7\"**\n - **\"#abc7\"**\n - **\"00FFFF\"**\n - **\"#00FFFF\"**\n - **\"00FFFF77\"**\n - **\"Orange\", \"Azure\", \"Tomato\"** Modern browsers support 140 color names ()\n - **\"Clear\"** [NSColor clearColor]\n - **\"Transparent\"** [NSColor clearColor]\n - **nil** [NSColor clearColor]\n - **empty string** [NSColor clearColor]\n */\n convenience init(hex: String?) {\n let normalizedHexString: String = NSColor.normalize(hex)\n var c: UInt64 = 0\n Scanner(string: normalizedHexString).scanHexInt64(&c)\n\n let cc = CUnsignedInt(c)\n\n self.init(\n red: NSColorMasks.redValue(cc),\n green: NSColorMasks.greenValue(cc),\n blue: NSColorMasks.blueValue(cc),\n alpha: NSColorMasks.alphaValue(cc)\n )\n }\n\n var hex: String { hexDescription(false) }\n var hexWithAlpha: String { hexDescription(true) }\n\n /**\n Returns a hex equivalent of this `NSColor`.\n\n - Parameter includeAlpha: Optional parameter to include the alpha hex, defaults to `false`.\n\n `color.hexDescription() -> \"ff0000\"`\n\n `color.hexDescription(true) -> \"ff0000aa\"`\n\n - Returns: A new string with `String` with the color's hexidecimal value.\n */\n func hexDescription(_ includeAlpha: Bool = false) -> String {\n guard cgColor.numberOfComponents == 4,\n let a = cgColor.components?.map({ Int($0 * CGFloat(255)) })\n else { return \"Color not RGB.\" }\n\n let color = String(format: \"%02x%02x%02x\", a[0], a[1], a[2])\n\n if includeAlpha {\n let alpha = String(format: \"%02x\", a[3])\n return \"\\(color)\\(alpha)\"\n }\n\n return color\n }\n\n fileprivate enum NSColorMasks: CUnsignedInt {\n case redMask = 0xFF00_0000\n case greenMask = 0x00FF_0000\n case blueMask = 0x0000_FF00\n case alphaMask = 0x0000_00FF\n\n static func redValue(_ value: CUnsignedInt) -> CGFloat {\n return CGFloat((value & redMask.rawValue) >> 24) / 255.0\n }\n\n static func greenValue(_ value: CUnsignedInt) -> CGFloat {\n return CGFloat((value & greenMask.rawValue) >> 16) / 255.0\n }\n\n static func blueValue(_ value: CUnsignedInt) -> CGFloat {\n return CGFloat((value & blueMask.rawValue) >> 8) / 255.0\n }\n\n static func alphaValue(_ value: CUnsignedInt) -> CGFloat {\n return CGFloat(value & alphaMask.rawValue) / 255.0\n }\n }\n\n fileprivate static func normalize(_ hex: String?) -> String {\n guard var hexString = hex else {\n return \"00000000\"\n }\n if let cssColor = cssToHexDictionary[hexString.uppercased()] {\n return cssColor.count == 8 ? cssColor : cssColor + \"ff\"\n }\n if hexString.hasPrefix(\"#\") {\n hexString = String(hexString.dropFirst())\n }\n if hexString.count == 3 || hexString.count == 4 {\n hexString = hexString.map { \"\\($0)\\($0)\" }.joined()\n }\n let hasAlpha = hexString.count > 7\n if !hasAlpha {\n hexString += \"ff\"\n }\n return hexString\n }\n\n /**\n All modern browsers support the following 140 color names (see http://www.w3schools.com/cssref/css_colornames.asp)\n */\n fileprivate static func hexFromCssName(_ cssName: String) -> String {\n let key = cssName.uppercased()\n if let hex = cssToHexDictionary[key] {\n return hex\n }\n return cssName\n }\n\n static let cssToHexDictionary: [String: String] = [\n \"CLEAR\": \"00000000\",\n \"TRANSPARENT\": \"00000000\",\n \"\": \"00000000\",\n \"ALICEBLUE\": \"F0F8FF\",\n \"ANTIQUEWHITE\": \"FAEBD7\",\n \"AQUA\": \"00FFFF\",\n \"AQUAMARINE\": \"7FFFD4\",\n \"AZURE\": \"F0FFFF\",\n \"BEIGE\": \"F5F5DC\",\n \"BISQUE\": \"FFE4C4\",\n \"BLACK\": \"000000\",\n \"BLANCHEDALMOND\": \"FFEBCD\",\n \"BLUE\": \"0000FF\",\n \"BLUEVIOLET\": \"8A2BE2\",\n \"BROWN\": \"A52A2A\",\n \"BURLYWOOD\": \"DEB887\",\n \"CADETBLUE\": \"5F9EA0\",\n \"CHARTREUSE\": \"7FFF00\",\n \"CHOCOLATE\": \"D2691E\",\n \"CORAL\": \"FF7F50\",\n \"CORNFLOWERBLUE\": \"6495ED\",\n \"CORNSILK\": \"FFF8DC\",\n \"CRIMSON\": \"DC143C\",\n \"CYAN\": \"00FFFF\",\n \"DARKBLUE\": \"00008B\",\n \"DARKCYAN\": \"008B8B\",\n \"DARKGOLDENROD\": \"B8860B\",\n \"DARKGRAY\": \"A9A9A9\",\n \"DARKGREY\": \"A9A9A9\",\n \"DARKGREEN\": \"006400\",\n \"DARKKHAKI\": \"BDB76B\",\n \"DARKMAGENTA\": \"8B008B\",\n \"DARKOLIVEGREEN\": \"556B2F\",\n \"DARKORANGE\": \"FF8C00\",\n \"DARKORCHID\": \"9932CC\",\n \"DARKRED\": \"8B0000\",\n \"DARKSALMON\": \"E9967A\",\n \"DARKSEAGREEN\": \"8FBC8F\",\n \"DARKSLATEBLUE\": \"483D8B\",\n \"DARKSLATEGRAY\": \"2F4F4F\",\n \"DARKSLATEGREY\": \"2F4F4F\",\n \"DARKTURQUOISE\": \"00CED1\",\n \"DARKVIOLET\": \"9400D3\",\n \"DEEPPINK\": \"FF1493\",\n \"DEEPSKYBLUE\": \"00BFFF\",\n \"DIMGRAY\": \"696969\",\n \"DIMGREY\": \"696969\",\n \"DODGERBLUE\": \"1E90FF\",\n \"FIREBRICK\": \"B22222\",\n \"FLORALWHITE\": \"FFFAF0\",\n \"FORESTGREEN\": \"228B22\",\n \"FUCHSIA\": \"FF00FF\",\n \"GAINSBORO\": \"DCDCDC\",\n \"GHOSTWHITE\": \"F8F8FF\",\n \"GOLD\": \"FFD700\",\n \"GOLDENROD\": \"DAA520\",\n \"GRAY\": \"808080\",\n \"GREY\": \"808080\",\n \"GREEN\": \"008000\",\n \"GREENYELLOW\": \"ADFF2F\",\n \"HONEYDEW\": \"F0FFF0\",\n \"HOTPINK\": \"FF69B4\",\n \"INDIANRED\": \"CD5C5C\",\n \"INDIGO\": \"4B0082\",\n \"IVORY\": \"FFFFF0\",\n \"KHAKI\": \"F0E68C\",\n \"LAVENDER\": \"E6E6FA\",\n \"LAVENDERBLUSH\": \"FFF0F5\",\n \"LAWNGREEN\": \"7CFC00\",\n \"LEMONCHIFFON\": \"FFFACD\",\n \"LIGHTBLUE\": \"ADD8E6\",\n \"LIGHTCORAL\": \"F08080\",\n \"LIGHTCYAN\": \"E0FFFF\",\n \"LIGHTGOLDENRODYELLOW\": \"FAFAD2\",\n \"LIGHTGRAY\": \"D3D3D3\",\n \"LIGHTGREY\": \"D3D3D3\",\n \"LIGHTGREEN\": \"90EE90\",\n \"LIGHTPINK\": \"FFB6C1\",\n \"LIGHTSALMON\": \"FFA07A\",\n \"LIGHTSEAGREEN\": \"20B2AA\",\n \"LIGHTSKYBLUE\": \"87CEFA\",\n \"LIGHTSLATEGRAY\": \"778899\",\n \"LIGHTSLATEGREY\": \"778899\",\n \"LIGHTSTEELBLUE\": \"B0C4DE\",\n \"LIGHTYELLOW\": \"FFFFE0\",\n \"LIME\": \"00FF00\",\n \"LIMEGREEN\": \"32CD32\",\n \"LINEN\": \"FAF0E6\",\n \"MAGENTA\": \"FF00FF\",\n \"MAROON\": \"800000\",\n \"MEDIUMAQUAMARINE\": \"66CDAA\",\n \"MEDIUMBLUE\": \"0000CD\",\n \"MEDIUMORCHID\": \"BA55D3\",\n \"MEDIUMPURPLE\": \"9370DB\",\n \"MEDIUMSEAGREEN\": \"3CB371\",\n \"MEDIUMSLATEBLUE\": \"7B68EE\",\n \"MEDIUMSPRINGGREEN\": \"00FA9A\",\n \"MEDIUMTURQUOISE\": \"48D1CC\",\n \"MEDIUMVIOLETRED\": \"C71585\",\n \"MIDNIGHTBLUE\": \"191970\",\n \"MINTCREAM\": \"F5FFFA\",\n \"MISTYROSE\": \"FFE4E1\",\n \"MOCCASIN\": \"FFE4B5\",\n \"NAVAJOWHITE\": \"FFDEAD\",\n \"NAVY\": \"000080\",\n \"OLDLACE\": \"FDF5E6\",\n \"OLIVE\": \"808000\",\n \"OLIVEDRAB\": \"6B8E23\",\n \"ORANGE\": \"FFA500\",\n \"ORANGERED\": \"FF4500\",\n \"ORCHID\": \"DA70D6\",\n \"PALEGOLDENROD\": \"EEE8AA\",\n \"PALEGREEN\": \"98FB98\",\n \"PALETURQUOISE\": \"AFEEEE\",\n \"PALEVIOLETRED\": \"DB7093\",\n \"PAPAYAWHIP\": \"FFEFD5\",\n \"PEACHPUFF\": \"FFDAB9\",\n \"PERU\": \"CD853F\",\n \"PINK\": \"FFC0CB\",\n \"PLUM\": \"DDA0DD\",\n \"POWDERBLUE\": \"B0E0E6\",\n \"PURPLE\": \"800080\",\n \"RED\": \"FF0000\",\n \"ROSYBROWN\": \"BC8F8F\",\n \"ROYALBLUE\": \"4169E1\",\n \"SADDLEBROWN\": \"8B4513\",\n \"SALMON\": \"FA8072\",\n \"SANDYBROWN\": \"F4A460\",\n \"SEAGREEN\": \"2E8B57\",\n \"SEASHELL\": \"FFF5EE\",\n \"SIENNA\": \"A0522D\",\n \"SILVER\": \"C0C0C0\",\n \"SKYBLUE\": \"87CEEB\",\n \"SLATEBLUE\": \"6A5ACD\",\n \"SLATEGRAY\": \"708090\",\n \"SLATEGREY\": \"708090\",\n \"SNOW\": \"FFFAFA\",\n \"SPRINGGREEN\": \"00FF7F\",\n \"STEELBLUE\": \"4682B4\",\n \"TAN\": \"D2B48C\",\n \"TEAL\": \"008080\",\n \"THISTLE\": \"D8BFD8\",\n \"TOMATO\": \"FF6347\",\n \"TURQUOISE\": \"40E0D0\",\n \"VIOLET\": \"EE82EE\",\n \"WHEAT\": \"F5DEB3\",\n \"WHITE\": \"FFFFFF\",\n \"WHITESMOKE\": \"F5F5F5\",\n \"YELLOW\": \"FFFF00\",\n \"YELLOWGREEN\": \"9ACD32\",\n ]\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/BrowserURL.swift", "import AppKit\nimport AXSwift\n\n// Update BrowserThatCanWatchBrowserAddressFocus as well\nenum Browser: String, CaseIterable {\n case Safari = \"com.apple.Safari\"\n case SafariTechnologyPreview = \"com.apple.SafariTechnologyPreview\"\n case Chrome = \"com.google.Chrome\"\n case Chromium = \"org.chromium.Chromium\"\n case Arc = \"company.thebrowser.Browser\"\n case Edge = \"com.microsoft.edgemac\"\n case Brave = \"com.brave.Browser\"\n case BraveBeta = \"com.brave.Browser.beta\"\n case BraveNightly = \"com.brave.Browser.nightly\"\n case Vivaldi = \"com.vivaldi.Vivaldi\"\n case Opera = \"com.operasoftware.Opera\"\n case Thorium = \"org.chromium.Thorium\"\n case Firefox = \"org.mozilla.firefox\"\n case FirefoxDeveloperEdition = \"org.mozilla.firefoxdeveloperedition\"\n case FirefoxNightly = \"org.mozilla.nightly\"\n case Zen = \"app.zen-browser.zen\"\n case Dia = \"company.thebrowser.dia\"\n\n var displayName: String {\n switch self {\n case .Safari:\n return \"Safari\"\n case .SafariTechnologyPreview:\n return \"Safari Technology Preview\"\n case .Chrome:\n return \"Chrome\"\n case .Chromium:\n return \"Chromium\"\n case .Arc:\n return \"Arc\"\n case .Edge:\n return \"Edge\"\n case .Brave:\n return \"Brave\"\n case .BraveBeta:\n return \"Brave Beta\"\n case .BraveNightly:\n return \"Brave Nightly\"\n case .Vivaldi:\n return \"Vivaldi\"\n case .Opera:\n return \"Opera\"\n case .Thorium:\n return \"Thorium\"\n case .Firefox:\n return \"Firefox\"\n case .FirefoxDeveloperEdition:\n return \"Firefox Developer Edition\"\n case .FirefoxNightly:\n return \"Firefox Nightly\"\n case .Zen:\n return \"Zen\"\n case .Dia:\n return \"Dia\"\n }\n }\n}\n\nextension Browser {\n func getCurrentTabURL(focusedWindow: UIElement) -> URL? {\n guard let windowElement = Element.initialize(rawElement: focusedWindow.element),\n let webArea = (try? QueryWebAreaService(windowElement: windowElement).perform()),\n let url = webArea.url\n else { return nil }\n\n if [\n \"favorites://\",\n \"edge://newtab/\",\n \"chrome://newtab/\",\n \"chrome://new-tab-page/\",\n \"chrome://vivaldi-webui/\",\n \"about:newtab\", // Firefox\n ].contains(where: { url.absoluteString.contains($0) }) {\n return .newtab\n } else {\n return url\n }\n }\n}\n\nextension Browser {\n static func isSupportedBrowser(bundleId: String) -> Bool {\n return allCases.contains { $0.rawValue == bundleId }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/PreferencesVM+BrowserAddress.swift", "import AppKit\nimport AXSwift\n\nprivate let chromiumSearchBarDescMap = [\n \"Aadressi- ja otsinguriba\": true,\n \"Address and search bar\": true,\n \"Address bar at bar sa paghahanap\": true,\n \"Adres ve arama çubuğu\": true,\n \"Adres- en soekbalk\": true,\n \"Adres- en zoekbalk\": true,\n \"Adreses un meklēšanas josla\": true,\n \"Adresna traka i traka za pretraživanje\": true,\n \"Adresní a vyhledávací řádek\": true,\n \"Adreso ir paieškos juosta\": true,\n \"Adress- och sökfält\": true,\n \"Adress- und Suchleiste\": true,\n \"Adresse og søgelinje\": true,\n \"Adresse- og søkefelt\": true,\n \"Bar alamat dan carian\": true,\n \"Bar cyfeiriad a chwilio\": true,\n \"Bara de adrese și de căutare\": true,\n \"Barra d'adreces i de cerca\": true,\n \"Barra de direcciones y de búsqueda\": true,\n \"Barra de direcciones y de búsqueda \": true,\n \"Barra de enderezos e de busca\": true,\n \"Barra de endereço e de pesquisa\": true,\n \"Barra de pesquisa e endereço\": true,\n \"Barra degli indirizzi e di ricerca\": true,\n \"Barre d'adresse et de recherche\": true,\n \"Bilah penelusuran dan alamat\": true,\n \"Cím- és keresősáv\": true,\n \"Helbide- eta bilaketa-barra\": true,\n \"Ikheli nebha yosesho\": true,\n \"Manzil va qidiruv paneli\": true,\n \"Naslovna in iskalna vrstica\": true,\n \"Osoite- ja hakupalkki\": true,\n \"Panel s adresou a vyhľadávací panel\": true,\n \"Pasek adresu i wyszukiwania\": true,\n \"Shiriti i adresës dhe i kërkimit\": true,\n \"Thanh địa chỉ và tìm kiếm\": true,\n \"Traka za adresu i pretragu\": true,\n \"Traka za adresu i pretraživanje\": true,\n \"Upau wa anwani na utafutaji\": true,\n \"Veffanga- og leitarstika\": true,\n \"Ünvan və axtarış paneli\": true,\n \"Γραμμή διευθύνσεων και αναζήτησης\": true,\n \"Адрасны радок і панэль пошуку\": true,\n \"Адресная строка и строка поиска\": true,\n \"Адресний і пошуковий рядок\": true,\n \"Дарек жана издөө тилкеси\": true,\n \"Лента за адреса и за пребарување\": true,\n \"Лента за адреси и за търсене\": true,\n \"Мекенжайы және іздеу жолағы\": true,\n \"Трака за адресу и претрагу\": true,\n \"Хаяг ба хайлтын цонх\": true,\n \"Հասցեագոտի և որոնման գոտի\": true,\n \"שורת חיפוש וכתובות אתרים\": true,\n \"شريط العناوين والبحث\": true,\n \"نوار جستجو و آدرس\": true,\n \"پتہ اور تلاش بار\": true,\n \"ठेगाना र खोज पट्टी\": true,\n \"पता और सर्च बार\": true,\n \"पत्ता आणि शोध बार\": true,\n \"ঠিকনা আৰু সন্ধানৰ বাৰ\": true,\n \"ঠিকানা এবং সার্চ দণ্ড\": true,\n \"ਪਤਾ ਅਤੇ ਖੋਜ ਬਾਰ\": true,\n \"સરનામું અને શોધ બાર\": true,\n \"ଠିକଣା ଏବଂ ସନ୍ଧାନ ବାର୍\": true,\n \"முகவரி மற்றும் தேடல் பட்டி\": true,\n \"అడ్రస్‌ మరియు శోధన బార్\": true,\n \"ವಿಳಾಸ ಹಾಗೂ ಹುಡುಕಾಟ ಪಟ್ಟಿ\": true,\n \"വിലാസവും തിരയൽ ബാറും\": true,\n \"ලිපිනය සහ සෙවීම් බාර් එක\": true,\n \"ที่อยู่และแถบค้นหา\": true,\n \"ແຖບ​ທີ່​ຢູ່​ ແລະ​ຄົ້ນ​ຫາ\": true,\n \"လိပ်စာ နှင့် ရှာဖွေရေး ဘား\": true,\n \"მისამართი და ძიების ზოლი\": true,\n \"የአድራሻ እና ፍለጋ አሞሌ\": true,\n \"អាសយដ្ឋាន និងរបាស្វែងរក\": true,\n \"アドレス検索バー\": true,\n \"地址和搜索栏\": true,\n \"網址與搜尋列\": true,\n \"주소창 및 검색창\": true,\n]\n\nenum BrowserThatCanWatchBrowserAddressFocus: CaseIterable {\n static var allBundleIdentifiers = allCases.map { $0.bundleIdentifier }\n\n static func createBy(bundleIdentifier: String?) -> BrowserThatCanWatchBrowserAddressFocus? {\n if let bundleIdentifier = bundleIdentifier {\n for item in allCases {\n if item.bundleIdentifier == bundleIdentifier {\n return item\n }\n }\n }\n\n return nil\n }\n\n case Safari, SafariTechnologyPreview, Chrome, Chromium, Brave, BraveBeta, BraveNightly, Edge, Vivaldi, Arc, Opera, Firefox, FirefoxNightly, FirefoxDeveloperEdition, Zen, Dia\n\n var bundleIdentifier: String {\n return browser.rawValue\n }\n\n var browser: Browser {\n switch self {\n case .Safari:\n return .Safari\n case .SafariTechnologyPreview:\n return .SafariTechnologyPreview\n case .Chrome:\n return .Chrome\n case .Chromium:\n return .Chromium\n case .Brave:\n return .Brave\n case .BraveBeta:\n return .BraveBeta\n case .BraveNightly:\n return .BraveNightly\n case .Edge:\n return .Edge\n case .Vivaldi:\n return .Vivaldi\n case .Arc:\n return .Arc\n case .Opera:\n return .Opera\n case .Firefox:\n return .Firefox\n case .FirefoxNightly:\n return .FirefoxNightly\n case .FirefoxDeveloperEdition:\n return .FirefoxDeveloperEdition\n case .Zen:\n return .Zen\n case .Dia:\n return .Dia\n }\n }\n\n func isFocusOnBrowserAddress(focusedElement: UIElement?) -> Bool {\n guard let focusedElement = focusedElement\n else { return false }\n\n switch self {\n case .Safari, .SafariTechnologyPreview:\n return focusedElement.domIdentifier() == \"WEB_BROWSER_ADDRESS_AND_SEARCH_FIELD\"\n\n case .Arc:\n return focusedElement.domIdentifier() == \"commandBarTextField\"\n\n case .Vivaldi:\n let classList = focusedElement.domClassList()\n return classList.contains(\"UrlBar-UrlField\") && classList.contains(\"vivaldi-addressfield\")\n\n case .Opera:\n return focusedElement.domClassList().contains(\"AddressTextfieldView\")\n\n case .Chromium, .Chrome, .Brave, .BraveBeta, .BraveNightly, .Edge, .Dia:\n if focusedElement.domClassList().contains(\"OmniboxViewViews\") {\n if let description = focusedElement.safeString(attribute: .description),\n chromiumSearchBarDescMap[description] == true\n {\n return true\n }\n\n if let title = focusedElement.safeString(attribute: .title),\n chromiumSearchBarDescMap[title] == true\n {\n return true\n }\n\n return false\n } else {\n return false\n }\n\n case .Firefox, .FirefoxNightly, .FirefoxDeveloperEdition, .Zen:\n return focusedElement.firefoxDomIdentifier() == \"urlbar-input\"\n }\n }\n}\n\nextension PreferencesVM {\n func isFocusOnBrowserAddress(app: NSRunningApplication?, focusedElement: UIElement?) -> Bool {\n return BrowserThatCanWatchBrowserAddressFocus\n .createBy(bundleIdentifier: app?.bundleIdentifier)?\n .isFocusOnBrowserAddress(focusedElement: focusedElement) ?? false\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/PopUpButtonPicker.swift", "import AppKit\nimport SwiftUI\n\nstruct PickerItem: Equatable, Identifiable {\n static let mixed = PickerItem(id: \"mixed\", title: \"Mixed\", toolTip: nil)\n static let empty = PickerItem(id: \"\", title: \"\", toolTip: nil)\n\n let id: String\n let title: String\n let toolTip: String?\n}\n\nstruct PopUpButtonPicker: NSViewRepresentable {\n final class Coordinator: NSObject {\n private let parent: PopUpButtonPicker\n\n init(parent: PopUpButtonPicker) {\n self.parent = parent\n }\n\n @IBAction\n func selectItem(_ sender: NSPopUpButton) {\n parent.onSelect(sender.indexOfSelectedItem)\n }\n }\n\n let items: [Item]\n var width: CGFloat? = nil\n var isItemEnabled: (Item) -> Bool = { _ in true }\n let isItemSelected: (Item) -> Bool\n let getTitle: (Item) -> String\n let getToolTip: (Item) -> String?\n let onSelect: (Int) -> Void\n\n func makeCoordinator() -> Coordinator {\n Coordinator(parent: self)\n }\n\n func makeNSView(context: Self.Context) -> NSPopUpButton {\n let popUpButton = NSPopUpButton(frame: .zero, pullsDown: false)\n popUpButton.autoenablesItems = false\n popUpButton.target = context.coordinator\n popUpButton.action = #selector(Coordinator.selectItem(_:))\n\n if let width = width {\n popUpButton.snp.makeConstraints { make in\n make.width.equalTo(width)\n }\n }\n\n return popUpButton\n }\n\n func updateNSView(_ popUpButton: NSPopUpButton, context _: Self.Context) {\n popUpButton.removeAllItems()\n\n for item in items {\n let menuItem = NSMenuItem()\n\n // in order for this to work, autoenablesItems must be set to false\n menuItem.isEnabled = isItemEnabled(item)\n menuItem.title = getTitle(item)\n menuItem.toolTip = getToolTip(item)\n\n popUpButton.menu?.addItem(menuItem)\n }\n\n if let selectedIndex = items.firstIndex(where: isItemSelected) {\n popUpButton.selectItem(at: selectedIndex)\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/PositionSettingsView.swift", "import AVKit\nimport SwiftUI\n\nstruct PositionSettingsView: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n @EnvironmentObject var navigationVM: NavigationVM\n\n @Environment(\\.colorScheme) var colorScheme: ColorScheme\n\n @State var displayIndicatorNearCursorTips = false\n @State var displayAlwaysOnIndicatorTips = false\n @State private var width = CGFloat.zero\n\n var body: some View {\n let sliderBinding = Binding(\n get: {\n Double(preferencesVM.preferences.indicatorPositionSpacing?.rawValue ?? 3)\n },\n set: { newValue in\n withAnimation(.easeInOut(duration: 0.2)) {\n preferencesVM.update {\n $0.indicatorPositionSpacing = .fromSlide(value: newValue)\n }\n }\n }\n )\n\n let positionBinding = Binding(\n get: {\n preferencesVM.preferences.indicatorPosition ?? .nearMouse\n },\n set: { newValue in\n withAnimation(.easeInOut(duration: 0.3)) {\n preferencesVM.update {\n $0.indicatorPosition = newValue\n }\n }\n }\n )\n\n ScrollView {\n VStack(spacing: 18) {\n SettingsSection(title: \"Position\") {\n VStack(spacing: 0) {\n IndicatorPositionEditor()\n .clipShape(RoundedRectangle(cornerRadius: 6))\n .padding(.horizontal)\n .padding(.top)\n\n Picker(\"Position\", selection: positionBinding) {\n ForEach(IndicatorPosition.allCases) { item in\n Text(item.name).tag(item)\n }\n }\n .labelsHidden()\n .pickerStyle(.segmented)\n .padding()\n\n if preferencesVM.preferences.indicatorPosition != .nearMouse {\n HStack {\n Text(\"Spacing\".i18n() + \":\")\n .alignedView(width: $width, alignment: .leading)\n\n HStack {\n Slider(value: sliderBinding, in: 0 ... 5, step: 1)\n\n if let name = preferencesVM.preferences.indicatorPositionSpacing?.name {\n Text(name)\n .foregroundColor(.primary)\n .frame(width: 50, height: 25)\n .background(Color.primary.opacity(0.05))\n .clipShape(RoundedRectangle(cornerRadius: 6))\n .noAnimation()\n }\n }\n }\n .padding()\n .border(width: 1, edges: [.top, .bottom], color: NSColor.border2.color)\n\n HStack {\n Text(\"Alignment\".i18n() + \":\")\n .alignedView(width: $width, alignment: .leading)\n\n HStack {\n PopUpButtonPicker(\n items: IndicatorPosition.Alignment.allCases,\n isItemSelected: { $0 == preferencesVM.preferences.indicatorPositionAlignment },\n getTitle: { $0.name },\n getToolTip: { $0.name },\n onSelect: { index in\n withAnimation(.easeInOut(duration: 0.3)) {\n preferencesVM.update {\n let value = IndicatorPosition.Alignment.allCases[index]\n $0.indicatorPositionAlignment = value\n }\n }\n }\n )\n }\n }\n .padding()\n }\n }\n }\n\n SettingsSection(title: \"Advanced\", tips: EnhancedModeRequiredBadge()) {\n VStack(spacing: 0) {\n HStack {\n Toggle(isOn: $preferencesVM.preferences.tryToDisplayIndicatorNearCursor) {}\n .toggleStyle(.switch)\n .disabled(!preferencesVM.preferences.isEnhancedModeEnabled)\n\n Text(\"tryToDisplayIndicatorNearCursor\".i18n())\n\n Spacer()\n\n QuestionButton(\n content: {\n SwiftUI.Image(systemName: \"video\")\n .font(.system(size: 11, weight: .bold))\n .padding(6)\n },\n popover: {\n PlayerView(url: Bundle.main.url(\n forResource: \"Indicator-Near-Cursor-Demo-\\($0 == .dark ? \"Dark\" : \"Light\")\",\n withExtension: \"mp4\"\n )!)\n .frame(height: 118)\n\n Text(\"Enhanced Mode Required Tips\".i18n())\n .font(.footnote)\n .opacity(0.6)\n .padding(.vertical, 10)\n }\n )\n }\n .padding(.horizontal)\n .padding(.vertical, 10)\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n\n VStack {\n let needDisableAlwaysOnIndicator = !preferencesVM.preferences.isEnhancedModeEnabled || !preferencesVM.preferences.tryToDisplayIndicatorNearCursor\n\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.isEnableAlwaysOnIndicator)\n .disabled(needDisableAlwaysOnIndicator)\n .toggleStyle(.switch)\n .labelsHidden()\n\n Text(\"isEnableAlwaysOnIndicator\".i18n())\n\n Spacer()\n\n QuestionButton(\n content: {\n SwiftUI.Image(systemName: \"video\")\n .font(.system(size: 11, weight: .bold))\n .padding(6)\n },\n popover: {\n PlayerView(url: Bundle.main.url(\n forResource: \"Always-On-Indicator-Demo-\\($0 == .dark ? \"Dark\" : \"Light\")\",\n withExtension: \"mp4\"\n )!)\n .frame(height: 118)\n\n Text(\"alwaysOnIndicatorTips\".i18n())\n .font(.footnote)\n .padding(.vertical, 10)\n .opacity(0.6)\n }\n )\n }\n }\n .padding(.horizontal)\n .padding(.vertical, 10)\n }\n }\n }\n .padding()\n .padding(.bottom)\n }\n .onAppear(perform: updatePreviewModeOnAppear)\n .background(NSColor.background1.color)\n }\n\n func updatePreviewModeOnAppear() {\n if preferencesVM.preferences.isAutoAppearanceMode {\n preferencesVM.preferences.appearanceMode = colorScheme == .dark ? .dark : .light\n }\n }\n\n func resetColors() {\n if preferencesVM.preferences.appearanceMode == .light {\n preferencesVM.preferences.indicatorForgegroundColor = IndicatorColor.forgeground.light\n preferencesVM.preferences.indicatorBackgroundColor = IndicatorColor.background.light\n }\n\n if preferencesVM.preferences.appearanceMode == .dark {\n preferencesVM.preferences.indicatorForgegroundColor = IndicatorColor.forgeground.dark\n preferencesVM.preferences.indicatorBackgroundColor = IndicatorColor.background.dark\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Controllers/PreferencesWindowController.swift", "import AppKit\nimport SwiftUI\n\n@MainActor\nclass PreferencesWindowController: NSWindowController {\n let navigationVM: NavigationVM\n let permissionsVM: PermissionsVM\n let preferencesVM: PreferencesVM\n let indicatorVM: IndicatorVM\n let feedbackVM: FeedbackVM\n let inputSourceVM: InputSourceVM\n\n init(\n navigationVM: NavigationVM,\n permissionsVM: PermissionsVM,\n preferencesVM: PreferencesVM,\n indicatorVM: IndicatorVM,\n feedbackVM: FeedbackVM,\n inputSourceVM: InputSourceVM\n ) {\n self.navigationVM = navigationVM\n self.permissionsVM = permissionsVM\n self.preferencesVM = preferencesVM\n self.indicatorVM = indicatorVM\n self.feedbackVM = feedbackVM\n self.inputSourceVM = inputSourceVM\n\n let window = NSWindow(\n contentViewController: NSHostingController(\n rootView: PreferencesView()\n .environmentObject(navigationVM)\n .environmentObject(preferencesVM)\n .environmentObject(indicatorVM)\n .environmentObject(permissionsVM)\n .environmentObject(feedbackVM)\n .environmentObject(inputSourceVM)\n )\n )\n\n super.init(window: window)\n\n window.delegate = self\n\n configureWindow()\n }\n\n @available(*, unavailable)\n required init?(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n\n private func configureWindow() {\n window?.standardWindowButton(NSWindow.ButtonType.zoomButton)?.isEnabled = false\n window?.standardWindowButton(NSWindow.ButtonType.miniaturizeButton)?.isEnabled = false\n\n window?.title = \"Input Source Pro\"\n window?.titleVisibility = .hidden\n window?.titlebarAppearsTransparent = true\n window?.styleMask.insert(.fullSizeContentView)\n }\n}\n\nextension PreferencesWindowController: NSWindowDelegate {\n func windowWillClose(_: Notification) {\n NSApp.setActivationPolicy(.accessory)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/NSToggleView.swift", "import AppKit\nimport SwiftUI\n\nenum NSToggleViewState {\n case on, off, mixed\n\n var controlState: NSControl.StateValue {\n switch self {\n case .on:\n return .on\n case .mixed:\n return .mixed\n case .off:\n return .off\n }\n }\n}\n\nstruct NSToggleView: NSViewRepresentable {\n let label: String\n let state: NSToggleViewState\n let onStateUpdate: () -> NSControl.StateValue\n\n func makeCoordinator() -> Coordinator {\n Coordinator(parent: self)\n }\n\n func makeNSView(context: Self.Context) -> NSButton {\n let button = NSButton()\n\n button.title = label\n button.allowsMixedState = true\n button.setButtonType(.switch)\n button.target = context.coordinator\n button.action = #selector(Coordinator.onClick(_:))\n\n return button\n }\n\n func updateNSView(_ button: NSButton, context _: Self.Context) {\n button.title = label\n button.state = state.controlState\n }\n}\n\nextension NSToggleView {\n final class Coordinator: NSObject {\n private let parent: NSToggleView\n\n init(parent: NSToggleView) {\n self.parent = parent\n }\n\n @IBAction\n func onClick(_ sender: NSButton) {\n sender.state = parent.onStateUpdate()\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Accessibility/AXSwift.swift", "import AXSwift\nimport Cocoa\n\nextension UIElement {\n func getCursorRectInfo() -> (rect: CGRect, isContainer: Bool)? {\n guard let focusedElement: UIElement = try? attribute(.focusedUIElement),\n Self.isInputContainer(focusedElement),\n let inputAreaRect = Self.findInputAreaRect(focusedElement)\n else { return nil }\n\n if let cursorRect = Self.findCursorRect(focusedElement),\n inputAreaRect.contains(cursorRect)\n {\n return (rect: cursorRect, isContainer: false)\n } else {\n return (rect: inputAreaRect, isContainer: true)\n }\n }\n}\n\nextension UIElement {\n static func isInputContainer(_ elm: UIElement?) -> Bool {\n guard let elm = elm,\n let role = try? elm.role()\n else { return false }\n\n return role == .textArea || role == .textField || role == .comboBox\n }\n\n static func findInputAreaRect(_ focusedElement: UIElement) -> CGRect? {\n if let parent: UIElement = try? focusedElement.attribute(.parent),\n let role = try? parent.role(),\n role == .scrollArea,\n let origin: CGPoint = try? parent.attribute(.position),\n let size: CGSize = try? parent.attribute(.size)\n {\n return NSScreen.convertFromQuartz(CGRect(origin: origin, size: size))\n }\n\n if let origin: CGPoint = try? focusedElement.attribute(.position),\n let size: CGSize = try? focusedElement.attribute(.size)\n {\n return NSScreen.convertFromQuartz(CGRect(origin: origin, size: size))\n }\n\n return nil\n }\n}\n\nextension UIElement {\n static func findCursorRect(_ focusedElement: UIElement) -> CGRect? {\n return findWebAreaCursor(focusedElement) ?? findNativeInputAreaCursor(focusedElement)\n }\n\n static func findWebAreaCursor(_ focusedElement: UIElement) -> CGRect? {\n guard let range: AXTextMarkerRange = try? focusedElement.attribute(\"AXSelectedTextMarkerRange\"),\n let bounds: CGRect = try? focusedElement.parameterizedAttribute(\"AXBoundsForTextMarkerRange\", param: range)\n else { return nil }\n\n return NSScreen.convertFromQuartz(bounds)\n }\n\n static func findNativeInputAreaCursor(_ focusedElement: UIElement) -> CGRect? {\n guard let selectedRange: CFRange = try? focusedElement.attribute(.selectedTextRange),\n let visibleRange: CFRange = try? focusedElement.attribute(.visibleCharacterRange),\n let rawValue: AnyObject = try? focusedElement.attribute(.value),\n CFGetTypeID(rawValue) == CFStringGetTypeID(),\n let value = rawValue as? String\n else { return nil }\n\n func getBounds(cursor location: Int) -> CGRect? {\n return try? focusedElement.parameterizedAttribute(\n kAXBoundsForRangeParameterizedAttribute,\n param: AXValue.range(CFRange(location: max(location, 0), length: 1))\n )\n .flatMap(NSScreen.convertFromQuartz)\n }\n\n func getCursorBounds() -> CGRect? {\n let lastCursor = visibleRange.location + visibleRange.length\n // Notes 最后存在两个换行符时会有问题\n // let isLastCursor = selectedRange.location >= (lastCursor - 1)\n let isLastCursor = selectedRange.location >= lastCursor\n let location = selectedRange.location - (isLastCursor ? 1 : 0)\n\n guard let bounds = getBounds(cursor: location)\n else { return nil }\n\n if isLastCursor, value.string(at: location) == \"\\n\" {\n if location > 0 {\n for offsetDiff in 1 ... location {\n let offset = location - offsetDiff\n\n if value.string(at: offset + 1) == \"\\n\",\n let prevNewLineBounds = getBounds(cursor: offset)\n {\n return CGRect(\n origin: CGPoint(\n x: prevNewLineBounds.origin.x,\n y: prevNewLineBounds.minY - prevNewLineBounds.height\n ),\n size: bounds.size\n )\n }\n }\n\n return nil\n } else {\n return nil\n }\n } else {\n return bounds\n }\n }\n\n func getLineBounds() -> CGRect? {\n guard let cursorLine: Int = try? focusedElement.attribute(.insertionPointLineNumber),\n let lineRange: CFRange = try? focusedElement.parameterizedAttribute(\"AXRangeForLine\", param: cursorLine),\n let bounds: CGRect = try? focusedElement.parameterizedAttribute(\n kAXBoundsForRangeParameterizedAttribute,\n param: AXValue.range(lineRange)\n )\n else { return nil }\n\n return NSScreen.convertFromQuartz(bounds)\n }\n\n return getCursorBounds() ?? getLineBounds()\n }\n}\n\nextension UIElement {\n func children() -> [UIElement]? {\n guard let children: [AXUIElement] = try? attribute(.children)\n else { return nil }\n\n return children.map { .init($0) }\n }\n}\n\nextension Role {\n static let validInputElms: [Role] = [.comboBox, .textArea, .textField]\n\n static let allCases: [Role] = [\n .unknown,\n .button,\n .radioButton,\n .checkBox,\n .slider,\n .tabGroup,\n .textField,\n .staticText,\n .textArea,\n .scrollArea,\n .popUpButton,\n .menuButton,\n .table,\n .application,\n .group,\n .radioGroup,\n .list,\n .scrollBar,\n .valueIndicator,\n .image,\n .menuBar,\n .menu,\n .menuItem,\n .column,\n .row,\n .toolbar,\n .busyIndicator,\n .progressIndicator,\n .window,\n .drawer,\n .systemWide,\n .outline,\n .incrementor,\n .browser,\n .comboBox,\n .splitGroup,\n .splitter,\n .colorWell,\n .growArea,\n .sheet,\n .helpTag,\n .matte,\n .ruler,\n .rulerMarker,\n .link,\n .disclosureTriangle,\n .grid,\n .relevanceIndicator,\n .levelIndicator,\n .cell,\n .popover,\n .layoutArea,\n .layoutItem,\n .handle,\n ]\n}\n\nextension AXNotification {\n static let allCases: [AXNotification] = [\n .mainWindowChanged,\n .focusedWindowChanged,\n .focusedUIElementChanged,\n .applicationActivated,\n .applicationDeactivated,\n .applicationHidden,\n .applicationShown,\n .windowCreated,\n .windowMoved,\n .windowResized,\n .windowMiniaturized,\n .windowDeminiaturized,\n .drawerCreated,\n .sheetCreated,\n .uiElementDestroyed,\n .valueChanged,\n .titleChanged,\n .resized,\n .moved,\n .created,\n .layoutChanged,\n .helpTagCreated,\n .selectedTextChanged,\n .rowCountChanged,\n .selectedChildrenChanged,\n .selectedRowsChanged,\n .selectedColumnsChanged,\n .rowExpanded,\n .rowCollapsed,\n .selectedCellsChanged,\n .unitsChanged,\n .selectedChildrenMoved,\n .announcementRequested,\n ]\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Indicator/IndicatorSize.swift", "import AppKit\n\nenum IndicatorSize: Int32, CaseIterable, Identifiable {\n case small = 1\n case medium = 2\n case large = 3\n\n var displayName: String {\n switch self {\n case .small:\n return \"Small\".i18n()\n case .medium:\n return \"Medium\".i18n()\n case .large:\n return \"Large\".i18n()\n }\n }\n\n var id: Self { self }\n}\n\nextension IndicatorSize: Codable {\n private enum CodingKeys: String, CodingKey {\n case base\n }\n\n func encode(to encoder: Encoder) throws {\n var container = encoder.container(keyedBy: CodingKeys.self)\n try container.encode(rawValue, forKey: .base)\n }\n\n init(from decoder: Decoder) throws {\n let container = try decoder.container(keyedBy: CodingKeys.self)\n let rawValue = try container.decode(Int32.self, forKey: .base)\n\n self = Self(rawValue: rawValue)!\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/UserDefault.swift", "// https://gist.github.com/simonbs/61c8269e1b0550feab606ee9890fa72b\nimport Cocoa\nimport Combine\n\n@propertyWrapper\nfinal class UserDefault: NSObject {\n // This ensures requirement 1 is fulfilled. The wrapped value is stored in user defaults.\n var wrappedValue: T {\n get {\n return userDefaults.object(forKey: key) as! T\n }\n set {\n userDefaults.setValue(newValue, forKey: key)\n }\n }\n\n var projectedValue: AnyPublisher {\n return subject.eraseToAnyPublisher()\n }\n\n private let key: String\n private let userDefaults: UserDefaults\n private var observerContext = 0\n private let subject: CurrentValueSubject\n\n init(wrappedValue defaultValue: T, _ key: String, userDefaults: UserDefaults = .standard) {\n self.key = key\n self.userDefaults = userDefaults\n subject = CurrentValueSubject(defaultValue)\n super.init()\n userDefaults.register(defaults: [key: defaultValue])\n // This fulfills requirement 4. Some implementations use NSUserDefaultsDidChangeNotification\n // but that is sent every time any value is updated in UserDefaults.\n userDefaults.addObserver(self, forKeyPath: key, options: .new, context: &observerContext)\n subject.value = wrappedValue\n }\n\n override func observeValue(\n forKeyPath keyPath: String?,\n of object: Any?,\n change: [NSKeyValueChangeKey: Any]?,\n context: UnsafeMutableRawPointer?\n ) {\n if context == &observerContext {\n subject.value = wrappedValue\n } else {\n super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)\n }\n }\n\n deinit {\n userDefaults.removeObserver(self, forKeyPath: key, context: &observerContext)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/System/AppDelegate.swift", "import Cocoa\nimport Combine\nimport SwiftUI\nimport Alamofire\nimport LaunchAtLogin\n\nclass AppDelegate: NSObject, NSApplicationDelegate {\n var navigationVM: NavigationVM!\n var indicatorVM: IndicatorVM!\n var preferencesVM: PreferencesVM!\n var permissionsVM: PermissionsVM!\n var applicationVM: ApplicationVM!\n var inputSourceVM: InputSourceVM!\n var feedbackVM: FeedbackVM!\n var indicatorWindowController: IndicatorWindowController!\n var statusItemController: StatusItemController!\n\n func applicationDidFinishLaunching(_: Notification) {\n feedbackVM = FeedbackVM()\n navigationVM = NavigationVM()\n permissionsVM = PermissionsVM()\n preferencesVM = PreferencesVM(permissionsVM: permissionsVM)\n applicationVM = ApplicationVM(preferencesVM: preferencesVM)\n inputSourceVM = InputSourceVM(preferencesVM: preferencesVM)\n indicatorVM = IndicatorVM(permissionsVM: permissionsVM, preferencesVM: preferencesVM, applicationVM: applicationVM, inputSourceVM: inputSourceVM)\n\n indicatorWindowController = IndicatorWindowController(\n permissionsVM: permissionsVM,\n preferencesVM: preferencesVM,\n indicatorVM: indicatorVM,\n applicationVM: applicationVM,\n inputSourceVM: inputSourceVM\n )\n\n statusItemController = StatusItemController(\n navigationVM: navigationVM,\n permissionsVM: permissionsVM,\n preferencesVM: preferencesVM,\n applicationVM: applicationVM,\n indicatorVM: indicatorVM,\n feedbackVM: feedbackVM,\n inputSourceVM: inputSourceVM\n )\n \n LaunchAtLogin.migrateIfNeeded()\n openPreferencesAtFirstLaunch()\n sendLaunchPing()\n updateInstallVersionInfo()\n }\n\n func applicationDidBecomeActive(_: Notification) {\n statusItemController.openPreferences()\n }\n\n @MainActor\n func openPreferencesAtFirstLaunch() {\n if preferencesVM.preferences.prevInstalledBuildVersion != preferencesVM.preferences.buildVersion {\n statusItemController.openPreferences()\n }\n }\n\n @MainActor\n func updateInstallVersionInfo() {\n preferencesVM.preferences.prevInstalledBuildVersion = preferencesVM.preferences.buildVersion\n }\n \n @MainActor\n func sendLaunchPing() {\n let url = \"https://inputsource.pro/api/launch\"\n let launchData: [String: String] = [\n \"prevInstalledBuildVersion\": \"\\(preferencesVM.preferences.prevInstalledBuildVersion)\",\n \"shortVersion\": Bundle.main.shortVersion,\n \"buildVersion\": \"\\(Bundle.main.buildVersion)\",\n \"osVersion\": ProcessInfo.processInfo.operatingSystemVersionString\n ]\n \n AF.request(\n url,\n method: .post,\n parameters: launchData,\n encoding: JSONEncoding.default\n )\n .response { response in\n switch response.result {\n case .success:\n print(\"Launch ping sent successfully.\")\n case let .failure(error):\n print(\"Failed to send launch ping:\", error)\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Controllers/IndicatorWindowController+Activation.swift", "import AppKit\nimport AXSwift\nimport Combine\nimport CombineExt\n\n// MARK: - Default indicator: auto hide\n\nextension IndicatorWindowController {\n func autoHidePublisher(\n event: IndicatorVM.ActivateEvent,\n inputSource: InputSource,\n appKind: AppKind\n ) -> AnyPublisher {\n return Just(event)\n .tap { [weak self] in self?.updateIndicator(event: $0, inputSource: inputSource) }\n .flatMapLatest { [weak self] _ -> AnyPublisher in\n guard let self = self,\n let appSize = self.getAppSize()\n else { return Empty().eraseToAnyPublisher() }\n\n return self.preferencesVM\n .getIndicatorPositionPublisher(appSize: appSize, app: appKind.getApp())\n .compactMap { $0 }\n .first()\n .tap { self.moveIndicator(position: $0) }\n .flatMapLatest { _ -> AnyPublisher in\n Publishers.Merge(\n Timer.delay(seconds: 1).mapToVoid(),\n // hover event\n self.indicatorVC.hoverableView.hoverdPublisher\n .filter { $0 }\n .first()\n .flatMapLatest { _ in\n Timer.delay(seconds: 0.15)\n }\n .mapToVoid()\n )\n .first()\n .mapTo(false)\n .prepend(true)\n .tap { isActive in\n self.isActive = isActive\n }\n .eraseToAnyPublisher()\n }\n .mapToVoid()\n .eraseToAnyPublisher()\n }\n .mapToVoid()\n .eraseToAnyPublisher()\n }\n}\n\n// MARK: - Default indicator: auto show\n\nextension IndicatorWindowController {\n func autoShowPublisher(\n event: IndicatorVM.ActivateEvent,\n inputSource: InputSource,\n appKind: AppKind\n ) -> AnyPublisher {\n let app = appKind.getApp()\n let application = app.getApplication(preferencesVM: preferencesVM)\n\n let needActivateAtFirstTime = {\n if preferencesVM.preferences.isActiveWhenSwitchApp {\n return true\n }\n\n if preferencesVM.preferences.isActiveWhenFocusedElementChangesEnabled,\n let focusedUIElement = app.focuedUIElement(application: application),\n UIElement.isInputContainer(focusedUIElement)\n {\n return true\n }\n\n return false\n }()\n\n if !needActivateAtFirstTime, isActive {\n isActive = false\n }\n\n return app\n .watchAX([.focusedUIElementChanged], [.application, .window])\n .compactMap { _ in app.focuedUIElement(application: application) }\n .removeDuplicates()\n .filter { UIElement.isInputContainer($0) }\n .mapTo(true)\n .prepend(needActivateAtFirstTime)\n .filter { $0 }\n .compactMap { [weak self] _ in self?.autoHidePublisher(event: event, inputSource: inputSource, appKind: appKind) }\n .switchToLatest()\n .eraseToAnyPublisher()\n }\n}\n\n// MARK: - Just hide indicator\n\nextension IndicatorWindowController {\n func justHidePublisher() -> AnyPublisher {\n Just(true)\n .tap { [weak self] _ in self?.isActive = false }\n .mapToVoid()\n .eraseToAnyPublisher()\n }\n}\n\n// MARK: - AlwaysOn\n\nextension IndicatorWindowController {\n @MainActor\n enum AlwaysOn {\n enum Event {\n case cursorMoved, showAlwaysOnIndicator, scrollStart, scrollEnd\n }\n\n struct State {\n typealias Changes = (current: State, prev: State)\n\n static let initial = State(isShowAlwaysOnIndicator: false, isScrolling: false)\n\n var isShowAlwaysOnIndicator: Bool\n var isScrolling: Bool\n\n func reducer(_ event: Event) -> State {\n switch event {\n case .scrollStart:\n return update {\n $0.isScrolling = true\n }\n case .scrollEnd:\n return update {\n $0.isScrolling = false\n }\n case .showAlwaysOnIndicator:\n return update {\n $0.isShowAlwaysOnIndicator = true\n }\n case .cursorMoved:\n return self\n }\n }\n\n func update(_ change: (inout State) -> Void) -> State {\n var draft = self\n\n change(&draft)\n\n return draft\n }\n }\n\n static func statePublisher(app: NSRunningApplication) -> AnyPublisher {\n let show = app.watchAX(\n [.selectedTextChanged],\n [.application, .window] + Role.validInputElms\n )\n .mapTo(Event.cursorMoved)\n\n let checkIfUnfocusedTimer = Timer.interval(seconds: 1)\n .mapTo(Event.cursorMoved)\n\n let showAlwaysOnIndicatorTimer = Timer.delay(seconds: 0.8)\n .mapTo(Event.showAlwaysOnIndicator)\n\n let hide = NSEvent.watch(matching: [.scrollWheel])\n .flatMapLatest { _ in Timer\n .delay(seconds: 0.3)\n .mapTo(Event.scrollEnd)\n .prepend(Event.scrollStart)\n }\n .removeDuplicates()\n .eraseToAnyPublisher()\n\n return Publishers.MergeMany([show, hide, checkIfUnfocusedTimer, showAlwaysOnIndicatorTimer])\n .prepend(.cursorMoved)\n .scan((State.initial, State.initial)) { changes, event -> State.Changes in\n (changes.current.reducer(event), changes.current)\n }\n .receive(on: DispatchQueue.main)\n .eraseToAnyPublisher()\n }\n }\n\n func alwaysOnPublisher(\n event: IndicatorVM.ActivateEvent,\n inputSource: InputSource,\n appKind: AppKind\n ) -> AnyPublisher {\n typealias Action = () -> Void\n\n let app = appKind.getApp()\n var isAlwaysOnIndicatorShowed = false\n\n updateIndicator(\n event: event,\n inputSource: inputSource\n )\n\n return AlwaysOn\n .statePublisher(app: app)\n .flatMapLatest { [weak self] state -> AnyPublisher in\n let ACTION_HIDE: Action = { self?.isActive = false }\n let ACTION_SHOW: Action = { self?.isActive = true }\n let ACTION_SHOW_ALWAYS_ON_INDICATOR: Action = { self?.indicatorVC.showAlwaysOnView() }\n\n if !state.current.isScrolling,\n let self = self,\n let appSize = self.getAppSize()\n {\n return self.preferencesVM.getIndicatorPositionPublisher(appSize: appSize, app: app)\n .map { position -> Action in\n guard let position = position\n else { return ACTION_HIDE }\n\n return {\n if state.current.isShowAlwaysOnIndicator,\n !isAlwaysOnIndicatorShowed\n {\n isAlwaysOnIndicatorShowed = true\n ACTION_SHOW_ALWAYS_ON_INDICATOR()\n }\n\n if position.kind.isInputArea {\n self.moveIndicator(position: position)\n ACTION_SHOW()\n } else {\n if state.current.isShowAlwaysOnIndicator {\n ACTION_HIDE()\n } else {\n self.moveIndicator(position: position)\n ACTION_SHOW()\n }\n }\n }\n }\n .eraseToAnyPublisher()\n } else {\n return Just(ACTION_HIDE).eraseToAnyPublisher()\n }\n }\n .tap { $0() }\n .mapToVoid()\n .eraseToAnyPublisher()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSMenuItem.swift", "import AppKit\n\nextension NSMenuItem {\n convenience init(\n title string: String,\n target: AnyObject = NSMenuItem.self as AnyObject,\n action selector: Selector?,\n keyEquivalent charCode: String,\n modifier: NSEvent.ModifierFlags = .command\n ) {\n self.init(title: string, action: selector, keyEquivalent: charCode)\n keyEquivalentModifierMask = modifier\n self.target = target\n }\n\n convenience init(title string: String, submenuItems: [NSMenuItem]) {\n self.init(title: string, action: nil, keyEquivalent: \"\")\n submenu = NSMenu()\n submenu?.items = submenuItems\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/LoopingPlayerNSView.swift", "import AppKit\nimport AVFoundation\nimport SwiftUI\n\nstruct PlayerView: NSViewRepresentable {\n let url: URL\n\n func updateNSView(_: NSViewType, context _: Context) {}\n\n func makeNSView(context _: Context) -> some NSView {\n return LoopingPlayerUIView(url: url)\n }\n}\n\nclass LoopingPlayerUIView: NSView {\n private let playerLayer = AVPlayerLayer()\n\n @available(*, unavailable)\n required init?(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n\n init(url: URL) {\n super.init(frame: .zero)\n\n // Setup the player\n let player = AVPlayer(url: url)\n playerLayer.player = player\n playerLayer.videoGravity = .resizeAspectFill\n\n wantsLayer = true\n layer?.addSublayer(playerLayer)\n\n // Setup looping\n player.actionAtItemEnd = .none\n NotificationCenter.default.addObserver(\n self,\n selector: #selector(playerItemDidReachEnd(notification:)),\n name: .AVPlayerItemDidPlayToEndTime,\n object: player.currentItem\n )\n\n // Start the movie\n player.play()\n }\n \n deinit {\n NotificationCenter.default.removeObserver(self)\n }\n\n @objc\n func playerItemDidReachEnd(notification _: Notification) {\n playerLayer.player?.seek(to: CMTime.zero)\n }\n\n override func layout() {\n super.layout()\n playerLayer.frame = bounds\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/InputSource/TISInputSource+Extension.swift", "import Carbon\nimport Foundation\n\nextension TISInputSource {\n enum Category {\n static var keyboardInputSource: String {\n return kTISCategoryKeyboardInputSource as String\n }\n }\n\n private func getProperty(_ key: CFString) -> AnyObject? {\n let cfType = TISGetInputSourceProperty(self, key)\n if cfType != nil {\n return Unmanaged.fromOpaque(cfType!).takeUnretainedValue()\n } else {\n return nil\n }\n }\n\n var id: String {\n return getProperty(kTISPropertyInputSourceID) as! String\n }\n\n var name: String {\n return getProperty(kTISPropertyLocalizedName) as! String\n }\n\n var category: String? {\n return getProperty(kTISPropertyInputSourceCategory) as? String\n }\n\n var isSelectable: Bool {\n return getProperty(kTISPropertyInputSourceIsSelectCapable) as? Bool ?? false\n }\n\n var sourceLanguages: [String] {\n return getProperty(kTISPropertyInputSourceLanguages) as? [String] ?? []\n }\n\n var iconImageURL: URL? {\n return getProperty(kTISPropertyIconImageURL) as? URL\n }\n\n var iconRef: IconRef? {\n return OpaquePointer(TISGetInputSourceProperty(self, kTISPropertyIconRef))\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/Data+SHA256.swift", "import CommonCrypto\nimport Foundation\n\nextension Data {\n public func sha256() -> String {\n return hexStringFromData(input: digest(input: self as NSData))\n }\n\n private func digest(input: NSData) -> NSData {\n let digestLength = Int(CC_SHA256_DIGEST_LENGTH)\n var hash = [UInt8](repeating: 0, count: digestLength)\n CC_SHA256(input.bytes, UInt32(input.length), &hash)\n return NSData(bytes: hash, length: digestLength)\n }\n\n private func hexStringFromData(input: NSData) -> String {\n var bytes = [UInt8](repeating: 0, count: input.length)\n input.getBytes(&bytes, length: input.length)\n\n var hexString = \"\"\n for byte in bytes {\n hexString += String(format: \"%02x\", UInt8(byte))\n }\n\n return hexString\n }\n}\n\npublic extension String {\n func sha256() -> String {\n if let stringData = data(using: String.Encoding.utf8) {\n return stringData.sha256()\n }\n return \"\"\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/IndicatorVM+Triggers.swift", "import AppKit\nimport AXSwift\nimport Combine\nimport CombineExt\n\nextension IndicatorVM {\n @MainActor\n enum ActivateEvent {\n case justHide\n case longMouseDown\n case appChanges(current: AppKind?, prev: AppKind?)\n case inputSourceChanges(InputSource, InputSourceChangeReason)\n\n func isAppChangesWithSameAppOrWebsite() -> Bool {\n switch self {\n case let .appChanges(current, prev):\n return current?.isSameAppOrWebsite(with: prev) == true\n case .inputSourceChanges:\n return false\n case .longMouseDown:\n return false\n case .justHide:\n return false\n }\n }\n\n var isJustHide: Bool {\n switch self {\n case .justHide: return true\n default: return false\n }\n }\n }\n\n func longMouseDownPublisher() -> AnyPublisher {\n AnyPublisher\n .create { observer in\n let monitor = NSEvent.addGlobalMonitorForEvents(\n matching: [.leftMouseDown, .leftMouseUp, .leftMouseDragged],\n handler: { observer.send($0) }\n )\n\n return AnyCancellable { NSEvent.removeMonitor(monitor!) }\n }\n .flatMapLatest { event -> AnyPublisher in\n if event.type == .leftMouseDown {\n return Timer\n .delay(seconds: 0.35)\n .mapToVoid()\n .eraseToAnyPublisher()\n } else {\n return Empty().eraseToAnyPublisher()\n }\n }\n .filter { [weak self] _ in\n self?.preferencesVM.preferences.isActiveWhenLongpressLeftMouse ?? false\n }\n .mapTo(.longMouseDown)\n }\n\n func stateChangesPublisher() -> AnyPublisher {\n $state\n .withPrevious()\n .map { [weak self] previous, current -> ActivateEvent in\n if let preferencesVM = self?.preferencesVM {\n if previous?.appKind?.getId() != current.appKind?.getId() {\n let event = ActivateEvent.appChanges(current: current.appKind, prev: previous?.appKind)\n\n if preferencesVM.preferences.isActiveWhenSwitchApp || preferencesVM.preferences.isActiveWhenFocusedElementChangesEnabled {\n if preferencesVM.preferences.isHideWhenSwitchAppWithForceKeyboard {\n switch current.inputSourceChangeReason {\n case let .appSpecified(status):\n switch status {\n case .cached:\n return event\n case .specified:\n return .justHide\n }\n default:\n return .justHide\n }\n } else {\n return event\n }\n } else {\n return .justHide\n }\n }\n\n if previous?.inputSource.id != current.inputSource.id {\n switch current.inputSourceChangeReason {\n case .noChanges:\n return .justHide\n case .system, .shortcut, .appSpecified:\n guard preferencesVM.preferences.isActiveWhenSwitchInputSource else { return .justHide }\n return .inputSourceChanges(current.inputSource, current.inputSourceChangeReason)\n }\n }\n }\n\n return .justHide\n }\n .eraseToAnyPublisher()\n }\n}\n\nextension IndicatorVM.ActivateEvent: @preconcurrency CustomStringConvertible {\n var description: String {\n switch self {\n case let .appChanges(current, prev):\n return \"appChanges(\\(String(describing: current)), \\(String(describing: prev))\"\n case .inputSourceChanges:\n return \"inputSourceChanges\"\n case .longMouseDown:\n return \"longMouseDown\"\n case .justHide:\n return \"justHide\"\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/PreferencesVM+KeyboardConfig.swift", "import AppKit\nimport Bodega\nimport Boutique\nimport Foundation\nimport SwiftUI\n\nextension PreferencesVM {\n func addKeyboardConfig(_ inputSource: InputSource) -> KeyboardConfig {\n if let config = getKeyboardConfig(inputSource) {\n return config\n } else {\n let config = KeyboardConfig(context: container.viewContext)\n\n config.id = inputSource.id\n\n saveContext()\n\n return config\n }\n }\n\n func update(_ config: KeyboardConfig, textColor: Color, bgColor: Color) {\n saveContext {\n config.textColor = textColor == self.preferences.indicatorForgegroundColor ? nil : textColor\n config.bgColor = bgColor == self.preferences.indicatorBackgroundColor ? nil : bgColor\n }\n }\n\n func getKeyboardConfig(_ inputSource: InputSource) -> KeyboardConfig? {\n return keyboardConfigs.first(where: { $0.id == inputSource.id })\n }\n\n func getOrCreateKeyboardConfig(_ inputSource: InputSource) -> KeyboardConfig {\n return getKeyboardConfig(inputSource) ?? addKeyboardConfig(inputSource)\n }\n}\n\nextension PreferencesVM {\n func getTextNSColor(_ inputSource: InputSource) -> NSColor? {\n let isAutoAppearanceMode = preferences.isAutoAppearanceMode\n\n if let keyboardColor = getKeyboardConfig(inputSource)?.textColor {\n return NSColor(keyboardColor)\n } else {\n return isAutoAppearanceMode\n ? preferences.indicatorForgeground?.dynamicColor\n : NSColor(preferences.indicatorForgegroundColor)\n }\n }\n\n func getTextColor(_ inputSource: InputSource) -> Color {\n if let nsColor = getTextNSColor(inputSource) {\n return Color(nsColor)\n } else {\n return preferences.indicatorForgegroundColor\n }\n }\n\n func getBgNSColor(_ inputSource: InputSource) -> NSColor? {\n let isAutoAppearanceMode = preferences.isAutoAppearanceMode\n\n if let bgColor = getKeyboardConfig(inputSource)?.bgColor {\n return NSColor(bgColor)\n } else {\n return isAutoAppearanceMode\n ? preferences.indicatorBackground?.dynamicColor\n : NSColor(preferences.indicatorBackgroundColor)\n }\n }\n\n func getBgColor(_ inputSource: InputSource) -> Color {\n if let nsColor = getBgNSColor(inputSource) {\n return Color(nsColor)\n } else {\n return preferences.indicatorBackgroundColor\n }\n }\n}\n\nextension PreferencesVM {\n struct DeprecatedKeyboardSettings: Codable & Equatable & Identifiable {\n let id: String\n\n var textColorHex: String?\n var bgColorHex: String?\n }\n\n func migratePreferncesIfNeed() {\n if preferences.prevInstalledBuildVersion <= 462 {\n update {\n $0.indicatorInfo = $0.isShowInputSourcesLabel ? .iconAndTitle : .iconOnly\n }\n }\n }\n\n func migrateBoutiqueIfNeed() {\n let storagePath = Store.documentsDirectory(appendingPath: \"KeyboardSettings\")\n\n guard preferences.prevInstalledBuildVersion == 316,\n FileManager.default.fileExists(atPath: storagePath.path) else { return }\n\n let store = Store(storagePath: storagePath)\n let inputSources = InputSource.sources\n\n store.$items\n .filter { $0.count > 0 }\n .first()\n .sink { [weak self] items in\n self?.saveContext {\n for item in items {\n guard let inputSource = inputSources.first(where: { $0.id == item.id }),\n let config = self?.getOrCreateKeyboardConfig(inputSource)\n else { continue }\n\n config.textColorHex = item.textColorHex\n config.bgColorHex = item.bgColorHex\n }\n }\n\n do {\n try FileManager.default.removeItem(at: storagePath)\n } catch {\n print(\"Boutique migration error: \\(error.localizedDescription)\")\n }\n }\n .store(in: cancelBag)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Accessibility/AXSwift+Browser.swift", "import AXSwift\nimport Cocoa\n\nextension UIElement {\n func domIdentifier() -> String? {\n return safeString(attribute: .identifier)\n }\n\n func firefoxDomIdentifier() -> String? {\n return safeString(attribute: \"AXDOMIdentifier\")\n }\n\n func safeString(attribute attr: Attribute) -> String? {\n if let anyObject: AnyObject = try? attribute(attr),\n CFGetTypeID(anyObject) == CFStringGetTypeID()\n {\n return anyObject as? String\n } else {\n return nil\n }\n }\n\n func safeString(attribute attr: String) -> String? {\n if let anyObject: AnyObject = try? attribute(attr),\n CFGetTypeID(anyObject) == CFStringGetTypeID()\n {\n return anyObject as? String\n } else {\n return nil\n }\n }\n\n func domClassList() -> [String] {\n if let rawDOMClassList: AnyObject = try? attribute(\"AXDOMClassList\"),\n CFGetTypeID(rawDOMClassList) == CFArrayGetTypeID(),\n let domClassList1 = rawDOMClassList as? [AnyObject],\n let rawDOMClass = domClassList1.first,\n CFGetTypeID(rawDOMClass) == CFStringGetTypeID(),\n let domClassList = domClassList1 as? [String]\n {\n return domClassList\n } else {\n return []\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/CodableUserDefault.swift", "import Cocoa\nimport Combine\n\n@propertyWrapper\nfinal class CodableUserDefault: NSObject {\n var wrappedValue: T? {\n get {\n guard let data = userDefaults.data(forKey: key) else { return nil }\n return try? JSONDecoder().decode(T.self, from: data)\n }\n\n set {\n do {\n let data = try JSONEncoder().encode(newValue)\n\n userDefaults.setValue(data, forKey: key)\n } catch {\n print(\"Unable to Encode (\\(error))\")\n }\n }\n }\n\n private let key: String\n private let userDefaults: UserDefaults\n private var observerContext = 0\n private let subject: CurrentValueSubject\n\n init(wrappedValue defaultValue: T, _ key: String, userDefaults: UserDefaults = .standard) {\n self.key = key\n self.userDefaults = userDefaults\n subject = CurrentValueSubject(defaultValue)\n\n super.init()\n\n do {\n try userDefaults.register(defaults: [key: JSONEncoder().encode(defaultValue)])\n // This fulfills requirement 4. Some implementations use NSUserDefaultsDidChangeNotification\n // but that is sent every time any value is updated in UserDefaults.\n userDefaults.addObserver(self, forKeyPath: key, options: .new, context: &observerContext)\n } catch {\n print(\"Unable to register (\\(error))\")\n }\n\n subject.value = wrappedValue\n }\n\n override func observeValue(\n forKeyPath keyPath: String?,\n of object: Any?,\n change: [NSKeyValueChangeKey: Any]?,\n context: UnsafeMutableRawPointer?\n ) {\n if context == &observerContext {\n subject.value = wrappedValue\n } else {\n super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)\n }\n }\n\n deinit {\n userDefaults.removeObserver(self, forKeyPath: key, context: &observerContext)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/PreferencesVM+AppCustomization.swift", "import AppKit\nimport Foundation\n\nextension PreferencesVM {\n @discardableResult\n func addAppCustomization(_ app: NSRunningApplication) -> AppRule? {\n guard let url = app.bundleURL ?? app.executableURL,\n let bundleId = app.bundleId()\n else { return nil }\n\n return addAppCustomization(url, bundleId: bundleId)\n }\n\n func addAppCustomization(_ url: URL, bundleId: String) -> AppRule {\n if let appCustomization = getAppCustomization(bundleId: bundleId) {\n return appCustomization\n }\n\n let appCustomization = AppRule(context: container.viewContext)\n\n appCustomization.createdAt = Date()\n appCustomization.url = url\n appCustomization.bundleId = url.bundleId()\n appCustomization.bundleName = FileManager.default.displayName(atPath: url.path)\n\n saveContext()\n\n return appCustomization\n }\n\n func removeAppCustomization(_ appCustomization: AppRule) {\n container.viewContext.delete(appCustomization)\n saveContext()\n }\n\n func setForceKeyboard(_ appCustomization: AppRule?, _ inputSourceId: String?) {\n guard let appCustomization = appCustomization else { return }\n\n saveContext {\n appCustomization.inputSourceId = inputSourceId\n }\n }\n\n func setDoRestoreKeyboard(_ appCustomization: AppRule?, _ doRestoreKeyboard: Bool) {\n guard let appCustomization = appCustomization else { return }\n\n saveContext {\n appCustomization.doRestoreKeyboard = doRestoreKeyboard\n }\n }\n\n func setDoNotRestoreKeyboard(_ appCustomization: AppRule?, _ doNotRestoreKeyboard: Bool) {\n guard let appCustomization = appCustomization else { return }\n\n saveContext {\n appCustomization.doNotRestoreKeyboard = doNotRestoreKeyboard\n }\n }\n\n func setHideIndicator(_ appCustomization: AppRule?, _ hideIndicator: Bool) {\n guard let appCustomization = appCustomization else { return }\n\n saveContext {\n appCustomization.hideIndicator = hideIndicator\n }\n }\n\n func getAppCustomization(app: NSRunningApplication) -> AppRule? {\n return getAppCustomization(bundleId: app.bundleId())\n }\n\n func getAppCustomization(bundleId: String?) -> AppRule? {\n guard let bundleId = bundleId else { return nil }\n\n let request = AppRule.fetchRequest()\n\n request.predicate = NSPredicate(format: \"bundleId == %@\", bundleId)\n\n do {\n return try container.viewContext.fetch(request).first\n } catch {\n print(\"getAppCustomization(bundleId) error: \\(error.localizedDescription)\")\n return nil\n }\n }\n\n func cleanRemovedAppCustomizationIfNeed() {\n guard preferences.prevInstalledBuildVersion < 308 else { return }\n\n let request = AppRule.fetchRequest()\n\n request.predicate = NSPredicate(format: \"removed == %@\", \"1\")\n\n do {\n let appRules = try container.viewContext.fetch(request)\n appRules.forEach { removeAppCustomization($0) }\n } catch {\n print(\"cleanRemovedAppCustomization error: \\(error.localizedDescription)\")\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSCFRange.swift", "import Foundation\n\nextension CFRange {\n init(range: NSRange) {\n self = CFRangeMake(range.location == NSNotFound ? kCFNotFound : range.location, range.length)\n }\n\n func cursorRange(offset: Int, value: String) -> NSRange {\n return NSRange(location: max(min(location + offset, value.count - 1), 0), length: 1)\n }\n}\n\nextension NSRange {\n init(range: CFRange) {\n self = NSMakeRange(range.location == kCFNotFound ? NSNotFound : range.location, range.length)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/QuestionButton.swift", "import SwiftUI\n\nstruct QuestionButton: View {\n @State var displayTips = false\n\n @Environment(\\.colorScheme) var colorScheme: ColorScheme\n\n let content: () -> Content\n let popover: (ColorScheme) -> Popover\n\n init(\n @ViewBuilder content: @escaping () -> Content,\n @ViewBuilder popover: @escaping (ColorScheme) -> Popover\n ) {\n self.content = content\n self.popover = popover\n }\n\n var body: some View {\n Button(action: { displayTips.toggle() }) {\n content()\n .font(.body.bold())\n }\n .buttonStyle(QuestionButtonStyle())\n .popover(isPresented: $displayTips, arrowEdge: .top) {\n VStack(spacing: 0) {\n popover(colorScheme)\n }\n .frame(width: 280)\n }\n }\n}\n\nstruct QuestionButtonStyle: ButtonStyle {\n @State var isHover = false\n\n func makeBody(configuration: Configuration) -> some View {\n configuration.label\n .opacity(isHover ? 1 : 0.8)\n .background(Color.gray.opacity(configuration.isPressed ? 0.6 : isHover ? 0.3 : 0.15))\n .clipShape(Circle())\n .animation(.easeOut(duration: 0.2), value: configuration.isPressed)\n .onHover { hover in\n withAnimation {\n isHover = hover\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/PreferencesVM+HotKeyGroup.swift", "import AppKit\nimport AXSwift\nimport Foundation\n\nextension PreferencesVM {\n func addHotKeyGroup(\n inputSources: [InputSource]\n ) {\n let rule = HotKeyGroup(context: container.viewContext)\n\n rule.createdAt = Date()\n rule.id = UUID().uuidString\n rule.inputSources = inputSources\n\n saveContext()\n }\n\n func deleteHotKeyGroup(_ group: HotKeyGroup) {\n container.viewContext.delete(group)\n saveContext()\n }\n\n func updateHotKeyGroup(\n _ group: HotKeyGroup,\n inputSources: [InputSource]\n ) {\n saveContext {\n group.inputSources = inputSources\n }\n }\n\n func getHotKeyGroups() -> [HotKeyGroup] {\n let request = NSFetchRequest(entityName: \"HotKeyGroup\")\n\n do {\n return try container.viewContext.fetch(request)\n } catch {\n print(\"getHotKeyGroups() error: \\(error.localizedDescription)\")\n return []\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/AppRuleMenuItem.swift", "import AppKit\n\n@MainActor\nclass AppRuleMenuItem: NSMenuItem {\n let app: NSRunningApplication\n let preferencesVM: PreferencesVM\n let inputSource: InputSource?\n\n var cancelBag = CancelBag()\n\n var appCustomization: AppRule? {\n preferencesVM.getAppCustomization(app: app)\n }\n\n init(app: NSRunningApplication, preferencesVM: PreferencesVM, inputSource: InputSource?) {\n self.app = app\n self.preferencesVM = preferencesVM\n self.inputSource = inputSource\n\n super.init(title: inputSource?.name ?? \"\", action: #selector(forceKeyboard(_:)), keyEquivalent: \"\")\n\n target = self\n\n updateState()\n watchChanges()\n }\n\n @available(*, unavailable)\n required init(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n\n @objc func forceKeyboard(_: Any) {\n let inputSourceId = inputSource?.id ?? \"\"\n\n if let appCustomization = appCustomization {\n preferencesVM.setForceKeyboard(appCustomization, inputSourceId)\n } else {\n preferencesVM.setForceKeyboard(\n preferencesVM.addAppCustomization(app),\n inputSourceId\n )\n }\n\n inputSource?.select(useCJKVFix: preferencesVM.isUseCJKVFix())\n\n watchChanges()\n }\n\n func watchChanges() {\n cancelBag.cancel()\n\n appCustomization?.publisher(for: \\.inputSourceId)\n .sink { [weak self] _ in self?.updateState() }\n .store(in: cancelBag)\n }\n\n func updateState() {\n state = appCustomization?.inputSourceId == inputSource?.id ? .on : .off\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/NavigationVM.swift", "import SwiftUI\n\n@MainActor\nclass NavigationVM: ObservableObject {\n enum Nav: String, CaseIterable, Identifiable {\n var id: String { rawValue }\n\n case general = \"General\"\n\n case appRules = \"App Rules\"\n case browserRules = \"Browser Rules\"\n\n case position = \"Position\"\n case appearance = \"Appearance\"\n\n case inputSourcesColorScheme = \"Input Sources Color Scheme\"\n case keyboardShortcut = \"Hot Keys\"\n\n case troubleshooting = \"Troubleshooting\"\n\n static var grouped: [(id: String, title: String, nav: [Nav])] {\n [\n (\"general\", \"\", [.general]),\n (\"rule\", \"Rules\", [.appRules, .browserRules]),\n (\"theme\", \"Indicator\", [.position, .appearance]),\n (\"keyboard\", \"Keyboard\", [.inputSourcesColorScheme, .keyboardShortcut]),\n (\"others\", \"Others\", [.troubleshooting]),\n ]\n }\n }\n\n @Published var selection: Nav = .general\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/PreferenceSection.swift", "import SwiftUI\n\nstruct PreferenceSection: View {\n let title: String\n\n let content: Content\n\n let hideDivider: Bool\n\n init(title: String, hideDivider: Bool = false, @ViewBuilder _ content: () -> Content) {\n self.title = title\n self.hideDivider = hideDivider\n self.content = content()\n }\n\n var body: some View {\n VStack(alignment: .leading, spacing: 0) {\n HStack(alignment: .firstTextBaseline) {\n VStack {\n Text(title.isEmpty ? title : \"\\(title.i18n()):\")\n .fontWeight(.bold)\n .tracking(0.2)\n .frame(width: 100, alignment: .leading)\n }\n\n VStack(alignment: .leading) {\n content\n }\n\n Spacer(minLength: 0)\n }\n\n if !hideDivider {\n Divider()\n .padding(.vertical)\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/ApplicationVM.swift", "import AppKit\nimport AXSwift\nimport Combine\nimport CombineExt\nimport os\n\n@MainActor\nfinal class ApplicationVM: ObservableObject {\n @Published private(set) var appKind: AppKind? = nil\n @Published private(set) var appsDiff: AppsDiff = .empty\n\n let logger = ISPLogger(category: String(describing: ApplicationVM.self))\n\n let cancelBag = CancelBag()\n let preferencesVM: PreferencesVM\n\n lazy var windowAXNotificationPublisher = ApplicationVM\n .createWindowAXNotificationPublisher(preferencesVM: preferencesVM)\n\n init(preferencesVM: PreferencesVM) {\n self.preferencesVM = preferencesVM\n appKind = .from(NSWorkspace.shared.frontmostApplication, preferencesVM: preferencesVM)\n\n activateAccessibilitiesForCurrentApp()\n watchApplicationChange()\n watchAppsDiffChange()\n }\n}\n\nextension ApplicationVM {\n private func watchApplicationChange() {\n let axNotification = windowAXNotificationPublisher.mapToVoid()\n\n let workspaceNotification = NSWorkspace.shared.notificationCenter\n .publisher(for: NSWorkspace.didActivateApplicationNotification, object: NSWorkspace.shared)\n .mapToVoid()\n\n Publishers\n .Merge(axNotification, workspaceNotification)\n .compactMap { [weak self] _ -> NSRunningApplication? in\n guard self?.preferencesVM.preferences.isEnhancedModeEnabled == true,\n let elm: UIElement = try? systemWideElement.attribute(.focusedApplication),\n let pid = try? elm.pid()\n else { return NSWorkspace.shared.frontmostApplication }\n return NSRunningApplication(processIdentifier: pid)\n }\n .removeDuplicates()\n .flatMapLatest { [weak self] (app: NSRunningApplication) -> AnyPublisher in\n guard let preferencesVM = self?.preferencesVM\n else { return Empty().eraseToAnyPublisher() }\n\n guard NSApplication.isBrowser(app)\n else { return Just(.from(app, preferencesVM: preferencesVM)).eraseToAnyPublisher() }\n\n return Timer\n .interval(seconds: 1)\n .prepend(Date())\n .compactMap { _ in app.focusedUIElement(preferencesVM: preferencesVM) }\n .first()\n .flatMapLatest { _ in\n app.watchAX([\n .focusedUIElementChanged,\n .titleChanged,\n .windowCreated,\n ], [.application, .window])\n .filter { $0.notification != .windowCreated }\n .map { event in event.runningApp }\n }\n .prepend(app)\n .compactMap { app -> AppKind? in .from(app, preferencesVM: preferencesVM) }\n .eraseToAnyPublisher()\n }\n .removeDuplicates(by: { $0.isSameAppOrWebsite(with: $1, detectAddressBar: true) })\n .sink { [weak self] in self?.appKind = $0 }\n .store(in: cancelBag)\n }\n}\n\nextension ApplicationVM {\n private func watchAppsDiffChange() {\n AppsDiff\n .publisher(preferencesVM: preferencesVM)\n .assign(to: &$appsDiff)\n }\n\n private func activateAccessibilitiesForCurrentApp() {\n $appKind\n .compactMap { $0 }\n .filter { [weak self] _ in self?.preferencesVM.preferences.isEnhancedModeEnabled == true }\n .filter { [weak self] in self?.preferencesVM.isHideIndicator($0) != true }\n .sink { $0.getApp().activateAccessibilities() }\n .store(in: cancelBag)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Indicator/IndicatorColor.swift", "import SwiftUI\n\nstruct IndicatorColor {\n let light: Color\n let dark: Color\n}\n\nextension IndicatorColor {\n var dynamicColor: NSColor {\n return NSColor(name: nil) { appearance in\n switch appearance.bestMatch(from: [.darkAqua]) {\n case .darkAqua?:\n return NSColor(self.dark)\n default:\n return NSColor(self.light)\n }\n }\n }\n}\n\nextension IndicatorColor {\n static let background = IndicatorColor(\n light: .white.opacity(0.95),\n dark: .black\n )\n\n static let forgeground = IndicatorColor(\n light: .black,\n dark: .white\n )\n}\n\nextension IndicatorColor: Codable {\n private enum CodingKeys: String, CodingKey { case light, dark }\n\n init(from decoder: Decoder) throws {\n let container = try decoder.container(keyedBy: CodingKeys.self)\n let lightStr = try container.decode(String.self, forKey: .light)\n let darkStr = try container.decode(String.self, forKey: .dark)\n\n light = Color(hex: lightStr)\n dark = Color(hex: darkStr)\n }\n\n func encode(to encoder: Encoder) throws {\n var container = encoder.container(keyedBy: CodingKeys.self)\n try container.encode(light.hexWithAlpha, forKey: .light)\n try container.encode(dark.hexWithAlpha, forKey: .dark)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Utilities/AlignedWidth.swift", "import SwiftUI\n\n// https://stackoverflow.com/a/63997630\n\n// The preference key used to advise parent views of a change in value.\nstruct AlignedWidthPreferenceKey: PreferenceKey {\n static var defaultValue: CGFloat = .zero\n\n static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {\n value = max(value, nextValue())\n }\n}\n\nextension View {\n func alignedView(width: Binding, alignment: Alignment = .trailing) -> some View {\n modifier(AlignedWidthView(width: width, alignment: alignment))\n }\n}\n\nstruct AlignedWidthView: ViewModifier {\n @Binding var width: CGFloat\n\n var alignment: Alignment\n\n func body(content: Content) -> some View {\n content\n .background(GeometryReader {\n Color.clear.preference(\n key: AlignedWidthPreferenceKey.self,\n value: $0.frame(in: .local).size.width\n )\n })\n .onPreferenceChange(AlignedWidthPreferenceKey.self) {\n if $0 > self.width {\n self.width = $0\n }\n }\n .frame(minWidth: width, alignment: alignment)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/BrowserRulesSettingsView.swift", "import SwiftUI\n\nstruct BrowserRulesSettingsView: View {\n @State var isPresented = false\n\n @State var permissionRequest: Browser? = nil\n\n @State var selectedRules = Set()\n\n @FetchRequest(sortDescriptors: [\n NSSortDescriptor(key: \"createdAt\", ascending: true),\n ])\n var browserRules: FetchedResults\n\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n @EnvironmentObject var permissionsVM: PermissionsVM\n\n var inputSourceItems: [PickerItem] {\n [PickerItem.empty]\n + InputSource.sources.map { PickerItem(id: $0.id, title: $0.name, toolTip: $0.id) }\n }\n\n var body: some View {\n let isShowPermissionRequest = Binding(\n get: { permissionRequest != nil },\n set: {\n if $0 == false {\n permissionRequest = nil\n }\n }\n )\n\n return VStack(spacing: 0) {\n VStack {\n HStack {\n Text(\"Default Keyboard for Address Bar\".i18n())\n\n PopUpButtonPicker(\n items: inputSourceItems,\n width: 150,\n isItemSelected: { $0?.id == preferencesVM.preferences.browserAddressDefaultKeyboardId },\n getTitle: { $0?.title ?? \"\" },\n getToolTip: { $0?.toolTip },\n onSelect: handleBrowserAddressDefaultKeyboardSelect\n )\n .disabled(!preferencesVM.preferences.isEnhancedModeEnabled)\n\n EnhancedModeRequiredBadge()\n\n Spacer(minLength: 0)\n }\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border.color)\n\n List(browserRules, id: \\.self, selection: $selectedRules) { rule in\n BrowserRuleRow(isSelected: selectedRules.contains(rule), rule: rule)\n }\n\n HStack(spacing: 0) {\n HStack(spacing: 5) {\n Button(action: addRule) {\n SwiftUI.Image(systemName: \"plus\")\n }\n\n Button(action: removeRules) {\n SwiftUI.Image(systemName: \"minus\")\n }\n .disabled(selectedRules.isEmpty)\n }\n\n Divider()\n .frame(height: 16)\n .padding(.horizontal, 8)\n\n ScrollView(.horizontal, showsIndicators: false) {\n HStack(spacing: 10) {\n ForEach(Browser.allCases.sorted { $0.rawValue < $1.rawValue }, id: \\.rawValue) { browser in\n if NSApplication.isBrowserInstalled(browser.rawValue) {\n Toggle(isOn: isEnableFor(browser)) {\n Text(\"\\(browser.displayName)\")\n }\n }\n }\n }\n }\n }\n .padding(10)\n .border(width: 1, edges: [.top], color: NSColor.gridColor.color)\n .sheet(isPresented: $isPresented, content: {\n BrowserRuleEditView(isPresented: $isPresented, rule: nil)\n })\n .sheet(isPresented: isShowPermissionRequest) {\n BrowserPermissionRequestView(\n isPresented: isShowPermissionRequest,\n onSuccess: permissionRequestSuccess\n )\n }\n }\n }\n\n func addRule() {\n isPresented = true\n }\n\n func removeRules() {\n for selectedRule in selectedRules {\n preferencesVM.deleteBrowserRule(selectedRule)\n }\n selectedRules.removeAll()\n }\n\n func isEnableFor(_ browser: Browser) -> Binding {\n Binding(\n get: { preferencesVM.isBrowserEnabled(browser) },\n set: { enableFor(browser, enable: $0) }\n )\n }\n\n func enableFor(_ browser: Browser, enable: Bool) {\n if enable {\n // TODO: replace `isAccessibilityEnabled` with enhance mode\n if permissionsVM.isAccessibilityEnabled {\n toggle(browser: browser, isEnable: true)\n } else {\n permissionRequest = browser\n }\n } else {\n toggle(browser: browser, isEnable: false)\n }\n }\n\n func permissionRequestSuccess() {\n guard let browser = permissionRequest\n else { return }\n\n toggle(browser: browser, isEnable: true)\n }\n\n func toggle(browser: Browser, isEnable: Bool) {\n preferencesVM.update {\n if isEnable {\n $0.isEnhancedModeEnabled = true\n }\n\n switch browser {\n case .Chrome:\n $0.isEnableURLSwitchForChrome = isEnable\n case .Chromium:\n $0.isEnableURLSwitchForChromium = isEnable\n case .Arc:\n $0.isEnableURLSwitchForArc = isEnable\n case .Safari:\n $0.isEnableURLSwitchForSafari = isEnable\n case .SafariTechnologyPreview:\n $0.isEnableURLSwitchForSafariTechnologyPreview = isEnable\n case .Edge:\n $0.isEnableURLSwitchForEdge = isEnable\n case .Brave:\n $0.isEnableURLSwitchForBrave = isEnable\n case .BraveBeta:\n $0.isEnableURLSwitchForBraveBeta = isEnable\n case .BraveNightly:\n $0.isEnableURLSwitchForBraveNightly = isEnable\n case .Vivaldi:\n $0.isEnableURLSwitchForVivaldi = isEnable\n case .Opera:\n $0.isEnableURLSwitchForOpera = isEnable\n case .Thorium:\n $0.isEnableURLSwitchForThorium = isEnable\n case .Firefox:\n $0.isEnableURLSwitchForFirefox = isEnable\n case .FirefoxDeveloperEdition:\n $0.isEnableURLSwitchForFirefoxDeveloperEdition = isEnable\n case .FirefoxNightly:\n $0.isEnableURLSwitchForFirefoxNightly = isEnable\n case .Zen:\n $0.isEnableURLSwitchForZen = isEnable\n case .Dia:\n $0.isEnableURLSwitchForDia = isEnable\n }\n }\n }\n\n func handleBrowserAddressDefaultKeyboardSelect(_ index: Int) {\n let browserAddressDefaultKeyboard = inputSourceItems[index]\n\n preferencesVM.update {\n $0.browserAddressDefaultKeyboardId = browserAddressDefaultKeyboard.id\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/PromotionBadge.swift", "import SwiftUI\n\nstruct PromotionBadge: View {\n var body: some View {\n VStack(alignment: .leading) {\n Text(\"Promotion\".i18n())\n \n Spacer(minLength: 10)\n \n HStack {\n Spacer()\n \n if #available(macOS 13, *) {\n ShareLink(item: .website) {\n Label {\n Text(\"Share with friends\".i18n())\n } icon: {\n Image(systemName: \"square.and.arrow.up.fill\")\n .foregroundColor(.blue)\n }\n }\n } else {\n Button(action: {\n URL.website.open()\n }) {\n Label {\n Text(\"Share with friends\".i18n())\n } icon: {\n Image(systemName: \"square.and.arrow.up.fill\")\n .foregroundColor(.blue)\n }\n }\n }\n \n \n Button(action: {\n URL(string: \"https://github.com/runjuu/InputSourcePro\")?.open()\n }) {\n Label {\n Text(\"Star on GitHub\".i18n())\n } icon: {\n Image(systemName: \"star.fill\")\n .foregroundColor(Color(red: 1.0, green: 0.84, blue: 0.0))\n }\n }\n \n Button(action: {\n URL(string: \"https://github.com/sponsors/runjuu\")?.open()\n }) {\n Label {\n Text(\"Sponsor\".i18n())\n } icon: {\n Image(systemName: \"heart.fill\")\n .foregroundColor(.pink)\n }\n }\n }\n }\n .padding()\n }\n}\n\n// add support for Canvas Preview\nstruct PromotionBadge_Previews: PreviewProvider {\n static var previews: some View {\n PromotionBadge()\n .frame(width: 635, height: 95)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/InputSourceVM.swift", "import AppKit\nimport AXSwift\nimport Carbon\nimport Combine\nimport Foundation\n\n@MainActor\nclass InputSourceVM: ObservableObject {\n let preferencesVM: PreferencesVM\n\n private var _isProgrammaticChange = false\n\n private var cancelBag = CancelBag()\n\n private let selectInputSourceSubject = PassthroughSubject()\n\n private let inputSourceChangesSubject = PassthroughSubject()\n\n let inputSourceChangesPublisher: AnyPublisher\n\n init(preferencesVM: PreferencesVM) {\n self.preferencesVM = preferencesVM\n inputSourceChangesPublisher = inputSourceChangesSubject.eraseToAnyPublisher()\n\n watchSystemNotification()\n\n selectInputSourceSubject\n .tap { [weak self] inputSource in\n guard let preferencesVM = self?.preferencesVM\n else { return }\n\n inputSource.select(useCJKVFix: preferencesVM.isUseCJKVFix())\n }\n .flatMapLatest { _ in\n Timer.interval(seconds: 0.2)\n .map { _ in InputSource.getCurrentInputSource() }\n .withPrevious()\n .filter { previous, current in\n guard let previous = previous else { return false }\n return previous.id == current.id\n }\n .map { _, current in current }\n .prefix(1)\n }\n .sink { [weak self] in\n self?.inputSourceChangesSubject.send($0)\n self?._isProgrammaticChange = false\n }\n .store(in: cancelBag)\n }\n\n func select(inputSource: InputSource) {\n _isProgrammaticChange = true\n selectInputSourceSubject.send(inputSource)\n }\n\n private func watchSystemNotification() {\n DistributedNotificationCenter.default()\n .publisher(for: Notification.Name(rawValue: kTISNotifySelectedKeyboardInputSourceChanged as String))\n .receive(on: DispatchQueue.main)\n .filter { [weak self] _ in self?._isProgrammaticChange == false }\n .map { _ in InputSource.getCurrentInputSource() }\n .sink { [weak self] in self?.inputSourceChangesSubject.send($0) }\n .store(in: cancelBag)\n }\n\n private func getInputSourceFromMenu() -> InputSource? {\n for app in NSWorkspace.shared.runningApplications {\n if app.bundleIdentifier == \"com.apple.TextInputMenuAgent\" {\n if let application = app.getApplication(preferencesVM: preferencesVM),\n let menuBar: UIElement = try? application.attribute(.extrasMenuBar)\n {\n for child in menuBar.children() ?? [] {\n if let description: String = try? child.attribute(.description),\n let inputSource = InputSource.sources.first(where: { $0.name == description })\n {\n return inputSource\n }\n }\n }\n\n return nil\n }\n }\n\n return nil\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Controllers/IndicatorWindowController.swift", "import AppKit\nimport AXSwift\nimport Carbon\nimport Combine\nimport CombineExt\nimport SnapKit\n\n@MainActor\nclass IndicatorWindowController: FloatWindowController {\n let permissionsVM: PermissionsVM\n let preferencesVM: PreferencesVM\n let indicatorVM: IndicatorVM\n let applicationVM: ApplicationVM\n let inputSourceVM: InputSourceVM\n\n let indicatorVC = IndicatorViewController()\n\n var isActive = false {\n didSet {\n if isActive {\n indicatorVC.view.animator().alphaValue = 1\n window?.displayIfNeeded()\n active()\n } else {\n indicatorVC.view.animator().alphaValue = 0\n deactive()\n }\n }\n }\n\n var cancelBag = CancelBag()\n\n init(\n permissionsVM: PermissionsVM,\n preferencesVM: PreferencesVM,\n indicatorVM: IndicatorVM,\n applicationVM: ApplicationVM,\n inputSourceVM: InputSourceVM\n ) {\n self.permissionsVM = permissionsVM\n self.preferencesVM = preferencesVM\n self.indicatorVM = indicatorVM\n self.applicationVM = applicationVM\n self.inputSourceVM = inputSourceVM\n\n super.init()\n\n contentViewController = indicatorVC\n\n let indicatorPublisher = indicatorVM.activateEventPublisher\n .receive(on: DispatchQueue.main)\n .map { (event: $0, inputSource: self.indicatorVM.state.inputSource) }\n .flatMapLatest { [weak self] params -> AnyPublisher in\n let event = params.event\n let inputSource = params.inputSource\n\n guard let self = self else { return Empty().eraseToAnyPublisher() }\n guard let appKind = self.applicationVM.appKind,\n !event.isJustHide,\n !preferencesVM.isHideIndicator(appKind)\n else { return self.justHidePublisher() }\n\n let app = appKind.getApp()\n\n if preferencesVM.isShowAlwaysOnIndicator(app: app) {\n return self.alwaysOnPublisher(event: event, inputSource: inputSource, appKind: appKind)\n } else if preferencesVM.needDetectFocusedFieldChanges(app: app) {\n return self.autoShowPublisher(event: event, inputSource: inputSource, appKind: appKind)\n } else {\n return self.autoHidePublisher(event: event, inputSource: inputSource, appKind: appKind)\n }\n }\n .eraseToAnyPublisher()\n\n indicatorVM.screenIsLockedPublisher\n .flatMapLatest { isLocked in isLocked ? Empty().eraseToAnyPublisher() : indicatorPublisher }\n .sink { _ in }\n .store(in: cancelBag)\n }\n\n @available(*, unavailable)\n required init?(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSWorkspace.swift", "import AppKit\n\nextension NSWorkspace {\n func openAccessibilityPreferences() {\n open(\n URL(string: \"x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility\")!\n )\n }\n\n func openAutomationPreferences() {\n open(\n URL(string: \"x-apple.systempreferences:com.apple.preference.security?Privacy_Automation\")!\n )\n }\n\n func openKeyboardPreferences() {\n open(\n URL(fileURLWithPath: \"/System/Library/PreferencePanes/Keyboard.prefPane\")\n )\n }\n}\n\nextension NSWorkspace {\n func desktopImage() -> NSImage? {\n guard let mainScreen = NSScreen.main,\n let url = desktopImageURL(for: mainScreen),\n let image = NSImage(contentsOf: url)\n else { return nil }\n\n return image\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/AddSwitchingGroupButton.swift", "import SwiftUI\n\nstruct AddSwitchingGroupButton: View {\n @State var isActive = false\n @State var selections = Set()\n\n let onSelect: ([InputSource]) -> Void\n\n var body: some View {\n Button(\"Add Switch Group\".i18n(), systemImage: \"plus.circle\") {\n isActive = true\n }\n .sheet(isPresented: $isActive, content: {\n VStack(alignment: .leading) {\n Text(\"Select Input Sources\".i18n())\n .font(.title)\n .padding(.bottom, 4)\n\n Text(\"Add a switch group to allow switching between multiple input sources using the same hotkey. Select at least two input sources.\".i18n())\n .lineLimit(nil)\n .multilineTextAlignment(.leading)\n .frame(width: 500)\n\n VStack(alignment: .leading) {\n ForEach(InputSource.sources, id: \\.id) { inputSource in\n VStack(alignment: .leading) {\n HStack(spacing: 6) {\n if selections.contains(inputSource.id) {\n Image(systemName: \"checkmark.circle.fill\")\n .foregroundColor(Color.accentColor)\n .font(.system(size: 16))\n } else {\n Image(systemName: \"circle\")\n .foregroundColor(.gray)\n .font(.system(size: 16))\n }\n\n Text(inputSource.name)\n }\n .frame(height: 12)\n\n Divider()\n }\n .contentShape(Rectangle())\n .onTapGesture {\n if selections.contains(inputSource.id) {\n selections.remove(inputSource.id)\n } else {\n selections.insert(inputSource.id)\n }\n }\n }\n }\n .padding(.vertical)\n\n HStack {\n Spacer()\n\n Button(\"Cancel\".i18n()) { hide() }\n .keyboardShortcut(.cancelAction)\n Button(\"Add\".i18n()) { add() }\n .keyboardShortcut(.defaultAction)\n .disabled(selections.count < 2)\n }\n }\n .padding()\n })\n }\n\n func add() {\n onSelect(InputSource.sources.filter { selections.contains($0.id) })\n hide()\n }\n\n func hide() {\n isActive = false\n selections.removeAll()\n }\n}\n\nstruct MultipleSelectionRow: View {\n var title: String\n var isSelected: Bool\n var action: () -> Void\n\n var body: some View {\n Button(action: action) {\n HStack {\n Text(self.title)\n if self.isSelected {\n Spacer()\n Image(systemName: \"checkmark\")\n }\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/Data+MD5.swift", "import CryptoKit\nimport Foundation\n\nextension Data {\n func md5() -> String {\n Insecure.MD5\n .hash(data: self)\n .map { String(format: \"%02hhx\", $0) }\n .joined()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Combine/Timer.swift", "import AppKit\nimport Combine\n\nextension Timer {\n static func delay(\n seconds: TimeInterval,\n tolerance _: TimeInterval? = nil,\n options _: RunLoop.SchedulerOptions? = nil\n ) -> AnyPublisher {\n return Timer.interval(seconds: seconds)\n .first()\n .eraseToAnyPublisher()\n }\n\n static func interval(\n seconds: TimeInterval\n ) -> AnyPublisher {\n return Timer.publish(every: seconds, on: .main, in: .common)\n .autoconnect()\n .ignoreFailure()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/Bundle+Version.swift", "import AppKit\n\nextension Bundle {\n var shortVersion: String {\n infoDictionary?[\"CFBundleShortVersionString\"] as? String ?? \"unknown\"\n }\n\n var buildVersion: Int {\n Int(infoDictionary?[\"CFBundleVersion\"] as? String ?? \"0\") ?? 0\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/FeedbackButton.swift", "import SwiftUI\n\nstruct FeedbackButton: View {\n @EnvironmentObject var feedbackVM: FeedbackVM\n\n var body: some View {\n Button(\n action: feedbackVM.show,\n label: {\n HStack {\n Text(\"Send Feedback\".i18n() + \"...\")\n Spacer()\n }\n }\n )\n .buttonStyle(SectionButtonStyle())\n }\n}\n\nstruct FeedbackModal: ViewModifier {\n @EnvironmentObject var feedbackVM: FeedbackVM\n\n func body(content: Content) -> some View {\n content\n .sheet(isPresented: .constant(feedbackVM.isPresented), content: {\n LoadingView(isShowing: feedbackVM.isSending) {\n VStack(alignment: .leading) {\n if feedbackVM.isSent {\n HStack {\n Spacer()\n\n VStack {\n Text(\"FeedbackSuccessTips\".i18n())\n .multilineTextAlignment(.center)\n .font(.system(size: 16))\n .padding(.horizontal)\n .padding(.vertical, 30)\n\n Button(\"Close\".i18n()) {\n feedbackVM.hide()\n }\n .keyboardShortcut(.defaultAction)\n .padding(.bottom)\n }\n\n Spacer()\n }\n } else {\n Text(\"FeedbackTips\".i18n())\n .foregroundColor(.primary.opacity(0.8))\n .padding(.vertical, 8)\n\n Text(\"FeedbackMessageTitle\".i18n() + \":\")\n\n ISPTextEditor(text: $feedbackVM.message, placeholder: \"FeedbackMessagePlaceholder\".i18n(), minHeight: 80)\n\n Text(\"FeedbackEmailTitle\".i18n() + \":\")\n .padding(.top, 8)\n\n ISPTextEditor(text: $feedbackVM.email, placeholder: \"support@inputsource.pro\", minHeight: 0)\n\n HStack {\n Spacer()\n\n Button(\"Cancel\".i18n()) {\n feedbackVM.hide()\n }\n .keyboardShortcut(.cancelAction)\n\n Button(\"Send Feedback\".i18n()) {\n Task {\n await feedbackVM.sendFeedback()\n }\n }\n .keyboardShortcut(.defaultAction)\n .disabled(feedbackVM.message.isEmpty)\n }\n .padding(.top)\n }\n }\n .lineLimit(nil)\n .padding()\n .fixedSize(horizontal: false, vertical: true)\n .frame(width: 450)\n .disabled(feedbackVM.isSending)\n }\n .background(NSColor.background.color)\n })\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Controllers/IndicatorWindowController+Indicator.swift", "import Foundation\n\nextension IndicatorWindowController {\n func getAppSize() -> CGSize? {\n return indicatorVC.fittingSize\n }\n\n func updateIndicator(event _: IndicatorVM.ActivateEvent, inputSource: InputSource) {\n let preferences = preferencesVM.preferences\n\n indicatorVC.prepare(config: IndicatorViewConfig(\n inputSource: inputSource,\n kind: preferences.indicatorKind,\n size: preferences.indicatorSize ?? .medium,\n bgColor: preferencesVM.getBgNSColor(inputSource),\n textColor: preferencesVM.getTextNSColor(inputSource)\n ))\n\n if isActive {\n indicatorVC.refresh()\n }\n }\n\n func moveIndicator(position: PreferencesVM.IndicatorPositionInfo) {\n indicatorVC.refresh()\n moveTo(point: position.point)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Persistence/MainStorage.swift", "import AppKit\nimport Combine\n\nclass MainStorage: NSObject {\n var keyboardConfigs = CurrentValueSubject<[KeyboardConfig], Never>([])\n\n let container: NSPersistentContainer\n\n private lazy var keyboardConfigsFRC: NSFetchedResultsController = {\n let fetchRequest = KeyboardConfig.fetchRequest()\n\n fetchRequest.sortDescriptors = [NSSortDescriptor(key: \"id\", ascending: true)]\n\n keyboardConfigsFRC = NSFetchedResultsController(\n fetchRequest: fetchRequest,\n managedObjectContext: container.viewContext,\n sectionNameKeyPath: nil,\n cacheName: nil\n )\n\n keyboardConfigsFRC.delegate = self\n\n return keyboardConfigsFRC\n }()\n\n init(container: NSPersistentContainer) {\n self.container = container\n\n super.init()\n }\n\n func refresh() {\n do {\n try keyboardConfigsFRC.performFetch()\n\n if let configs = keyboardConfigsFRC.fetchedObjects {\n keyboardConfigs.send(configs)\n }\n } catch {\n print(\"MainStorage refresh error: \\(error.localizedDescription)\")\n }\n }\n}\n\nextension MainStorage: NSFetchedResultsControllerDelegate {\n func controllerDidChangeContent(_ controller: NSFetchedResultsController) {\n if let configs = controller.fetchedObjects as? [KeyboardConfig] {\n keyboardConfigs.send(configs)\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/FileManager+Ext.swift", "import Foundation\n\nextension FileManager {\n func isDirectory(atPath path: String) -> Bool {\n let fileManager = FileManager.default\n var isDir: ObjCBool = false\n\n if fileManager.fileExists(atPath: path, isDirectory: &isDir) {\n return isDir.boolValue\n } else {\n return false\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/RulesApplicationPicker.swift", "import SwiftUI\n\nstruct ApplicationPicker: View {\n @Binding var selectedApp: Set\n\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n @FetchRequest(sortDescriptors: [NSSortDescriptor(key: \"bundleName\", ascending: true)])\n var appCustomizations: FetchedResults\n\n let appIconSize: CGFloat = 18\n let keyboardIconSize: CGFloat = 16\n\n var body: some View {\n VStack(spacing: 0) {\n List(appCustomizations, id: \\.self, selection: $selectedApp) { app in\n HStack {\n if let image = app.image {\n SwiftUI.Image(nsImage: image)\n .resizable()\n .frame(width: appIconSize, height: appIconSize)\n } else {\n SwiftUI.Image(systemName: \"app.dashed\")\n .resizable()\n .frame(width: appIconSize, height: appIconSize)\n }\n\n Text(app.bundleName ?? \"(unknown)\")\n .lineLimit(1)\n\n Spacer()\n\n if app.hideIndicator {\n SwiftUI.Image(systemName: \"eye.slash.circle.fill\")\n .opacity(0.7)\n }\n\n if preferencesVM.needDisplayEnhancedModePrompt(bundleIdentifier: app.bundleId) {\n SwiftUI.Image(systemName: \"exclamationmark.triangle.fill\")\n .foregroundColor(Color(red: 1.0, green: 0.84, blue: 0.0))\n }\n\n if preferencesVM.preferences.isRestorePreviouslyUsedInputSource {\n if app.doNotRestoreKeyboard {\n SwiftUI.Image(systemName: \"d.circle.fill\")\n .foregroundColor(selectedApp.contains(app) ? .primary : .green)\n .opacity(selectedApp.contains(app) ? 0.7 : 1.0)\n }\n } else {\n if app.doRestoreKeyboard {\n SwiftUI.Image(systemName: \"arrow.uturn.left.circle.fill\")\n .foregroundColor(selectedApp.contains(app) ? .primary : .blue)\n .opacity(selectedApp.contains(app) ? 0.7 : 1.0)\n }\n }\n\n if let icon = app.forcedKeyboard?.icon {\n SwiftUI.Image(nsImage: icon)\n .resizable()\n .scaledToFit()\n .frame(width: keyboardIconSize, height: keyboardIconSize)\n .opacity(0.7)\n }\n }\n .help(app.bundleName ?? app.url?.path ?? \"(unknown)\")\n }\n .listRowInsets(EdgeInsets())\n }\n .onAppear {\n if let app = appCustomizations.first {\n selectedApp.update(with: app)\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/NSViewHoverable.swift", "import AppKit\nimport Combine\n\nclass NSViewHoverable: NSView {\n private let hoverdSubject: PassthroughSubject\n\n let hoverdPublisher: AnyPublisher\n\n override init(frame frameRect: NSRect) {\n hoverdSubject = PassthroughSubject()\n hoverdPublisher = hoverdSubject.eraseToAnyPublisher()\n\n super.init(frame: frameRect)\n }\n\n @available(*, unavailable)\n required init?(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n\n override func updateTrackingAreas() {\n trackingAreas.forEach { removeTrackingArea($0) }\n\n addTrackingArea(\n NSTrackingArea(\n rect: bounds,\n options: [.activeAlways, .mouseMoved, .mouseEnteredAndExited],\n owner: self,\n userInfo: nil\n )\n )\n }\n\n override func mouseMoved(with _: NSEvent) {\n hoverdSubject.send(true)\n }\n\n override func mouseExited(with _: NSEvent) {\n hoverdSubject.send(false)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Window/FloatWindow.swift", "import AppKit\n\nclass FloatWindow: NSPanel {\n private let _canBecomeKey: Bool\n\n override var canBecomeKey: Bool {\n return _canBecomeKey\n }\n\n init(\n canBecomeKey: Bool,\n contentRect: CGRect,\n styleMask style: NSWindow.StyleMask,\n backing backingStoreType: NSWindow.BackingStoreType,\n defer flag: Bool\n ) {\n _canBecomeKey = canBecomeKey\n\n super.init(\n contentRect: contentRect,\n styleMask: style,\n backing: backingStoreType,\n defer: flag\n )\n\n level = .screenSaver\n\n hasShadow = false\n isOpaque = false\n backgroundColor = .clear\n isMovableByWindowBackground = true\n hidesOnDeactivate = false\n\n titleVisibility = .hidden\n titlebarAppearsTransparent = true\n\n styleMask.insert(.nonactivatingPanel)\n\n collectionBehavior = [\n .moveToActiveSpace,\n .fullScreenAuxiliary,\n .stationary,\n .ignoresCycle,\n ]\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/AppearanceSettingsView.swift", "import AVKit\nimport SwiftUI\n\nstruct AppearanceSettingsView: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n @EnvironmentObject var navigationVM: NavigationVM\n\n @Environment(\\.colorScheme) var colorScheme: ColorScheme\n\n @State private var width = CGFloat.zero\n\n var body: some View {\n let infoBinding = Binding(\n get: {\n preferencesVM.preferences.indicatorInfo ?? .iconAndTitle\n },\n set: { newValue in\n withAnimation(.easeInOut(duration: 0.3)) {\n preferencesVM.update {\n $0.indicatorInfo = newValue\n }\n }\n }\n )\n\n let sizeBinding = Binding(\n get: {\n preferencesVM.preferences.indicatorSize ?? .medium\n },\n set: { newValue in\n withAnimation(.easeInOut(duration: 0.3)) {\n preferencesVM.update {\n $0.indicatorSize = newValue\n }\n }\n }\n )\n\n ScrollView {\n VStack(alignment: .leading, spacing: 18) {\n SettingsSection(title: \"Indicator Info\") {\n VStack(spacing: 0) {\n ItemSection {\n IndicatorView()\n }\n .frame(height: 100)\n .padding(.horizontal)\n .padding(.top)\n\n Picker(\"Position\", selection: infoBinding) {\n ForEach(IndicatorInfo.allCases) { item in\n Text(item.name).tag(item)\n }\n }\n .labelsHidden()\n .pickerStyle(.segmented)\n .padding()\n }\n }\n\n SettingsSection(title: \"Indicator Size\") {\n Picker(\"Size\", selection: sizeBinding) {\n ForEach(IndicatorSize.allCases) { item in\n Text(item.displayName).tag(item)\n }\n }\n .labelsHidden()\n .pickerStyle(.segmented)\n .padding()\n }\n\n SettingsSection(title: \"Color Scheme\") {\n VStack(spacing: 0) {\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.isAutoAppearanceMode)\n .toggleStyle(.switch)\n .labelsHidden()\n\n Text(\"Sync with OS\".i18n())\n\n Spacer()\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n\n VStack(spacing: 16) {\n Picker(\"\", selection: $preferencesVM.preferences.appearanceMode) {\n Text(\"In Light Mode\".i18n()).tag(Optional(Preferences.AppearanceMode.light))\n Text(\"In Dark Mode\".i18n()).tag(Optional(Preferences.AppearanceMode.dark))\n }\n .labelsHidden()\n .pickerStyle(.segmented)\n\n ColorBlocks(\n onSelectColor: { scheme in\n preferencesVM.update {\n $0.indicatorForgegroundColor = scheme.a\n $0.indicatorBackgroundColor = scheme.b\n }\n }\n )\n\n ItemSection {\n IndicatorView()\n\n HStack {\n ColorPicker(\n \"Color\",\n selection: $preferencesVM.preferences.indicatorForgegroundColor\n )\n .labelsHidden()\n\n Button(\n action: {\n preferencesVM.update {\n let a = $0.indicatorForgegroundColor\n let b = $0.indicatorBackgroundColor\n\n $0.indicatorForgegroundColor = b\n $0.indicatorBackgroundColor = a\n }\n },\n label: {\n Image(systemName: \"repeat\")\n }\n )\n\n ColorPicker(\n \"Background\",\n selection: $preferencesVM.preferences.indicatorBackgroundColor\n )\n .labelsHidden()\n }\n }\n .frame(height: 130)\n }\n .padding()\n }\n }\n }\n .padding()\n .padding(.bottom)\n }\n .background(NSColor.background1.color)\n .onAppear(perform: updatePreviewModeOnAppear)\n .onDisappear {\n NSColorPanel.shared.close()\n }\n }\n\n func updatePreviewModeOnAppear() {\n if preferencesVM.preferences.isAutoAppearanceMode {\n preferencesVM.preferences.appearanceMode = colorScheme == .dark ? .dark : .light\n }\n }\n\n func resetColors() {\n if preferencesVM.preferences.appearanceMode == .light {\n preferencesVM.preferences.indicatorForgegroundColor = IndicatorColor.forgeground.light\n preferencesVM.preferences.indicatorBackgroundColor = IndicatorColor.background.light\n }\n\n if preferencesVM.preferences.appearanceMode == .dark {\n preferencesVM.preferences.indicatorForgegroundColor = IndicatorColor.forgeground.dark\n preferencesVM.preferences.indicatorBackgroundColor = IndicatorColor.background.dark\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Accessibility/Element.swift", "import AXSwift\nimport Cocoa\n\nclass Element {\n let rawElement: AXUIElement\n let role: String\n let url: URL?\n\n var clippedFrame: NSRect?\n\n static func initialize(rawElement: AXUIElement) -> Element? {\n let uiElement = UIElement(rawElement)\n let valuesOptional = try? uiElement.getMultipleAttributes([.role, .url])\n\n guard let values = valuesOptional else { return nil }\n guard let role: String = values[Attribute.role] as! String? else { return nil }\n\n return Element(rawElement: rawElement, role: role, url: values[Attribute.url] as? URL)\n }\n\n init(rawElement: AXUIElement, role: String, url: URL?) {\n self.rawElement = rawElement\n self.role = role\n self.url = url\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/ApplicationVM+AXNotification.swift", "import AppKit\nimport AXSwift\nimport Combine\nimport Foundation\n\nextension ApplicationVM {\n static func createWindowAXNotificationPublisher(\n preferencesVM: PreferencesVM\n ) -> AnyPublisher {\n return preferencesVM.$preferences\n .flatMapLatest { preferences -> AnyPublisher in\n guard preferences.isEnhancedModeEnabled\n else { return Empty().eraseToAnyPublisher() }\n\n return NSWorkspace.shared\n .publisher(for: \\.runningApplications)\n .map { $0.filter { NSApplication.isFloatingApp($0.bundleIdentifier) } }\n .removeDuplicates()\n .flatMapLatest { apps in\n Publishers.MergeMany(apps\n .map {\n $0.watchAX(\n [.windowCreated, .uiElementDestroyed],\n [.application, .window]\n )\n }\n )\n }\n .eraseToAnyPublisher()\n }\n .share()\n .eraseToAnyPublisher()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSRegularExpression.swift", "import Foundation\n\nextension NSRegularExpression {\n func matches(_ string: String) -> Bool {\n let range = NSRange(location: 0, length: string.utf16.count)\n return firstMatch(in: string, options: [], range: range) != nil\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/IndicatorAlignmentView.swift", "import SwiftUI\n\nstruct IndicatorAlignmentView: View {\n let content: Content\n\n let alignment: IndicatorPosition.Alignment\n\n init(\n alignment: IndicatorPosition.Alignment,\n @ViewBuilder content: () -> Content\n ) {\n self.content = content()\n self.alignment = alignment\n }\n\n var body: some View {\n VStack {\n if [.bottomLeft, .bottomRight, .bottomCenter].contains(alignment) {\n Spacer(minLength: 0)\n }\n\n HStack {\n if [.topRight, .bottomRight, .centerRight].contains(alignment) {\n Spacer(minLength: 0)\n }\n\n content\n\n if [.topLeft, .bottomLeft, .centerLeft].contains(alignment) {\n Spacer(minLength: 0)\n }\n }\n\n if [.topRight, .topLeft, .topCenter].contains(alignment) {\n Spacer(minLength: 0)\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/RunningApplicationsPicker.swift", "import SwiftUI\n\nstruct RunningApplicationsPicker: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n let appIconSize: CGFloat = 18\n\n let onSelect: (NSRunningApplication) -> Void\n\n init(onSelect: @escaping (NSRunningApplication) -> Void) {\n self.onSelect = onSelect\n }\n\n var body: some View {\n Menu(\"Add Running Apps\") {\n ForEach(preferencesVM.filterApps(NSWorkspace.shared.runningApplications), id: \\.processIdentifier) { app in\n Button(action: { onSelect(app) }) {\n Text(app.localizedName ?? app.bundleId() ?? app.description)\n\n if let url = app.bundleURL {\n let image = NSWorkspace.shared.icon(forFile: url.path)\n\n SwiftUI.Image(nsImage: image)\n .resizable()\n .frame(width: appIconSize, height: appIconSize)\n } else {\n SwiftUI.Image(systemName: \"app.dashed\")\n .resizable()\n .frame(width: appIconSize, height: appIconSize)\n }\n }\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Accessibility/QueryWebAreaService.swift", "import AXSwift\nimport Cocoa\nimport RxSwift\n\nclass QueryWebAreaService {\n let windowElement: Element\n\n init(windowElement: Element) {\n self.windowElement = windowElement\n }\n\n func perform() throws -> Element? {\n try fetchScrollArea()\n }\n\n private func fetchScrollArea() throws -> Element? {\n var stack: [Element] = [windowElement]\n\n while stack.count > 0 {\n let element = stack.popLast()!\n\n if element.role == \"AXWebArea\",\n element.url?.scheme != \"chrome-extension\"\n {\n return element\n }\n\n let children = try fetchChildren(element) ?? []\n for child in children {\n stack.append(child)\n }\n }\n\n return nil\n }\n\n private func fetchChildren(_ element: Element) throws -> [Element]? {\n let rawElementsOptional: [AXUIElement]? = try {\n if element.role == \"AXTable\" || element.role == \"AXOutline\" {\n return try UIElement(element.rawElement).attribute(.visibleRows)\n }\n return try UIElement(element.rawElement).attribute(.children)\n }()\n\n guard let rawElements = rawElementsOptional else {\n return nil\n }\n\n return rawElements\n .map { Element.initialize(rawElement: $0) }\n .compactMap { $0 }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSEvent.swift", "import AppKit\nimport Combine\n\nextension NSEvent {\n static func watch(matching: NSEvent.EventTypeMask) -> AnyPublisher {\n AnyPublisher\n .create { observer in\n let monitor = self.addGlobalMonitorForEvents(\n matching: matching,\n handler: { observer.send($0) }\n )\n\n return AnyCancellable { NSEvent.removeMonitor(monitor!) }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/GeneralSettingsView.swift", "import SwiftUI\n\nstruct GeneralSettingsView: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n @EnvironmentObject var permissionsVM: PermissionsVM\n\n @State var isDetectSpotlightLikeApp = false\n\n var items: [PickerItem] {\n [PickerItem.empty]\n + InputSource.sources.map { PickerItem(id: $0.id, title: $0.name, toolTip: $0.id) }\n }\n\n var body: some View {\n let keyboardRestoreStrategyBinding = Binding(\n get: { preferencesVM.preferences.isRestorePreviouslyUsedInputSource ?\n KeyboardRestoreStrategy.RestorePreviouslyUsedOne :\n KeyboardRestoreStrategy.UseDefaultKeyboardInstead\n },\n set: { newValue in\n preferencesVM.update {\n switch newValue {\n case .RestorePreviouslyUsedOne:\n $0.isRestorePreviouslyUsedInputSource = true\n case .UseDefaultKeyboardInstead:\n $0.isRestorePreviouslyUsedInputSource = false\n }\n }\n }\n )\n\n ScrollView {\n VStack(alignment: .leading, spacing: 18) {\n SettingsSection(title: \"\") {\n PromotionBadge()\n }\n \n SettingsSection(title: \"\") {\n EnhancedModeToggle()\n }\n\n SettingsSection(title: \"Default Keyboard\") {\n HStack {\n Text(\"For All Apps and Websites\".i18n())\n\n PopUpButtonPicker(\n items: items,\n isItemSelected: { $0?.id == preferencesVM.preferences.systemWideDefaultKeyboardId },\n getTitle: { $0?.title ?? \"\" },\n getToolTip: { $0?.toolTip },\n onSelect: handleSystemWideDefaultKeyboardSelect\n )\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n }\n\n SettingsSection(title: \"Keyboard Restore Strategy\") {\n VStack(alignment: .leading) {\n Text(\"When Switching Back to the App or Website\".i18n() + \":\")\n\n Picker(\"Keyboard Restore Strategy\", selection: keyboardRestoreStrategyBinding) {\n ForEach(KeyboardRestoreStrategy.allCases) { item in\n Text(item.name).tag(item)\n }\n }\n .pickerStyle(.segmented)\n }\n .padding()\n }\n\n Group {\n SettingsSection(title: \"Indicator Triggers\") {\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.isActiveWhenLongpressLeftMouse)\n\n Text(\"isActiveWhenLongpressLeftMouse\".i18n())\n\n Spacer()\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.isActiveWhenSwitchInputSource)\n\n Text(\"isActiveWhenSwitchInputSource\".i18n())\n\n Spacer()\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.isActiveWhenSwitchApp)\n\n Text(\"isActiveWhenSwitchApp\".i18n())\n\n Spacer()\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.isActiveWhenFocusedElementChanges)\n .disabled(!preferencesVM.preferences.isEnhancedModeEnabled)\n\n Text(\"isActiveWhenFocusedElementChanges\".i18n())\n\n Spacer()\n\n EnhancedModeRequiredBadge()\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n }\n\n SettingsSection(title: \"\") {\n HStack {\n Toggle(\"\",\n isOn: $preferencesVM.preferences.isHideWhenSwitchAppWithForceKeyboard)\n .disabled(!(\n preferencesVM.preferences.isActiveWhenSwitchApp ||\n preferencesVM.preferences.isActiveWhenSwitchInputSource ||\n preferencesVM.preferences.isActiveWhenFocusedElementChanges\n ))\n\n Text(\"isHideWhenSwitchAppWithForceKeyboard\")\n\n Spacer()\n }\n .padding()\n }\n }\n\n Group {\n SettingsSection(title: \"System\") {\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.isLaunchAtLogin)\n Text(\"Launch at Login\".i18n())\n Spacer()\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.isShowIconInMenuBar)\n Text(\"Display Icon in Menu Bar\".i18n())\n Spacer()\n }\n .padding()\n }\n\n SettingsSection(title: \"Updates\") {\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.receiveBetaUpdates)\n Text(\"Receive Beta Updates\".i18n())\n Spacer()\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n \n Button(action: { preferencesVM.checkUpdates() }, label: {\n HStack {\n Text(\"Check for Updates\".i18n() + \"...\")\n\n Spacer()\n\n Text(\" \\(preferencesVM.versionStr) (\\(preferencesVM.buildStr))\")\n .foregroundColor(Color.primary.opacity(0.5))\n }\n })\n .buttonStyle(SectionButtonStyle())\n }\n }\n\n Group {\n SettingsSection(title: \"Find Us\", tips: Text(\"Right click each section to copy link\").font(.subheadline).opacity(0.5)) {\n Button(action: { URL.website.open() }, label: {\n HStack {\n Text(\"Website\".i18n())\n .foregroundColor(Color.primary)\n\n Spacer()\n\n Text(URL.website.absoluteString)\n }\n })\n .buttonStyle(SectionButtonStyle())\n .contextMenu {\n Button(\"Copy\") {\n NSPasteboard.general.clearContents()\n NSPasteboard.general.setString(URL.website.absoluteString, forType: .string)\n }\n }\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n\n Button(action: { URL.twitter.open() }, label: {\n HStack {\n Text(\"Twitter\")\n .foregroundColor(Color.primary)\n\n Spacer()\n\n Text(\"@Runjuu\")\n }\n })\n .buttonStyle(SectionButtonStyle())\n .contextMenu {\n Button(\"Copy\") {\n NSPasteboard.general.clearContents()\n NSPasteboard.general.setString(URL.twitter.absoluteString, forType: .string)\n }\n }\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n\n Button(action: { URL.email.open() }, label: {\n HStack {\n Text(\"Email\")\n .foregroundColor(Color.primary)\n\n Spacer()\n\n Text(URL.emailString)\n }\n })\n .buttonStyle(SectionButtonStyle())\n .contextMenu {\n Button(\"Copy\") {\n NSPasteboard.general.clearContents()\n NSPasteboard.general.setString(URL.emailString, forType: .string)\n }\n }\n }\n\n SettingsSection(title: \"\") {\n FeedbackButton()\n }\n }\n\n SettingsSection(title: \"Privacy\") {\n HStack {\n Text(\"Privacy Content\".i18n())\n .multilineTextAlignment(.leading)\n .padding()\n .opacity(0.8)\n\n Spacer(minLength: 0)\n }\n }\n\n HStack {\n Spacer()\n Text(\"Created by Runjuu & Die2\")\n Spacer()\n }\n .font(.footnote)\n .opacity(0.5)\n }\n .padding()\n }\n .labelsHidden()\n .toggleStyle(.switch)\n .background(NSColor.background1.color)\n .onAppear(perform: disableIsDetectSpotlightLikeAppIfNeed)\n }\n\n func disableIsDetectSpotlightLikeAppIfNeed() {\n if !permissionsVM.isAccessibilityEnabled && preferencesVM.preferences.isEnhancedModeEnabled {\n preferencesVM.update {\n $0.isEnhancedModeEnabled = false\n }\n }\n }\n\n func handleSystemWideDefaultKeyboardSelect(_ index: Int) {\n let defaultKeyboard = items[index]\n\n preferencesVM.update {\n $0.systemWideDefaultKeyboardId = defaultKeyboard.id\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/FeedbackVM.swift", "import Alamofire\nimport SwiftUI\n\n@MainActor\nfinal class FeedbackVM: ObservableObject {\n enum Status {\n case hided, editing, sending, sent\n }\n\n var isSent: Bool { status == .sent }\n\n var isSending: Bool { status == .sending }\n\n var isPresented: Bool { status != .hided }\n\n @Published private(set) var status = Status.hided\n\n @Published var message = \"\"\n\n @Published var email = \"\"\n\n func show() {\n if status == .hided {\n status = .editing\n }\n }\n\n func hide() {\n if status != .sending {\n status = .hided\n }\n }\n\n func sendFeedback() async {\n withAnimation {\n status = .sending\n }\n\n let _ = await AF\n .request(\n \"https://inputsource.pro/api/feedback\",\n method: .post,\n parameters: [\n \"message\": message,\n \"email\": email,\n \"version\": \"\\(Bundle.main.shortVersion) \\(Bundle.main.buildVersion)\",\n \"osVersion\": ProcessInfo.processInfo.operatingSystemVersionString,\n ],\n encoder: .json\n )\n .serializingDecodable(Alamofire.Empty.self, emptyResponseCodes: [200])\n .response\n\n message = \"\"\n email = \"\"\n\n withAnimation {\n status = .sent\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/IndicatorView.swift", "import SwiftUI\n\nstruct IndicatorView: NSViewControllerRepresentable {\n @EnvironmentObject var preferencesVM: PreferencesVM\n @EnvironmentObject var indicatorVM: IndicatorVM\n @EnvironmentObject var inputSourceVM: InputSourceVM\n\n func makeNSViewController(context _: Context) -> IndicatorViewController {\n return IndicatorViewController()\n }\n\n func updateNSViewController(_ indicatorViewController: IndicatorViewController, context _: Context) {\n indicatorViewController.prepare(config: IndicatorViewConfig(\n inputSource: indicatorVM.state.inputSource,\n kind: preferencesVM.preferences.indicatorKind,\n size: preferencesVM.preferences.indicatorSize ?? .medium,\n bgColor: NSColor(preferencesVM.preferences.indicatorBackgroundColor),\n textColor: NSColor(preferencesVM.preferences.indicatorForgegroundColor)\n ))\n\n indicatorViewController.refresh()\n }\n}\n\nstruct DumpIndicatorView: NSViewControllerRepresentable {\n let config: IndicatorViewConfig\n\n init(config: IndicatorViewConfig) {\n self.config = config\n }\n\n func makeNSViewController(context _: Context) -> IndicatorViewController {\n return IndicatorViewController()\n }\n\n func updateNSViewController(_ indicatorViewController: IndicatorViewController, context _: Context) {\n indicatorViewController.prepare(config: config)\n indicatorViewController.refresh()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/KeyboardCustomization.swift", "import SwiftUI\nimport VisualEffects\n\nstruct KeyboardCustomization: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n @State var textColor: Color = .clear\n @State var bgColor: Color = .clear\n\n let inputSource: InputSource\n\n let columns = [\n GridItem(.fixed(100), alignment: .trailing),\n GridItem(.flexible(minimum: 50, maximum: .infinity), alignment: .leading),\n ]\n\n let indicatorColumns = [\n GridItem(.flexible(minimum: 50, maximum: .infinity), alignment: .center),\n GridItem(.flexible(minimum: 50, maximum: .infinity), alignment: .center),\n ]\n\n var body: some View {\n let keyboardConfig = preferencesVM.getOrCreateKeyboardConfig(inputSource)\n\n VStack(alignment: .leading) {\n ZStack {\n LazyVGrid(columns: indicatorColumns) {\n DumpIndicatorView(config: IndicatorViewConfig(\n inputSource: inputSource,\n kind: .alwaysOn,\n size: preferencesVM.preferences.indicatorSize ?? .medium,\n bgColor: NSColor(bgColor),\n textColor: NSColor(textColor)\n ))\n\n DumpIndicatorView(config: IndicatorViewConfig(\n inputSource: inputSource,\n kind: preferencesVM.preferences.indicatorKind,\n size: preferencesVM.preferences.indicatorSize ?? .medium,\n bgColor: NSColor(bgColor),\n textColor: NSColor(textColor)\n ))\n\n Text(\"Always-On Indicator Style\")\n .font(.caption)\n .opacity(0.5)\n\n Text(\"Keyboard Indicator Style\")\n .font(.caption)\n .opacity(0.5)\n }\n .padding()\n .itemSectionStyle()\n\n VStack {\n Spacer()\n\n HStack {\n Spacer()\n Button(action: { reset(keyboardConfig) }) {\n Text(\"Reset\")\n }\n .buttonStyle(GhostButton(icon: Image(systemName: \"arrow.clockwise\")))\n }\n }\n .padding(.trailing, 4)\n .padding(.bottom, 4)\n }\n\n VStack(alignment: .center) {\n ColorBlocks(onSelectColor: {\n textColor = $0.a\n bgColor = $0.b\n })\n .padding(.vertical, 8)\n\n HStack {\n ColorPicker(\"Color\", selection: $textColor)\n\n Button(\n action: {\n let a = textColor\n let b = bgColor\n\n textColor = b\n bgColor = a\n },\n label: {\n Image(systemName: \"repeat\")\n }\n )\n\n ColorPicker(\"Background\", selection: $bgColor)\n }\n .labelsHidden()\n }\n .padding(.horizontal)\n }\n .padding()\n .onAppear {\n textColor = preferencesVM.getTextColor(inputSource)\n bgColor = preferencesVM.getBgColor(inputSource)\n }\n .onChange(of: bgColor, perform: { _ in save(keyboardConfig) })\n .onChange(of: textColor, perform: { _ in save(keyboardConfig) })\n .onDisappear {\n NSColorPanel.shared.close()\n }\n }\n\n func save(_ keyboardConfig: KeyboardConfig) {\n preferencesVM.update(keyboardConfig, textColor: textColor, bgColor: bgColor)\n }\n\n func reset(_: KeyboardConfig) {\n bgColor = preferencesVM.preferences.indicatorBackgroundColor\n textColor = preferencesVM.preferences.indicatorForgegroundColor\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSRunningApplication+WindowInfo.swift", "import AppKit\nimport Combine\nimport Foundation\n\nprivate func isValidWindow(windowAlpha: CGFloat, windowBounds: CGRect) -> Bool {\n // ----------------------------------------\n // Ignore windows.\n //\n // There are well known windows that we need ignore:\n // * Google Chrome has some transparent windows.\n // * Google Chrome's status bar which is shown when mouse cursor is on links.\n // * Karabiner's status message windows.\n //\n // Do not forget to treat this situations:\n // * Do not ignore menubar.\n // * Do not ignore popup menu.\n // * Do not ignore alert window on web browsers.\n // * Do not ignore iTunes's preferences window which has some special behavior.\n\n // Ignore transparent windows.\n let transparentThreshold: CGFloat = 0.001\n\n if windowAlpha < transparentThreshold {\n return false\n }\n\n // Ignore small windows. (For example, a status bar of Google Chrome.)\n let windowSizeThreshold: CGFloat = 40\n if windowBounds.size.width < windowSizeThreshold ||\n windowBounds.size.height < windowSizeThreshold\n {\n return false\n }\n\n // Xcode and some app have some invisable window at fullscreen mode\n if let screen = NSScreen.getScreenInclude(rect: windowBounds),\n windowBounds.width == screen.frame.width,\n windowBounds.height < 70\n {\n return false\n }\n\n return true\n}\n\nextension NSRunningApplication {\n static func getWindowInfoPublisher(processIdentifier: pid_t) -> AnyPublisher {\n AnyPublisher.create { observer in\n let thread = Thread(block: {\n observer.send(getWindowInfo(processIdentifier: processIdentifier))\n observer.send(completion: .finished)\n })\n\n thread.start()\n\n return AnyCancellable { thread.cancel() }\n }\n .receive(on: DispatchQueue.main)\n .eraseToAnyPublisher()\n }\n\n func getWindowInfoPublisher() -> AnyPublisher {\n return NSRunningApplication.getWindowInfoPublisher(processIdentifier: processIdentifier)\n }\n}\n\nstruct WindowInfo {\n let bounds: CGRect\n let layer: Int\n}\n\nprivate func getWindowInfo(processIdentifier: pid_t) -> WindowInfo? {\n guard let windows = CGWindowListCopyWindowInfo(.optionOnScreenAboveWindow, kCGNullWindowID) as? [[String: Any]]\n else { return nil }\n\n for window in windows {\n // Target windows:\n // * frontmostApplication\n // * loginwindow (shutdown dialog)\n // * Launchpad\n //\n // Limitations:\n // * There is not reliable way to judge whether Dashboard is shown.\n\n guard\n let windowOwnerPID = window[\"kCGWindowOwnerPID\"] as? pid_t,\n let windowLayer = window[\"kCGWindowLayer\"] as? Int,\n let windowAlpha = window[\"kCGWindowAlpha\"] as? CGFloat,\n let windowBounds = CGRect(dictionaryRepresentation: window[\"kCGWindowBounds\"] as! CFDictionary)\n else { continue }\n\n guard windowOwnerPID == processIdentifier\n else { continue }\n\n if isValidWindow(windowAlpha: windowAlpha, windowBounds: windowBounds) {\n return .init(bounds: windowBounds, layer: windowLayer)\n }\n }\n\n return nil\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/ItemSection.swift", "import SwiftUI\n\nstruct ItemSection: View {\n let content: Content\n\n init(@ViewBuilder _ content: () -> Content) {\n self.content = content()\n }\n\n var body: some View {\n HStack {\n Spacer()\n VStack {\n Spacer()\n content\n Spacer()\n }\n Spacer()\n }\n .itemSectionStyle()\n }\n}\n\nstruct ItemSectionStyle: ViewModifier {\n func body(content: Content) -> some View {\n content\n .background(NSColor.background1.color)\n .clipShape(RoundedRectangle(cornerRadius: 6))\n .overlay(\n RoundedRectangle(cornerRadius: 6)\n .stroke(NSColor.border2.color, lineWidth: 1)\n )\n }\n}\n\nextension View {\n func itemSectionStyle() -> some View {\n modifier(ItemSectionStyle())\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/CustomizedIndicatorView.swift", "import SwiftUI\n\nstruct CustomizedIndicatorView: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n let inputSource: InputSource\n\n init(inputSource: InputSource) {\n self.inputSource = inputSource\n }\n\n var body: some View {\n return Group {\n DumpIndicatorView(config: IndicatorViewConfig(\n inputSource: inputSource,\n kind: preferencesVM.preferences.indicatorKind,\n size: preferencesVM.preferences.indicatorSize ?? .medium,\n bgColor: NSColor(preferencesVM.getBgColor(inputSource)),\n textColor: NSColor(preferencesVM.getTextColor(inputSource))\n ))\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Window/FloatWindowController.swift", "import AppKit\n\nclass FloatWindowController: NSWindowController, NSWindowDelegate {\n init(canBecomeKey: Bool = false) {\n super.init(window: FloatWindow(\n canBecomeKey: canBecomeKey,\n contentRect: CGRect(origin: .zero, size: .zero),\n styleMask: [.borderless, .fullSizeContentView, .nonactivatingPanel],\n backing: .buffered,\n defer: false\n ))\n\n window?.delegate = self\n window?.ignoresMouseEvents = true\n window?.standardWindowButton(.zoomButton)?.isEnabled = false\n window?.standardWindowButton(.miniaturizeButton)?.isEnabled = false\n }\n\n @available(*, unavailable)\n required init?(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n}\n\nextension FloatWindowController {\n func active() {\n window?.orderFront(nil)\n }\n\n func deactive() {\n window?.orderOut(nil)\n }\n\n func moveTo(point: CGPoint) {\n window?.setFrameOrigin(point)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Combine/Combine.swift", "import AppKit\nimport Combine\n\nextension Publisher {\n func tap(_ receiveOutput: @escaping (Output) -> Void) -> AnyPublisher {\n handleEvents(receiveOutput: { output in\n receiveOutput(output)\n })\n .eraseToAnyPublisher()\n }\n}\n\nextension Publisher {\n func mapTo(_ value: T) -> AnyPublisher {\n map { _ in value }\n .eraseToAnyPublisher()\n }\n}\n\nextension Publisher {\n typealias WithPrevious = (previous: T?, current: T)\n\n /// Includes the current element as well as the previous element from the upstream publisher in a tuple where the previous element is optional.\n /// The first time the upstream publisher emits an element, the previous element will be `nil`.\n ///\n /// ```\n /// let range = (1...5)\n /// let subscription = range.publisher\n /// .pairwise()\n /// .sink { print(\"(\\($0.previous), \\($0.current))\", terminator: \" \") }\n /// ```\n /// Prints: \"(nil, 1) (Optional(1), 2) (Optional(2), 3) (Optional(3), 4) (Optional(4), 5)\".\n ///\n /// - Returns: A publisher of a tuple of the previous and current elements from the upstream publisher.\n ///\n /// - Note: Based on .\n func withPrevious() -> AnyPublisher, Failure> {\n // `scan()` needs an initial value, which is `nil` in our case.\n // Therefore we have to return an optional here and use `compactMap()` below the remove the optional type.\n scan(nil) { previousPair, currentElement -> WithPrevious? in\n WithPrevious(previous: previousPair?.current, current: currentElement)\n }\n .compactMap { $0 }\n .eraseToAnyPublisher()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSImage+Extension.swift", "import AppKit\n\nextension NSImage {\n func markTemplateIfGrayScaleOrPdf(url: URL? = nil) -> NSImage {\n let image = copy() as! NSImage\n\n if url?.pathExtension == \"pdf\" || isGrayScale() {\n image.isTemplate = true\n }\n\n return image\n }\n\n func isGrayScale() -> Bool {\n guard let imageRef = cgImage(),\n let colorSpace = imageRef.colorSpace\n else { return false }\n\n if colorSpace.model == .monochrome {\n return true\n }\n\n guard let imageData = imageRef.dataProvider?.data,\n let rawData = CFDataGetBytePtr(imageData)\n else { return false }\n\n var byteIndex = 0\n\n for _ in 0 ..< imageRef.width * imageRef.height {\n let r = rawData[byteIndex]\n let g = rawData[byteIndex + 1]\n let b = rawData[byteIndex + 2]\n\n if r == g && g == b {\n byteIndex += 4\n } else {\n return false\n }\n }\n\n return true\n }\n\n func cgImage() -> CGImage? {\n var rect = CGRect(origin: .zero, size: size)\n return cgImage(forProposedRect: &rect, context: nil, hints: nil)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/CJKVFixEnableFailedView.swift", "import SwiftUI\n\nstruct CJKVFixEnableFailedView: View {\n @Binding var isPresented: Bool\n\n @State var isOpened = false\n\n var body: some View {\n VStack(spacing: 0) {\n Text(\"Enabled CJKV Fix Failed Desc\")\n\n Image(\"Enabled CJKV Fix Shortcut Img\".i18n())\n .resizable()\n .aspectRatio(contentMode: .fit)\n .shadow(color: .black.opacity(0.26), radius: 8)\n .padding(20)\n\n HStack {\n Spacer()\n\n if isOpened {\n Button(\"Close\", action: { isPresented = false })\n .keyboardShortcut(.defaultAction)\n } else {\n Button(\"Cancel\", action: { isPresented = false })\n .keyboardShortcut(.cancelAction)\n\n Button(\"Open Keyboard Settings\", action: {\n NSWorkspace.shared.openKeyboardPreferences()\n isOpened = true\n })\n .keyboardShortcut(.defaultAction)\n }\n }\n }\n .padding()\n .frame(width: 480)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/RulesSettingsView.swift", "import SwiftUI\n\nstruct RulesSettingsView: View {\n @State var selectedApp = Set()\n\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n var items: [PickerItem] {\n [PickerItem.empty]\n + InputSource.sources.map { PickerItem(id: $0.id, title: $0.name, toolTip: $0.id) }\n }\n\n var body: some View {\n VStack(alignment: .leading, spacing: 0) {\n HStack(spacing: 0) {\n VStack(alignment: .leading, spacing: 0) {\n ApplicationPicker(selectedApp: $selectedApp)\n .border(width: 1, edges: [.bottom], color: Color(NSColor.gridColor))\n\n HStack(spacing: 5) {\n Button(action: selectApp) {\n SwiftUI.Image(systemName: \"plus\")\n }\n\n Button(action: removeApp) {\n SwiftUI.Image(systemName: \"minus\")\n }\n .disabled(selectedApp.isEmpty)\n\n RunningApplicationsPicker(onSelect: selectRunningApp)\n }\n .padding(10)\n }\n .frame(width: 245)\n .border(width: 1, edges: [.trailing], color: Color(NSColor.gridColor))\n\n ApplicationDetail(selectedApp: $selectedApp)\n .padding()\n\n Spacer(minLength: 0)\n }\n }\n }\n\n func selectApp() {\n let panel = NSOpenPanel()\n\n panel.allowsMultipleSelection = true\n panel.canChooseDirectories = false\n panel.allowedContentTypes = [.application]\n\n if let applicationPath = NSSearchPathForDirectoriesInDomains(\n .applicationDirectory,\n .localDomainMask,\n true\n ).first {\n panel.directoryURL = URL(fileURLWithPath: applicationPath, isDirectory: true)\n }\n\n if panel.runModal() == .OK {\n selectedApp = Set(panel.urls.map {\n preferencesVM.addAppCustomization($0, bundleId: $0.bundleId())\n })\n }\n }\n\n func removeApp() {\n for app in selectedApp {\n preferencesVM.removeAppCustomization(app)\n }\n selectedApp.removeAll()\n }\n\n func selectRunningApp(_ app: NSRunningApplication) {\n if let appRule = preferencesVM.addAppCustomization(app) {\n selectedApp = Set([appRule])\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSScreen.swift", "import AppKit\n\nextension NSScreen {\n static func getScreenWithMouse() -> NSScreen? {\n let mouseLocation = NSEvent.mouseLocation\n let screens = NSScreen.screens\n\n return screens.first(where: { NSMouseInRect(mouseLocation, $0.frame, false) })\n }\n\n static func getScreenInclude(rect: CGRect) -> NSScreen? {\n return NSScreen.screens\n .map { screen in (screen, screen.frame.intersection(rect)) }\n .filter { _, intersect in !intersect.isNull }\n .map { screen, intersect in (screen, intersect.size.width * intersect.size.height) }\n .max { lhs, rhs in lhs.1 < rhs.1 }?.0\n }\n}\n\nextension NSScreen {\n /// The screen whose bottom left is at (0, 0).\n static var primary: NSScreen? {\n return NSScreen.screens.first\n }\n\n /// Converts the rectangle from Quartz \"display space\" to Cocoa \"screen space\".\n /// \n static func convertFromQuartz(_ rect: CGRect) -> CGRect? {\n return NSScreen.primary.map { screen in\n var result = rect\n result.origin.y = screen.frame.maxY - result.maxY\n return result\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSRunningApplication+FocusedElement.swift", "import AXSwift\nimport Cocoa\n\nextension NSRunningApplication {\n @MainActor\n func focusedUIElement(preferencesVM: PreferencesVM?) -> UIElement? {\n return focuedUIElement(application: getApplication(preferencesVM: preferencesVM))\n }\n\n @MainActor\n func focuedUIElement(application: Application?) -> UIElement? {\n if let application = application {\n return try? application.attribute(.focusedUIElement)\n } else {\n return nil\n }\n }\n\n @MainActor\n func getApplication(preferencesVM: PreferencesVM?) -> Application? {\n if let preferencesVM = preferencesVM,\n preferencesVM.preferences.isEnhancedModeEnabled,\n !NSApplication.isFloatingApp(bundleIdentifier)\n {\n return Application(self)\n } else {\n return nil\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/EnhancedModeToggle.swift", "import SwiftUI\n\nstruct EnhancedModeToggle: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n @EnvironmentObject var permissionsVM: PermissionsVM\n\n @State var isShowAccessibilityRequest = false\n\n var body: some View {\n let isDetectSpotlightLikeAppBinding = Binding(\n get: { preferencesVM.preferences.isEnhancedModeEnabled },\n set: { onNeedDetectSpotlightLikeApp($0) }\n )\n\n VStack(alignment: .leading) {\n HStack {\n Toggle(\"\", isOn: isDetectSpotlightLikeAppBinding)\n .sheet(isPresented: $isShowAccessibilityRequest) {\n AccessibilityPermissionRequestView(isPresented: $isShowAccessibilityRequest)\n }\n\n Text(\"Enhanced Mode\".i18n())\n\n Spacer()\n }\n\n Text(.init(\"Enhanced Mode Description\".i18n()))\n .font(.system(size: 12))\n .opacity(0.8)\n }\n .padding()\n }\n\n func onNeedDetectSpotlightLikeApp(_ isDetectSpotlightLikeApp: Bool) {\n preferencesVM.update {\n if isDetectSpotlightLikeApp {\n if permissionsVM.isAccessibilityEnabled {\n $0.isEnhancedModeEnabled = true\n } else {\n isShowAccessibilityRequest = true\n }\n } else {\n $0.isEnhancedModeEnabled = false\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/ISPTextEditor.swift", "//\n// ISPTextEditor.swift\n// Input Source Pro\n//\n// Created by runjuu on 2023-03-05.\n//\n\nimport SwiftUI\n\nstruct ISPTextEditor: View {\n @Binding var text: String\n\n var placeholder: String\n\n let minHeight: CGFloat\n\n var body: some View {\n ZStack(alignment: .topLeading) {\n TextEditor(text: $text)\n .padding(.vertical, 7)\n .padding(.horizontal, 2)\n .frame(minHeight: minHeight, maxHeight: 500, alignment: .leading)\n .foregroundColor(Color(.labelColor))\n .multilineTextAlignment(.leading)\n .background(Color(NSColor.textBackgroundColor))\n .clipShape(RoundedRectangle(cornerRadius: 6))\n .overlay(\n RoundedRectangle(cornerRadius: 6)\n .stroke(Color.primary.opacity(0.3), lineWidth: 1)\n )\n\n Text(placeholder)\n .padding(.vertical, 7)\n .padding(.horizontal, 7)\n .foregroundColor(Color(.placeholderTextColor))\n .opacity(text.isEmpty ? 1 : 0)\n .allowsHitTesting(false)\n }\n .font(.body)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/BrowserPermissionRequestView.swift", "import Combine\nimport SwiftUI\n\nstruct BrowserPermissionRequestView: View {\n @EnvironmentObject var permissionsVM: PermissionsVM\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n @Binding var isPresented: Bool\n\n @State var isDisableTips: Bool = true\n\n var onSuccess: () -> Void\n\n let timer = Timer\n .interval(seconds: 1)\n .mapToVoid()\n .ignoreFailure()\n .eraseToAnyPublisher()\n\n let fakeTimer = Empty(outputType: Void.self, failureType: Never.self)\n .eraseToAnyPublisher()\n\n var body: some View {\n VStack {\n Text(\"Permission Required\")\n .font(.title)\n .fontWeight(.medium)\n .padding(.vertical, 10)\n\n VStack(alignment: .leading) {\n Text(\"Browser Rules Accessibility Permission Description\")\n\n HStack {\n Spacer()\n\n if permissionsVM.isAccessibilityEnabled {\n SwiftUI.Image(systemName: \"checkmark.circle.fill\")\n .resizable()\n .frame(width: 16, height: 16)\n .foregroundColor(.green)\n\n Button(\"Authorized\", action: openAccessibilityPreferences)\n .disabled(true)\n } else {\n Button(\"Open Accessibility Preferences\", action: openAccessibilityPreferences)\n .keyboardShortcut(.defaultAction)\n }\n }\n .padding(.top, 5)\n }\n\n Divider()\n .padding(.vertical, 10)\n\n HStack {\n Button(action: URL.howToEnableBrowserRule.open) {\n SwiftUI.Image(systemName: \"questionmark\")\n }\n .font(.system(size: 10).weight(.bold))\n .frame(width: 18, height: 18)\n .clipShape(RoundedRectangle(cornerRadius: 99))\n .disabled(isDisableTips)\n\n Spacer()\n\n Button(\"Close\", action: close)\n .keyboardShortcut(.cancelAction)\n }\n }\n .lineLimit(nil)\n .fixedSize(horizontal: false, vertical: true)\n .padding()\n .frame(width: 400)\n .onAppear {\n DispatchQueue.main.async {\n isDisableTips = false\n }\n }\n .onChange(of: permissionsVM.isAccessibilityEnabled) { _ in\n onAuthorizeSuccess()\n }\n }\n\n func close() {\n isPresented = false\n }\n\n func openAccessibilityPreferences() {\n NSWorkspace.shared.openAccessibilityPreferences()\n }\n\n func openAutomationPreferences() {\n NSWorkspace.shared.openAutomationPreferences()\n }\n\n func onAuthorizeSuccess() {\n onSuccess()\n close()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/KeyboardsSettingsView.swift", "import KeyboardShortcuts\nimport SwiftUI\n\nstruct KeyboardsSettingsView: View {\n @FetchRequest(sortDescriptors: [NSSortDescriptor(key: \"createdAt\", ascending: true)])\n var hotKeyGroups: FetchedResults\n\n @EnvironmentObject var preferencesVM: PreferencesVM\n @EnvironmentObject var indicatorVM: IndicatorVM\n\n let imgSize: CGFloat = 16\n\n var body: some View {\n ScrollView {\n VStack(spacing: 0) {\n normalSection\n groupSection\n AddSwitchingGroupButton(onSelect: preferencesVM.addHotKeyGroup)\n }\n .padding()\n }\n .background(NSColor.background1.color)\n }\n\n var normalSection: some View {\n ForEach(InputSource.sources, id: \\.id) { inputSource in\n SettingsSection(title: \"\") {\n HStack {\n CustomizedIndicatorView(inputSource: inputSource)\n .help(inputSource.id)\n\n Spacer()\n\n KeyboardShortcuts.Recorder(for: .init(inputSource.id), onChange: { _ in\n indicatorVM.refreshShortcut()\n })\n }\n .padding()\n }\n .padding(.bottom)\n }\n }\n\n var groupSection: some View {\n ForEach(hotKeyGroups, id: \\.self) { group in\n SettingsSection(title: \"\") {\n HStack(alignment: .top) {\n VStack(alignment: .leading) {\n ForEach(group.inputSources, id: \\.id) { inputSource in\n CustomizedIndicatorView(inputSource: inputSource)\n .help(inputSource.id)\n }\n }\n\n Spacer()\n\n VStack(alignment: .trailing) {\n KeyboardShortcuts.Recorder(for: .init(group.id!), onChange: { _ in\n indicatorVM.refreshShortcut()\n })\n\n HStack {\n Button(\"Delete\".i18n()) {\n deleteGroup(group: group)\n }\n }\n }\n }\n .padding()\n }\n .padding(.bottom)\n }\n }\n\n func deleteGroup(group: HotKeyGroup) {\n KeyboardShortcuts.reset([.init(group.id!)])\n preferencesVM.deleteHotKeyGroup(group)\n indicatorVM.refreshShortcut()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/RebootRequiredBadge.swift", "import SwiftUI\n\nstruct RebootRequiredBadge: View {\n let isRequired: Bool\n \n var body: some View {\n Button(action: {}) {\n Text(\"System Reboot Required\".i18n())\n }\n .buttonStyle(RebootRequiredButtonStyle())\n .opacity(isRequired ? 1 : 0)\n .animation(.easeInOut, value: isRequired)\n }\n}\n\nstruct RebootRequiredButtonStyle: ButtonStyle {\n func makeBody(configuration: Self.Configuration) -> some View {\n configuration.label\n .font(.system(size: 10))\n .padding(.horizontal, 4)\n .padding(.vertical, 3)\n .background(Color.gray)\n .foregroundColor(Color.white)\n .clipShape(RoundedRectangle(cornerRadius: 4))\n .contentShape(Rectangle())\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/TroubleshootingSettingsView.swift", "import SwiftUI\n\nstruct TroubleshootingSettingsView: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n @State var isShowCJKVFixEnableFailedView = false\n\n var body: some View {\n let isCJKVFixEnabledBinding = Binding(\n get: { preferencesVM.preferences.isCJKVFixEnabled },\n set: { onToggleCJKVFix($0) }\n )\n\n ScrollView {\n VStack(spacing: 18) {\n SettingsSection(title: \"\") {\n VStack(alignment: .leading) {\n HStack {\n Toggle(\"\", isOn: isCJKVFixEnabledBinding)\n .disabled(!preferencesVM.preferences.isEnhancedModeEnabled)\n .toggleStyle(.switch)\n .labelsHidden()\n\n Text(\"Enabled CJKV Fix\".i18n())\n .font(.headline)\n\n Spacer()\n\n EnhancedModeRequiredBadge()\n }\n\n Text(.init(\"Enabled CJKV Fix Description\".i18n()))\n .font(.system(size: 12))\n .opacity(0.8)\n }\n .padding()\n }\n \n SettingsSection(title: \"\") {\n CursorLagFixView()\n }\n\n SettingsSection(title: \"\") {\n FeedbackButton()\n }\n }\n .padding()\n }\n .background(NSColor.background1.color)\n .sheet(isPresented: $isShowCJKVFixEnableFailedView) {\n CJKVFixEnableFailedView(isPresented: $isShowCJKVFixEnableFailedView)\n }\n }\n\n func onToggleCJKVFix(_ isCJKVFixEnabled: Bool) {\n if isCJKVFixEnabled {\n if InputSource.getSelectPreviousShortcut() == nil {\n isShowCJKVFixEnableFailedView = true\n } else {\n preferencesVM.update {\n $0.isCJKVFixEnabled = true\n }\n }\n } else {\n preferencesVM.update {\n $0.isCJKVFixEnabled = false\n }\n }\n }\n}\n\nenum CursorSettingStatus {\n case enabled\n case disabled\n case undefined\n case unknown\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Indicator/IndicatorViewConfig.swift", "import AppKit\n\nenum IndicatorKind {\n case icon\n case title\n case iconAndTitle\n case alwaysOn\n}\n\n@MainActor\nstruct IndicatorViewConfig {\n let inputSource: InputSource\n let kind: IndicatorKind\n let size: IndicatorSize\n let bgColor: NSColor?\n let textColor: NSColor?\n\n func render() -> NSView? {\n switch kind {\n case .iconAndTitle:\n return renderWithLabel()\n case .icon:\n return renderWithoutLabel()\n case .title:\n return renderOnlyLabel()\n case .alwaysOn:\n return renderAlwaysOn()\n }\n }\n\n func renderAlwaysOn() -> NSView? {\n let containerView = getContainerView()\n\n containerView.layer?.cornerRadius = 8\n\n containerView.snp.makeConstraints {\n $0.width.height.equalTo(8)\n }\n\n return containerView\n }\n\n private func renderWithLabel() -> NSView? {\n guard let imageView = getImageView(inputSource)\n else { return renderOnlyLabel() }\n\n let containerView = getContainerView()\n let labelView = NSTextField(labelWithString: inputSource.name)\n let stackView = NSStackView(views: [imageView, labelView])\n\n switch size {\n case .small:\n containerView.layer?.cornerRadius = 3\n stackView.spacing = 3\n labelView.font = .systemFont(ofSize: 10)\n case .medium:\n containerView.layer?.cornerRadius = 4\n stackView.spacing = 5\n labelView.font = .systemFont(ofSize: 12.6)\n case .large:\n containerView.layer?.cornerRadius = 6\n stackView.spacing = 8\n labelView.font = .systemFont(ofSize: 20)\n }\n\n labelView.textColor = textColor\n stackView.alignment = .centerY\n containerView.addSubview(stackView)\n\n stackView.snp.makeConstraints { make in\n switch size {\n case .small:\n make.edges.equalToSuperview().inset(NSEdgeInsets(top: 3, left: 3, bottom: 3, right: 3))\n case .medium:\n make.edges.equalToSuperview().inset(NSEdgeInsets(top: 4, left: 4, bottom: 4, right: 4))\n case .large:\n make.edges.equalToSuperview().inset(NSEdgeInsets(top: 6, left: 6, bottom: 6, right: 6))\n }\n }\n\n return containerView\n }\n\n private func renderWithoutLabel() -> NSView? {\n guard let imageView = getImageView(inputSource)\n else { return renderOnlyLabel() }\n\n let containerView = getContainerView()\n let stackView = NSStackView(views: [imageView])\n\n containerView.layer?.cornerRadius = 4\n containerView.addSubview(stackView)\n\n stackView.snp.makeConstraints { make in\n make.edges.equalToSuperview().inset(NSEdgeInsets(top: 3, left: 3, bottom: 3, right: 3))\n }\n\n return containerView\n }\n\n private func renderOnlyLabel() -> NSView? {\n let containerView = getContainerView()\n let labelView = NSTextField(labelWithString: inputSource.name)\n let stackView = NSStackView(views: [labelView])\n\n switch size {\n case .small:\n containerView.layer?.cornerRadius = 3\n stackView.spacing = 3\n labelView.font = .systemFont(ofSize: 10)\n case .medium:\n containerView.layer?.cornerRadius = 4\n stackView.spacing = 5\n labelView.font = .systemFont(ofSize: 12.6)\n case .large:\n containerView.layer?.cornerRadius = 6\n stackView.spacing = 8\n labelView.font = .systemFont(ofSize: 20)\n }\n\n labelView.textColor = textColor\n stackView.alignment = .centerY\n containerView.addSubview(stackView)\n\n stackView.snp.makeConstraints { make in\n switch size {\n case .small:\n make.edges.equalToSuperview().inset(NSEdgeInsets(top: 3, left: 3, bottom: 3, right: 3))\n case .medium:\n make.edges.equalToSuperview().inset(NSEdgeInsets(top: 4, left: 4, bottom: 4, right: 4))\n case .large:\n make.edges.equalToSuperview().inset(NSEdgeInsets(top: 6, left: 6, bottom: 6, right: 6))\n }\n }\n\n return containerView\n }\n\n private func getImageView(_ inputSource: InputSource) -> NSView? {\n// if let textImage = getTextImageView(inputSource) { return textImage }\n\n guard let image = inputSource.icon\n else { return nil }\n\n let imageView = NSImageView(image: image)\n\n imageView.contentTintColor = textColor\n\n imageView.snp.makeConstraints { make in\n let size = imageView.image?.size ?? .zero\n let ratio = size.height / size.width\n let width: CGFloat = {\n switch self.size {\n case .small:\n return 12\n case .medium:\n return 16\n case .large:\n return 24\n }\n }()\n let height = ratio * width\n\n make.size.equalTo(CGSize(width: width, height: height))\n }\n\n return imageView\n }\n\n private func getTextImageView(_ inputSource: InputSource) -> NSView? {\n guard let labelName = inputSource.getSystemLabelName()\n else { return nil }\n\n let labelView = NSTextField(labelWithString: labelName)\n let view = NSView()\n\n view.addSubview(labelView)\n view.wantsLayer = true\n view.layer?.backgroundColor = textColor?.cgColor\n view.layer?.cornerRadius = 2\n\n labelView.snp.makeConstraints {\n $0.center.equalTo(view)\n }\n\n view.snp.makeConstraints {\n// $0.width.equalTo(22)\n $0.width.height.equalTo(16)\n }\n\n labelView.textColor = bgColor\n labelView.font = .systemFont(ofSize: labelName.count > 1 ? 10 : 11, weight: .regular)\n\n return view\n }\n\n private func getContainerView() -> NSView {\n let containerView = NSView()\n\n containerView.wantsLayer = true\n containerView.setValue(bgColor, forKey: \"backgroundColor\")\n\n containerView.layer?.borderWidth = 1\n containerView.layer?.borderColor = NSColor.black.withAlphaComponent(0.1 * (bgColor?.alphaComponent ?? 1)).cgColor\n\n return containerView\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/ColorBlock.swift", "import SwiftUI\n\nstruct ColorBlocks: View {\n typealias Scheme = (a: Color, b: Color)\n\n let onSelectColor: (Scheme) -> Void\n\n let colors: [Scheme] = [\n (.init(hex: \"#FFF\"), .init(hex: \"#000\")),\n (.init(hex: \"#FFF\"), .init(hex: \"#ef233c\")),\n (.init(hex: \"#FFF\"), .init(hex: \"#f77f00\")),\n (.init(hex: \"#000\"), .init(hex: \"#F6CB56\")),\n (.init(hex: \"#FFF\"), .init(hex: \"#2c6e49\")),\n (.init(hex: \"#FFF\"), .init(hex: \"#0c7489\")),\n (.init(hex: \"#FFF\"), .init(hex: \"#023e8a\")),\n (.init(hex: \"#FFF\"), .init(hex: \"#7209b7\")),\n ]\n\n var body: some View {\n HStack {\n ForEach(Array(zip(colors.indices, colors)), id: \\.0) { _, scheme in\n Spacer()\n ColorBlock(colorA: scheme.a, colorB: scheme.b)\n .onTapGesture {\n onSelectColor(scheme)\n }\n Spacer()\n }\n }\n }\n}\n\nstruct ColorBlock: View {\n let colorA: Color\n\n let colorB: Color\n\n var body: some View {\n RoundedRectangle(cornerRadius: 4)\n .fill(colorB)\n .overlay(\n SwiftUI.Image(systemName: \"textformat\")\n .foregroundColor(colorA)\n .font(.system(size: 12, weight: .semibold))\n )\n .frame(width: 28, height: 20)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/EnhancedModeRequiredBadge.swift", "import SwiftUI\n\nstruct EnhancedModeRequiredBadge: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n var body: some View {\n Button(action: {}) {\n Text(\"Enhanced Mode Required\".i18n())\n }\n .buttonStyle(EnhanceModeRequiredButtonStyle())\n .opacity(preferencesVM.preferences.isEnhancedModeEnabled ? 0 : 1)\n .animation(.easeInOut, value: preferencesVM.preferences.isEnhancedModeEnabled)\n }\n}\n\nstruct EnhanceModeRequiredButtonStyle: ButtonStyle {\n func makeBody(configuration: Self.Configuration) -> some View {\n configuration.label\n .font(.system(size: 10))\n .padding(.horizontal, 4)\n .padding(.vertical, 3)\n .background(Color.yellow)\n .foregroundColor(Color.black)\n .clipShape(RoundedRectangle(cornerRadius: 4))\n .contentShape(Rectangle())\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/BrowserRuleRow.swift", "import SwiftUI\n\nstruct BrowserRuleRow: View {\n @State var showModal = false\n \n var isSelected: Bool = false\n \n @ObservedObject var rule: BrowserRule\n\n let imgSize: CGFloat = 16\n\n var body: some View {\n HStack {\n Text(rule.value ?? \"\")\n\n Spacer()\n\n if rule.hideIndicator == true {\n Image(systemName: \"eye.slash.circle.fill\")\n .opacity(0.7)\n .frame(width: imgSize, height: imgSize)\n }\n\n if let keyboardRestoreStrategy = rule.keyboardRestoreStrategy {\n let symbolName = keyboardRestoreStrategy.systemImageName\n let color: Color = {\n switch symbolName {\n case \"d.circle.fill\", \"d.square.fill\":\n return isSelected ? .primary.opacity(0.7) : .green\n case \"arrow.uturn.left.circle.fill\":\n return isSelected ? .primary.opacity(0.7) : .blue\n default:\n return .primary\n }\n }()\n Image(systemName: symbolName)\n .foregroundColor(color)\n .frame(width: imgSize, height: imgSize)\n }\n\n if let forcedKeyboard = rule.forcedKeyboard {\n SwiftUI.Image(nsImage: forcedKeyboard.icon ?? NSImage())\n .resizable()\n .scaledToFit()\n .frame(width: imgSize, height: imgSize)\n .opacity(0.7)\n }\n\n Text(rule.type.name)\n .font(.footnote)\n .padding(.horizontal, 4)\n .padding(.vertical, 2)\n .foregroundColor(.white)\n .background(Color.accentColor)\n .clipShape(RoundedRectangle(cornerRadius: 2))\n\n Button(\"Edit\") {\n showModal = true\n }\n }\n .sheet(isPresented: $showModal, content: {\n BrowserRuleEditView(isPresented: $showModal, rule: rule)\n })\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/QuestionMark.swift", "import SwiftUI\n\nstruct QuestionMark: View {\n @State var isPresented: Bool = false\n\n let content: Content\n\n init(@ViewBuilder content: () -> Content) {\n self.content = content()\n }\n\n var body: some View {\n Button(action: { isPresented.toggle() }) {\n SwiftUI.Image(systemName: \"questionmark\")\n }\n .font(.system(size: 10).weight(.bold))\n .frame(width: 18, height: 18)\n .clipShape(RoundedRectangle(cornerRadius: 99))\n .popover(isPresented: $isPresented, arrowEdge: .top) {\n content\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/MockWindowView.swift", "import SwiftUI\nimport VisualEffects\n\nstruct MockWindowView: View {\n var body: some View {\n ZStack {\n VisualEffectBlur(\n material: .windowBackground,\n blendingMode: .withinWindow,\n state: .active\n )\n\n VStack {\n HStack {\n Circle()\n .frame(width: 10, height: 10)\n .foregroundColor(Color(NSColor.close))\n\n Circle()\n .frame(width: 10, height: 10)\n .foregroundColor(Color(NSColor.minimise))\n\n Circle()\n .frame(width: 10, height: 10)\n .foregroundColor(Color(NSColor.maximise))\n Spacer()\n }\n Spacer()\n }\n .padding(10)\n }\n .clipShape(RoundedRectangle(cornerRadius: 9))\n .shadow(color: Color.black.opacity(0.2), radius: 5, x: 3, y: 3)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/AccessibilityPermissionRequestView.swift", "import SwiftUI\n\nstruct AccessibilityPermissionRequestView: View {\n @EnvironmentObject var permissionsVM: PermissionsVM\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n @Binding var isPresented: Bool\n\n @State var isDisableTips: Bool = true\n\n var body: some View {\n VStack(alignment: .leading) {\n Text(.init(\"Enhanced Mode Permission Description\".i18n()))\n .lineSpacing(4)\n\n HStack {\n Button(action: URL.howToEnableAccessbility.open) {\n SwiftUI.Image(systemName: \"questionmark\")\n }\n .font(.system(size: 10).weight(.bold))\n .frame(width: 18, height: 18)\n .clipShape(RoundedRectangle(cornerRadius: 99))\n .disabled(isDisableTips)\n\n Spacer()\n\n Button(\"Open Accessibility Preferences\") {\n NSWorkspace.shared.openAccessibilityPreferences()\n }\n .keyboardShortcut(.defaultAction)\n\n Button(\"Cancel\", action: cancel)\n .keyboardShortcut(.cancelAction)\n }\n .padding(.top)\n }\n .padding()\n .lineLimit(nil)\n .frame(width: 400)\n .onChange(of: permissionsVM.isAccessibilityEnabled, perform: whenAccessibilityEnabled)\n .onAppear {\n DispatchQueue.main.async {\n isDisableTips = false\n }\n }\n }\n\n func cancel() {\n isPresented = false\n }\n\n func whenAccessibilityEnabled(_ isAccessibilityEnabled: Bool) {\n if isAccessibilityEnabled {\n isPresented = false\n preferencesVM.update {\n $0.isEnhancedModeEnabled = true\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/LoadingView.swift", "import SwiftUI\n\nstruct LoadingView: View where Content: View {\n var isShowing: Bool\n\n var content: () -> Content\n\n var body: some View {\n ZStack(alignment: .center) {\n self.content()\n .disabled(isShowing)\n .opacity(isShowing ? 0.5 : 1)\n\n VStack {\n ProgressView()\n .frame(width: 30, height: 30)\n }\n .opacity(isShowing ? 1 : 0)\n .animation(.easeOut, value: isShowing)\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Utilities/ButtonStyle.swift", "import SwiftUI\n\nstruct GhostButton: ButtonStyle {\n @State var isHover = false\n\n let icon: Icon\n\n func makeBody(configuration: Configuration) -> some View {\n HStack(spacing: 4) {\n icon\n\n if isHover {\n configuration.label\n .scaleEffect(0.9)\n }\n }\n .padding(.vertical, 4)\n .padding(.horizontal, 6)\n .opacity(isHover ? 1 : 0.6)\n .background(Color.gray.opacity(configuration.isPressed ? 0.6 : isHover ? 0.3 : 0))\n .clipShape(Capsule())\n .animation(.easeOut(duration: 0.2), value: configuration.isPressed)\n .onHover { hover in\n withAnimation {\n isHover = hover\n }\n }\n }\n}\n\nstruct SectionButtonStyle: ButtonStyle {\n func makeBody(configuration: Self.Configuration) -> some View {\n configuration.label\n .padding()\n .frame(maxWidth: .infinity)\n .background(configuration.isPressed ? Color.gray.opacity(0.05) : Color.clear)\n .foregroundColor(Color.accentColor)\n .clipShape(RoundedRectangle(cornerRadius: 6))\n .contentShape(Rectangle())\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Accessibility/Accessibility.swift", "import AppKit\nimport ApplicationServices\n\nextension AXValue {\n private func get(_ type: AXValueType, initial: T) -> T? {\n var result = initial\n return AXValueGetValue(self, type, &result) ? result : nil\n }\n\n var asPoint: CGPoint? { return get(.cgPoint, initial: .zero) }\n var asSize: CGSize? { return get(.cgSize, initial: .zero) }\n var asRect: CGRect? { return get(.cgRect, initial: .zero) }\n var asRange: CFRange? { return get(.cfRange, initial: CFRange()) }\n var asError: AXError? { return get(.axError, initial: .success) }\n\n private static func create(_ type: AXValueType, _ value: T) -> AXValue {\n var value = value\n return AXValueCreate(type, &value)!\n }\n\n static func point(_ v: CGPoint) -> AXValue { return create(.cgPoint, v) }\n static func size(_ v: CGSize) -> AXValue { return create(.cgSize, v) }\n static func rect(_ v: CGRect) -> AXValue { return create(.cgRect, v) }\n static func range(_ v: CFRange) -> AXValue { return create(.cfRange, v) }\n static func error(_ v: AXError) -> AXValue { return create(.axError, v) }\n}\n"], ["/InputSourcePro/Input Source Pro/Controllers/IndicatorViewController.swift", "import AppKit\nimport SnapKit\n\n@MainActor\nclass IndicatorViewController: NSViewController {\n let hoverableView = NSViewHoverable(frame: .zero)\n\n private(set) var config: IndicatorViewConfig? = nil {\n didSet {\n nextAlwaysOnView = config?.renderAlwaysOn()\n nextNormalView = config?.render()\n\n if normalView == nil || alwaysOnView == nil {\n refresh()\n }\n }\n }\n\n var fittingSize: CGSize? {\n nextNormalView?.fittingSize ?? normalView?.fittingSize\n }\n\n private(set) var nextNormalView: NSView? = nil\n private(set) var nextAlwaysOnView: NSView? = nil\n\n private(set) var normalView: NSView? = nil {\n didSet {\n oldValue?.removeFromSuperview()\n\n if let normalView = normalView {\n view.addSubview(normalView)\n\n normalView.snp.makeConstraints { make in\n let size = normalView.fittingSize\n\n make.edges.equalToSuperview()\n make.width.equalTo(size.width)\n make.height.equalTo(size.height)\n }\n }\n }\n }\n\n private(set) var alwaysOnView: NSView? = nil {\n didSet {\n oldValue?.removeFromSuperview()\n\n if let alwaysOnView = alwaysOnView {\n alwaysOnView.alphaValue = 0\n view.addSubview(alwaysOnView)\n\n alwaysOnView.snp.makeConstraints { make in\n make.leading.bottom.equalToSuperview()\n }\n }\n }\n }\n\n init() {\n super.init(nibName: nil, bundle: nil)\n }\n\n @available(*, unavailable)\n required init?(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n\n func prepare(config: IndicatorViewConfig) {\n self.config = config\n }\n\n func refresh() {\n if let nextNormalView = nextNormalView {\n normalView = nextNormalView\n self.nextNormalView = nil\n }\n\n if let nextAlwaysOnView = nextAlwaysOnView {\n alwaysOnView = nextAlwaysOnView\n self.nextAlwaysOnView = nil\n }\n }\n\n func showAlwaysOnView() {\n normalView?.animator().alphaValue = 0\n alwaysOnView?.animator().alphaValue = 1\n }\n\n override func loadView() {\n view = hoverableView\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/CGRect.swift", "import AppKit\nimport Foundation\n\nextension CGRect {\n func relativeTo(screen: NSScreen) -> CGRect {\n let point = CGPoint(x: minX, y: screen.frame.maxY - maxY)\n\n return CGRect(origin: point, size: size)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/InputSource/InputSource+Name.swift", "import Carbon\nimport Cocoa\nimport Combine\nimport CoreGraphics\n\nprivate let nameMap = [\n \"com.apple.inputmethod.Korean.2SetKorean\": \"한\",\n \"com.apple.inputmethod.Korean.3SetKorean\": \"한\",\n \"com.apple.inputmethod.Korean.390Sebulshik\": \"한\",\n \"com.apple.inputmethod.Korean.GongjinCheongRomaja\": \"한\",\n \"com.apple.inputmethod.Korean.HNCRomaja\": \"한\",\n\n \"com.apple.inputmethod.Kotoeri.RomajiTyping.Japanese\": \"あ\",\n \"com.apple.inputmethod.Kotoeri.KanaTyping.Japanese\": \"あ\",\n\n \"com.apple.keylayout.Irish\": \"IE\",\n \"com.apple.keylayout.Dvorak-Right\": \"DV\",\n \"com.apple.keylayout.DVORAK-QWERTYCMD\": \"DV\",\n \"com.apple.keylayout.Dvorak-Left\": \"DV\",\n \"com.apple.keylayout.Dvorak\": \"DV\",\n \"com.apple.keylayout.Colemak\": \"CO\",\n \"com.apple.keylayout.British-PC\": \"GB\",\n \"com.apple.keylayout.British\": \"GB\",\n \"com.apple.keylayout.Australian\": \"AU\",\n \"com.apple.keylayout.ABC-India\": \"IN\",\n \"com.apple.keylayout.USInternational-PC\": \"US\",\n \"com.apple.keylayout.US\": \"US\",\n \"com.apple.keylayout.USExtended\": \"A\",\n \"com.apple.keylayout.ABC\": \"A\",\n \"com.apple.keylayout.Canadian\": \"CA\",\n\n \"com.apple.inputmethod.TCIM.Cangjie\": \"倉\",\n \"com.apple.inputmethod.TCIM.Pinyin\": \"繁拼\",\n \"com.apple.inputmethod.TCIM.Shuangpin\": \"雙\",\n \"com.apple.inputmethod.TCIM.WBH\": \"畫\",\n \"com.apple.inputmethod.TCIM.Jianyi\": \"速\",\n \"com.apple.inputmethod.TCIM.Zhuyin\": \"注\",\n \"com.apple.inputmethod.TCIM.ZhuyinEten\": \"注\",\n\n \"com.apple.inputmethod.TYIM.Sucheng\": \"速\",\n \"com.apple.inputmethod.TYIM.Stroke\": \"畫\",\n \"com.apple.inputmethod.TYIM.Phonetic\": \"粤拼\",\n \"com.apple.inputmethod.TYIM.Cangjie\": \"倉\",\n\n \"com.apple.inputmethod.SCIM.WBX\": \"五\",\n \"com.apple.inputmethod.SCIM.WBH\": \"画\",\n \"com.apple.inputmethod.SCIM.Shuangpin\": \"双\",\n \"com.apple.inputmethod.SCIM.ITABC\": \"拼\",\n]\n\nextension InputSource {\n func getSystemLabelName() -> String? {\n return nameMap[id]\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppsDiff.swift", "import AppKit\nimport Combine\n\n@MainActor\nstruct AppsDiff {\n let removed: Set\n let added: Set\n let all: Set\n\n func diff(_ runningApps: Set) -> AppsDiff {\n let removedApps = all.subtracting(runningApps)\n let addedApps = runningApps.subtracting(all)\n\n return AppsDiff(removed: removedApps, added: addedApps, all: runningApps)\n }\n}\n\nextension AppsDiff {\n static var empty = AppsDiff(removed: [], added: [], all: [])\n\n static func publisher(preferencesVM: PreferencesVM) -> AnyPublisher {\n NSWorkspace.shared\n .publisher(for: \\.runningApplications)\n .map { apps in Set(preferencesVM.filterApps(apps)) }\n .scan(.empty) { appsDiff, runningApps -> AppsDiff in\n appsDiff.diff(runningApps)\n }\n .replaceError(with: .empty)\n .eraseToAnyPublisher()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/PermissionsVM.swift", "import AppKit\nimport Combine\n\n@MainActor\nfinal class PermissionsVM: ObservableObject {\n @discardableResult\n static func checkAccessibility(prompt: Bool) -> Bool {\n let checkOptPrompt = kAXTrustedCheckOptionPrompt.takeUnretainedValue() as NSString\n return AXIsProcessTrustedWithOptions([checkOptPrompt: prompt] as CFDictionary?)\n }\n\n @Published var isAccessibilityEnabled = PermissionsVM.checkAccessibility(prompt: false)\n\n init() {\n watchAccessibilityChange()\n }\n\n private func watchAccessibilityChange() {\n guard !isAccessibilityEnabled else { return }\n\n Timer\n .interval(seconds: 1)\n .map { _ in Self.checkAccessibility(prompt: false) }\n .filter { $0 }\n .first()\n .assign(to: &$isAccessibilityEnabled)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/InputSourcesAppearanceSettingsView.swift", "import SwiftUI\n\nstruct InputSourcesAppearanceSettingsView: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n let imgSize: CGFloat = 16\n\n var body: some View {\n ScrollView {\n VStack(spacing: 18) {\n ForEach(InputSource.sources, id: \\.id) { inputSource in\n SettingsSection(title: inputSource.name, noI18N: true) {\n KeyboardCustomization(inputSource: inputSource)\n }\n }\n }\n .padding()\n .padding(.bottom)\n }\n .background(NSColor.background1.color)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Persistence/HotKeyGroup.swift", "import Cocoa\n\nextension HotKeyGroup {\n private static let separator = \"∆\"\n\n private var ids: [String] {\n return inputSourceIds?.components(separatedBy: Self.separator) ?? []\n }\n\n @MainActor\n var inputSources: [InputSource] {\n get {\n return InputSource.sources\n .filter { ids.contains($0.id) }\n }\n set {\n inputSourceIds = newValue.map { $0.id }.joined(separator: Self.separator)\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Persistence/KeyboardConfig.swift", "import Cocoa\nimport SwiftUI\n\nextension KeyboardConfig {\n var textColor: Color? {\n get {\n if let hex = textColorHex {\n return Color(hex: hex)\n } else {\n return nil\n }\n }\n\n set {\n textColorHex = newValue?.hexWithAlpha\n }\n }\n\n var bgColor: Color? {\n get {\n if let hex = bgColorHex {\n return Color(hex: hex)\n } else {\n return nil\n }\n }\n\n set {\n bgColorHex = newValue?.hexWithAlpha\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Utilities/Border.swift", "import SwiftUI\n\nprivate struct EdgeBorder: Shape {\n var width: CGFloat\n var edges: [Edge]\n\n func path(in rect: CGRect) -> Path {\n var path = Path()\n for edge in edges {\n var x: CGFloat {\n switch edge {\n case .top, .bottom, .leading: return rect.minX\n case .trailing: return rect.maxX - width\n }\n }\n\n var y: CGFloat {\n switch edge {\n case .top, .leading, .trailing: return rect.minY\n case .bottom: return rect.maxY - width\n }\n }\n\n var w: CGFloat {\n switch edge {\n case .top, .bottom: return rect.width\n case .leading, .trailing: return width\n }\n }\n\n var h: CGFloat {\n switch edge {\n case .top, .bottom: return width\n case .leading, .trailing: return rect.height\n }\n }\n path.addPath(Path(CGRect(x: x, y: y, width: w, height: h)))\n }\n return path\n }\n}\n\nextension View {\n func border(width: CGFloat, edges: [Edge], color: Color) -> some View {\n overlay(EdgeBorder(width: width, edges: edges).foregroundColor(color))\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Utilities/NoAnimation.swift", "import SwiftUI\n\nstruct NoAnimation: ViewModifier {\n func body(content: Content) -> some View {\n content\n .transaction { transaction in\n transaction.animation = nil\n }\n }\n}\n\nextension View {\n func noAnimation() -> some View {\n modifier(NoAnimation())\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/InputSource/IconMap.swift", "import Foundation\n\nextension InputSource {\n static let iconMap = [\n \"12234107\": \"62E0CC7B-901A-411D-818A-0AFC810B0532\",\n \"19304143\": \"A479A7C2-F39C-4374-AE69-C8C181374291\",\n \"27026352\": \"4117A20B-DF89-4304-88FA-D96B8237F822\",\n \"28098003\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"30160324\": \"671AD248-E86D-4294-B01C-6D40E2D19BFF\",\n \"71800932\": \"42A0793D-A1F0-4633-956C-6C24C4770D5A\",\n \"86338706\": \"3A6F6B79-D429-4602-8AE8-0AF37175355A\",\n \"94679192\": \"C9301AC0-A972-4DEB-81AD-9EAB0C71E2B1\",\n \"b1ce8378\": \"47101D70-F7EC-4CAF-9E79-EE417ED6D70F\",\n \"a2293646\": \"9722A832-91F4-4A67-B406-E2FC59074563\",\n \"db454877\": \"99529B6C-0A4D-440E-9A64-911D2515EAFE\",\n \"cbce68ac\": \"45FE4808-C8D9-4C20-9395-38ADC56EED6F\",\n \"e1761b42\": \"0BDE5D8A-61C4-4970-9CFD-A57FECCD0F06\",\n \"33d33781\": \"41F3F960-D979-43E9-ABD9-6F9697A99B9B\",\n \"e40293fa\": \"14005E12-0506-4BF2-9666-8211AFD754D5\",\n \"1ce2f0f3\": \"24B1B420-B287-4BB0-969C-8BFCC678B866\",\n \"8309b9ec\": \"9AC7481F-9AAD-4ED6-A0A2-7C0AFE5B2BE5\",\n \"89da7463\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"a4939376\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"867457f1\": \"BE86C109-31F8-4C1D-9578-F46DF1DEF2B7\",\n \"3899e9a3\": \"40599FAA-AFB1-4C6C-815D-13E6B6BB1E7B\",\n \"698bfbc3\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"e20e8a42\": \"7A47F327-58BA-4B48-AF85-BDBB8BACFA3A\",\n \"f4877994\": \"2DE6399A-0326-4D57-ACE8-6183305BBB28\",\n \"d815cf37\": \"ABA144C9-F007-44C1-82B9-1EC79B30DEA7\",\n \"43754cd2\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"400ffcd6\": \"63249E4A-3105-4D59-B641-458B1B8F9F4F\",\n \"07ab0602\": \"0BDE5D8A-61C4-4970-9CFD-A57FECCD0F06\",\n \"93c001bf\": \"DEF03A5D-FBDA-44FE-9903-1BA349C70742\",\n \"e744f5fc\": \"8D2979B6-7689-4EA6-866D-17210B2A5D5C\",\n \"f17ec27f\": \"F2E5DCED-0628-4491-A683-BAD29FBAE546\",\n \"315a0635\": \"6318A437-3962-4957-8F00-17BDE8292C9A\",\n \"86e12f79\": \"EFD62836-76A2-4B24-A9E4-A29CADCAA1D8\",\n \"b6715cbf\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"9d104945\": \"0BDE5D8A-61C4-4970-9CFD-A57FECCD0F06\",\n \"bbdae7cc\": \"D6DD6280-34D5-4A09-8406-913055E80D4F\",\n \"266d37f0\": \"E93D2928-BB12-4B7A-B148-023FE368F768\",\n \"1c41d885\": \"1544DF19-FC49-4EB9-BB59-E6ED8C57A272\",\n \"eec3fd6f\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"6e03fe80\": \"ABA144C9-F007-44C1-82B9-1EC79B30DEA7\",\n \"29006a72\": \"7BB5DD15-393B-4879-BA2E-45B6E1E1761F\",\n \"2b70ad68\": \"F592A155-59CD-4590-8840-7726FC215730\",\n \"5c63cc7b\": \"1150F661-C12C-49B5-9DD3-51C5C942277C\",\n \"cb0d578c\": \"671AD248-E86D-4294-B01C-6D40E2D19BFF\",\n \"4090640c\": \"DC3DA07D-A07D-425D-A817-FEFABFDB711A\",\n \"7079724c\": \"F0AF7FDB-DE37-4A76-92ED-88AB988A003A\",\n \"719ce030\": \"8C320B5A-772D-4DF3-A34F-2EC07B6D054D\",\n \"ea17e573\": \"12D06541-2675-4160-8827-7E5A32D23627\",\n \"c8e12572\": \"614A664B-068F-4B5B-AD3F-CE72AF912B48\",\n \"d87c5553\": \"0BDE5D8A-61C4-4970-9CFD-A57FECCD0F06\",\n \"1998ce3c\": \"94E6C24D-05D3-401A-9463-F8CDCBB6DFAE\",\n \"5c739cd8\": \"7EF95678-BCA9-4FD0-AD73-6F2EC0C3BA58\",\n \"02a8a069\": \"9BC01780-5C89-49BF-B2C7-B799A0FE317E\",\n \"86f29ad0\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"ad4f3484\": \"4AEC0DCA-2F80-4A63-B23A-6D505B4C55F3\",\n \"8ad2e816\": \"854BCE43-D01E-485B-A3E9-0D0F518B4A86\",\n \"a6b5c89c\": \"F0AF7FDB-DE37-4A76-92ED-88AB988A003A\",\n \"4869720f\": \"E45828A1-28C1-4EB2-B744-C0AFFD49B3D5\",\n \"d60e5c94\": \"D7B94935-4BF7-4A08-ABB7-5816817137B5\",\n \"dc1c63c0\": \"E4E1A898-4128-459D-89C7-D6B7867C0C08\",\n \"df6450c9\": \"2CE658AC-E8B0-4D4C-A893-B9C2A891E846\",\n \"d8bf107e\": \"9AC7481F-9AAD-4ED6-A0A2-7C0AFE5B2BE5\",\n \"a9b362f7\": \"2CC5AE74-F920-4D34-B5E4-F4AEF09D7F9C\",\n \"b89471aa\": \"381071E4-417A-4002-9699-8B8645DEFF4C\",\n \"9ff686a8\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"fc7e017e\": \"DEF03A5D-FBDA-44FE-9903-1BA349C70742\",\n \"3be0b38a\": \"47E931D1-7440-43D0-AB56-49794D42A628\",\n \"0e5acd60\": \"DE5AAF98-BC8F-4BE7-A4F8-80BCD7259C3E\",\n \"ee376a01\": \"85412A26-63FA-4936-B552-0F6065E7E6FB\",\n \"cfc23f4d\": \"1D9651C9-1D1D-47B9-95C0-C2A66EB4198C\",\n \"09ffadd1\": \"5AFD3681-A38F-43A9-A635-0356419453BA\",\n \"5851afb9\": \"8C320B5A-772D-4DF3-A34F-2EC07B6D054D\",\n \"fa478f42\": \"32D98AFC-7792-4F71-91F3-F83013A0A941\",\n \"d3b8669e\": \"1728813A-8FB3-43DF-B3A8-01F0E440004F\",\n \"2b467b65\": \"5D7B1D1A-612A-4FDC-9F55-FAE62A4DF863\",\n \"db9a7d9a\": \"E8BCEBD3-C407-4C02-AF7D-915F0B61E1E2\",\n \"2616d538\": \"4117A20B-DF89-4304-88FA-D96B8237F822\",\n \"63591e06\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"a7c2d310\": \"B7746411-299F-46CE-AD31-6BD27E8F6AC8\",\n \"0c0e3e33\": \"0BDE5D8A-61C4-4970-9CFD-A57FECCD0F06\",\n \"0b92667b\": \"D1BF4948-15E4-4EE3-9133-A417B13B742A\",\n \"a85e0f12\": \"59B13CD3-BF1C-4688-A7D8-DED5DA7AD503\",\n \"1baf6530\": \"1D54967C-A538-43EF-B14F-E6999261915C\",\n \"a86dbf81\": \"9EB423B4-42BD-414D-9863-B424C4C1C7A2\",\n \"2829274f\": \"418EAD09-94C8-442F-A1EB-22610C8D0F22\",\n \"b179bb4a\": \"E4E1A898-4128-459D-89C7-D6B7867C0C08\",\n \"d4769388\": \"B6DF802E-3059-49AC-8B46-C5D138CEEF09\",\n \"9495c4e2\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"c189531b\": \"22B821CC-B495-4D04-8D0C-99A9F5009B91\",\n \"a6a891b5\": \"2F1B18A2-1F6E-47F2-AAE9-1683A7D7E3DD\",\n \"247cf24e\": \"2F367878-36F4-4ACA-A74A-3B3FBD1B2DB7\",\n \"400f17c4\": \"0FAF403B-67A6-49F5-B1CF-CCD72D3CFC77\",\n \"668a30d6\": \"CA58FF15-8944-48BD-8B13-85C62A3032E7\",\n \"27a63ca6\": \"48911C5C-2BDF-4625-B3FC-D6042D485FDC\",\n \"7d054a33\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"bc781ecf\": \"0A1E7B88-A30E-47FD-AA31-0EEF8D7B308D\",\n \"18b0c1bf\": \"A685B482-A0AB-4E5F-9D98-B657D2579A02\",\n \"888f7d7e\": \"44A7B552-951C-439D-9B66-E481025CDA3D\",\n \"eb0b34fc\": \"555C454B-E3D5-4D4B-A4FA-04BE776A18E3\",\n \"3bde5571\": \"EE3B4F8F-EDB9-4906-BBD5-55572518E589\",\n \"d29022b7\": \"24B1B420-B287-4BB0-969C-8BFCC678B866\",\n \"50dcc406\": \"9798FD62-3724-4EBB-BF08-C2BA9CDBD051\",\n \"de55325e\": \"AD82741E-E3E0-457F-944D-4089589FAA74\",\n \"a616c527\": \"1544DF19-FC49-4EB9-BB59-E6ED8C57A272\",\n \"be2451e3\": \"64E0097C-D022-4AD1-B1F8-8179AF922347\",\n \"b547c79f\": \"F1FB3965-B448-4281-B88E-797CCB5E1CB9\",\n \"8929985c\": \"2F367878-36F4-4ACA-A74A-3B3FBD1B2DB7\",\n \"004ed606\": \"7CAE6A9D-6A41-4E35-A00D-EB026314432B\",\n \"1a4118ec\": \"726FFB0C-D838-4634-B815-C1120AC2EB1A\",\n \"f7b1c48f\": \"95D21DA5-73D7-466A-9FBA-21B5D3EAF44C\",\n \"e0b93787\": \"F6BBAA30-D51C-4393-9319-BC3DA549B474\",\n \"bf9de7ac\": \"0D015644-FE01-4E47-BC69-211D3907596E\",\n \"ea497b29\": \"B2D3048B-1F94-4A61-B270-F29DDE09A508\",\n \"b9f2f630\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"a09dca9f\": \"1D9651C9-1D1D-47B9-95C0-C2A66EB4198C\",\n \"cc2855c4\": \"726FFB0C-D838-4634-B815-C1120AC2EB1A\",\n \"69436caa\": \"47720907-47A7-43F0-A7A6-1C3D45FF6E82\",\n \"e30f5f53\": \"22B821CC-B495-4D04-8D0C-99A9F5009B91\",\n \"61aab9c3\": \"E45828A1-28C1-4EB2-B744-C0AFFD49B3D5\",\n \"ce5bb9ee\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"07619740\": \"D6DD6280-34D5-4A09-8406-913055E80D4F\",\n \"3d317f9f\": \"24B1B420-B287-4BB0-969C-8BFCC678B866\",\n \"e3a30f0e\": \"D7699CD3-4A59-49A5-AF99-F1A3A3B2373E\",\n \"0c148ae3\": \"AE4C2970-F3F8-45EE-AF18-39904D636ACE\",\n \"27179b5f\": \"8B90F012-4A1A-4E85-BACC-0401F1865A90\",\n \"3e04932f\": \"84684E50-4D01-4EB5-A087-A9C7B9BC9D17\",\n \"a10ee111\": \"2A96FBC0-D2D5-411F-9B6B-F24BD6104BF7\",\n \"25bcbcdb\": \"48911C5C-2BDF-4625-B3FC-D6042D485FDC\",\n \"c9d00a71\": \"94E6C24D-05D3-401A-9463-F8CDCBB6DFAE\",\n \"4feb8e48\": \"7C65C690-0665-4A7A-9864-36428242789C\",\n \"c7aded35\": \"7498631E-1C04-4207-9407-CA1F02E5C7D5\",\n \"d18ebad8\": \"BDA09217-C081-4FC8-BBE3-B2FF3BA7EC52\",\n \"dc04c9bf\": \"288281B7-EAC6-4F63-9D09-E7A2E2D67D30\",\n \"963f1da1\": \"BEB80FC2-E80D-494B-B718-E3CBED7BB533\",\n \"b97f77dc\": \"D9E09252-5C10-481B-9F33-773669D889BA\",\n \"6e9e1330\": \"8C320B5A-772D-4DF3-A34F-2EC07B6D054D\",\n \"ad812fc8\": \"24B1B420-B287-4BB0-969C-8BFCC678B866\",\n \"74bcc5c7\": \"1C5CAE31-7AAB-4F7E-9ECD-CD34DAC44D35\",\n \"c70f027b\": \"887279DC-0339-4C84-A8C9-C1FBC1D06050\",\n \"b98bc34d\": \"6D7B8A06-FE11-4A7F-9F02-E0E070556E44\",\n \"1ea92671\": \"D9E09252-5C10-481B-9F33-773669D889BA\",\n \"c92c8bf8\": \"9DBF63D5-5CC1-4D83-8C3D-861C3C894C6D\",\n \"7f29e426\": \"04C19F60-EDE3-481D-828F-5542A5FC38D4\",\n \"ea34a8c9\": \"FDC80D50-AF7B-449D-A560-D3AD2EE1D038\",\n \"adf9f70b\": \"41F3F960-D979-43E9-ABD9-6F9697A99B9B\",\n \"4186b088\": \"F0AF7FDB-DE37-4A76-92ED-88AB988A003A\",\n \"2d2388fb\": \"6870AC38-D7B5-4209-B086-3C23ECBBDC13\",\n \"97aba18b\": \"5D7B1D1A-612A-4FDC-9F55-FAE62A4DF863\",\n \"12a8787d\": \"41AB5B71-C470-4F5F-994C-B4FEB8C27A38\",\n \"7ecb03b0\": \"BD82C314-90FF-4966-B5FB-671432C60B14\",\n \"7065b10a\": \"0A420457-A462-4857-A114-EFB4C6E2A402\",\n \"7ed9e71c\": \"06391E5F-D86B-4F73-A9AF-5206A7D2092C\",\n \"786d39b4\": \"B581ADA5-4D62-4680-ACEF-A7ABBA85A9D7\",\n \"a405ec7f\": \"DE5AAF98-BC8F-4BE7-A4F8-80BCD7259C3E\",\n \"3c8f642e\": \"FDC80D50-AF7B-449D-A560-D3AD2EE1D038\",\n \"58455c57\": \"E45828A1-28C1-4EB2-B744-C0AFFD49B3D5\",\n \"235dd000\": \"997494BF-9144-4987-BB62-D70FDD0270A2\",\n \"6510e391\": \"7F227C36-226B-4465-80C4-3BA4AE270A95\",\n \"0d796371\": \"9AC7481F-9AAD-4ED6-A0A2-7C0AFE5B2BE5\",\n \"7abf92cc\": \"555C454B-E3D5-4D4B-A4FA-04BE776A18E3\",\n \"0f6c2128\": \"84684E50-4D01-4EB5-A087-A9C7B9BC9D17\",\n \"1c6dfb89\": \"7F280C1A-8742-424F-8E69-E7CA50810C0E\",\n \"6738fbef\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"f85cad76\": \"F2E5DCED-0628-4491-A683-BAD29FBAE546\",\n \"e8a7b7ac\": \"525E9E05-97C9-4198-AEB1-D159ED6BEFFE\",\n \"998008af\": \"9A8AAAA9-FDE9-46DD-9344-B25CCF79400A\",\n \"a9223b6b\": \"80AB9670-E6EE-4C30-A31C-AC3E6752F42D\",\n \"85fdb832\": \"6D594AFC-54B9-41AE-861E-FE6640176F0F\",\n \"985b9c1c\": \"47101D70-F7EC-4CAF-9E79-EE417ED6D70F\",\n \"b3fd6e15\": \"47101D70-F7EC-4CAF-9E79-EE417ED6D70F\",\n \"e9c087a5\": \"B7746411-299F-46CE-AD31-6BD27E8F6AC8\",\n \"b2ff3df1\": \"2A96FBC0-D2D5-411F-9B6B-F24BD6104BF7\",\n \"cac39a88\": \"7D3DA8CA-D663-4D76-9F2F-61AD2E8C474F\",\n \"cf08c795\": \"7C913FED-1E33-4B8D-AF83-EF9ADD8BF7ED\",\n \"62a32f72\": \"8D2979B6-7689-4EA6-866D-17210B2A5D5C\",\n \"69d17de6\": \"43D1D1FE-193A-4730-89B6-01EBF3F9D6CA\",\n \"f5f80979\": \"DAC2C56F-DC3C-40F9-A468-EFB72BE78E5E\",\n \"2c08766a\": \"E45828A1-28C1-4EB2-B744-C0AFFD49B3D5\",\n \"6c663dfe\": \"85412A26-63FA-4936-B552-0F6065E7E6FB\",\n \"4877037d\": \"0291D80B-1C39-4ECD-8ADB-570D2FAF3204\",\n \"9214334f\": \"C65B1C88-A254-4A3E-9A31-FF63C3579140\",\n \"6f37b707\": \"80AB9670-E6EE-4C30-A31C-AC3E6752F42D\",\n \"5510f56b\": \"24B1B420-B287-4BB0-969C-8BFCC678B866\",\n \"978271a2\": \"8B90F012-4A1A-4E85-BACC-0401F1865A90\",\n \"eee37628\": \"9AC7481F-9AAD-4ED6-A0A2-7C0AFE5B2BE5\",\n \"c635e696\": \"DAC92286-021D-4E7C-8064-9172E53FD37C\",\n \"ffbdd714\": \"49176BD9-5A86-437A-AA07-B027198B21A4\",\n \"6e1e6064\": \"E45828A1-28C1-4EB2-B744-C0AFFD49B3D5\",\n \"cd43b6a4\": \"588AAF70-3342-4DEB-ACC4-18C6DAAF070B\",\n \"83ce500f\": \"515356B7-FCE0-46A7-B6E6-EA1E20F9440A\",\n \"8b62fd42\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"b91b29e1\": \"D7699CD3-4A59-49A5-AF99-F1A3A3B2373E\",\n \"aad82b0e\": \"341AF28C-8140-4BF5-BBD2-DE48ED54B52E\",\n \"359130dd\": \"9AC7481F-9AAD-4ED6-A0A2-7C0AFE5B2BE5\",\n \"208de7e6\": \"ABA144C9-F007-44C1-82B9-1EC79B30DEA7\",\n \"16e15af7\": \"70419D3C-491D-446F-810F-34B656695F84\",\n \"0dee34a1\": \"1BF82110-8702-414B-BBE7-0D4AEBC8CE59\",\n \"fd60e6e1\": \"E76B0F98-61EF-4BB4-A174-33C636778D2D\",\n \"4b1fc25e\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"fb856728\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"c498db0d\": \"42A17026-B747-43FE-856F-08E5E1F3B375\",\n \"58e42a83\": \"88F0C365-5336-4C6E-97B4-C849412B2AFE\",\n \"97270e25\": \"7F227C36-226B-4465-80C4-3BA4AE270A95\",\n \"d46bd534\": \"2F367878-36F4-4ACA-A74A-3B3FBD1B2DB7\",\n \"525f4b59\": \"D7B64293-CCFC-478D-838D-25CEECE1D581\",\n \"c58e71bf\": \"5D7B1D1A-612A-4FDC-9F55-FAE62A4DF863\",\n \"3296bbf9\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"539a2414\": \"6D594AFC-54B9-41AE-861E-FE6640176F0F\",\n \"d05ecc0e\": \"2C36545F-B948-45CA-8814-6AA884AF4414\",\n \"234f9818\": \"DAC92286-021D-4E7C-8064-9172E53FD37C\",\n \"49a2fe1e\": \"0EB6F607-10E3-4310-9476-14BD0CDCDB00\",\n \"18dbea05\": \"F6BBAA30-D51C-4393-9319-BC3DA549B474\",\n \"2ff577b6\": \"49176BD9-5A86-437A-AA07-B027198B21A4\",\n \"d2d2113d\": \"7757DA96-25F6-4BD0-B2AD-3C5192C1B8CA\",\n \"3479a4e7\": \"0BDE5D8A-61C4-4970-9CFD-A57FECCD0F06\",\n \"bbf248dc\": \"CC364542-2678-46FE-8841-19EE238CDB36\",\n \"4b361b85\": \"457ED6AA-4EE9-4F5B-85CB-234415406853\",\n \"be426c78\": \"001359CD-55CF-49FA-A3A6-8A5E018A3CBB\",\n \"73e81f14\": \"5AFD3681-A38F-43A9-A635-0356419453BA\",\n \"218762fe\": \"45B52BCC-ED70-4BD2-9B8C-B2A2E64AC8E4\",\n \"4e49cac1\": \"BE86C109-31F8-4C1D-9578-F46DF1DEF2B7\",\n \"da5bb098\": \"5B2F9F82-2ACF-4608-A138-93B67AFEC8B5\",\n \"9f25876a\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"62b0a598\": \"8D2979B6-7689-4EA6-866D-17210B2A5D5C\",\n \"6e278b38\": \"BA1AA637-942E-40FD-A754-61953BC423B5\",\n \"e95c1507\": \"43D1D1FE-193A-4730-89B6-01EBF3F9D6CA\",\n \"75317e2c\": \"3F8CAF4E-01C7-4CCC-A3AB-C2041CCF678A\",\n \"bfab0f6e\": \"8D2979B6-7689-4EA6-866D-17210B2A5D5C\",\n \"154bf45a\": \"1265ADE8-35CA-4D70-9945-4CAE0D2A2FAD\",\n \"0569f839\": \"DEF03A5D-FBDA-44FE-9903-1BA349C70742\",\n \"3b22c4c6\": \"47720907-47A7-43F0-A7A6-1C3D45FF6E82\",\n \"0167a31d\": \"32B9FF3C-8D94-4B10-AD4F-1A70341C2E73\",\n \"3f1989f1\": \"744B5137-BB36-48C2-A4D1-08C186443ADD\",\n \"7ffc9c42\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"624655b7\": \"5AFD3681-A38F-43A9-A635-0356419453BA\",\n \"4e4f177f\": \"06391E5F-D86B-4F73-A9AF-5206A7D2092C\",\n \"9b527cbb\": \"F0297169-B077-4E67-B95C-F7F8F94D196A\",\n \"8969ae38\": \"ABA144C9-F007-44C1-82B9-1EC79B30DEA7\",\n \"d674736c\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"fbeafd09\": \"1C5CAE31-7AAB-4F7E-9ECD-CD34DAC44D35\",\n \"b586d8a0\": \"00773942-1BE4-49ED-8655-6FC675F6C949\",\n \"c914ede2\": \"0A420457-A462-4857-A114-EFB4C6E2A402\",\n \"a589f266\": \"BBA79BC5-78A5-4EA0-A8F0-9D12A54FDAB4\",\n \"47ed8329\": \"E489417D-13AA-4ED6-B1C7-735A2520F7F9\",\n \"2472b4bc\": \"A685B482-A0AB-4E5F-9D98-B657D2579A02\",\n \"754b228a\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"bd098872\": \"7D09137D-C942-427E-90E0-2C8A33CE4917\",\n \"1526f53f\": \"9AC7481F-9AAD-4ED6-A0A2-7C0AFE5B2BE5\",\n \"36fec563\": \"1265ADE8-35CA-4D70-9945-4CAE0D2A2FAD\",\n \"9ba7f97f\": \"2F1B18A2-1F6E-47F2-AAE9-1683A7D7E3DD\",\n \"b2576fc4\": \"7C913FED-1E33-4B8D-AF83-EF9ADD8BF7ED\",\n \"9bc85978\": \"7EEE2901-804F-4A11-BC7E-97277587428C\",\n \"9c8b76e3\": \"5B2F9F82-2ACF-4608-A138-93B67AFEC8B5\",\n \"451243b4\": \"0E555052-1D93-4F25-98F3-99D2E1300929\",\n \"429c3811\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"128ff90c\": \"4DA12B48-8B78-40BD-A705-F16816B17077\",\n \"58beffc7\": \"77B325ED-16B1-4468-B936-FB71DCC547CD\",\n \"a97f103b\": \"BA1AA637-942E-40FD-A754-61953BC423B5\",\n \"da8f20e9\": \"ABA144C9-F007-44C1-82B9-1EC79B30DEA7\",\n \"bf974976\": \"8C320B5A-772D-4DF3-A34F-2EC07B6D054D\",\n \"6b8fe3f8\": \"88F0C365-5336-4C6E-97B4-C849412B2AFE\",\n \"f85be9a9\": \"8D2979B6-7689-4EA6-866D-17210B2A5D5C\",\n \"ac660083\": \"588B83A7-540C-4329-9DCF-FA4F15EB2A29\",\n \"0edede09\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"1875dff7\": \"9722A832-91F4-4A67-B406-E2FC59074563\",\n \"41c01b9d\": \"3AE73689-3E55-4681-A0F4-25FED9B6F7DE\",\n \"3880c1ab\": \"2C36545F-B948-45CA-8814-6AA884AF4414\",\n \"46923cf2\": \"0BDE5D8A-61C4-4970-9CFD-A57FECCD0F06\",\n \"13d24b22\": \"C5E4C22D-6421-4823-9327-513CFD5F89B9\",\n \"fd2528e3\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n ]\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSTableView+RemoveBG.swift", "import AppKit\n\n// Removes background from List in SwiftUI\nextension NSTableView {\n override open func viewDidMoveToWindow() {\n super.viewDidMoveToWindow()\n\n backgroundColor = NSColor.clear\n if let esv = enclosingScrollView {\n esv.drawsBackground = false\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSRunningApplication+FloatingApp.swift", "import AppKit\nimport Foundation\n\nextension NSRunningApplication {\n // FIXME: check window info\n var isFloatingApp: Bool {\n NSApplication.isFloatingApp(bundleIdentifier)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Persistence/AppRule.swift", "import Cocoa\n\nextension AppRule {\n var image: NSImage? {\n guard let path = url else { return nil }\n\n return NSWorkspace.shared.icon(forFile: path.path)\n }\n}\n\nextension AppRule {\n @MainActor\n var forcedKeyboard: InputSource? {\n guard let inputSourceId = inputSourceId else { return nil }\n\n return InputSource.sources.first { $0.id == inputSourceId }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/FocusAwareTextField.swift", "import AppKit\nimport RxRelay\n\nclass FocusAwareTextField: NSTextField {\n let focus$ = PublishRelay()\n\n override func becomeFirstResponder() -> Bool {\n focus$.accept(true)\n return super.becomeFirstResponder()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSToolbarItem+Identifier.swift", "import AppKit\n\nextension NSToolbar.Identifier {\n static let preferencesWindowToolbarIdentifier = NSToolbar.Identifier(\"PreferencesWindowToolbar\")\n}\n\nextension NSToolbarItem.Identifier {\n static let toolbarShareButtonItem = NSToolbarItem.Identifier(rawValue: \"ToolbarShareButtonItem\")\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/CancelBag.swift", "import Combine\n\nfinal class CancelBag {\n fileprivate(set) var subscriptions = Set()\n\n func cancel() {\n subscriptions.removeAll()\n }\n}\n\nextension AnyCancellable {\n func store(in cancelBag: CancelBag) {\n cancelBag.subscriptions.insert(self)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSColor.swift", "import AppKit\nimport SwiftUI\n\nextension NSColor {\n var color: Color {\n Color(self)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/System/main.swift", "import Cocoa\n\nlet delegate = AppDelegate()\nlet menu = AppMenu()\n\nNSApplication.shared.delegate = delegate\nNSApplication.shared.mainMenu = menu\n\n_ = NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv)\n"]], "task_instance_info": {"created_time": "2025-08-21 03:17:35", "created_task_model": "DeepSeek-R1", "function_skeleton": "func i18n ( comment: String = \"\" , tableName: String = \"Localizable\" ) -> String { }", "code_description": "This code segment functions to: Retrieve localized string representations based on the current environment configuration and apply visual indicators for untranslated text during development phases."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```swift\n[TASK_BEGIN]\nfunc i18n(comment: String = \"\", tableName: String = \"Localizable\") -> String {\n return NSLocalizedString(\n self,\n tableName: tableName,\n bundle: .main,\n value: self,\n comment: comment\n )\n}\n[TASK_END]\n```", "inference_time": "2025-08-21 03-17-51"}, "editdistance_info": {"edit_distance": 38.75, "calculate_time": "2025-08-21 03:17:51", "true_code_clean": "func i18n(\n comment: String = \"\",\n tableName: String = \"Localizable\"\n ) -> String {\n #if DEBUG\n let fallback = \"**\\(self)**\"\n #else\n let fallback = self\n #endif\n return NSLocalizedString(\n self,\n tableName: tableName,\n value: fallback,\n comment: comment\n )\n }", "predict_code_clean": "func i18n(comment: String = \"\", tableName: String = \"Localizable\") -> String {\n return NSLocalizedString(\n self,\n tableName: tableName,\n bundle: .main,\n value: self,\n comment: comment\n )\n}"}} +{"repo_name": "InputSourcePro", "file_name": "/InputSourcePro/Input Source Pro/UI/Components/IndicatorPositionEditor.swift", "inference_info": {"prefix_code": "import SwiftUI\nimport VisualEffects\n\nstruct IndicatorPositionEditor: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n let columns = Array(repeating: GridItem(.flexible(), spacing: 0), count: 3)\n\n @State var hoveredAlignment: IndicatorPosition.Alignment? = nil\n\n let height: CGFloat = 230\n let windowHPadding: CGFloat = 30\n let windowVPadding: CGFloat = 15\n\n var selectedAlignment: IndicatorPosition.Alignment {\n preferencesVM.preferences.indicatorPositionAlignment ?? .bottomRight\n }\n\n var position: IndicatorPosition {\n preferencesVM.preferences.indicatorPosition ?? .nearMouse\n }\n\n var alignmentHPadding: CGFloat {\n let offset = position == .windowCorner ? windowHPadding : 0\n let minLength = position == .windowCorner ? height - offset * 2 : height\n let spacing = preferencesVM.calcSpacing(minLength: minLength)\n\n return spacing + offset\n }\n\n var alignmentVPadding: CGFloat {\n let offset = position == .windowCorner ? windowVPadding : 0\n let minLength = position == .windowCorner ? height - offset * 2 : height\n let spacing = preferencesVM.calcSpacing(minLength: minLength)\n\n return spacing + offset\n }\n\n let items: [IndicatorPosition.Alignment] = [\n .topLeft, .topCenter, .topRight,\n .centerLeft, .center, .centerRight,\n .bottomLeft, .bottomCenter, .bottomRight,\n ]\n\n var body: some View {\n LazyVGrid(columns: columns, spacing: 0) {\n ForEach(items, id: \\.self) { (alignment: IndicatorPosition.Alignment) in\n IndicatorAlignmentItem(\n alignment: alignment,\n position: position,\n isSelected: selectedAlignment == alignment,\n content: {\n let offset = offset(alignment: alignment)\n\n alignment.indicator()\n .rotationEffect(alignment.rotate)\n .offset(x: offset.x, y: offset.y)\n .foregroundColor(Color.primary)\n }\n )\n .frame(height: height / 3)\n .onTapGesture {\n withAnimation {\n preferencesVM.update {\n $0.indicatorPositionAlignment = alignment\n }\n }\n }\n }\n .opacity(position == .nearMouse ? 0 : 1)\n }\n .background(\n IndicatorAlignmentView(\n alignment: position == .nearMouse ? .center : selectedAlignment\n ) {\n IndicatorView()\n .fixedSize()\n .padding(.horizontal, alignmentHPadding)\n .padding(.vertical, alignmentVPadding)\n }\n )\n .background(\n windowIndicator()\n )\n .background(\n Image(\"FakeDesktop\")\n .resizable()\n .aspectRatio(contentMode: .fill)\n .scaledToFill()\n )\n }\n\n @ViewBuilder\n func windowIndicator() -> some View {\n MockWindowView()\n .padding(.horizontal, windowHPadding)\n .padding(.vertical, windowVPadding)\n .frame(height: height)\n .opacity(position == .windowCorner ? 1 : 0)\n .offset(x: 0, y: position == .windowCorner ? 0 : height)\n }\n\n func offset(alignment: IndicatorPosition.Alignment) -> (x: Double, y: Double) {\n switch alignment {\n case .center:\n return (0, 0)\n case .centerLeft:\n return (alignmentHPadding, 0)\n case .centerRight:\n return (-alignmentHPadding, 0)\n case .topLeft:\n return (alignmentHPadding, alignmentVPadding)\n case .topCenter:\n return (0, alignmentVPadding)\n case .topRight:\n return (-alignmentHPadding, alignmentVPadding)\n case .bottomLeft:\n return (alignmentHPadding, -alignmentVPadding)\n case .bottomCenter:\n return (0, -alignmentVPadding)\n case .bottomRight:\n return (-alignmentHPadding, -alignmentVPadding)\n }\n }\n}\n\nstruct IndicatorAlignmentItem: View {\n let alignment: IndicatorPosition.Alignment\n\n let position: IndicatorPosition\n\n let isSelected: Bool\n\n let content: Content\n\n @State var isHovered: Bool = false\n\n init(alignment: IndicatorPosition.Alignment, position: IndicatorPosition, isSelected: Bool, @ViewBuilder content: () -> Content) {\n self.alignment = alignment\n self.position = position\n self.isSelected = isSelected\n self.content = content()\n }\n\n var body: some View {\n IndicatorAlignmentView(alignment: alignment) {\n content\n }\n .frame(maxWidth: .infinity, maxHeight: .infinity)\n .contentShape(Rectangle())\n .opacity(isSelected ? 0 : 1)\n .opacity(isHovered ? 0.9 : 0.3)\n .animation(.default, value: isSelected)\n .animation(.default, value: isHovered)\n .onHover(perform: { isHovered = $0 })\n }\n}\n\nprivate extension IndicatorPosition.Alignment {\n var rotate: Angle {\n switch self {\n case .topLeft:\n return .degrees(-90)\n case .topRight:\n return .zero\n case .bottomLeft:\n return .degrees(180)\n case .bottomRight:\n return .degrees(90)\n case .center:\n return .degrees(45)\n case .centerLeft:\n return .zero\n case .centerRight:\n return .zero\n case .topCenter:\n return .zero\n case .bottomCenter:\n return .zero\n }\n }\n\n ", "suffix_code": "\n}\n", "middle_code": "@ViewBuilder\n func indicator() -> some View {\n switch self {\n case .center:\n RoundedRectangle(cornerRadius: 3)\n .frame(width: 30, height: 30)\n case .topCenter, .bottomCenter:\n RoundedRectangle(cornerRadius: 2)\n .frame(width: 44, height: 8)\n case .centerLeft, .centerRight:\n RoundedRectangle(cornerRadius: 2)\n .frame(width: 8, height: 30)\n default:\n Image(nsImage: .triangle)\n .resizable()\n .scaledToFit()\n .frame(width: 30)\n }\n }", "code_description": null, "fill_type": "FUNCTION_TYPE", "language_type": "swift", "sub_task_type": null}, "context_code": [["/InputSourcePro/Input Source Pro/Models/PreferencesVM+IndicatorPosition.swift", "import AppKit\nimport AXSwift\nimport Combine\nimport CombineExt\n\nextension PreferencesVM {\n func calcSpacing(minLength: CGFloat) -> CGFloat {\n guard let spacing = preferences.indicatorPositionSpacing else { return 0 }\n\n switch spacing {\n case .none:\n return 0\n case .xs:\n return minLength * 0.02\n case .s:\n return minLength * 0.05\n case .m:\n return minLength * 0.08\n case .l:\n return minLength * 0.13\n case .xl:\n return minLength * 0.21\n }\n }\n\n typealias IndicatorPositionInfo = (kind: IndicatorActuallyPositionKind, point: CGPoint)\n\n func getIndicatorPositionPublisher(\n appSize: CGSize,\n app: NSRunningApplication\n ) -> AnyPublisher {\n Just(preferences.indicatorPosition)\n .compactMap { $0 }\n .flatMapLatest { [weak self] position -> AnyPublisher in\n let DEFAULT = self?.getIndicatorBasePosition(\n appSize: appSize,\n app: app,\n position: position\n ) ?? Empty(completeImmediately: true).eraseToAnyPublisher()\n\n guard let self = self\n else { return DEFAULT }\n\n return self.getPositionAroundFloatingWindow(app, size: appSize)\n .flatMapLatest { positionForFloatingWindow -> AnyPublisher in\n if let positionForFloatingWindow = positionForFloatingWindow {\n return Just((.floatingApp, positionForFloatingWindow)).eraseToAnyPublisher()\n }\n\n if self.preferences.isEnhancedModeEnabled,\n self.preferences.tryToDisplayIndicatorNearCursor == true,\n self.isAbleToQueryLocation(app)\n {\n return self.getPositionAroundInputCursor(size: appSize)\n .map { cursorPosition -> AnyPublisher in\n guard let cursorPosition = cursorPosition else { return DEFAULT }\n\n return Just((cursorPosition.isContainer ? .inputRect : .inputCursor, cursorPosition.point))\n .eraseToAnyPublisher()\n }\n .switchToLatest()\n .eraseToAnyPublisher()\n }\n\n return DEFAULT\n }\n .eraseToAnyPublisher()\n }\n .eraseToAnyPublisher()\n }\n\n func getIndicatorBasePosition(\n appSize: CGSize,\n app: NSRunningApplication,\n position: IndicatorPosition\n ) -> AnyPublisher {\n Just(position)\n .flatMapLatest { [weak self] _ -> AnyPublisher in\n guard let self = self else { return Just(nil).eraseToAnyPublisher() }\n\n switch position {\n case .nearMouse:\n return self.getPositionNearMouse(size: appSize)\n .map {\n guard let position = $0 else { return nil }\n return (.nearMouse, position)\n }\n .eraseToAnyPublisher()\n case .windowCorner:\n return self.getPositionRelativeToAppWindow(size: appSize, app)\n .map {\n guard let position = $0 else { return nil }\n return (.windowCorner, position)\n }\n .eraseToAnyPublisher()\n case .screenCorner:\n return self.getPositionRelativeToScreen(size: appSize, app)\n .map {\n guard let position = $0 else { return nil }\n return (.screenCorner, position)\n }\n .eraseToAnyPublisher()\n }\n }\n .eraseToAnyPublisher()\n }\n}\n\nprivate extension PreferencesVM {\n func getPositionAroundInputCursor(\n size _: CGSize\n ) -> AnyPublisher<(point: CGPoint, isContainer: Bool)?, Never> {\n Future { promise in\n DispatchQueue.global().async {\n guard let rectInfo = systemWideElement.getCursorRectInfo(),\n let screen = NSScreen.getScreenInclude(rect: rectInfo.rect)\n else { return promise(.success(nil)) }\n\n if rectInfo.isContainer,\n rectInfo.rect.width / screen.frame.width > 0.7 &&\n rectInfo.rect.height / screen.frame.height > 0.7\n {\n return promise(.success(nil))\n }\n\n let offset: CGFloat = 6\n\n return promise(.success((\n CGPoint(x: rectInfo.rect.minX, y: rectInfo.rect.maxY + offset),\n rectInfo.isContainer\n )))\n }\n }\n .receive(on: DispatchQueue.main)\n .eraseToAnyPublisher()\n }\n\n func getPositionNearMouse(size: CGSize) -> AnyPublisher {\n AnyPublisher.create { observer in\n guard let screen = NSScreen.getScreenWithMouse() else { return AnyCancellable {} }\n\n let offset: CGFloat = 12\n let padding: CGFloat = 5\n let maxXPoint = screen.visibleFrame.origin.x + screen.visibleFrame.width\n\n var mousePoint = CGPoint(x: NSEvent.mouseLocation.x, y: NSEvent.mouseLocation.y)\n\n // default offset\n mousePoint.x += offset\n mousePoint.y -= offset\n\n // move app to cursor's right/bottom edge\n mousePoint.y -= size.height\n\n // avoid overflow\n mousePoint.x = min(maxXPoint - size.width - padding, mousePoint.x)\n mousePoint.y = max(padding, mousePoint.y)\n\n observer.send(mousePoint)\n observer.send(completion: .finished)\n\n return AnyCancellable {}\n }\n }\n\n func getPositionRelativeToAppWindow(\n size: CGSize,\n _ app: NSRunningApplication\n ) -> AnyPublisher {\n app.getWindowInfoPublisher()\n .map { [weak self] windowInfo -> CGPoint? in\n guard let self = self,\n let windowBounds = windowInfo?.bounds,\n let screen = NSScreen.getScreenInclude(rect: windowBounds)\n else { return nil }\n\n let rect = windowBounds.relativeTo(screen: screen)\n\n return self.getPositionWithin(\n rect: rect,\n size: size,\n alignment: self.preferences.indicatorPositionAlignment ?? .bottomRight\n )\n }\n .eraseToAnyPublisher()\n }\n\n func getPositionRelativeToScreen(\n size: CGSize,\n _ app: NSRunningApplication\n ) -> AnyPublisher {\n app.getWindowInfoPublisher()\n .map { [weak self] windowInfo -> CGPoint? in\n guard let self = self,\n let windowBounds = windowInfo?.bounds,\n let screen = NSScreen.getScreenInclude(rect: windowBounds) ??\n NSScreen.getScreenWithMouse() ??\n NSScreen.main\n else { return nil }\n\n return self.getPositionWithin(\n rect: screen.visibleFrame,\n size: size,\n alignment: self.preferences.indicatorPositionAlignment ?? .bottomRight\n )\n }\n .eraseToAnyPublisher()\n }\n\n func getPositionAround(rect: CGRect) -> (NSScreen, CGPoint)? {\n guard let screen = NSScreen.getScreenInclude(rect: rect) else { return nil }\n\n return (screen, rect.relativeTo(screen: screen).origin)\n }\n\n func getPositionAroundFloatingWindow(\n _ app: NSRunningApplication, size: CGSize\n ) -> AnyPublisher {\n guard NSApplication.isSpotlightLikeApp(app.bundleIdentifier) else { return Just(nil).eraseToAnyPublisher() }\n\n return app.getWindowInfoPublisher()\n .map { [weak self] windowInfo -> CGPoint? in\n guard let self = self,\n let rect = windowInfo?.bounds,\n let (screen, point) = self.getPositionAround(rect: rect)\n else { return nil }\n\n let offset: CGFloat = 6\n\n let position = CGPoint(\n x: point.x,\n y: point.y + rect.height + offset\n )\n\n if screen.frame.contains(CGRect(origin: position, size: size)) {\n return position\n } else {\n return nil\n }\n }\n .eraseToAnyPublisher()\n }\n\n func getPositionWithin(\n rect: NSRect,\n size: CGSize,\n alignment: IndicatorPosition.Alignment\n ) -> CGPoint {\n let spacing = calcSpacing(minLength: min(rect.width, rect.height))\n\n switch alignment {\n case .topLeft:\n return CGPoint(\n x: rect.minX + spacing,\n y: rect.maxY - size.height - spacing\n )\n case .topCenter:\n return CGPoint(\n x: rect.midX - size.width / 2,\n y: rect.maxY - size.height - spacing\n )\n case .topRight:\n return CGPoint(\n x: rect.maxX - size.width - spacing,\n y: rect.maxY - size.height - spacing\n )\n case .center:\n return CGPoint(\n x: rect.midX - size.width / 2,\n y: rect.midY + size.height / 2\n )\n case .centerLeft:\n return CGPoint(\n x: rect.minX + spacing,\n y: rect.midY - size.height / 2\n )\n case .centerRight:\n return CGPoint(\n x: rect.maxX - size.width - spacing,\n y: rect.midY - size.height / 2\n )\n case .bottomLeft:\n return CGPoint(\n x: rect.minX + spacing,\n y: rect.minY + spacing\n )\n case .bottomCenter:\n return CGPoint(\n x: rect.midX - size.width / 2,\n y: rect.minY + spacing\n )\n case .bottomRight:\n return CGPoint(\n x: rect.maxX - size.width - spacing,\n y: rect.minY + spacing\n )\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/PositionSettingsView.swift", "import AVKit\nimport SwiftUI\n\nstruct PositionSettingsView: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n @EnvironmentObject var navigationVM: NavigationVM\n\n @Environment(\\.colorScheme) var colorScheme: ColorScheme\n\n @State var displayIndicatorNearCursorTips = false\n @State var displayAlwaysOnIndicatorTips = false\n @State private var width = CGFloat.zero\n\n var body: some View {\n let sliderBinding = Binding(\n get: {\n Double(preferencesVM.preferences.indicatorPositionSpacing?.rawValue ?? 3)\n },\n set: { newValue in\n withAnimation(.easeInOut(duration: 0.2)) {\n preferencesVM.update {\n $0.indicatorPositionSpacing = .fromSlide(value: newValue)\n }\n }\n }\n )\n\n let positionBinding = Binding(\n get: {\n preferencesVM.preferences.indicatorPosition ?? .nearMouse\n },\n set: { newValue in\n withAnimation(.easeInOut(duration: 0.3)) {\n preferencesVM.update {\n $0.indicatorPosition = newValue\n }\n }\n }\n )\n\n ScrollView {\n VStack(spacing: 18) {\n SettingsSection(title: \"Position\") {\n VStack(spacing: 0) {\n IndicatorPositionEditor()\n .clipShape(RoundedRectangle(cornerRadius: 6))\n .padding(.horizontal)\n .padding(.top)\n\n Picker(\"Position\", selection: positionBinding) {\n ForEach(IndicatorPosition.allCases) { item in\n Text(item.name).tag(item)\n }\n }\n .labelsHidden()\n .pickerStyle(.segmented)\n .padding()\n\n if preferencesVM.preferences.indicatorPosition != .nearMouse {\n HStack {\n Text(\"Spacing\".i18n() + \":\")\n .alignedView(width: $width, alignment: .leading)\n\n HStack {\n Slider(value: sliderBinding, in: 0 ... 5, step: 1)\n\n if let name = preferencesVM.preferences.indicatorPositionSpacing?.name {\n Text(name)\n .foregroundColor(.primary)\n .frame(width: 50, height: 25)\n .background(Color.primary.opacity(0.05))\n .clipShape(RoundedRectangle(cornerRadius: 6))\n .noAnimation()\n }\n }\n }\n .padding()\n .border(width: 1, edges: [.top, .bottom], color: NSColor.border2.color)\n\n HStack {\n Text(\"Alignment\".i18n() + \":\")\n .alignedView(width: $width, alignment: .leading)\n\n HStack {\n PopUpButtonPicker(\n items: IndicatorPosition.Alignment.allCases,\n isItemSelected: { $0 == preferencesVM.preferences.indicatorPositionAlignment },\n getTitle: { $0.name },\n getToolTip: { $0.name },\n onSelect: { index in\n withAnimation(.easeInOut(duration: 0.3)) {\n preferencesVM.update {\n let value = IndicatorPosition.Alignment.allCases[index]\n $0.indicatorPositionAlignment = value\n }\n }\n }\n )\n }\n }\n .padding()\n }\n }\n }\n\n SettingsSection(title: \"Advanced\", tips: EnhancedModeRequiredBadge()) {\n VStack(spacing: 0) {\n HStack {\n Toggle(isOn: $preferencesVM.preferences.tryToDisplayIndicatorNearCursor) {}\n .toggleStyle(.switch)\n .disabled(!preferencesVM.preferences.isEnhancedModeEnabled)\n\n Text(\"tryToDisplayIndicatorNearCursor\".i18n())\n\n Spacer()\n\n QuestionButton(\n content: {\n SwiftUI.Image(systemName: \"video\")\n .font(.system(size: 11, weight: .bold))\n .padding(6)\n },\n popover: {\n PlayerView(url: Bundle.main.url(\n forResource: \"Indicator-Near-Cursor-Demo-\\($0 == .dark ? \"Dark\" : \"Light\")\",\n withExtension: \"mp4\"\n )!)\n .frame(height: 118)\n\n Text(\"Enhanced Mode Required Tips\".i18n())\n .font(.footnote)\n .opacity(0.6)\n .padding(.vertical, 10)\n }\n )\n }\n .padding(.horizontal)\n .padding(.vertical, 10)\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n\n VStack {\n let needDisableAlwaysOnIndicator = !preferencesVM.preferences.isEnhancedModeEnabled || !preferencesVM.preferences.tryToDisplayIndicatorNearCursor\n\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.isEnableAlwaysOnIndicator)\n .disabled(needDisableAlwaysOnIndicator)\n .toggleStyle(.switch)\n .labelsHidden()\n\n Text(\"isEnableAlwaysOnIndicator\".i18n())\n\n Spacer()\n\n QuestionButton(\n content: {\n SwiftUI.Image(systemName: \"video\")\n .font(.system(size: 11, weight: .bold))\n .padding(6)\n },\n popover: {\n PlayerView(url: Bundle.main.url(\n forResource: \"Always-On-Indicator-Demo-\\($0 == .dark ? \"Dark\" : \"Light\")\",\n withExtension: \"mp4\"\n )!)\n .frame(height: 118)\n\n Text(\"alwaysOnIndicatorTips\".i18n())\n .font(.footnote)\n .padding(.vertical, 10)\n .opacity(0.6)\n }\n )\n }\n }\n .padding(.horizontal)\n .padding(.vertical, 10)\n }\n }\n }\n .padding()\n .padding(.bottom)\n }\n .onAppear(perform: updatePreviewModeOnAppear)\n .background(NSColor.background1.color)\n }\n\n func updatePreviewModeOnAppear() {\n if preferencesVM.preferences.isAutoAppearanceMode {\n preferencesVM.preferences.appearanceMode = colorScheme == .dark ? .dark : .light\n }\n }\n\n func resetColors() {\n if preferencesVM.preferences.appearanceMode == .light {\n preferencesVM.preferences.indicatorForgegroundColor = IndicatorColor.forgeground.light\n preferencesVM.preferences.indicatorBackgroundColor = IndicatorColor.background.light\n }\n\n if preferencesVM.preferences.appearanceMode == .dark {\n preferencesVM.preferences.indicatorForgegroundColor = IndicatorColor.forgeground.dark\n preferencesVM.preferences.indicatorBackgroundColor = IndicatorColor.background.dark\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/IndicatorAlignmentView.swift", "import SwiftUI\n\nstruct IndicatorAlignmentView: View {\n let content: Content\n\n let alignment: IndicatorPosition.Alignment\n\n init(\n alignment: IndicatorPosition.Alignment,\n @ViewBuilder content: () -> Content\n ) {\n self.content = content()\n self.alignment = alignment\n }\n\n var body: some View {\n VStack {\n if [.bottomLeft, .bottomRight, .bottomCenter].contains(alignment) {\n Spacer(minLength: 0)\n }\n\n HStack {\n if [.topRight, .bottomRight, .centerRight].contains(alignment) {\n Spacer(minLength: 0)\n }\n\n content\n\n if [.topLeft, .bottomLeft, .centerLeft].contains(alignment) {\n Spacer(minLength: 0)\n }\n }\n\n if [.topRight, .topLeft, .topCenter].contains(alignment) {\n Spacer(minLength: 0)\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Indicator/IndicatorPosition.swift", "import AppKit\n\nenum IndicatorActuallyPositionKind {\n case floatingApp\n case inputCursor\n case inputRect\n case nearMouse\n case windowCorner\n case screenCorner\n\n var isInputArea: Bool {\n self == .inputRect || self == .inputCursor\n }\n}\n\nenum IndicatorPosition: Int32, CaseIterable, Identifiable {\n case nearMouse = 0\n case windowCorner = 1\n case screenCorner = 2\n\n var id: Self { self }\n\n enum Alignment: Int32, CaseIterable {\n case topLeft = 0\n case topCenter = 5\n case topRight = 1\n case centerLeft = 7\n case center = 2\n case centerRight = 8\n case bottomLeft = 3\n case bottomCenter = 6\n case bottomRight = 4\n }\n\n enum Spacing: Int32, CaseIterable {\n case none = 0\n case xs = 1\n case s = 2\n case m = 3\n case l = 4\n case xl = 5\n }\n}\n\nextension IndicatorPosition {\n var name: String {\n switch self {\n case .nearMouse:\n return \"Follow Mouse\".i18n()\n case .windowCorner:\n return \"Relative to App\".i18n()\n case .screenCorner:\n return \"Relative to Screen\".i18n()\n }\n }\n}\n\nextension IndicatorPosition.Alignment {\n var name: String {\n switch self {\n case .topLeft:\n return \"Top-Left Corner\".i18n()\n case .topRight:\n return \"Top-Right Corner\".i18n()\n case .topCenter:\n return \"Top-Center\".i18n()\n case .center:\n return \"Center\".i18n()\n case .centerLeft:\n return \"Center-Left\".i18n()\n case .centerRight:\n return \"Center-Right\".i18n()\n case .bottomLeft:\n return \"Bottom-Left Corner\".i18n()\n case .bottomCenter:\n return \"Bottom-Center\".i18n()\n case .bottomRight:\n return \"Bottom-Right Corner\".i18n()\n }\n }\n}\n\nextension IndicatorPosition.Spacing {\n static func fromSlide(value: Double) -> Self {\n return .init(rawValue: Int32(value)) ?? .m\n }\n\n var name: String {\n switch self {\n case .none:\n return \"Nope\".i18n()\n case .xs:\n return \"XS\".i18n()\n case .s:\n return \"S\".i18n()\n case .m:\n return \"M\".i18n()\n case .l:\n return \"L\".i18n()\n case .xl:\n return \"XL\".i18n()\n }\n }\n}\n\nextension IndicatorPosition: Codable {\n private enum CodingKeys: String, CodingKey {\n case base\n }\n\n private enum Base: String, Codable {\n case nearMouse, windowCorner, screenCorner\n }\n\n func encode(to encoder: Encoder) throws {\n var container = encoder.container(keyedBy: CodingKeys.self)\n\n switch self {\n case .nearMouse:\n try container.encode(Base.nearMouse, forKey: .base)\n case .windowCorner:\n try container.encode(Base.windowCorner, forKey: .base)\n case .screenCorner:\n try container.encode(Base.screenCorner, forKey: .base)\n }\n }\n\n init(from decoder: Decoder) throws {\n let container = try decoder.container(keyedBy: CodingKeys.self)\n let base = try container.decode(Base.self, forKey: .base)\n\n switch base {\n case .nearMouse:\n self = .nearMouse\n case .windowCorner:\n self = .windowCorner\n case .screenCorner:\n self = .screenCorner\n }\n }\n}\n\nextension IndicatorPosition.Alignment: Codable {\n private enum CodingKeys: String, CodingKey {\n case base\n }\n\n func encode(to encoder: Encoder) throws {\n var container = encoder.container(keyedBy: CodingKeys.self)\n try container.encode(rawValue, forKey: .base)\n }\n\n init(from decoder: Decoder) throws {\n let container = try decoder.container(keyedBy: CodingKeys.self)\n let rawValue = try container.decode(Int32.self, forKey: .base)\n\n self = Self(rawValue: rawValue)!\n }\n}\n\nextension IndicatorPosition.Spacing: Codable {\n private enum CodingKeys: String, CodingKey {\n case base\n }\n\n func encode(to encoder: Encoder) throws {\n var container = encoder.container(keyedBy: CodingKeys.self)\n try container.encode(rawValue, forKey: .base)\n }\n\n init(from decoder: Decoder) throws {\n let container = try decoder.container(keyedBy: CodingKeys.self)\n let rawValue = try container.decode(Int32.self, forKey: .base)\n\n self = Self(rawValue: rawValue)!\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/PreferencesView.swift", "import SwiftUI\nimport VisualEffects\n\nstruct PreferencesView: View {\n @EnvironmentObject var navigationVM: NavigationVM\n @EnvironmentObject var preferencesVM: PreferencesVM\n @EnvironmentObject var indicatorVM: IndicatorVM\n\n @State private var asyncSelection: NavigationVM.Nav = .general\n\n var body: some View {\n return HStack(spacing: 0) {\n ZStack {\n VisualEffectBlur(material: .sidebar, blendingMode: .behindWindow, state: .followsWindowActiveState)\n\n HStack {\n VStack {\n Button(action: {}) {\n // Trap default focus ring\n Text(\"Input Source Pro\")\n }\n\n Spacer()\n }\n Spacer()\n }\n .opacity(0)\n\n VStack(spacing: 12) {\n ForEach(NavigationVM.Nav.grouped, id: \\.id) { group in\n VStack(spacing: 2) {\n if !group.title.isEmpty {\n HStack {\n Text(group.title.i18n())\n .font(.system(size: 10))\n .opacity(0.6)\n Spacer()\n }\n .padding(.leading, 20)\n .padding(.bottom, 2)\n }\n\n ForEach(group.nav) { nav in\n let onSelect = { navigationVM.selection = nav }\n\n Button(action: onSelect) {\n Text(nav.displayName)\n }\n .buttonStyle(\n NavButtonStyle(\n icon: nav.icon,\n isActive: navigationVM.selection == nav\n )\n )\n }\n }\n }\n\n Spacer()\n\n Text(\" \\(preferencesVM.versionStr) (\\(preferencesVM.buildStr))\")\n .opacity(0.5)\n .font(.system(size: 12))\n }\n .padding(.top, 40)\n .padding(.vertical)\n }\n .frame(width: 200)\n\n HStack {\n VStack(spacing: 0) {\n HStack {\n SwiftUI.Image(systemName: asyncSelection.icon)\n .font(.system(size: 18, weight: .medium))\n .opacity(0.8)\n .frame(width: 20)\n\n VStack(alignment: .leading, spacing: 0) {\n Text(\"Input Source Pro\")\n .font(.system(size: 12, weight: .semibold))\n .opacity(0.8)\n\n Text(asyncSelection.displayName)\n .font(.system(size: 11))\n .opacity(0.6)\n }\n\n Spacer()\n }\n .frame(height: 52)\n .padding(.horizontal)\n .border(width: 1, edges: [.bottom], color: NSColor.border.color)\n\n asyncSelection.getView()\n Spacer(minLength: 0)\n }\n\n Spacer(minLength: 0)\n }\n .border(width: 1, edges: [.leading], color: NSColor.border.color)\n }\n .frame(minWidth: 780, minHeight: 620)\n .background(NSColor.background.color)\n .environment(\\.managedObjectContext, preferencesVM.container.viewContext)\n .onChange(of: navigationVM.selection) { _ in\n asyncSelection = navigationVM.selection\n }\n .onAppear {\n asyncSelection = navigationVM.selection\n }\n .edgesIgnoringSafeArea(.top)\n .modifier(FeedbackModal())\n }\n}\n\nextension NavigationVM.Nav {\n var icon: String {\n switch self {\n case .general:\n return \"slider.horizontal.3\"\n\n case .appRules:\n return \"square.grid.2x2\"\n\n case .browserRules:\n return \"safari\"\n\n case .position:\n return \"arrow.up.and.down.and.arrow.left.and.right\"\n\n case .appearance:\n return \"paintbrush\"\n\n case .inputSourcesColorScheme:\n return \"paintpalette\"\n\n case .keyboardShortcut:\n return \"command\"\n\n case .troubleshooting:\n return \"ladybug\"\n }\n }\n\n var displayName: String {\n switch self {\n case .inputSourcesColorScheme:\n return \"Color Scheme\".i18n()\n default:\n return rawValue.i18n()\n }\n }\n\n @ViewBuilder\n func getView() -> some View {\n switch self {\n case .general:\n GeneralSettingsView()\n\n case .appRules:\n RulesSettingsView()\n\n case .browserRules:\n BrowserRulesSettingsView()\n\n case .position:\n PositionSettingsView()\n\n case .appearance:\n AppearanceSettingsView()\n\n case .inputSourcesColorScheme:\n InputSourcesAppearanceSettingsView()\n\n case .keyboardShortcut:\n KeyboardsSettingsView()\n\n case .troubleshooting:\n TroubleshootingSettingsView()\n }\n }\n}\n\nstruct NavButtonStyle: ButtonStyle {\n let icon: String\n\n let isActive: Bool\n\n func makeBody(configuration: Self.Configuration) -> some View {\n HStack {\n VStack {\n SwiftUI.Image(systemName: icon)\n .font(.system(size: 15, weight: .medium))\n .frame(width: 15, height: 15)\n .opacity(0.9)\n }\n\n configuration.label\n .lineLimit(1)\n\n Spacer()\n }\n .padding(.leading, 10)\n .padding(.trailing, 5)\n .padding(.vertical, 8)\n .frame(maxWidth: .infinity)\n .background(isActive ? Color.gray.opacity(0.2) : Color.clear)\n .background(configuration.isPressed ? Color.gray.opacity(0.1) : Color.clear)\n .foregroundColor(Color.primary)\n .clipShape(RoundedRectangle(cornerRadius: 6))\n .contentShape(Rectangle())\n .padding(.horizontal, 10)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/BrowserRuleEditView.swift", "import SwiftUI\n\nstruct BrowserRuleEditView: View {\n @State var value: String = \"\"\n @State var sampleValue: String = \"\"\n @State var ruleType = BrowserRuleType.domainSuffix\n @State var inputSourceItem = PickerItem.empty\n @State var restoreStrategyItem = PickerItem.empty\n @State var hideIndicator = false\n\n @State var isPopover = false\n\n @State private var width = CGFloat.zero\n\n @Binding var isPresented: Bool\n\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n let rule: BrowserRule?\n\n var ruleTypes: [BrowserRuleType] {\n BrowserRuleType.allCases\n }\n\n var inputSourceItems: [PickerItem] {\n [PickerItem.empty]\n + InputSource.sources.map { PickerItem(id: $0.id, title: $0.name, toolTip: $0.id) }\n }\n\n var restoreStrategyItems: [PickerItem] {\n [PickerItem.empty]\n + KeyboardRestoreStrategy.allCases.map { PickerItem(id: $0.rawValue, title: $0.name, toolTip: nil) }\n }\n\n var sampleURL: URL? {\n guard !sampleValue.isEmpty else { return nil }\n\n if sampleValue.starts(with: \"http://\") || sampleValue.starts(with: \"https://\") {\n return URL(string: sampleValue)\n } else {\n return URL(string: \"http://\\(sampleValue)\")\n }\n }\n\n var body: some View {\n VStack(spacing: 0) {\n VStack(alignment: .leading, spacing: 5) {\n Text(\"Match\".i18n().uppercased())\n .font(.footnote)\n .fontWeight(.medium)\n .opacity(0.5)\n\n VStack {\n HStack {\n Text(\"Sample URL\".i18n() + \":\")\n .alignedView(width: $width, alignment: .trailing)\n TextField(\"https://www.twitter.com/runjuuu\", text: $sampleValue)\n }\n\n HStack {\n Text(\"Rule Type\".i18n() + \":\")\n .alignedView(width: $width, alignment: .trailing)\n HStack {\n PopUpButtonPicker(\n items: ruleTypes,\n isItemSelected: { $0 == ruleType },\n getTitle: { $0.name },\n getToolTip: { $0.explanation },\n onSelect: handleSelectRule\n )\n\n Button(action: { isPopover.toggle() }) {\n SwiftUI.Image(systemName: \"questionmark\")\n }\n .font(.system(size: 10).weight(.bold))\n .frame(width: 18, height: 18)\n .clipShape(RoundedRectangle(cornerRadius: 99))\n .popover(\n isPresented: self.$isPopover,\n arrowEdge: .bottom\n ) {\n VStack {\n Text(.init(ruleType.explanation))\n .lineSpacing(3)\n }\n .frame(width: 280)\n .padding()\n }\n }\n }\n\n HStack {\n Text(\"Domain\".i18n() + \":\")\n .alignedView(width: $width, alignment: .trailing)\n HStack {\n TextField(\"twitter.com\", text: $value)\n if let url = sampleURL, !value.isEmpty {\n if BrowserRule.validate(type: ruleType, url: url, value: value) {\n Image(systemName: \"checkmark.circle.fill\")\n .foregroundColor(.green)\n .frame(width: 18, height: 18)\n } else {\n Image(systemName: \"x.circle.fill\")\n .foregroundColor(.red)\n .frame(width: 18, height: 18)\n }\n }\n }\n }\n }\n .padding()\n .background(Color.gray.opacity(0.1))\n .clipShape(RoundedRectangle(cornerRadius: 8))\n .padding(.bottom)\n }\n\n VStack(alignment: .leading, spacing: 5) {\n Text(\"Keyboard\".i18n().uppercased())\n .font(.footnote)\n .fontWeight(.medium)\n .opacity(0.5)\n\n VStack {\n HStack {\n Text(\"Default Keyboard\".i18n() + \":\")\n .alignedView(width: $width, alignment: .trailing)\n PopUpButtonPicker(\n items: inputSourceItems,\n isItemSelected: { $0 == inputSourceItem },\n getTitle: { $0?.title ?? \"\" },\n getToolTip: { $0?.toolTip },\n onSelect: handleSelectInputSource\n )\n }\n\n HStack {\n Text(\"Restore Strategy\".i18n() + \":\")\n .alignedView(width: $width, alignment: .trailing)\n PopUpButtonPicker(\n items: restoreStrategyItems,\n isItemSelected: { $0 == restoreStrategyItem },\n getTitle: { $0?.title ?? \"\" },\n getToolTip: { $0?.toolTip },\n onSelect: handleRestoreStrategy\n )\n }\n }\n .padding()\n .background(Color.gray.opacity(0.1))\n .clipShape(RoundedRectangle(cornerRadius: 8))\n .padding(.bottom)\n }\n\n VStack(alignment: .leading, spacing: 5) {\n Text(\"Tooltip\".i18n().uppercased())\n .font(.footnote)\n .fontWeight(.medium)\n .opacity(0.5)\n\n VStack {\n HStack {\n HStack(spacing: 4) {\n Image(systemName: \"eye.slash.circle.fill\")\n .foregroundColor(.gray)\n Text(\"Hide Indicator\".i18n() + \":\")\n }\n .alignedView(width: $width, alignment: .trailing)\n\n Toggle(\"\", isOn: $hideIndicator)\n .toggleStyle(.switch)\n\n Spacer()\n }\n }\n .padding()\n .background(Color.gray.opacity(0.1))\n .clipShape(RoundedRectangle(cornerRadius: 8))\n .padding(.bottom)\n }\n\n HStack {\n Spacer()\n\n Button(\"Cancel\".i18n(), action: cancel)\n .keyboardShortcut(.cancelAction)\n\n Button(\"\\(rule == nil ? \"Add\" : \"Save\")\".i18n(), action: save)\n .disabled(value.isEmpty)\n .keyboardShortcut(.defaultAction)\n }\n .padding(.top, 6)\n }\n .padding()\n .frame(width: 480)\n .onAppear {\n value = rule?.value ?? \"\"\n sampleValue = rule?.sample ?? \"\"\n ruleType = rule?.type ?? .domainSuffix\n hideIndicator = rule?.hideIndicator ?? false\n\n if let inputSource = rule?.forcedKeyboard {\n inputSourceItem = PickerItem(id: inputSource.id, title: inputSource.name, toolTip: inputSource.id)\n }\n\n if let keyboardRestoreStrategy = rule?.keyboardRestoreStrategy {\n restoreStrategyItem = PickerItem(\n id: keyboardRestoreStrategy.rawValue,\n title: keyboardRestoreStrategy.name,\n toolTip: nil\n )\n }\n }\n }\n\n func handleSelectInputSource(_ index: Int) {\n inputSourceItem = inputSourceItems[index]\n }\n\n func handleRestoreStrategy(_ index: Int) {\n restoreStrategyItem = restoreStrategyItems[index]\n }\n\n func handleSelectRule(_ index: Int) {\n ruleType = ruleTypes[index]\n }\n\n func cancel() {\n isPresented = false\n }\n\n func save() {\n guard !value.isEmpty else { return }\n\n let keyboardRestoreStrategy = restoreStrategyItem == .empty ? nil : KeyboardRestoreStrategy(rawValue: restoreStrategyItem.id)\n\n if let rule = rule {\n preferencesVM.updateBrowserRule(\n rule,\n type: ruleType,\n value: value,\n sample: sampleValue,\n inputSourceId: inputSourceItem.id,\n hideIndicator: hideIndicator,\n keyboardRestoreStrategy: keyboardRestoreStrategy\n )\n } else {\n preferencesVM.addBrowserRule(\n type: ruleType,\n value: value,\n sample: sampleValue,\n inputSourceId: inputSourceItem.id,\n hideIndicator: hideIndicator,\n keyboardRestoreStrategy: keyboardRestoreStrategy\n )\n }\n\n isPresented = false\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/KeyboardCustomization.swift", "import SwiftUI\nimport VisualEffects\n\nstruct KeyboardCustomization: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n @State var textColor: Color = .clear\n @State var bgColor: Color = .clear\n\n let inputSource: InputSource\n\n let columns = [\n GridItem(.fixed(100), alignment: .trailing),\n GridItem(.flexible(minimum: 50, maximum: .infinity), alignment: .leading),\n ]\n\n let indicatorColumns = [\n GridItem(.flexible(minimum: 50, maximum: .infinity), alignment: .center),\n GridItem(.flexible(minimum: 50, maximum: .infinity), alignment: .center),\n ]\n\n var body: some View {\n let keyboardConfig = preferencesVM.getOrCreateKeyboardConfig(inputSource)\n\n VStack(alignment: .leading) {\n ZStack {\n LazyVGrid(columns: indicatorColumns) {\n DumpIndicatorView(config: IndicatorViewConfig(\n inputSource: inputSource,\n kind: .alwaysOn,\n size: preferencesVM.preferences.indicatorSize ?? .medium,\n bgColor: NSColor(bgColor),\n textColor: NSColor(textColor)\n ))\n\n DumpIndicatorView(config: IndicatorViewConfig(\n inputSource: inputSource,\n kind: preferencesVM.preferences.indicatorKind,\n size: preferencesVM.preferences.indicatorSize ?? .medium,\n bgColor: NSColor(bgColor),\n textColor: NSColor(textColor)\n ))\n\n Text(\"Always-On Indicator Style\")\n .font(.caption)\n .opacity(0.5)\n\n Text(\"Keyboard Indicator Style\")\n .font(.caption)\n .opacity(0.5)\n }\n .padding()\n .itemSectionStyle()\n\n VStack {\n Spacer()\n\n HStack {\n Spacer()\n Button(action: { reset(keyboardConfig) }) {\n Text(\"Reset\")\n }\n .buttonStyle(GhostButton(icon: Image(systemName: \"arrow.clockwise\")))\n }\n }\n .padding(.trailing, 4)\n .padding(.bottom, 4)\n }\n\n VStack(alignment: .center) {\n ColorBlocks(onSelectColor: {\n textColor = $0.a\n bgColor = $0.b\n })\n .padding(.vertical, 8)\n\n HStack {\n ColorPicker(\"Color\", selection: $textColor)\n\n Button(\n action: {\n let a = textColor\n let b = bgColor\n\n textColor = b\n bgColor = a\n },\n label: {\n Image(systemName: \"repeat\")\n }\n )\n\n ColorPicker(\"Background\", selection: $bgColor)\n }\n .labelsHidden()\n }\n .padding(.horizontal)\n }\n .padding()\n .onAppear {\n textColor = preferencesVM.getTextColor(inputSource)\n bgColor = preferencesVM.getBgColor(inputSource)\n }\n .onChange(of: bgColor, perform: { _ in save(keyboardConfig) })\n .onChange(of: textColor, perform: { _ in save(keyboardConfig) })\n .onDisappear {\n NSColorPanel.shared.close()\n }\n }\n\n func save(_ keyboardConfig: KeyboardConfig) {\n preferencesVM.update(keyboardConfig, textColor: textColor, bgColor: bgColor)\n }\n\n func reset(_: KeyboardConfig) {\n bgColor = preferencesVM.preferences.indicatorBackgroundColor\n textColor = preferencesVM.preferences.indicatorForgegroundColor\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/BrowserRuleRow.swift", "import SwiftUI\n\nstruct BrowserRuleRow: View {\n @State var showModal = false\n \n var isSelected: Bool = false\n \n @ObservedObject var rule: BrowserRule\n\n let imgSize: CGFloat = 16\n\n var body: some View {\n HStack {\n Text(rule.value ?? \"\")\n\n Spacer()\n\n if rule.hideIndicator == true {\n Image(systemName: \"eye.slash.circle.fill\")\n .opacity(0.7)\n .frame(width: imgSize, height: imgSize)\n }\n\n if let keyboardRestoreStrategy = rule.keyboardRestoreStrategy {\n let symbolName = keyboardRestoreStrategy.systemImageName\n let color: Color = {\n switch symbolName {\n case \"d.circle.fill\", \"d.square.fill\":\n return isSelected ? .primary.opacity(0.7) : .green\n case \"arrow.uturn.left.circle.fill\":\n return isSelected ? .primary.opacity(0.7) : .blue\n default:\n return .primary\n }\n }()\n Image(systemName: symbolName)\n .foregroundColor(color)\n .frame(width: imgSize, height: imgSize)\n }\n\n if let forcedKeyboard = rule.forcedKeyboard {\n SwiftUI.Image(nsImage: forcedKeyboard.icon ?? NSImage())\n .resizable()\n .scaledToFit()\n .frame(width: imgSize, height: imgSize)\n .opacity(0.7)\n }\n\n Text(rule.type.name)\n .font(.footnote)\n .padding(.horizontal, 4)\n .padding(.vertical, 2)\n .foregroundColor(.white)\n .background(Color.accentColor)\n .clipShape(RoundedRectangle(cornerRadius: 2))\n\n Button(\"Edit\") {\n showModal = true\n }\n }\n .sheet(isPresented: $showModal, content: {\n BrowserRuleEditView(isPresented: $showModal, rule: rule)\n })\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/RulesApplicationDetail.swift", "import SwiftUI\n\n// 新增 ToggleLabel 组件\nstruct ToggleLabel: View {\n let systemImageName: String\n let text: String\n var body: some View {\n HStack(spacing: 6) {\n Image(systemName: systemImageName)\n Text(text)\n }\n }\n}\n\nstruct ApplicationDetail: View {\n @Binding var selectedApp: Set\n\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n @State var forceKeyboard: PickerItem?\n @State var doRestoreKeyboardState = NSToggleViewState.off\n @State var doNotRestoreKeyboardState = NSToggleViewState.off\n @State var hideIndicator = NSToggleViewState.off\n\n var mixed: Bool {\n Set(selectedApp.map { $0.forcedKeyboard?.id }).count > 1\n }\n\n var items: [PickerItem] {\n [mixed ? PickerItem.mixed : nil, PickerItem.empty].compactMap { $0 }\n + InputSource.sources.map { PickerItem(id: $0.id, title: $0.name, toolTip: $0.id) }\n }\n\n var body: some View {\n VStack(alignment: .leading) {\n Text(String(format: \"%@ App(s) Selected\".i18n(), \"\\(selectedApp.count)\"))\n .font(.subheadline.monospacedDigit())\n .opacity(0.5)\n .padding(.bottom, 5)\n\n VStack(alignment: .leading) {\n Text(\"Default Keyboard\".i18n())\n .fontWeight(.medium)\n\n PopUpButtonPicker(\n items: items,\n isItemEnabled: { $0?.id != \"mixed\" },\n isItemSelected: { $0 == forceKeyboard },\n getTitle: { $0?.title ?? \"\" },\n getToolTip: { $0?.toolTip },\n onSelect: handleSelect\n )\n }\n\n Divider()\n .padding(.vertical, 4)\n\n VStack(alignment: .leading) {\n Text(\"Keyboard Restore Strategy\".i18n())\n .fontWeight(.medium)\n\n HStack {\n Image(systemName: \"d.circle.fill\")\n .foregroundColor(.green)\n NSToggleView(\n label: restoreStrategyName(strategy: .UseDefaultKeyboardInstead),\n state: preferencesVM.preferences.isRestorePreviouslyUsedInputSource\n ? doNotRestoreKeyboardState\n : .on,\n onStateUpdate: handleToggleDoNotRestoreKeyboard\n )\n .fixedSize()\n .disabled(!preferencesVM.preferences.isRestorePreviouslyUsedInputSource)\n }\n\n HStack {\n Image(systemName: \"arrow.uturn.left.circle.fill\")\n .foregroundColor(.blue)\n NSToggleView(\n label: restoreStrategyName(strategy: .RestorePreviouslyUsedOne),\n state: preferencesVM.preferences.isRestorePreviouslyUsedInputSource\n ? .on\n : doRestoreKeyboardState,\n onStateUpdate: handleToggleDoRestoreKeyboard\n )\n .fixedSize()\n .disabled(preferencesVM.preferences.isRestorePreviouslyUsedInputSource)\n }\n }\n\n Divider()\n .padding(.vertical, 4)\n\n VStack(alignment: .leading) {\n Text(\"Indicator\".i18n())\n .fontWeight(.medium)\n HStack {\n Image(systemName: \"eye.slash.circle.fill\")\n .foregroundColor(.gray)\n NSToggleView(\n label: \"Hide Indicator\".i18n(),\n state: hideIndicator,\n onStateUpdate: handleToggleHideIndicator\n )\n .fixedSize()\n }\n }\n\n if selectedApp.contains(where: { preferencesVM.needDisplayEnhancedModePrompt(bundleIdentifier: $0.bundleId) }) {\n Divider().padding(.vertical, 4)\n\n EnhancedModeRequiredBadge()\n }\n\n Spacer()\n }\n .disabled(selectedApp.isEmpty)\n .onChange(of: selectedApp) { _ in\n updateForceKeyboardId()\n updateDoRestoreKeyboardState()\n updateDoNotRestoreKeyboardState()\n updateHideIndicatorState()\n }\n }\n\n func updateForceKeyboardId() {\n if mixed {\n forceKeyboard = PickerItem.mixed\n } else if let keyboard = selectedApp.first?.forcedKeyboard {\n forceKeyboard = PickerItem(id: keyboard.id, title: keyboard.name, toolTip: keyboard.id)\n } else {\n forceKeyboard = PickerItem.empty\n }\n }\n\n func updateDoRestoreKeyboardState() {\n let stateSet = Set(selectedApp.map { $0.doRestoreKeyboard })\n\n if stateSet.count > 1 {\n doRestoreKeyboardState = .mixed\n } else {\n doRestoreKeyboardState = stateSet.first == true ? .on : .off\n }\n }\n\n func updateDoNotRestoreKeyboardState() {\n let stateSet = Set(selectedApp.map { $0.doNotRestoreKeyboard })\n\n if stateSet.count > 1 {\n doNotRestoreKeyboardState = .mixed\n } else {\n doNotRestoreKeyboardState = stateSet.first == true ? .on : .off\n }\n }\n\n func updateHideIndicatorState() {\n let stateSet = Set(selectedApp.map { $0.hideIndicator })\n\n if stateSet.count > 1 {\n hideIndicator = .mixed\n } else {\n hideIndicator = stateSet.first == true ? .on : .off\n }\n }\n\n func handleSelect(_ index: Int) {\n forceKeyboard = items[index]\n\n for app in selectedApp {\n preferencesVM.setForceKeyboard(app, forceKeyboard?.id)\n }\n }\n\n func handleToggleDoNotRestoreKeyboard() -> NSControl.StateValue {\n switch doNotRestoreKeyboardState {\n case .on:\n selectedApp.forEach { preferencesVM.setDoNotRestoreKeyboard($0, false) }\n doNotRestoreKeyboardState = .off\n return .off\n case .off, .mixed:\n selectedApp.forEach { preferencesVM.setDoNotRestoreKeyboard($0, true) }\n doNotRestoreKeyboardState = .on\n return .on\n }\n }\n\n func handleToggleDoRestoreKeyboard() -> NSControl.StateValue {\n switch doRestoreKeyboardState {\n case .on:\n selectedApp.forEach { preferencesVM.setDoRestoreKeyboard($0, false) }\n doRestoreKeyboardState = .off\n return .off\n case .off, .mixed:\n selectedApp.forEach { preferencesVM.setDoRestoreKeyboard($0, true) }\n doRestoreKeyboardState = .on\n return .on\n }\n }\n\n func handleToggleHideIndicator() -> NSControl.StateValue {\n switch hideIndicator {\n case .on:\n selectedApp.forEach { preferencesVM.setHideIndicator($0, false) }\n hideIndicator = .off\n return .off\n case .off, .mixed:\n selectedApp.forEach { preferencesVM.setHideIndicator($0, true) }\n hideIndicator = .on\n return .on\n }\n }\n\n func restoreStrategyName(strategy: KeyboardRestoreStrategy) -> String {\n strategy.name + restoreStrategyTips(strategy: strategy)\n }\n\n func restoreStrategyTips(strategy: KeyboardRestoreStrategy) -> String {\n switch strategy {\n case .RestorePreviouslyUsedOne:\n return preferencesVM.preferences.isRestorePreviouslyUsedInputSource ? \" (\\(\"Default\".i18n()))\" : \"\"\n case .UseDefaultKeyboardInstead:\n return !preferencesVM.preferences.isRestorePreviouslyUsedInputSource ? \" (\\(\"Default\".i18n()))\" : \"\"\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/AppearanceSettingsView.swift", "import AVKit\nimport SwiftUI\n\nstruct AppearanceSettingsView: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n @EnvironmentObject var navigationVM: NavigationVM\n\n @Environment(\\.colorScheme) var colorScheme: ColorScheme\n\n @State private var width = CGFloat.zero\n\n var body: some View {\n let infoBinding = Binding(\n get: {\n preferencesVM.preferences.indicatorInfo ?? .iconAndTitle\n },\n set: { newValue in\n withAnimation(.easeInOut(duration: 0.3)) {\n preferencesVM.update {\n $0.indicatorInfo = newValue\n }\n }\n }\n )\n\n let sizeBinding = Binding(\n get: {\n preferencesVM.preferences.indicatorSize ?? .medium\n },\n set: { newValue in\n withAnimation(.easeInOut(duration: 0.3)) {\n preferencesVM.update {\n $0.indicatorSize = newValue\n }\n }\n }\n )\n\n ScrollView {\n VStack(alignment: .leading, spacing: 18) {\n SettingsSection(title: \"Indicator Info\") {\n VStack(spacing: 0) {\n ItemSection {\n IndicatorView()\n }\n .frame(height: 100)\n .padding(.horizontal)\n .padding(.top)\n\n Picker(\"Position\", selection: infoBinding) {\n ForEach(IndicatorInfo.allCases) { item in\n Text(item.name).tag(item)\n }\n }\n .labelsHidden()\n .pickerStyle(.segmented)\n .padding()\n }\n }\n\n SettingsSection(title: \"Indicator Size\") {\n Picker(\"Size\", selection: sizeBinding) {\n ForEach(IndicatorSize.allCases) { item in\n Text(item.displayName).tag(item)\n }\n }\n .labelsHidden()\n .pickerStyle(.segmented)\n .padding()\n }\n\n SettingsSection(title: \"Color Scheme\") {\n VStack(spacing: 0) {\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.isAutoAppearanceMode)\n .toggleStyle(.switch)\n .labelsHidden()\n\n Text(\"Sync with OS\".i18n())\n\n Spacer()\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n\n VStack(spacing: 16) {\n Picker(\"\", selection: $preferencesVM.preferences.appearanceMode) {\n Text(\"In Light Mode\".i18n()).tag(Optional(Preferences.AppearanceMode.light))\n Text(\"In Dark Mode\".i18n()).tag(Optional(Preferences.AppearanceMode.dark))\n }\n .labelsHidden()\n .pickerStyle(.segmented)\n\n ColorBlocks(\n onSelectColor: { scheme in\n preferencesVM.update {\n $0.indicatorForgegroundColor = scheme.a\n $0.indicatorBackgroundColor = scheme.b\n }\n }\n )\n\n ItemSection {\n IndicatorView()\n\n HStack {\n ColorPicker(\n \"Color\",\n selection: $preferencesVM.preferences.indicatorForgegroundColor\n )\n .labelsHidden()\n\n Button(\n action: {\n preferencesVM.update {\n let a = $0.indicatorForgegroundColor\n let b = $0.indicatorBackgroundColor\n\n $0.indicatorForgegroundColor = b\n $0.indicatorBackgroundColor = a\n }\n },\n label: {\n Image(systemName: \"repeat\")\n }\n )\n\n ColorPicker(\n \"Background\",\n selection: $preferencesVM.preferences.indicatorBackgroundColor\n )\n .labelsHidden()\n }\n }\n .frame(height: 130)\n }\n .padding()\n }\n }\n }\n .padding()\n .padding(.bottom)\n }\n .background(NSColor.background1.color)\n .onAppear(perform: updatePreviewModeOnAppear)\n .onDisappear {\n NSColorPanel.shared.close()\n }\n }\n\n func updatePreviewModeOnAppear() {\n if preferencesVM.preferences.isAutoAppearanceMode {\n preferencesVM.preferences.appearanceMode = colorScheme == .dark ? .dark : .light\n }\n }\n\n func resetColors() {\n if preferencesVM.preferences.appearanceMode == .light {\n preferencesVM.preferences.indicatorForgegroundColor = IndicatorColor.forgeground.light\n preferencesVM.preferences.indicatorBackgroundColor = IndicatorColor.background.light\n }\n\n if preferencesVM.preferences.appearanceMode == .dark {\n preferencesVM.preferences.indicatorForgegroundColor = IndicatorColor.forgeground.dark\n preferencesVM.preferences.indicatorBackgroundColor = IndicatorColor.background.dark\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Controllers/IndicatorWindowController+Activation.swift", "import AppKit\nimport AXSwift\nimport Combine\nimport CombineExt\n\n// MARK: - Default indicator: auto hide\n\nextension IndicatorWindowController {\n func autoHidePublisher(\n event: IndicatorVM.ActivateEvent,\n inputSource: InputSource,\n appKind: AppKind\n ) -> AnyPublisher {\n return Just(event)\n .tap { [weak self] in self?.updateIndicator(event: $0, inputSource: inputSource) }\n .flatMapLatest { [weak self] _ -> AnyPublisher in\n guard let self = self,\n let appSize = self.getAppSize()\n else { return Empty().eraseToAnyPublisher() }\n\n return self.preferencesVM\n .getIndicatorPositionPublisher(appSize: appSize, app: appKind.getApp())\n .compactMap { $0 }\n .first()\n .tap { self.moveIndicator(position: $0) }\n .flatMapLatest { _ -> AnyPublisher in\n Publishers.Merge(\n Timer.delay(seconds: 1).mapToVoid(),\n // hover event\n self.indicatorVC.hoverableView.hoverdPublisher\n .filter { $0 }\n .first()\n .flatMapLatest { _ in\n Timer.delay(seconds: 0.15)\n }\n .mapToVoid()\n )\n .first()\n .mapTo(false)\n .prepend(true)\n .tap { isActive in\n self.isActive = isActive\n }\n .eraseToAnyPublisher()\n }\n .mapToVoid()\n .eraseToAnyPublisher()\n }\n .mapToVoid()\n .eraseToAnyPublisher()\n }\n}\n\n// MARK: - Default indicator: auto show\n\nextension IndicatorWindowController {\n func autoShowPublisher(\n event: IndicatorVM.ActivateEvent,\n inputSource: InputSource,\n appKind: AppKind\n ) -> AnyPublisher {\n let app = appKind.getApp()\n let application = app.getApplication(preferencesVM: preferencesVM)\n\n let needActivateAtFirstTime = {\n if preferencesVM.preferences.isActiveWhenSwitchApp {\n return true\n }\n\n if preferencesVM.preferences.isActiveWhenFocusedElementChangesEnabled,\n let focusedUIElement = app.focuedUIElement(application: application),\n UIElement.isInputContainer(focusedUIElement)\n {\n return true\n }\n\n return false\n }()\n\n if !needActivateAtFirstTime, isActive {\n isActive = false\n }\n\n return app\n .watchAX([.focusedUIElementChanged], [.application, .window])\n .compactMap { _ in app.focuedUIElement(application: application) }\n .removeDuplicates()\n .filter { UIElement.isInputContainer($0) }\n .mapTo(true)\n .prepend(needActivateAtFirstTime)\n .filter { $0 }\n .compactMap { [weak self] _ in self?.autoHidePublisher(event: event, inputSource: inputSource, appKind: appKind) }\n .switchToLatest()\n .eraseToAnyPublisher()\n }\n}\n\n// MARK: - Just hide indicator\n\nextension IndicatorWindowController {\n func justHidePublisher() -> AnyPublisher {\n Just(true)\n .tap { [weak self] _ in self?.isActive = false }\n .mapToVoid()\n .eraseToAnyPublisher()\n }\n}\n\n// MARK: - AlwaysOn\n\nextension IndicatorWindowController {\n @MainActor\n enum AlwaysOn {\n enum Event {\n case cursorMoved, showAlwaysOnIndicator, scrollStart, scrollEnd\n }\n\n struct State {\n typealias Changes = (current: State, prev: State)\n\n static let initial = State(isShowAlwaysOnIndicator: false, isScrolling: false)\n\n var isShowAlwaysOnIndicator: Bool\n var isScrolling: Bool\n\n func reducer(_ event: Event) -> State {\n switch event {\n case .scrollStart:\n return update {\n $0.isScrolling = true\n }\n case .scrollEnd:\n return update {\n $0.isScrolling = false\n }\n case .showAlwaysOnIndicator:\n return update {\n $0.isShowAlwaysOnIndicator = true\n }\n case .cursorMoved:\n return self\n }\n }\n\n func update(_ change: (inout State) -> Void) -> State {\n var draft = self\n\n change(&draft)\n\n return draft\n }\n }\n\n static func statePublisher(app: NSRunningApplication) -> AnyPublisher {\n let show = app.watchAX(\n [.selectedTextChanged],\n [.application, .window] + Role.validInputElms\n )\n .mapTo(Event.cursorMoved)\n\n let checkIfUnfocusedTimer = Timer.interval(seconds: 1)\n .mapTo(Event.cursorMoved)\n\n let showAlwaysOnIndicatorTimer = Timer.delay(seconds: 0.8)\n .mapTo(Event.showAlwaysOnIndicator)\n\n let hide = NSEvent.watch(matching: [.scrollWheel])\n .flatMapLatest { _ in Timer\n .delay(seconds: 0.3)\n .mapTo(Event.scrollEnd)\n .prepend(Event.scrollStart)\n }\n .removeDuplicates()\n .eraseToAnyPublisher()\n\n return Publishers.MergeMany([show, hide, checkIfUnfocusedTimer, showAlwaysOnIndicatorTimer])\n .prepend(.cursorMoved)\n .scan((State.initial, State.initial)) { changes, event -> State.Changes in\n (changes.current.reducer(event), changes.current)\n }\n .receive(on: DispatchQueue.main)\n .eraseToAnyPublisher()\n }\n }\n\n func alwaysOnPublisher(\n event: IndicatorVM.ActivateEvent,\n inputSource: InputSource,\n appKind: AppKind\n ) -> AnyPublisher {\n typealias Action = () -> Void\n\n let app = appKind.getApp()\n var isAlwaysOnIndicatorShowed = false\n\n updateIndicator(\n event: event,\n inputSource: inputSource\n )\n\n return AlwaysOn\n .statePublisher(app: app)\n .flatMapLatest { [weak self] state -> AnyPublisher in\n let ACTION_HIDE: Action = { self?.isActive = false }\n let ACTION_SHOW: Action = { self?.isActive = true }\n let ACTION_SHOW_ALWAYS_ON_INDICATOR: Action = { self?.indicatorVC.showAlwaysOnView() }\n\n if !state.current.isScrolling,\n let self = self,\n let appSize = self.getAppSize()\n {\n return self.preferencesVM.getIndicatorPositionPublisher(appSize: appSize, app: app)\n .map { position -> Action in\n guard let position = position\n else { return ACTION_HIDE }\n\n return {\n if state.current.isShowAlwaysOnIndicator,\n !isAlwaysOnIndicatorShowed\n {\n isAlwaysOnIndicatorShowed = true\n ACTION_SHOW_ALWAYS_ON_INDICATOR()\n }\n\n if position.kind.isInputArea {\n self.moveIndicator(position: position)\n ACTION_SHOW()\n } else {\n if state.current.isShowAlwaysOnIndicator {\n ACTION_HIDE()\n } else {\n self.moveIndicator(position: position)\n ACTION_SHOW()\n }\n }\n }\n }\n .eraseToAnyPublisher()\n } else {\n return Just(ACTION_HIDE).eraseToAnyPublisher()\n }\n }\n .tap { $0() }\n .mapToVoid()\n .eraseToAnyPublisher()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/PreferencesVM.swift", "import AppKit\nimport AXSwift\nimport Combine\nimport CombineExt\nimport LaunchAtLogin\nimport Sparkle\nimport SwiftUI\n\nprivate enum UpdateFeed {\n static let stable = URL(string: \"https://inputsource.pro/stable/appcast.xml\")!\n static let beta = URL(string: \"https://inputsource.pro/beta/appcast.xml\")!\n}\n\n@MainActor\nfinal class PreferencesVM: NSObject, ObservableObject {\n @Published\n var preferences = Preferences()\n\n @Published\n var keyboardConfigs: [KeyboardConfig] = []\n\n var permissionsVM: PermissionsVM\n\n var updaterController: SPUStandardUpdaterController?\n\n var cancelBag = CancelBag()\n\n var appKeyboardCache = AppKeyboardCache()\n\n let container: NSPersistentContainer\n let mainStorage: MainStorage\n\n let versionStr = \"\\(Bundle.main.infoDictionary?[\"CFBundleShortVersionString\"] as? String ?? \"unknown\")\"\n\n let buildStr = \"\\(Bundle.main.infoDictionary?[\"CFBundleVersion\"] as? String ?? \"unknown\")\"\n\n @Published\n var automaticallyChecksForUpdates = false\n\n @Published\n var canChecksForUpdates = false\n\n init(permissionsVM: PermissionsVM) {\n self.permissionsVM = permissionsVM\n container = NSPersistentContainer(name: \"Main\")\n mainStorage = MainStorage(container: container)\n \n super.init();\n \n setupAutoUpdate()\n\n // TODO: - Move to MainStorage\n container.loadPersistentStores { _, error in\n if let error = error {\n print(\"Core Data 'Main' failed to load: \\(error.localizedDescription)\")\n } else {\n self.mainStorage.refresh()\n }\n }\n\n if preferences.prevInstalledBuildVersion == 0 {\n for filterApp in filterApps(NSWorkspace.shared.runningApplications) {\n addAppCustomization(filterApp)\n }\n }\n\n cleanRemovedAppCustomizationIfNeed()\n migratePreferncesIfNeed()\n migrateBoutiqueIfNeed()\n watchKeyboardConfigsChange()\n watchPreferenceChanges()\n }\n\n func update(_ change: (inout Preferences) -> Void) {\n var draft = preferences\n\n change(&draft)\n\n preferences = draft\n }\n\n func saveContext(_ callback: (() -> Void)? = nil) {\n if let callback = callback {\n container.viewContext.performAndWait {\n callback()\n save()\n }\n } else {\n save()\n }\n\n func save() {\n do {\n try container.viewContext.save()\n } catch {\n print(\"saveAppCustomization error: \\(error.localizedDescription)\")\n }\n }\n }\n}\n\nextension PreferencesVM {\n private func watchPreferenceChanges() {\n $preferences\n .map(\\.isLaunchAtLogin)\n .removeDuplicates()\n .sink { LaunchAtLogin.isEnabled = $0 }\n .store(in: cancelBag)\n }\n \n private func watchKeyboardConfigsChange() {\n mainStorage.keyboardConfigs\n .assign(to: &$keyboardConfigs)\n }\n}\n\nextension PreferencesVM: @preconcurrency SPUUpdaterDelegate {\n private func setupAutoUpdate() {\n updaterController = SPUStandardUpdaterController(\n startingUpdater: true,\n updaterDelegate: self,\n userDriverDelegate: nil\n )\n\n updaterController?.updater\n .publisher(for: \\.automaticallyChecksForUpdates)\n .removeDuplicates()\n .assign(to: &$automaticallyChecksForUpdates)\n\n $automaticallyChecksForUpdates\n .dropFirst()\n .sink { [weak self] in self?.updaterController?.updater.automaticallyChecksForUpdates = $0 }\n .store(in: cancelBag)\n\n updaterController?.updater\n .publisher(for: \\.canCheckForUpdates)\n .debounce(for: 0.5, scheduler: DispatchQueue.main)\n .assign(to: &$canChecksForUpdates)\n }\n\n func checkUpdates() {\n updaterController?.updater.checkForUpdates()\n }\n \n func feedURLString(for updater: SPUUpdater) -> String? {\n let url = preferences.receiveBetaUpdates ? UpdateFeed.beta : UpdateFeed.stable\n return url.absoluteString\n }\n}\n\nextension PreferencesVM {\n func getBrowserURL(_ bundleIdentifier: String?, application: Application?) -> URL? {\n guard\n permissionsVM.isAccessibilityEnabled,\n let bundleIdentifier = bundleIdentifier,\n let browser = Browser(rawValue: bundleIdentifier)\n else { return nil }\n\n switch browser {\n case .Safari:\n guard preferences.isEnableURLSwitchForSafari else { return nil }\n case .SafariTechnologyPreview:\n guard preferences.isEnableURLSwitchForSafariTechnologyPreview else { return nil }\n case .Chrome:\n guard preferences.isEnableURLSwitchForChrome else { return nil }\n case .Chromium:\n guard preferences.isEnableURLSwitchForChromium else { return nil }\n case .Arc:\n guard preferences.isEnableURLSwitchForArc else { return nil }\n case .Edge:\n guard preferences.isEnableURLSwitchForEdge else { return nil }\n case .Brave:\n guard preferences.isEnableURLSwitchForBrave else { return nil }\n case .BraveBeta:\n guard preferences.isEnableURLSwitchForBraveBeta else { return nil }\n case .BraveNightly:\n guard preferences.isEnableURLSwitchForBraveNightly else { return nil }\n case .Vivaldi:\n guard preferences.isEnableURLSwitchForVivaldi else { return nil }\n case .Opera:\n guard preferences.isEnableURLSwitchForOpera else { return nil }\n case .Thorium:\n guard preferences.isEnableURLSwitchForThorium else { return nil }\n case .Firefox:\n guard preferences.isEnableURLSwitchForFirefox else { return nil }\n case .FirefoxDeveloperEdition:\n guard preferences.isEnableURLSwitchForFirefoxDeveloperEdition else { return nil }\n case .FirefoxNightly:\n guard preferences.isEnableURLSwitchForFirefoxNightly else { return nil }\n case .Zen:\n guard preferences.isEnableURLSwitchForZen else { return nil }\n case .Dia:\n guard preferences.isEnableURLSwitchForDia else { return nil }\n }\n\n if let application = application,\n let focusedWindow: UIElement = try? application.attribute(.focusedWindow),\n let url = browser.getCurrentTabURL(focusedWindow: focusedWindow)\n {\n return url\n } else {\n if browser == .Safari || browser == .SafariTechnologyPreview {\n return .newtab\n } else {\n return nil\n }\n }\n }\n\n func filterApps(_ apps: [NSRunningApplication]) -> [NSRunningApplication] {\n let isDetectSpotlightLikeApp = preferences.isEnhancedModeEnabled\n\n return apps.filter { app in\n (isDetectSpotlightLikeApp && NSApplication.isFloatingApp(app.bundleIdentifier))\n || app.activationPolicy == .regular\n }\n }\n}\n\nstruct Preferences {\n enum AppearanceMode: String, CaseIterable, Codable, Equatable {\n case dark = \"Dark\"\n case light = \"Light\"\n }\n\n private enum Key {\n static let prevInstalledBuildVersion = \"prevInstalledBuildVersion\"\n\n static let isLaunchAtLogin = \"isLaunchAtLogin\"\n static let isShowIconInMenuBar = \"isShowIconInMenuBar\"\n static let isEnhancedModeEnabled = \"isDetectSpotlightLikeApp\"\n static let isCJKVFixEnabled = \"isCJKVFixEnabled\"\n\n static let systemWideDefaultKeyboardId = \"systemWideDefaultKeyboardId\"\n\n static let browserAddressDefaultKeyboardId = \"browserAddressDefaultKeyboardId\"\n static let isActiveWhenLongpressLeftMouse = \"isActiveWhenLongpressLeftMouse\"\n static let isActiveWhenFocusedElementChanges = \"isActiveWhenFocusedElementChanges\"\n static let isActiveWhenSwitchApp = \"isActiveWhenSwitchApp\"\n static let isHideWhenSwitchAppWithForceKeyboard = \"isHideWhenSwitchAppWithForceKeyboard\"\n static let isActiveWhenSwitchInputSource = \"isActiveWhenSwitchInputSource\"\n\n static let isRestorePreviouslyUsedInputSource = \"isRestorePreviouslyUsedInputSource\"\n\n static let isEnableURLSwitchForSafari = \"isEnableURLSwitchForSafari\"\n static let isEnableURLSwitchForSafariTechnologyPreview = \"isEnableURLSwitchForSafariTechnologyPreview\"\n static let isEnableURLSwitchForChrome = \"isEnableURLSwitchForChrome\"\n static let isEnableURLSwitchForChromium = \"isEnableURLSwitchForChromium\"\n static let isEnableURLSwitchForArc = \"isEnableURLSwitchForArc\"\n static let isEnableURLSwitchForEdge = \"isEnableURLSwitchForEdge\"\n static let isEnableURLSwitchForBrave = \"isEnableURLSwitchForBrave\"\n static let isEnableURLSwitchForBraveBeta = \"isEnableURLSwitchForBraveBeta\"\n static let isEnableURLSwitchForBraveNightly = \"isEnableURLSwitchForBraveNightly\"\n static let isEnableURLSwitchForVivaldi = \"isEnableURLSwitchForVivaldi\"\n static let isEnableURLSwitchForOpera = \"isEnableURLSwitchForOpera\"\n static let isEnableURLSwitchForThorium = \"isEnableURLSwitchForThorium\"\n static let isEnableURLSwitchForFirefox = \"isEnableURLSwitchForFirefox\"\n static let isEnableURLSwitchForFirefoxDeveloperEdition = \"isEnableURLSwitchForFirefoxDeveloperEdition\"\n static let isEnableURLSwitchForFirefoxNightly = \"isEnableURLSwitchForFirefoxNightly\"\n static let isEnableURLSwitchForZen = \"isEnableURLSwitchForZen\"\n static let isEnableURLSwitchForDia = \"isEnableURLSwitchForDia\"\n\n static let isAutoAppearanceMode = \"isAutoAppearanceMode\"\n static let appearanceMode = \"appearanceMode\"\n static let isShowInputSourcesLabel = \"isShowInputSourcesLabel\"\n static let indicatorBackground = \"indicatorBackground\"\n static let indicatorForgeground = \"indicatorForgeground\"\n\n static let tryToDisplayIndicatorNearCursor = \"tryToDisplayIndicatorNearCursor\"\n static let isEnableAlwaysOnIndicator = \"isEnableAlwaysOnIndicator\"\n\n static let indicatorPosition = \"indicatorPosition\"\n static let indicatorPositionAlignment = \"indicatorPositionAlignment\"\n static let indicatorPositionSpacing = \"indicatorPositionSpacing\"\n\n static let indicatorSize = \"indicatorSize\"\n static let indicatorInfo = \"indicatorInfo\"\n \n static let receiveBetaUpdates = \"receiveBetaUpdates\"\n }\n\n fileprivate init() {}\n\n @UserDefault(Preferences.Key.prevInstalledBuildVersion)\n var prevInstalledBuildVersion = 0\n\n // MARK: - General\n\n @UserDefault(Preferences.Key.isLaunchAtLogin)\n var isLaunchAtLogin = LaunchAtLogin.isEnabled\n\n @UserDefault(Preferences.Key.isShowIconInMenuBar)\n var isShowIconInMenuBar = true\n\n @UserDefault(Preferences.Key.isEnhancedModeEnabled)\n var isEnhancedModeEnabled = false\n\n @UserDefault(Preferences.Key.isCJKVFixEnabled)\n var isCJKVFixEnabled = false\n \n @UserDefault(Preferences.Key.receiveBetaUpdates)\n var receiveBetaUpdates = false\n\n // MARK: - Triggers\n\n @UserDefault(Preferences.Key.isActiveWhenLongpressLeftMouse)\n var isActiveWhenLongpressLeftMouse = true\n\n @UserDefault(Preferences.Key.isActiveWhenSwitchApp)\n var isActiveWhenSwitchApp = true\n\n @UserDefault(Preferences.Key.isHideWhenSwitchAppWithForceKeyboard)\n var isHideWhenSwitchAppWithForceKeyboard = false\n\n @UserDefault(Preferences.Key.isActiveWhenSwitchInputSource)\n var isActiveWhenSwitchInputSource = true\n\n @UserDefault(Preferences.Key.isActiveWhenFocusedElementChanges)\n var isActiveWhenFocusedElementChanges = true\n\n // MARK: - Input Source\n\n @UserDefault(Preferences.Key.isRestorePreviouslyUsedInputSource)\n var isRestorePreviouslyUsedInputSource = false\n\n // MARK: - App Rules\n\n @UserDefault(Preferences.Key.systemWideDefaultKeyboardId)\n var systemWideDefaultKeyboardId = \"\"\n\n // MARK: - Browser Rules\n\n @UserDefault(Preferences.Key.browserAddressDefaultKeyboardId)\n var browserAddressDefaultKeyboardId = \"\"\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForSafari)\n var isEnableURLSwitchForSafari = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForSafariTechnologyPreview)\n var isEnableURLSwitchForSafariTechnologyPreview = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForChrome)\n var isEnableURLSwitchForChrome = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForChromium)\n var isEnableURLSwitchForChromium = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForArc)\n var isEnableURLSwitchForArc = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForEdge)\n var isEnableURLSwitchForEdge = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForBrave)\n var isEnableURLSwitchForBrave = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForBraveBeta)\n var isEnableURLSwitchForBraveBeta = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForBraveNightly)\n var isEnableURLSwitchForBraveNightly = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForVivaldi)\n var isEnableURLSwitchForVivaldi = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForOpera)\n var isEnableURLSwitchForOpera = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForThorium)\n var isEnableURLSwitchForThorium = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForFirefox)\n var isEnableURLSwitchForFirefox = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForFirefoxDeveloperEdition)\n var isEnableURLSwitchForFirefoxDeveloperEdition = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForFirefoxNightly)\n var isEnableURLSwitchForFirefoxNightly = false\n\n @UserDefault(Preferences.Key.isEnableURLSwitchForZen)\n var isEnableURLSwitchForZen = false\n \n @UserDefault(Preferences.Key.isEnableURLSwitchForDia)\n var isEnableURLSwitchForDia = false\n\n // MARK: - Appearance\n\n @available(*, deprecated, message: \"Use indicatorInfo instead\")\n @UserDefault(Preferences.Key.isShowInputSourcesLabel)\n var isShowInputSourcesLabel = true\n\n @CodableUserDefault(Preferences.Key.indicatorInfo)\n var indicatorInfo = IndicatorInfo.iconAndTitle\n\n @CodableUserDefault(Preferences.Key.indicatorSize)\n var indicatorSize = IndicatorSize.medium\n\n @UserDefault(Preferences.Key.isAutoAppearanceMode)\n var isAutoAppearanceMode = true\n\n @CodableUserDefault(Preferences.Key.appearanceMode)\n var appearanceMode = AppearanceMode.dark\n\n @CodableUserDefault(Preferences.Key.indicatorBackground)\n var indicatorBackground = IndicatorColor.background\n\n @CodableUserDefault(Preferences.Key.indicatorForgeground)\n var indicatorForgeground = IndicatorColor.forgeground\n\n @UserDefault(Preferences.Key.tryToDisplayIndicatorNearCursor)\n var tryToDisplayIndicatorNearCursor = true\n\n @UserDefault(Preferences.Key.isEnableAlwaysOnIndicator)\n var isEnableAlwaysOnIndicator = false\n\n @CodableUserDefault(Preferences.Key.indicatorPosition)\n var indicatorPosition = IndicatorPosition.nearMouse\n\n @CodableUserDefault(Preferences.Key.indicatorPositionAlignment)\n var indicatorPositionAlignment = IndicatorPosition.Alignment.bottomRight\n\n @CodableUserDefault(Preferences.Key.indicatorPositionSpacing)\n var indicatorPositionSpacing = IndicatorPosition.Spacing.s\n}\n\nextension Preferences {\n var shortVersion: String {\n Bundle.main.shortVersion\n }\n\n var buildVersion: Int {\n Bundle.main.buildVersion\n }\n\n var isActiveWhenFocusedElementChangesEnabled: Bool {\n return isEnhancedModeEnabled && isActiveWhenFocusedElementChanges\n }\n\n var indicatorKind: IndicatorKind {\n guard let indicatorInfo = indicatorInfo else { return .iconAndTitle }\n\n switch indicatorInfo {\n case .iconAndTitle:\n return .iconAndTitle\n case .iconOnly:\n return .icon\n case .titleOnly:\n return .title\n }\n }\n\n var indicatorBackgroundColor: Color {\n get {\n switch appearanceMode {\n case .dark?:\n return indicatorBackground?.dark ?? IndicatorColor.background.dark\n default:\n return indicatorBackground?.light ?? IndicatorColor.background.light\n }\n }\n\n set {\n guard let appearanceMode = appearanceMode,\n let indicatorBackground = indicatorBackground\n else { return }\n\n switch appearanceMode {\n case .dark:\n self.indicatorBackground = IndicatorColor(\n light: indicatorBackground.light,\n dark: newValue\n )\n case .light:\n self.indicatorBackground = IndicatorColor(\n light: newValue,\n dark: indicatorBackground.dark\n )\n }\n }\n }\n\n var indicatorForgegroundColor: Color {\n get {\n switch appearanceMode {\n case .dark?:\n return indicatorForgeground?.dark ?? IndicatorColor.forgeground.dark\n default:\n return indicatorForgeground?.light ?? IndicatorColor.forgeground.light\n }\n }\n\n set {\n guard let appearanceMode = appearanceMode,\n let indicatorForgeground = indicatorForgeground\n else { return }\n\n switch appearanceMode {\n case .dark:\n self.indicatorForgeground = IndicatorColor(\n light: indicatorForgeground.light,\n dark: newValue\n )\n case .light:\n self.indicatorForgeground = IndicatorColor(\n light: newValue,\n dark: indicatorForgeground.dark\n )\n }\n }\n }\n}\n\nextension PreferencesVM {\n var systemWideDefaultKeyboard: InputSource? {\n return InputSource.sources.first { $0.id == preferences.systemWideDefaultKeyboardId }\n }\n\n var browserAddressDefaultKeyboard: InputSource? {\n return InputSource.sources.first { $0.id == preferences.browserAddressDefaultKeyboardId }\n }\n}\n\nextension PreferencesVM {\n func isUseCJKVFix() -> Bool {\n return preferences.isEnhancedModeEnabled && preferences.isCJKVFixEnabled\n }\n\n func isAbleToQueryLocation(_ app: NSRunningApplication) -> Bool {\n if app.bundleIdentifier == \"com.tencent.WeWorkMac\" {\n return false\n } else {\n return true\n }\n }\n\n func isShowAlwaysOnIndicator(app: NSRunningApplication) -> Bool {\n if preferences.isEnableAlwaysOnIndicator,\n isAbleToQueryLocation(app)\n {\n return true\n } else {\n return false\n }\n }\n\n func needDetectFocusedFieldChanges(app: NSRunningApplication) -> Bool {\n if preferences.isActiveWhenFocusedElementChangesEnabled,\n isAbleToQueryLocation(app)\n {\n return true\n } else {\n return false\n }\n }\n\n func isHideIndicator(_ appKind: AppKind) -> Bool {\n if let browserRule = appKind.getBrowserInfo()?.rule,\n browserRule.hideIndicator\n {\n return true\n }\n\n return getAppCustomization(app: appKind.getApp())?.hideIndicator == true\n }\n\n func needDisplayEnhancedModePrompt(bundleIdentifier: String?) -> Bool {\n NSApplication.isFloatingApp(bundleIdentifier) && !preferences.isEnhancedModeEnabled\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/BrowserRulesSettingsView.swift", "import SwiftUI\n\nstruct BrowserRulesSettingsView: View {\n @State var isPresented = false\n\n @State var permissionRequest: Browser? = nil\n\n @State var selectedRules = Set()\n\n @FetchRequest(sortDescriptors: [\n NSSortDescriptor(key: \"createdAt\", ascending: true),\n ])\n var browserRules: FetchedResults\n\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n @EnvironmentObject var permissionsVM: PermissionsVM\n\n var inputSourceItems: [PickerItem] {\n [PickerItem.empty]\n + InputSource.sources.map { PickerItem(id: $0.id, title: $0.name, toolTip: $0.id) }\n }\n\n var body: some View {\n let isShowPermissionRequest = Binding(\n get: { permissionRequest != nil },\n set: {\n if $0 == false {\n permissionRequest = nil\n }\n }\n )\n\n return VStack(spacing: 0) {\n VStack {\n HStack {\n Text(\"Default Keyboard for Address Bar\".i18n())\n\n PopUpButtonPicker(\n items: inputSourceItems,\n width: 150,\n isItemSelected: { $0?.id == preferencesVM.preferences.browserAddressDefaultKeyboardId },\n getTitle: { $0?.title ?? \"\" },\n getToolTip: { $0?.toolTip },\n onSelect: handleBrowserAddressDefaultKeyboardSelect\n )\n .disabled(!preferencesVM.preferences.isEnhancedModeEnabled)\n\n EnhancedModeRequiredBadge()\n\n Spacer(minLength: 0)\n }\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border.color)\n\n List(browserRules, id: \\.self, selection: $selectedRules) { rule in\n BrowserRuleRow(isSelected: selectedRules.contains(rule), rule: rule)\n }\n\n HStack(spacing: 0) {\n HStack(spacing: 5) {\n Button(action: addRule) {\n SwiftUI.Image(systemName: \"plus\")\n }\n\n Button(action: removeRules) {\n SwiftUI.Image(systemName: \"minus\")\n }\n .disabled(selectedRules.isEmpty)\n }\n\n Divider()\n .frame(height: 16)\n .padding(.horizontal, 8)\n\n ScrollView(.horizontal, showsIndicators: false) {\n HStack(spacing: 10) {\n ForEach(Browser.allCases.sorted { $0.rawValue < $1.rawValue }, id: \\.rawValue) { browser in\n if NSApplication.isBrowserInstalled(browser.rawValue) {\n Toggle(isOn: isEnableFor(browser)) {\n Text(\"\\(browser.displayName)\")\n }\n }\n }\n }\n }\n }\n .padding(10)\n .border(width: 1, edges: [.top], color: NSColor.gridColor.color)\n .sheet(isPresented: $isPresented, content: {\n BrowserRuleEditView(isPresented: $isPresented, rule: nil)\n })\n .sheet(isPresented: isShowPermissionRequest) {\n BrowserPermissionRequestView(\n isPresented: isShowPermissionRequest,\n onSuccess: permissionRequestSuccess\n )\n }\n }\n }\n\n func addRule() {\n isPresented = true\n }\n\n func removeRules() {\n for selectedRule in selectedRules {\n preferencesVM.deleteBrowserRule(selectedRule)\n }\n selectedRules.removeAll()\n }\n\n func isEnableFor(_ browser: Browser) -> Binding {\n Binding(\n get: { preferencesVM.isBrowserEnabled(browser) },\n set: { enableFor(browser, enable: $0) }\n )\n }\n\n func enableFor(_ browser: Browser, enable: Bool) {\n if enable {\n // TODO: replace `isAccessibilityEnabled` with enhance mode\n if permissionsVM.isAccessibilityEnabled {\n toggle(browser: browser, isEnable: true)\n } else {\n permissionRequest = browser\n }\n } else {\n toggle(browser: browser, isEnable: false)\n }\n }\n\n func permissionRequestSuccess() {\n guard let browser = permissionRequest\n else { return }\n\n toggle(browser: browser, isEnable: true)\n }\n\n func toggle(browser: Browser, isEnable: Bool) {\n preferencesVM.update {\n if isEnable {\n $0.isEnhancedModeEnabled = true\n }\n\n switch browser {\n case .Chrome:\n $0.isEnableURLSwitchForChrome = isEnable\n case .Chromium:\n $0.isEnableURLSwitchForChromium = isEnable\n case .Arc:\n $0.isEnableURLSwitchForArc = isEnable\n case .Safari:\n $0.isEnableURLSwitchForSafari = isEnable\n case .SafariTechnologyPreview:\n $0.isEnableURLSwitchForSafariTechnologyPreview = isEnable\n case .Edge:\n $0.isEnableURLSwitchForEdge = isEnable\n case .Brave:\n $0.isEnableURLSwitchForBrave = isEnable\n case .BraveBeta:\n $0.isEnableURLSwitchForBraveBeta = isEnable\n case .BraveNightly:\n $0.isEnableURLSwitchForBraveNightly = isEnable\n case .Vivaldi:\n $0.isEnableURLSwitchForVivaldi = isEnable\n case .Opera:\n $0.isEnableURLSwitchForOpera = isEnable\n case .Thorium:\n $0.isEnableURLSwitchForThorium = isEnable\n case .Firefox:\n $0.isEnableURLSwitchForFirefox = isEnable\n case .FirefoxDeveloperEdition:\n $0.isEnableURLSwitchForFirefoxDeveloperEdition = isEnable\n case .FirefoxNightly:\n $0.isEnableURLSwitchForFirefoxNightly = isEnable\n case .Zen:\n $0.isEnableURLSwitchForZen = isEnable\n case .Dia:\n $0.isEnableURLSwitchForDia = isEnable\n }\n }\n }\n\n func handleBrowserAddressDefaultKeyboardSelect(_ index: Int) {\n let browserAddressDefaultKeyboard = inputSourceItems[index]\n\n preferencesVM.update {\n $0.browserAddressDefaultKeyboardId = browserAddressDefaultKeyboard.id\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Indicator/IndicatorViewConfig.swift", "import AppKit\n\nenum IndicatorKind {\n case icon\n case title\n case iconAndTitle\n case alwaysOn\n}\n\n@MainActor\nstruct IndicatorViewConfig {\n let inputSource: InputSource\n let kind: IndicatorKind\n let size: IndicatorSize\n let bgColor: NSColor?\n let textColor: NSColor?\n\n func render() -> NSView? {\n switch kind {\n case .iconAndTitle:\n return renderWithLabel()\n case .icon:\n return renderWithoutLabel()\n case .title:\n return renderOnlyLabel()\n case .alwaysOn:\n return renderAlwaysOn()\n }\n }\n\n func renderAlwaysOn() -> NSView? {\n let containerView = getContainerView()\n\n containerView.layer?.cornerRadius = 8\n\n containerView.snp.makeConstraints {\n $0.width.height.equalTo(8)\n }\n\n return containerView\n }\n\n private func renderWithLabel() -> NSView? {\n guard let imageView = getImageView(inputSource)\n else { return renderOnlyLabel() }\n\n let containerView = getContainerView()\n let labelView = NSTextField(labelWithString: inputSource.name)\n let stackView = NSStackView(views: [imageView, labelView])\n\n switch size {\n case .small:\n containerView.layer?.cornerRadius = 3\n stackView.spacing = 3\n labelView.font = .systemFont(ofSize: 10)\n case .medium:\n containerView.layer?.cornerRadius = 4\n stackView.spacing = 5\n labelView.font = .systemFont(ofSize: 12.6)\n case .large:\n containerView.layer?.cornerRadius = 6\n stackView.spacing = 8\n labelView.font = .systemFont(ofSize: 20)\n }\n\n labelView.textColor = textColor\n stackView.alignment = .centerY\n containerView.addSubview(stackView)\n\n stackView.snp.makeConstraints { make in\n switch size {\n case .small:\n make.edges.equalToSuperview().inset(NSEdgeInsets(top: 3, left: 3, bottom: 3, right: 3))\n case .medium:\n make.edges.equalToSuperview().inset(NSEdgeInsets(top: 4, left: 4, bottom: 4, right: 4))\n case .large:\n make.edges.equalToSuperview().inset(NSEdgeInsets(top: 6, left: 6, bottom: 6, right: 6))\n }\n }\n\n return containerView\n }\n\n private func renderWithoutLabel() -> NSView? {\n guard let imageView = getImageView(inputSource)\n else { return renderOnlyLabel() }\n\n let containerView = getContainerView()\n let stackView = NSStackView(views: [imageView])\n\n containerView.layer?.cornerRadius = 4\n containerView.addSubview(stackView)\n\n stackView.snp.makeConstraints { make in\n make.edges.equalToSuperview().inset(NSEdgeInsets(top: 3, left: 3, bottom: 3, right: 3))\n }\n\n return containerView\n }\n\n private func renderOnlyLabel() -> NSView? {\n let containerView = getContainerView()\n let labelView = NSTextField(labelWithString: inputSource.name)\n let stackView = NSStackView(views: [labelView])\n\n switch size {\n case .small:\n containerView.layer?.cornerRadius = 3\n stackView.spacing = 3\n labelView.font = .systemFont(ofSize: 10)\n case .medium:\n containerView.layer?.cornerRadius = 4\n stackView.spacing = 5\n labelView.font = .systemFont(ofSize: 12.6)\n case .large:\n containerView.layer?.cornerRadius = 6\n stackView.spacing = 8\n labelView.font = .systemFont(ofSize: 20)\n }\n\n labelView.textColor = textColor\n stackView.alignment = .centerY\n containerView.addSubview(stackView)\n\n stackView.snp.makeConstraints { make in\n switch size {\n case .small:\n make.edges.equalToSuperview().inset(NSEdgeInsets(top: 3, left: 3, bottom: 3, right: 3))\n case .medium:\n make.edges.equalToSuperview().inset(NSEdgeInsets(top: 4, left: 4, bottom: 4, right: 4))\n case .large:\n make.edges.equalToSuperview().inset(NSEdgeInsets(top: 6, left: 6, bottom: 6, right: 6))\n }\n }\n\n return containerView\n }\n\n private func getImageView(_ inputSource: InputSource) -> NSView? {\n// if let textImage = getTextImageView(inputSource) { return textImage }\n\n guard let image = inputSource.icon\n else { return nil }\n\n let imageView = NSImageView(image: image)\n\n imageView.contentTintColor = textColor\n\n imageView.snp.makeConstraints { make in\n let size = imageView.image?.size ?? .zero\n let ratio = size.height / size.width\n let width: CGFloat = {\n switch self.size {\n case .small:\n return 12\n case .medium:\n return 16\n case .large:\n return 24\n }\n }()\n let height = ratio * width\n\n make.size.equalTo(CGSize(width: width, height: height))\n }\n\n return imageView\n }\n\n private func getTextImageView(_ inputSource: InputSource) -> NSView? {\n guard let labelName = inputSource.getSystemLabelName()\n else { return nil }\n\n let labelView = NSTextField(labelWithString: labelName)\n let view = NSView()\n\n view.addSubview(labelView)\n view.wantsLayer = true\n view.layer?.backgroundColor = textColor?.cgColor\n view.layer?.cornerRadius = 2\n\n labelView.snp.makeConstraints {\n $0.center.equalTo(view)\n }\n\n view.snp.makeConstraints {\n// $0.width.equalTo(22)\n $0.width.height.equalTo(16)\n }\n\n labelView.textColor = bgColor\n labelView.font = .systemFont(ofSize: labelName.count > 1 ? 10 : 11, weight: .regular)\n\n return view\n }\n\n private func getContainerView() -> NSView {\n let containerView = NSView()\n\n containerView.wantsLayer = true\n containerView.setValue(bgColor, forKey: \"backgroundColor\")\n\n containerView.layer?.borderWidth = 1\n containerView.layer?.borderColor = NSColor.black.withAlphaComponent(0.1 * (bgColor?.alphaComponent ?? 1)).cgColor\n\n return containerView\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/GeneralSettingsView.swift", "import SwiftUI\n\nstruct GeneralSettingsView: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n @EnvironmentObject var permissionsVM: PermissionsVM\n\n @State var isDetectSpotlightLikeApp = false\n\n var items: [PickerItem] {\n [PickerItem.empty]\n + InputSource.sources.map { PickerItem(id: $0.id, title: $0.name, toolTip: $0.id) }\n }\n\n var body: some View {\n let keyboardRestoreStrategyBinding = Binding(\n get: { preferencesVM.preferences.isRestorePreviouslyUsedInputSource ?\n KeyboardRestoreStrategy.RestorePreviouslyUsedOne :\n KeyboardRestoreStrategy.UseDefaultKeyboardInstead\n },\n set: { newValue in\n preferencesVM.update {\n switch newValue {\n case .RestorePreviouslyUsedOne:\n $0.isRestorePreviouslyUsedInputSource = true\n case .UseDefaultKeyboardInstead:\n $0.isRestorePreviouslyUsedInputSource = false\n }\n }\n }\n )\n\n ScrollView {\n VStack(alignment: .leading, spacing: 18) {\n SettingsSection(title: \"\") {\n PromotionBadge()\n }\n \n SettingsSection(title: \"\") {\n EnhancedModeToggle()\n }\n\n SettingsSection(title: \"Default Keyboard\") {\n HStack {\n Text(\"For All Apps and Websites\".i18n())\n\n PopUpButtonPicker(\n items: items,\n isItemSelected: { $0?.id == preferencesVM.preferences.systemWideDefaultKeyboardId },\n getTitle: { $0?.title ?? \"\" },\n getToolTip: { $0?.toolTip },\n onSelect: handleSystemWideDefaultKeyboardSelect\n )\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n }\n\n SettingsSection(title: \"Keyboard Restore Strategy\") {\n VStack(alignment: .leading) {\n Text(\"When Switching Back to the App or Website\".i18n() + \":\")\n\n Picker(\"Keyboard Restore Strategy\", selection: keyboardRestoreStrategyBinding) {\n ForEach(KeyboardRestoreStrategy.allCases) { item in\n Text(item.name).tag(item)\n }\n }\n .pickerStyle(.segmented)\n }\n .padding()\n }\n\n Group {\n SettingsSection(title: \"Indicator Triggers\") {\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.isActiveWhenLongpressLeftMouse)\n\n Text(\"isActiveWhenLongpressLeftMouse\".i18n())\n\n Spacer()\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.isActiveWhenSwitchInputSource)\n\n Text(\"isActiveWhenSwitchInputSource\".i18n())\n\n Spacer()\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.isActiveWhenSwitchApp)\n\n Text(\"isActiveWhenSwitchApp\".i18n())\n\n Spacer()\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.isActiveWhenFocusedElementChanges)\n .disabled(!preferencesVM.preferences.isEnhancedModeEnabled)\n\n Text(\"isActiveWhenFocusedElementChanges\".i18n())\n\n Spacer()\n\n EnhancedModeRequiredBadge()\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n }\n\n SettingsSection(title: \"\") {\n HStack {\n Toggle(\"\",\n isOn: $preferencesVM.preferences.isHideWhenSwitchAppWithForceKeyboard)\n .disabled(!(\n preferencesVM.preferences.isActiveWhenSwitchApp ||\n preferencesVM.preferences.isActiveWhenSwitchInputSource ||\n preferencesVM.preferences.isActiveWhenFocusedElementChanges\n ))\n\n Text(\"isHideWhenSwitchAppWithForceKeyboard\")\n\n Spacer()\n }\n .padding()\n }\n }\n\n Group {\n SettingsSection(title: \"System\") {\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.isLaunchAtLogin)\n Text(\"Launch at Login\".i18n())\n Spacer()\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.isShowIconInMenuBar)\n Text(\"Display Icon in Menu Bar\".i18n())\n Spacer()\n }\n .padding()\n }\n\n SettingsSection(title: \"Updates\") {\n HStack {\n Toggle(\"\", isOn: $preferencesVM.preferences.receiveBetaUpdates)\n Text(\"Receive Beta Updates\".i18n())\n Spacer()\n }\n .padding()\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n \n Button(action: { preferencesVM.checkUpdates() }, label: {\n HStack {\n Text(\"Check for Updates\".i18n() + \"...\")\n\n Spacer()\n\n Text(\" \\(preferencesVM.versionStr) (\\(preferencesVM.buildStr))\")\n .foregroundColor(Color.primary.opacity(0.5))\n }\n })\n .buttonStyle(SectionButtonStyle())\n }\n }\n\n Group {\n SettingsSection(title: \"Find Us\", tips: Text(\"Right click each section to copy link\").font(.subheadline).opacity(0.5)) {\n Button(action: { URL.website.open() }, label: {\n HStack {\n Text(\"Website\".i18n())\n .foregroundColor(Color.primary)\n\n Spacer()\n\n Text(URL.website.absoluteString)\n }\n })\n .buttonStyle(SectionButtonStyle())\n .contextMenu {\n Button(\"Copy\") {\n NSPasteboard.general.clearContents()\n NSPasteboard.general.setString(URL.website.absoluteString, forType: .string)\n }\n }\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n\n Button(action: { URL.twitter.open() }, label: {\n HStack {\n Text(\"Twitter\")\n .foregroundColor(Color.primary)\n\n Spacer()\n\n Text(\"@Runjuu\")\n }\n })\n .buttonStyle(SectionButtonStyle())\n .contextMenu {\n Button(\"Copy\") {\n NSPasteboard.general.clearContents()\n NSPasteboard.general.setString(URL.twitter.absoluteString, forType: .string)\n }\n }\n .border(width: 1, edges: [.bottom], color: NSColor.border2.color)\n\n Button(action: { URL.email.open() }, label: {\n HStack {\n Text(\"Email\")\n .foregroundColor(Color.primary)\n\n Spacer()\n\n Text(URL.emailString)\n }\n })\n .buttonStyle(SectionButtonStyle())\n .contextMenu {\n Button(\"Copy\") {\n NSPasteboard.general.clearContents()\n NSPasteboard.general.setString(URL.emailString, forType: .string)\n }\n }\n }\n\n SettingsSection(title: \"\") {\n FeedbackButton()\n }\n }\n\n SettingsSection(title: \"Privacy\") {\n HStack {\n Text(\"Privacy Content\".i18n())\n .multilineTextAlignment(.leading)\n .padding()\n .opacity(0.8)\n\n Spacer(minLength: 0)\n }\n }\n\n HStack {\n Spacer()\n Text(\"Created by Runjuu & Die2\")\n Spacer()\n }\n .font(.footnote)\n .opacity(0.5)\n }\n .padding()\n }\n .labelsHidden()\n .toggleStyle(.switch)\n .background(NSColor.background1.color)\n .onAppear(perform: disableIsDetectSpotlightLikeAppIfNeed)\n }\n\n func disableIsDetectSpotlightLikeAppIfNeed() {\n if !permissionsVM.isAccessibilityEnabled && preferencesVM.preferences.isEnhancedModeEnabled {\n preferencesVM.update {\n $0.isEnhancedModeEnabled = false\n }\n }\n }\n\n func handleSystemWideDefaultKeyboardSelect(_ index: Int) {\n let defaultKeyboard = items[index]\n\n preferencesVM.update {\n $0.systemWideDefaultKeyboardId = defaultKeyboard.id\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/ISPTextEditor.swift", "//\n// ISPTextEditor.swift\n// Input Source Pro\n//\n// Created by runjuu on 2023-03-05.\n//\n\nimport SwiftUI\n\nstruct ISPTextEditor: View {\n @Binding var text: String\n\n var placeholder: String\n\n let minHeight: CGFloat\n\n var body: some View {\n ZStack(alignment: .topLeading) {\n TextEditor(text: $text)\n .padding(.vertical, 7)\n .padding(.horizontal, 2)\n .frame(minHeight: minHeight, maxHeight: 500, alignment: .leading)\n .foregroundColor(Color(.labelColor))\n .multilineTextAlignment(.leading)\n .background(Color(NSColor.textBackgroundColor))\n .clipShape(RoundedRectangle(cornerRadius: 6))\n .overlay(\n RoundedRectangle(cornerRadius: 6)\n .stroke(Color.primary.opacity(0.3), lineWidth: 1)\n )\n\n Text(placeholder)\n .padding(.vertical, 7)\n .padding(.horizontal, 7)\n .foregroundColor(Color(.placeholderTextColor))\n .opacity(text.isEmpty ? 1 : 0)\n .allowsHitTesting(false)\n }\n .font(.body)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/QuestionButton.swift", "import SwiftUI\n\nstruct QuestionButton: View {\n @State var displayTips = false\n\n @Environment(\\.colorScheme) var colorScheme: ColorScheme\n\n let content: () -> Content\n let popover: (ColorScheme) -> Popover\n\n init(\n @ViewBuilder content: @escaping () -> Content,\n @ViewBuilder popover: @escaping (ColorScheme) -> Popover\n ) {\n self.content = content\n self.popover = popover\n }\n\n var body: some View {\n Button(action: { displayTips.toggle() }) {\n content()\n .font(.body.bold())\n }\n .buttonStyle(QuestionButtonStyle())\n .popover(isPresented: $displayTips, arrowEdge: .top) {\n VStack(spacing: 0) {\n popover(colorScheme)\n }\n .frame(width: 280)\n }\n }\n}\n\nstruct QuestionButtonStyle: ButtonStyle {\n @State var isHover = false\n\n func makeBody(configuration: Configuration) -> some View {\n configuration.label\n .opacity(isHover ? 1 : 0.8)\n .background(Color.gray.opacity(configuration.isPressed ? 0.6 : isHover ? 0.3 : 0.15))\n .clipShape(Circle())\n .animation(.easeOut(duration: 0.2), value: configuration.isPressed)\n .onHover { hover in\n withAnimation {\n isHover = hover\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/FeedbackButton.swift", "import SwiftUI\n\nstruct FeedbackButton: View {\n @EnvironmentObject var feedbackVM: FeedbackVM\n\n var body: some View {\n Button(\n action: feedbackVM.show,\n label: {\n HStack {\n Text(\"Send Feedback\".i18n() + \"...\")\n Spacer()\n }\n }\n )\n .buttonStyle(SectionButtonStyle())\n }\n}\n\nstruct FeedbackModal: ViewModifier {\n @EnvironmentObject var feedbackVM: FeedbackVM\n\n func body(content: Content) -> some View {\n content\n .sheet(isPresented: .constant(feedbackVM.isPresented), content: {\n LoadingView(isShowing: feedbackVM.isSending) {\n VStack(alignment: .leading) {\n if feedbackVM.isSent {\n HStack {\n Spacer()\n\n VStack {\n Text(\"FeedbackSuccessTips\".i18n())\n .multilineTextAlignment(.center)\n .font(.system(size: 16))\n .padding(.horizontal)\n .padding(.vertical, 30)\n\n Button(\"Close\".i18n()) {\n feedbackVM.hide()\n }\n .keyboardShortcut(.defaultAction)\n .padding(.bottom)\n }\n\n Spacer()\n }\n } else {\n Text(\"FeedbackTips\".i18n())\n .foregroundColor(.primary.opacity(0.8))\n .padding(.vertical, 8)\n\n Text(\"FeedbackMessageTitle\".i18n() + \":\")\n\n ISPTextEditor(text: $feedbackVM.message, placeholder: \"FeedbackMessagePlaceholder\".i18n(), minHeight: 80)\n\n Text(\"FeedbackEmailTitle\".i18n() + \":\")\n .padding(.top, 8)\n\n ISPTextEditor(text: $feedbackVM.email, placeholder: \"support@inputsource.pro\", minHeight: 0)\n\n HStack {\n Spacer()\n\n Button(\"Cancel\".i18n()) {\n feedbackVM.hide()\n }\n .keyboardShortcut(.cancelAction)\n\n Button(\"Send Feedback\".i18n()) {\n Task {\n await feedbackVM.sendFeedback()\n }\n }\n .keyboardShortcut(.defaultAction)\n .disabled(feedbackVM.message.isEmpty)\n }\n .padding(.top)\n }\n }\n .lineLimit(nil)\n .padding()\n .fixedSize(horizontal: false, vertical: true)\n .frame(width: 450)\n .disabled(feedbackVM.isSending)\n }\n .background(NSColor.background.color)\n })\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/PreferenceSection.swift", "import SwiftUI\n\nstruct PreferenceSection: View {\n let title: String\n\n let content: Content\n\n let hideDivider: Bool\n\n init(title: String, hideDivider: Bool = false, @ViewBuilder _ content: () -> Content) {\n self.title = title\n self.hideDivider = hideDivider\n self.content = content()\n }\n\n var body: some View {\n VStack(alignment: .leading, spacing: 0) {\n HStack(alignment: .firstTextBaseline) {\n VStack {\n Text(title.isEmpty ? title : \"\\(title.i18n()):\")\n .fontWeight(.bold)\n .tracking(0.2)\n .frame(width: 100, alignment: .leading)\n }\n\n VStack(alignment: .leading) {\n content\n }\n\n Spacer(minLength: 0)\n }\n\n if !hideDivider {\n Divider()\n .padding(.vertical)\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/SettingsSection.swift", "import SwiftUI\n\nstruct SettingsSection: View {\n let title: String\n\n let tips: Tips?\n\n let noI18N: Bool\n\n let content: Content\n\n init(title: String, noI18N: Bool = false, tips: Tips? = nil, @ViewBuilder _ content: () -> Content) {\n self.title = title\n self.noI18N = noI18N\n self.tips = tips\n self.content = content()\n }\n\n var body: some View {\n VStack(alignment: .leading) {\n if !title.isEmpty || tips != nil {\n HStack {\n if !title.isEmpty {\n Text(noI18N ? title : title.i18n())\n .opacity(0.8)\n }\n\n tips\n }\n .padding(.horizontal)\n }\n\n VStack(alignment: .leading, spacing: 0) {\n content\n }\n .frame(maxWidth: .infinity)\n .background(NSColor.background2.color)\n .clipShape(RoundedRectangle(cornerRadius: 8))\n .overlay(\n RoundedRectangle(cornerRadius: 8)\n .stroke(NSColor.border2.color, lineWidth: 1)\n )\n }\n }\n}\n\n// Support optional footer\nextension SettingsSection where Tips == EmptyView {\n init(title: String, noI18N: Bool = false, @ViewBuilder _ content: () -> Content) {\n self.title = title\n self.noI18N = noI18N\n tips = nil\n self.content = content()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/LoadingView.swift", "import SwiftUI\n\nstruct LoadingView: View where Content: View {\n var isShowing: Bool\n\n var content: () -> Content\n\n var body: some View {\n ZStack(alignment: .center) {\n self.content()\n .disabled(isShowing)\n .opacity(isShowing ? 0.5 : 1)\n\n VStack {\n ProgressView()\n .frame(width: 30, height: 30)\n }\n .opacity(isShowing ? 1 : 0)\n .animation(.easeOut, value: isShowing)\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/AddSwitchingGroupButton.swift", "import SwiftUI\n\nstruct AddSwitchingGroupButton: View {\n @State var isActive = false\n @State var selections = Set()\n\n let onSelect: ([InputSource]) -> Void\n\n var body: some View {\n Button(\"Add Switch Group\".i18n(), systemImage: \"plus.circle\") {\n isActive = true\n }\n .sheet(isPresented: $isActive, content: {\n VStack(alignment: .leading) {\n Text(\"Select Input Sources\".i18n())\n .font(.title)\n .padding(.bottom, 4)\n\n Text(\"Add a switch group to allow switching between multiple input sources using the same hotkey. Select at least two input sources.\".i18n())\n .lineLimit(nil)\n .multilineTextAlignment(.leading)\n .frame(width: 500)\n\n VStack(alignment: .leading) {\n ForEach(InputSource.sources, id: \\.id) { inputSource in\n VStack(alignment: .leading) {\n HStack(spacing: 6) {\n if selections.contains(inputSource.id) {\n Image(systemName: \"checkmark.circle.fill\")\n .foregroundColor(Color.accentColor)\n .font(.system(size: 16))\n } else {\n Image(systemName: \"circle\")\n .foregroundColor(.gray)\n .font(.system(size: 16))\n }\n\n Text(inputSource.name)\n }\n .frame(height: 12)\n\n Divider()\n }\n .contentShape(Rectangle())\n .onTapGesture {\n if selections.contains(inputSource.id) {\n selections.remove(inputSource.id)\n } else {\n selections.insert(inputSource.id)\n }\n }\n }\n }\n .padding(.vertical)\n\n HStack {\n Spacer()\n\n Button(\"Cancel\".i18n()) { hide() }\n .keyboardShortcut(.cancelAction)\n Button(\"Add\".i18n()) { add() }\n .keyboardShortcut(.defaultAction)\n .disabled(selections.count < 2)\n }\n }\n .padding()\n })\n }\n\n func add() {\n onSelect(InputSource.sources.filter { selections.contains($0.id) })\n hide()\n }\n\n func hide() {\n isActive = false\n selections.removeAll()\n }\n}\n\nstruct MultipleSelectionRow: View {\n var title: String\n var isSelected: Bool\n var action: () -> Void\n\n var body: some View {\n Button(action: action) {\n HStack {\n Text(self.title)\n if self.isSelected {\n Spacer()\n Image(systemName: \"checkmark\")\n }\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Utilities/ButtonStyle.swift", "import SwiftUI\n\nstruct GhostButton: ButtonStyle {\n @State var isHover = false\n\n let icon: Icon\n\n func makeBody(configuration: Configuration) -> some View {\n HStack(spacing: 4) {\n icon\n\n if isHover {\n configuration.label\n .scaleEffect(0.9)\n }\n }\n .padding(.vertical, 4)\n .padding(.horizontal, 6)\n .opacity(isHover ? 1 : 0.6)\n .background(Color.gray.opacity(configuration.isPressed ? 0.6 : isHover ? 0.3 : 0))\n .clipShape(Capsule())\n .animation(.easeOut(duration: 0.2), value: configuration.isPressed)\n .onHover { hover in\n withAnimation {\n isHover = hover\n }\n }\n }\n}\n\nstruct SectionButtonStyle: ButtonStyle {\n func makeBody(configuration: Self.Configuration) -> some View {\n configuration.label\n .padding()\n .frame(maxWidth: .infinity)\n .background(configuration.isPressed ? Color.gray.opacity(0.05) : Color.clear)\n .foregroundColor(Color.accentColor)\n .clipShape(RoundedRectangle(cornerRadius: 6))\n .contentShape(Rectangle())\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/RulesApplicationPicker.swift", "import SwiftUI\n\nstruct ApplicationPicker: View {\n @Binding var selectedApp: Set\n\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n @FetchRequest(sortDescriptors: [NSSortDescriptor(key: \"bundleName\", ascending: true)])\n var appCustomizations: FetchedResults\n\n let appIconSize: CGFloat = 18\n let keyboardIconSize: CGFloat = 16\n\n var body: some View {\n VStack(spacing: 0) {\n List(appCustomizations, id: \\.self, selection: $selectedApp) { app in\n HStack {\n if let image = app.image {\n SwiftUI.Image(nsImage: image)\n .resizable()\n .frame(width: appIconSize, height: appIconSize)\n } else {\n SwiftUI.Image(systemName: \"app.dashed\")\n .resizable()\n .frame(width: appIconSize, height: appIconSize)\n }\n\n Text(app.bundleName ?? \"(unknown)\")\n .lineLimit(1)\n\n Spacer()\n\n if app.hideIndicator {\n SwiftUI.Image(systemName: \"eye.slash.circle.fill\")\n .opacity(0.7)\n }\n\n if preferencesVM.needDisplayEnhancedModePrompt(bundleIdentifier: app.bundleId) {\n SwiftUI.Image(systemName: \"exclamationmark.triangle.fill\")\n .foregroundColor(Color(red: 1.0, green: 0.84, blue: 0.0))\n }\n\n if preferencesVM.preferences.isRestorePreviouslyUsedInputSource {\n if app.doNotRestoreKeyboard {\n SwiftUI.Image(systemName: \"d.circle.fill\")\n .foregroundColor(selectedApp.contains(app) ? .primary : .green)\n .opacity(selectedApp.contains(app) ? 0.7 : 1.0)\n }\n } else {\n if app.doRestoreKeyboard {\n SwiftUI.Image(systemName: \"arrow.uturn.left.circle.fill\")\n .foregroundColor(selectedApp.contains(app) ? .primary : .blue)\n .opacity(selectedApp.contains(app) ? 0.7 : 1.0)\n }\n }\n\n if let icon = app.forcedKeyboard?.icon {\n SwiftUI.Image(nsImage: icon)\n .resizable()\n .scaledToFit()\n .frame(width: keyboardIconSize, height: keyboardIconSize)\n .opacity(0.7)\n }\n }\n .help(app.bundleName ?? app.url?.path ?? \"(unknown)\")\n }\n .listRowInsets(EdgeInsets())\n }\n .onAppear {\n if let app = appCustomizations.first {\n selectedApp.update(with: app)\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/IndicatorVM+Triggers.swift", "import AppKit\nimport AXSwift\nimport Combine\nimport CombineExt\n\nextension IndicatorVM {\n @MainActor\n enum ActivateEvent {\n case justHide\n case longMouseDown\n case appChanges(current: AppKind?, prev: AppKind?)\n case inputSourceChanges(InputSource, InputSourceChangeReason)\n\n func isAppChangesWithSameAppOrWebsite() -> Bool {\n switch self {\n case let .appChanges(current, prev):\n return current?.isSameAppOrWebsite(with: prev) == true\n case .inputSourceChanges:\n return false\n case .longMouseDown:\n return false\n case .justHide:\n return false\n }\n }\n\n var isJustHide: Bool {\n switch self {\n case .justHide: return true\n default: return false\n }\n }\n }\n\n func longMouseDownPublisher() -> AnyPublisher {\n AnyPublisher\n .create { observer in\n let monitor = NSEvent.addGlobalMonitorForEvents(\n matching: [.leftMouseDown, .leftMouseUp, .leftMouseDragged],\n handler: { observer.send($0) }\n )\n\n return AnyCancellable { NSEvent.removeMonitor(monitor!) }\n }\n .flatMapLatest { event -> AnyPublisher in\n if event.type == .leftMouseDown {\n return Timer\n .delay(seconds: 0.35)\n .mapToVoid()\n .eraseToAnyPublisher()\n } else {\n return Empty().eraseToAnyPublisher()\n }\n }\n .filter { [weak self] _ in\n self?.preferencesVM.preferences.isActiveWhenLongpressLeftMouse ?? false\n }\n .mapTo(.longMouseDown)\n }\n\n func stateChangesPublisher() -> AnyPublisher {\n $state\n .withPrevious()\n .map { [weak self] previous, current -> ActivateEvent in\n if let preferencesVM = self?.preferencesVM {\n if previous?.appKind?.getId() != current.appKind?.getId() {\n let event = ActivateEvent.appChanges(current: current.appKind, prev: previous?.appKind)\n\n if preferencesVM.preferences.isActiveWhenSwitchApp || preferencesVM.preferences.isActiveWhenFocusedElementChangesEnabled {\n if preferencesVM.preferences.isHideWhenSwitchAppWithForceKeyboard {\n switch current.inputSourceChangeReason {\n case let .appSpecified(status):\n switch status {\n case .cached:\n return event\n case .specified:\n return .justHide\n }\n default:\n return .justHide\n }\n } else {\n return event\n }\n } else {\n return .justHide\n }\n }\n\n if previous?.inputSource.id != current.inputSource.id {\n switch current.inputSourceChangeReason {\n case .noChanges:\n return .justHide\n case .system, .shortcut, .appSpecified:\n guard preferencesVM.preferences.isActiveWhenSwitchInputSource else { return .justHide }\n return .inputSourceChanges(current.inputSource, current.inputSourceChangeReason)\n }\n }\n }\n\n return .justHide\n }\n .eraseToAnyPublisher()\n }\n}\n\nextension IndicatorVM.ActivateEvent: @preconcurrency CustomStringConvertible {\n var description: String {\n switch self {\n case let .appChanges(current, prev):\n return \"appChanges(\\(String(describing: current)), \\(String(describing: prev))\"\n case .inputSourceChanges:\n return \"inputSourceChanges\"\n case .longMouseDown:\n return \"longMouseDown\"\n case .justHide:\n return \"justHide\"\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/BrowserPermissionRequestView.swift", "import Combine\nimport SwiftUI\n\nstruct BrowserPermissionRequestView: View {\n @EnvironmentObject var permissionsVM: PermissionsVM\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n @Binding var isPresented: Bool\n\n @State var isDisableTips: Bool = true\n\n var onSuccess: () -> Void\n\n let timer = Timer\n .interval(seconds: 1)\n .mapToVoid()\n .ignoreFailure()\n .eraseToAnyPublisher()\n\n let fakeTimer = Empty(outputType: Void.self, failureType: Never.self)\n .eraseToAnyPublisher()\n\n var body: some View {\n VStack {\n Text(\"Permission Required\")\n .font(.title)\n .fontWeight(.medium)\n .padding(.vertical, 10)\n\n VStack(alignment: .leading) {\n Text(\"Browser Rules Accessibility Permission Description\")\n\n HStack {\n Spacer()\n\n if permissionsVM.isAccessibilityEnabled {\n SwiftUI.Image(systemName: \"checkmark.circle.fill\")\n .resizable()\n .frame(width: 16, height: 16)\n .foregroundColor(.green)\n\n Button(\"Authorized\", action: openAccessibilityPreferences)\n .disabled(true)\n } else {\n Button(\"Open Accessibility Preferences\", action: openAccessibilityPreferences)\n .keyboardShortcut(.defaultAction)\n }\n }\n .padding(.top, 5)\n }\n\n Divider()\n .padding(.vertical, 10)\n\n HStack {\n Button(action: URL.howToEnableBrowserRule.open) {\n SwiftUI.Image(systemName: \"questionmark\")\n }\n .font(.system(size: 10).weight(.bold))\n .frame(width: 18, height: 18)\n .clipShape(RoundedRectangle(cornerRadius: 99))\n .disabled(isDisableTips)\n\n Spacer()\n\n Button(\"Close\", action: close)\n .keyboardShortcut(.cancelAction)\n }\n }\n .lineLimit(nil)\n .fixedSize(horizontal: false, vertical: true)\n .padding()\n .frame(width: 400)\n .onAppear {\n DispatchQueue.main.async {\n isDisableTips = false\n }\n }\n .onChange(of: permissionsVM.isAccessibilityEnabled) { _ in\n onAuthorizeSuccess()\n }\n }\n\n func close() {\n isPresented = false\n }\n\n func openAccessibilityPreferences() {\n NSWorkspace.shared.openAccessibilityPreferences()\n }\n\n func openAutomationPreferences() {\n NSWorkspace.shared.openAutomationPreferences()\n }\n\n func onAuthorizeSuccess() {\n onSuccess()\n close()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/AccessibilityPermissionRequestView.swift", "import SwiftUI\n\nstruct AccessibilityPermissionRequestView: View {\n @EnvironmentObject var permissionsVM: PermissionsVM\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n @Binding var isPresented: Bool\n\n @State var isDisableTips: Bool = true\n\n var body: some View {\n VStack(alignment: .leading) {\n Text(.init(\"Enhanced Mode Permission Description\".i18n()))\n .lineSpacing(4)\n\n HStack {\n Button(action: URL.howToEnableAccessbility.open) {\n SwiftUI.Image(systemName: \"questionmark\")\n }\n .font(.system(size: 10).weight(.bold))\n .frame(width: 18, height: 18)\n .clipShape(RoundedRectangle(cornerRadius: 99))\n .disabled(isDisableTips)\n\n Spacer()\n\n Button(\"Open Accessibility Preferences\") {\n NSWorkspace.shared.openAccessibilityPreferences()\n }\n .keyboardShortcut(.defaultAction)\n\n Button(\"Cancel\", action: cancel)\n .keyboardShortcut(.cancelAction)\n }\n .padding(.top)\n }\n .padding()\n .lineLimit(nil)\n .frame(width: 400)\n .onChange(of: permissionsVM.isAccessibilityEnabled, perform: whenAccessibilityEnabled)\n .onAppear {\n DispatchQueue.main.async {\n isDisableTips = false\n }\n }\n }\n\n func cancel() {\n isPresented = false\n }\n\n func whenAccessibilityEnabled(_ isAccessibilityEnabled: Bool) {\n if isAccessibilityEnabled {\n isPresented = false\n preferencesVM.update {\n $0.isEnhancedModeEnabled = true\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/RulesSettingsView.swift", "import SwiftUI\n\nstruct RulesSettingsView: View {\n @State var selectedApp = Set()\n\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n var items: [PickerItem] {\n [PickerItem.empty]\n + InputSource.sources.map { PickerItem(id: $0.id, title: $0.name, toolTip: $0.id) }\n }\n\n var body: some View {\n VStack(alignment: .leading, spacing: 0) {\n HStack(spacing: 0) {\n VStack(alignment: .leading, spacing: 0) {\n ApplicationPicker(selectedApp: $selectedApp)\n .border(width: 1, edges: [.bottom], color: Color(NSColor.gridColor))\n\n HStack(spacing: 5) {\n Button(action: selectApp) {\n SwiftUI.Image(systemName: \"plus\")\n }\n\n Button(action: removeApp) {\n SwiftUI.Image(systemName: \"minus\")\n }\n .disabled(selectedApp.isEmpty)\n\n RunningApplicationsPicker(onSelect: selectRunningApp)\n }\n .padding(10)\n }\n .frame(width: 245)\n .border(width: 1, edges: [.trailing], color: Color(NSColor.gridColor))\n\n ApplicationDetail(selectedApp: $selectedApp)\n .padding()\n\n Spacer(minLength: 0)\n }\n }\n }\n\n func selectApp() {\n let panel = NSOpenPanel()\n\n panel.allowsMultipleSelection = true\n panel.canChooseDirectories = false\n panel.allowedContentTypes = [.application]\n\n if let applicationPath = NSSearchPathForDirectoriesInDomains(\n .applicationDirectory,\n .localDomainMask,\n true\n ).first {\n panel.directoryURL = URL(fileURLWithPath: applicationPath, isDirectory: true)\n }\n\n if panel.runModal() == .OK {\n selectedApp = Set(panel.urls.map {\n preferencesVM.addAppCustomization($0, bundleId: $0.bundleId())\n })\n }\n }\n\n func removeApp() {\n for app in selectedApp {\n preferencesVM.removeAppCustomization(app)\n }\n selectedApp.removeAll()\n }\n\n func selectRunningApp(_ app: NSRunningApplication) {\n if let appRule = preferencesVM.addAppCustomization(app) {\n selectedApp = Set([appRule])\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Controllers/StatusItemController.swift", "import Cocoa\nimport Combine\n\n@MainActor\nclass StatusItemController {\n let navigationVM: NavigationVM\n let permissionsVM: PermissionsVM\n let preferencesVM: PreferencesVM\n let applicationVM: ApplicationVM\n let indicatorVM: IndicatorVM\n let feedbackVM: FeedbackVM\n let inputSourceVM: InputSourceVM\n\n let cancelBag = CancelBag()\n\n var statusItem: NSStatusItem?\n var hasPreferencesShown = false\n\n var addRuleMenu: NSMenuItem? {\n guard let app = applicationVM.appKind?.getApp() else { return nil }\n\n var items: [NSMenuItem] = [\n AppRuleMenuItem(app: app, preferencesVM: preferencesVM, inputSource: nil),\n NSMenuItem.separator(),\n ]\n\n items[0].toolTip = \"Default Keyboard Tooltip\".i18n()\n\n items += InputSource.sources.map {\n AppRuleMenuItem(app: app, preferencesVM: preferencesVM, inputSource: $0)\n }\n\n items\n .filter { (($0 as? AppRuleMenuItem) != nil) ? true : false }\n .enumerated()\n .forEach { index, item in\n if index < 10 {\n item.keyEquivalent = \"\\(index)\"\n item.keyEquivalentModifierMask = .command\n }\n }\n\n let menu = NSMenuItem(\n title: String(format: \"Default Keyboard for %@\".i18n(), app.localizedName ?? \"Current App\".i18n()),\n submenuItems: items\n )\n\n menu.toolTip = app.bundleIdentifier\n\n return menu\n }\n\n var addBrowserRuleMenu: NSMenuItem? {\n guard let browserInfo = applicationVM.appKind?.getBrowserInfo(),\n let host = browserInfo.url.host\n else { return nil }\n\n var items: [NSMenuItem] = [\n BrowserRuleMenuItem(url: browserInfo.url, preferencesVM: preferencesVM, inputSource: nil),\n NSMenuItem.separator(),\n ]\n\n items[0].toolTip = \"Default Keyboard Tooltip\".i18n()\n\n items += InputSource.sources.map {\n BrowserRuleMenuItem(url: browserInfo.url, preferencesVM: preferencesVM, inputSource: $0)\n }\n\n items\n .filter { (($0 as? BrowserRuleMenuItem) != nil) ? true : false }\n .enumerated()\n .forEach { index, item in\n if index < 10 {\n item.keyEquivalent = \"\\(index)\"\n item.keyEquivalentModifierMask = .command\n }\n }\n\n return NSMenuItem(\n title: String(format: \"Default Keyboard for %@\".i18n(), host),\n submenuItems: items\n )\n }\n\n var settingsMenu: NSMenuItem? {\n NSMenuItem(\n title: \"Preferences\".i18n() + \"...\",\n target: self,\n action: #selector(openPreferences),\n keyEquivalent: \",\"\n )\n }\n\n var changelogMenu: NSMenuItem? {\n NSMenuItem(\n title: \"Changelog\".i18n(),\n target: self,\n action: #selector(openChangelog),\n keyEquivalent: \"\"\n )\n }\n\n var checkUpdatesMenu: NSMenuItem? {\n NSMenuItem(\n title: \"Check for Updates\".i18n() + \"...\",\n target: self,\n action: #selector(checkForUpdates),\n keyEquivalent: \"\"\n )\n }\n\n var menu: NSMenu {\n let menu = NSMenu()\n\n let items = [\n NSMenuItem(title: \"Input Source Pro\".i18n(), action: nil, keyEquivalent: \"\"),\n addBrowserRuleMenu ?? addRuleMenu,\n NSMenuItem.separator(),\n changelogMenu,\n checkUpdatesMenu,\n settingsMenu,\n NSMenuItem.separator(),\n NSMenuItem(\n title: \"Quit\".i18n(),\n action: #selector(NSApplication.shared.terminate(_:)),\n keyEquivalent: \"q\"\n ),\n ]\n .compactMap { $0 }\n\n items.forEach { menu.addItem($0) }\n\n return menu\n }\n\n lazy var preferencesWindowController = PreferencesWindowController(\n navigationVM: self.navigationVM,\n permissionsVM: self.permissionsVM,\n preferencesVM: self.preferencesVM,\n indicatorVM: self.indicatorVM,\n feedbackVM: self.feedbackVM,\n inputSourceVM: self.inputSourceVM\n )\n\n init(\n navigationVM: NavigationVM,\n permissionsVM: PermissionsVM,\n preferencesVM: PreferencesVM,\n applicationVM: ApplicationVM,\n indicatorVM: IndicatorVM,\n feedbackVM: FeedbackVM,\n inputSourceVM: InputSourceVM\n ) {\n self.navigationVM = navigationVM\n self.permissionsVM = permissionsVM\n self.preferencesVM = preferencesVM\n self.applicationVM = applicationVM\n self.indicatorVM = indicatorVM\n self.feedbackVM = feedbackVM\n self.inputSourceVM = inputSourceVM\n\n preferencesVM.$preferences\n .map(\\.isShowIconInMenuBar)\n .removeDuplicates()\n .map { isShow -> AnyPublisher in\n if isShow {\n return AnyPublisher.create { [unowned self] _ in\n statusItem = NSStatusBar.system.statusItem(\n withLength: NSStatusItem.squareLength\n )\n\n statusItem?.button?.image = NSImage(named: \"MenuBarIcon\")\n statusItem?.button?.image?.size = NSSize(width: 16, height: 16)\n statusItem?.button?.image?.isTemplate = true\n statusItem?.button?.target = self\n statusItem?.button?.action = #selector(self.displayMenu)\n\n return AnyCancellable { [unowned self] in\n self.statusItem = nil\n }\n }\n } else {\n return Empty().eraseToAnyPublisher()\n }\n }\n .switchToLatest()\n .sink {}\n .store(in: cancelBag)\n }\n\n @objc func displayMenu() {\n // https://stackoverflow.com/a/57612963\n statusItem?.menu = menu\n statusItem?.button?.performClick(nil)\n statusItem?.menu = nil\n }\n\n @objc func openPreferences() {\n NSApp.setActivationPolicy(.regular)\n NSApplication.shared.activate(ignoringOtherApps: true)\n if let window = preferencesWindowController.window {\n DispatchQueue.main.async {\n if !self.hasPreferencesShown {\n self.hasPreferencesShown = true\n window.center()\n }\n \n window.makeKeyAndOrderFront(nil)\n }\n }\n }\n\n @objc func openChangelog() {\n if let url = URL(string: \"https://inputsource.pro/changelog\") {\n NSWorkspace.shared.open(url)\n }\n }\n\n @objc func checkForUpdates() {\n preferencesVM.checkUpdates()\n }\n\n @objc func openFeedback() {\n feedbackVM.show()\n navigationVM.selection = .troubleshooting\n openPreferences()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/IndicatorVM.swift", "import AppKit\nimport AXSwift\nimport Carbon\nimport Combine\nimport CombineExt\nimport KeyboardShortcuts\nimport os\n\n@MainActor\nfinal class IndicatorVM: ObservableObject {\n private var cancelBag = CancelBag()\n\n let applicationVM: ApplicationVM\n let preferencesVM: PreferencesVM\n let inputSourceVM: InputSourceVM\n let permissionsVM: PermissionsVM\n\n let logger = ISPLogger(category: String(describing: IndicatorVM.self))\n\n @Published\n private(set) var state: State\n\n var actionSubject = PassthroughSubject()\n\n var refreshShortcutSubject = PassthroughSubject()\n\n private(set) lazy var activateEventPublisher = Publishers.MergeMany([\n longMouseDownPublisher(),\n stateChangesPublisher(),\n ])\n .share()\n\n private(set) lazy var screenIsLockedPublisher = Publishers.MergeMany([\n DistributedNotificationCenter.default()\n .publisher(for: Notification.Name(rawValue: \"com.apple.screenIsLocked\"))\n .mapTo(true),\n\n DistributedNotificationCenter.default()\n .publisher(for: NSWorkspace.willSleepNotification)\n .mapTo(true),\n\n DistributedNotificationCenter.default()\n .publisher(for: Notification.Name(rawValue: \"com.apple.screenIsUnlocked\"))\n .mapTo(false),\n\n DistributedNotificationCenter.default()\n .publisher(for: NSWorkspace.didWakeNotification)\n .mapTo(false),\n ])\n .receive(on: DispatchQueue.main)\n .prepend(false)\n .removeDuplicates()\n .share()\n\n init(\n permissionsVM: PermissionsVM,\n preferencesVM: PreferencesVM,\n applicationVM: ApplicationVM,\n inputSourceVM: InputSourceVM\n ) {\n self.permissionsVM = permissionsVM\n self.preferencesVM = preferencesVM\n self.applicationVM = applicationVM\n self.inputSourceVM = inputSourceVM\n state = .from(\n preferencesVM: preferencesVM,\n inputSourceChangeReason: .system,\n applicationVM.appKind,\n InputSource.getCurrentInputSource()\n )\n\n clearAppKeyboardCacheIfNeed()\n watchState()\n }\n\n private func clearAppKeyboardCacheIfNeed() {\n applicationVM.$appsDiff\n .sink { [weak self] appsDiff in\n appsDiff.removed\n .compactMap { $0.bundleIdentifier }\n .forEach { bundleId in\n self?.preferencesVM.removeKeyboardCacheFor(bundleId: bundleId)\n }\n }\n .store(in: cancelBag)\n\n preferencesVM.$preferences\n .map(\\.isRestorePreviouslyUsedInputSource)\n .filter { $0 == false }\n .sink { [weak self] _ in\n self?.preferencesVM.clearKeyboardCache()\n }\n .store(in: cancelBag)\n }\n}\n\nextension IndicatorVM {\n enum InputSourceChangeReason {\n case noChanges, system, shortcut, appSpecified(PreferencesVM.AppAutoSwitchKeyboardStatus)\n }\n\n @MainActor\n struct State {\n let appKind: AppKind?\n let inputSource: InputSource\n let inputSourceChangeReason: InputSourceChangeReason\n\n func isSame(with other: State) -> Bool {\n return State.isSame(self, other)\n }\n\n static func isSame(_ lhs: IndicatorVM.State, _ rhs: IndicatorVM.State) -> Bool {\n guard let appKind1 = lhs.appKind, let appKind2 = rhs.appKind\n else { return lhs.appKind == nil && rhs.appKind == nil }\n\n guard appKind1.isSameAppOrWebsite(with: appKind2, detectAddressBar: true)\n else { return false }\n\n guard lhs.inputSource.id == rhs.inputSource.id\n else { return false }\n\n return true\n }\n\n static func from(\n preferencesVM _: PreferencesVM,\n inputSourceChangeReason: InputSourceChangeReason,\n _ appKind: AppKind?,\n _ inputSource: InputSource\n ) -> State {\n return .init(\n appKind: appKind,\n inputSource: inputSource,\n inputSourceChangeReason: inputSourceChangeReason\n )\n }\n }\n\n enum Action {\n case start\n case appChanged(AppKind)\n case switchInputSourceByShortcut(InputSource)\n case inputSourceChanged(InputSource)\n }\n\n func send(_ action: Action) {\n actionSubject.send(action)\n }\n\n func refreshShortcut() {\n refreshShortcutSubject.send(())\n }\n\n func watchState() {\n actionSubject\n .scan(state) { [weak self] state, action -> State in\n guard let preferencesVM = self?.preferencesVM,\n let inputSourceVM = self?.inputSourceVM\n else { return state }\n\n @MainActor\n func updateState(appKind: AppKind?, inputSource: InputSource, inputSourceChangeReason: InputSourceChangeReason) -> State {\n // TODO: Move to outside\n if let appKind = appKind {\n preferencesVM.cacheKeyboardFor(appKind, keyboard: inputSource)\n }\n\n return .from(\n preferencesVM: preferencesVM,\n inputSourceChangeReason: inputSourceChangeReason,\n appKind,\n inputSource\n )\n }\n\n switch action {\n case .start:\n return state\n case let .appChanged(appKind):\n if let status = preferencesVM.getAppAutoSwitchKeyboard(appKind) {\n inputSourceVM.select(inputSource: status.inputSource)\n\n return updateState(\n appKind: appKind,\n inputSource: status.inputSource,\n inputSourceChangeReason: .appSpecified(status)\n )\n } else {\n return updateState(\n appKind: appKind,\n inputSource: state.inputSource,\n inputSourceChangeReason: .noChanges\n )\n }\n case let .inputSourceChanged(inputSource):\n guard inputSource.id != state.inputSource.id else { return state }\n\n return updateState(appKind: state.appKind, inputSource: inputSource, inputSourceChangeReason: .system)\n case let .switchInputSourceByShortcut(inputSource):\n inputSourceVM.select(inputSource: inputSource)\n\n return updateState(appKind: state.appKind, inputSource: inputSource, inputSourceChangeReason: .shortcut)\n }\n }\n .removeDuplicates(by: { $0.isSame(with: $1) })\n .assign(to: &$state)\n\n applicationVM.$appKind\n .compactMap { $0 }\n .sink(receiveValue: { [weak self] in self?.send(.appChanged($0)) })\n .store(in: cancelBag)\n\n inputSourceVM.inputSourceChangesPublisher\n .sink(receiveValue: { [weak self] in self?.send(.inputSourceChanged($0)) })\n .store(in: cancelBag)\n\n refreshShortcutSubject\n .sink { [weak self] _ in\n KeyboardShortcuts.removeAllHandlers()\n\n for inputSource in InputSource.sources {\n KeyboardShortcuts.onKeyUp(for: .init(inputSource.id)) {\n self?.send(.switchInputSourceByShortcut(inputSource))\n }\n }\n\n self?.preferencesVM.getHotKeyGroups().forEach { group in\n KeyboardShortcuts.onKeyUp(for: .init(group.id!)) {\n guard group.inputSources.count > 0 else { return }\n\n let currIps = InputSource.getCurrentInputSource()\n let nextIdx = (\n (group.inputSources.firstIndex(where: { currIps.id == $0.id }) ?? -1) + 1\n ) % group.inputSources.count\n\n self?.send(.switchInputSourceByShortcut(group.inputSources[nextIdx]))\n }\n }\n }\n .store(in: cancelBag)\n\n refreshShortcut()\n send(.start)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Utilities/AlignedWidth.swift", "import SwiftUI\n\n// https://stackoverflow.com/a/63997630\n\n// The preference key used to advise parent views of a change in value.\nstruct AlignedWidthPreferenceKey: PreferenceKey {\n static var defaultValue: CGFloat = .zero\n\n static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {\n value = max(value, nextValue())\n }\n}\n\nextension View {\n func alignedView(width: Binding, alignment: Alignment = .trailing) -> some View {\n modifier(AlignedWidthView(width: width, alignment: alignment))\n }\n}\n\nstruct AlignedWidthView: ViewModifier {\n @Binding var width: CGFloat\n\n var alignment: Alignment\n\n func body(content: Content) -> some View {\n content\n .background(GeometryReader {\n Color.clear.preference(\n key: AlignedWidthPreferenceKey.self,\n value: $0.frame(in: .local).size.width\n )\n })\n .onPreferenceChange(AlignedWidthPreferenceKey.self) {\n if $0 > self.width {\n self.width = $0\n }\n }\n .frame(minWidth: width, alignment: alignment)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/KeyboardsSettingsView.swift", "import KeyboardShortcuts\nimport SwiftUI\n\nstruct KeyboardsSettingsView: View {\n @FetchRequest(sortDescriptors: [NSSortDescriptor(key: \"createdAt\", ascending: true)])\n var hotKeyGroups: FetchedResults\n\n @EnvironmentObject var preferencesVM: PreferencesVM\n @EnvironmentObject var indicatorVM: IndicatorVM\n\n let imgSize: CGFloat = 16\n\n var body: some View {\n ScrollView {\n VStack(spacing: 0) {\n normalSection\n groupSection\n AddSwitchingGroupButton(onSelect: preferencesVM.addHotKeyGroup)\n }\n .padding()\n }\n .background(NSColor.background1.color)\n }\n\n var normalSection: some View {\n ForEach(InputSource.sources, id: \\.id) { inputSource in\n SettingsSection(title: \"\") {\n HStack {\n CustomizedIndicatorView(inputSource: inputSource)\n .help(inputSource.id)\n\n Spacer()\n\n KeyboardShortcuts.Recorder(for: .init(inputSource.id), onChange: { _ in\n indicatorVM.refreshShortcut()\n })\n }\n .padding()\n }\n .padding(.bottom)\n }\n }\n\n var groupSection: some View {\n ForEach(hotKeyGroups, id: \\.self) { group in\n SettingsSection(title: \"\") {\n HStack(alignment: .top) {\n VStack(alignment: .leading) {\n ForEach(group.inputSources, id: \\.id) { inputSource in\n CustomizedIndicatorView(inputSource: inputSource)\n .help(inputSource.id)\n }\n }\n\n Spacer()\n\n VStack(alignment: .trailing) {\n KeyboardShortcuts.Recorder(for: .init(group.id!), onChange: { _ in\n indicatorVM.refreshShortcut()\n })\n\n HStack {\n Button(\"Delete\".i18n()) {\n deleteGroup(group: group)\n }\n }\n }\n }\n .padding()\n }\n .padding(.bottom)\n }\n }\n\n func deleteGroup(group: HotKeyGroup) {\n KeyboardShortcuts.reset([.init(group.id!)])\n preferencesVM.deleteHotKeyGroup(group)\n indicatorVM.refreshShortcut()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/MockWindowView.swift", "import SwiftUI\nimport VisualEffects\n\nstruct MockWindowView: View {\n var body: some View {\n ZStack {\n VisualEffectBlur(\n material: .windowBackground,\n blendingMode: .withinWindow,\n state: .active\n )\n\n VStack {\n HStack {\n Circle()\n .frame(width: 10, height: 10)\n .foregroundColor(Color(NSColor.close))\n\n Circle()\n .frame(width: 10, height: 10)\n .foregroundColor(Color(NSColor.minimise))\n\n Circle()\n .frame(width: 10, height: 10)\n .foregroundColor(Color(NSColor.maximise))\n Spacer()\n }\n Spacer()\n }\n .padding(10)\n }\n .clipShape(RoundedRectangle(cornerRadius: 9))\n .shadow(color: Color.black.opacity(0.2), radius: 5, x: 3, y: 3)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/TroubleshootingSettingsView.swift", "import SwiftUI\n\nstruct TroubleshootingSettingsView: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n @State var isShowCJKVFixEnableFailedView = false\n\n var body: some View {\n let isCJKVFixEnabledBinding = Binding(\n get: { preferencesVM.preferences.isCJKVFixEnabled },\n set: { onToggleCJKVFix($0) }\n )\n\n ScrollView {\n VStack(spacing: 18) {\n SettingsSection(title: \"\") {\n VStack(alignment: .leading) {\n HStack {\n Toggle(\"\", isOn: isCJKVFixEnabledBinding)\n .disabled(!preferencesVM.preferences.isEnhancedModeEnabled)\n .toggleStyle(.switch)\n .labelsHidden()\n\n Text(\"Enabled CJKV Fix\".i18n())\n .font(.headline)\n\n Spacer()\n\n EnhancedModeRequiredBadge()\n }\n\n Text(.init(\"Enabled CJKV Fix Description\".i18n()))\n .font(.system(size: 12))\n .opacity(0.8)\n }\n .padding()\n }\n \n SettingsSection(title: \"\") {\n CursorLagFixView()\n }\n\n SettingsSection(title: \"\") {\n FeedbackButton()\n }\n }\n .padding()\n }\n .background(NSColor.background1.color)\n .sheet(isPresented: $isShowCJKVFixEnableFailedView) {\n CJKVFixEnableFailedView(isPresented: $isShowCJKVFixEnableFailedView)\n }\n }\n\n func onToggleCJKVFix(_ isCJKVFixEnabled: Bool) {\n if isCJKVFixEnabled {\n if InputSource.getSelectPreviousShortcut() == nil {\n isShowCJKVFixEnableFailedView = true\n } else {\n preferencesVM.update {\n $0.isCJKVFixEnabled = true\n }\n }\n } else {\n preferencesVM.update {\n $0.isCJKVFixEnabled = false\n }\n }\n }\n}\n\nenum CursorSettingStatus {\n case enabled\n case disabled\n case undefined\n case unknown\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Accessibility/AXSwift.swift", "import AXSwift\nimport Cocoa\n\nextension UIElement {\n func getCursorRectInfo() -> (rect: CGRect, isContainer: Bool)? {\n guard let focusedElement: UIElement = try? attribute(.focusedUIElement),\n Self.isInputContainer(focusedElement),\n let inputAreaRect = Self.findInputAreaRect(focusedElement)\n else { return nil }\n\n if let cursorRect = Self.findCursorRect(focusedElement),\n inputAreaRect.contains(cursorRect)\n {\n return (rect: cursorRect, isContainer: false)\n } else {\n return (rect: inputAreaRect, isContainer: true)\n }\n }\n}\n\nextension UIElement {\n static func isInputContainer(_ elm: UIElement?) -> Bool {\n guard let elm = elm,\n let role = try? elm.role()\n else { return false }\n\n return role == .textArea || role == .textField || role == .comboBox\n }\n\n static func findInputAreaRect(_ focusedElement: UIElement) -> CGRect? {\n if let parent: UIElement = try? focusedElement.attribute(.parent),\n let role = try? parent.role(),\n role == .scrollArea,\n let origin: CGPoint = try? parent.attribute(.position),\n let size: CGSize = try? parent.attribute(.size)\n {\n return NSScreen.convertFromQuartz(CGRect(origin: origin, size: size))\n }\n\n if let origin: CGPoint = try? focusedElement.attribute(.position),\n let size: CGSize = try? focusedElement.attribute(.size)\n {\n return NSScreen.convertFromQuartz(CGRect(origin: origin, size: size))\n }\n\n return nil\n }\n}\n\nextension UIElement {\n static func findCursorRect(_ focusedElement: UIElement) -> CGRect? {\n return findWebAreaCursor(focusedElement) ?? findNativeInputAreaCursor(focusedElement)\n }\n\n static func findWebAreaCursor(_ focusedElement: UIElement) -> CGRect? {\n guard let range: AXTextMarkerRange = try? focusedElement.attribute(\"AXSelectedTextMarkerRange\"),\n let bounds: CGRect = try? focusedElement.parameterizedAttribute(\"AXBoundsForTextMarkerRange\", param: range)\n else { return nil }\n\n return NSScreen.convertFromQuartz(bounds)\n }\n\n static func findNativeInputAreaCursor(_ focusedElement: UIElement) -> CGRect? {\n guard let selectedRange: CFRange = try? focusedElement.attribute(.selectedTextRange),\n let visibleRange: CFRange = try? focusedElement.attribute(.visibleCharacterRange),\n let rawValue: AnyObject = try? focusedElement.attribute(.value),\n CFGetTypeID(rawValue) == CFStringGetTypeID(),\n let value = rawValue as? String\n else { return nil }\n\n func getBounds(cursor location: Int) -> CGRect? {\n return try? focusedElement.parameterizedAttribute(\n kAXBoundsForRangeParameterizedAttribute,\n param: AXValue.range(CFRange(location: max(location, 0), length: 1))\n )\n .flatMap(NSScreen.convertFromQuartz)\n }\n\n func getCursorBounds() -> CGRect? {\n let lastCursor = visibleRange.location + visibleRange.length\n // Notes 最后存在两个换行符时会有问题\n // let isLastCursor = selectedRange.location >= (lastCursor - 1)\n let isLastCursor = selectedRange.location >= lastCursor\n let location = selectedRange.location - (isLastCursor ? 1 : 0)\n\n guard let bounds = getBounds(cursor: location)\n else { return nil }\n\n if isLastCursor, value.string(at: location) == \"\\n\" {\n if location > 0 {\n for offsetDiff in 1 ... location {\n let offset = location - offsetDiff\n\n if value.string(at: offset + 1) == \"\\n\",\n let prevNewLineBounds = getBounds(cursor: offset)\n {\n return CGRect(\n origin: CGPoint(\n x: prevNewLineBounds.origin.x,\n y: prevNewLineBounds.minY - prevNewLineBounds.height\n ),\n size: bounds.size\n )\n }\n }\n\n return nil\n } else {\n return nil\n }\n } else {\n return bounds\n }\n }\n\n func getLineBounds() -> CGRect? {\n guard let cursorLine: Int = try? focusedElement.attribute(.insertionPointLineNumber),\n let lineRange: CFRange = try? focusedElement.parameterizedAttribute(\"AXRangeForLine\", param: cursorLine),\n let bounds: CGRect = try? focusedElement.parameterizedAttribute(\n kAXBoundsForRangeParameterizedAttribute,\n param: AXValue.range(lineRange)\n )\n else { return nil }\n\n return NSScreen.convertFromQuartz(bounds)\n }\n\n return getCursorBounds() ?? getLineBounds()\n }\n}\n\nextension UIElement {\n func children() -> [UIElement]? {\n guard let children: [AXUIElement] = try? attribute(.children)\n else { return nil }\n\n return children.map { .init($0) }\n }\n}\n\nextension Role {\n static let validInputElms: [Role] = [.comboBox, .textArea, .textField]\n\n static let allCases: [Role] = [\n .unknown,\n .button,\n .radioButton,\n .checkBox,\n .slider,\n .tabGroup,\n .textField,\n .staticText,\n .textArea,\n .scrollArea,\n .popUpButton,\n .menuButton,\n .table,\n .application,\n .group,\n .radioGroup,\n .list,\n .scrollBar,\n .valueIndicator,\n .image,\n .menuBar,\n .menu,\n .menuItem,\n .column,\n .row,\n .toolbar,\n .busyIndicator,\n .progressIndicator,\n .window,\n .drawer,\n .systemWide,\n .outline,\n .incrementor,\n .browser,\n .comboBox,\n .splitGroup,\n .splitter,\n .colorWell,\n .growArea,\n .sheet,\n .helpTag,\n .matte,\n .ruler,\n .rulerMarker,\n .link,\n .disclosureTriangle,\n .grid,\n .relevanceIndicator,\n .levelIndicator,\n .cell,\n .popover,\n .layoutArea,\n .layoutItem,\n .handle,\n ]\n}\n\nextension AXNotification {\n static let allCases: [AXNotification] = [\n .mainWindowChanged,\n .focusedWindowChanged,\n .focusedUIElementChanged,\n .applicationActivated,\n .applicationDeactivated,\n .applicationHidden,\n .applicationShown,\n .windowCreated,\n .windowMoved,\n .windowResized,\n .windowMiniaturized,\n .windowDeminiaturized,\n .drawerCreated,\n .sheetCreated,\n .uiElementDestroyed,\n .valueChanged,\n .titleChanged,\n .resized,\n .moved,\n .created,\n .layoutChanged,\n .helpTagCreated,\n .selectedTextChanged,\n .rowCountChanged,\n .selectedChildrenChanged,\n .selectedRowsChanged,\n .selectedColumnsChanged,\n .rowExpanded,\n .rowCollapsed,\n .selectedCellsChanged,\n .unitsChanged,\n .selectedChildrenMoved,\n .announcementRequested,\n ]\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/ColorBlock.swift", "import SwiftUI\n\nstruct ColorBlocks: View {\n typealias Scheme = (a: Color, b: Color)\n\n let onSelectColor: (Scheme) -> Void\n\n let colors: [Scheme] = [\n (.init(hex: \"#FFF\"), .init(hex: \"#000\")),\n (.init(hex: \"#FFF\"), .init(hex: \"#ef233c\")),\n (.init(hex: \"#FFF\"), .init(hex: \"#f77f00\")),\n (.init(hex: \"#000\"), .init(hex: \"#F6CB56\")),\n (.init(hex: \"#FFF\"), .init(hex: \"#2c6e49\")),\n (.init(hex: \"#FFF\"), .init(hex: \"#0c7489\")),\n (.init(hex: \"#FFF\"), .init(hex: \"#023e8a\")),\n (.init(hex: \"#FFF\"), .init(hex: \"#7209b7\")),\n ]\n\n var body: some View {\n HStack {\n ForEach(Array(zip(colors.indices, colors)), id: \\.0) { _, scheme in\n Spacer()\n ColorBlock(colorA: scheme.a, colorB: scheme.b)\n .onTapGesture {\n onSelectColor(scheme)\n }\n Spacer()\n }\n }\n }\n}\n\nstruct ColorBlock: View {\n let colorA: Color\n\n let colorB: Color\n\n var body: some View {\n RoundedRectangle(cornerRadius: 4)\n .fill(colorB)\n .overlay(\n SwiftUI.Image(systemName: \"textformat\")\n .foregroundColor(colorA)\n .font(.system(size: 12, weight: .semibold))\n )\n .frame(width: 28, height: 20)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/QuestionMark.swift", "import SwiftUI\n\nstruct QuestionMark: View {\n @State var isPresented: Bool = false\n\n let content: Content\n\n init(@ViewBuilder content: () -> Content) {\n self.content = content()\n }\n\n var body: some View {\n Button(action: { isPresented.toggle() }) {\n SwiftUI.Image(systemName: \"questionmark\")\n }\n .font(.system(size: 10).weight(.bold))\n .frame(width: 18, height: 18)\n .clipShape(RoundedRectangle(cornerRadius: 99))\n .popover(isPresented: $isPresented, arrowEdge: .top) {\n content\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/CursorLagFixView.swift", "import SwiftUI\n\nstruct CursorLagFixView: View {\n @State private var isCursorLagFixEnabled = false\n @State private var isRunningCommand = false\n @State private var isRebootRequired = false\n \n var body: some View {\n let toggleBinding = Binding(\n get: { isCursorLagFixEnabled },\n set: {\n isCursorLagFixEnabled = $0\n toggleRedesignedTextCursor(disable: $0)\n }\n )\n \n VStack(alignment: .leading, spacing: 12) {\n HStack {\n Toggle(\"\", isOn: toggleBinding)\n .disabled(isRunningCommand)\n .toggleStyle(.switch)\n .labelsHidden()\n \n Text(\"Cursor Lag Fix\".i18n())\n .font(.headline)\n \n Spacer()\n \n RebootRequiredBadge(isRequired: isRebootRequired)\n }\n \n Text(.init(\"Cursor Lag Fix Description\".i18n()))\n .font(.system(size: 12))\n .opacity(0.8)\n }\n .padding()\n .onAppear(perform: checkCursorSetting)\n }\n \n func toggleRedesignedTextCursor(disable: Bool) {\n guard !isRunningCommand else { return }\n \n let command = \"sudo defaults write /Library/Preferences/FeatureFlags/Domain/UIKit.plist redesigned_text_cursor -dict-add Enabled -bool \\(disable ? \"NO\" : \"YES\")\"\n \n isRunningCommand = true\n \n command.runCommand(\n requireSudo: true,\n completion: { _, _, _ in\n isRunningCommand = false\n isRebootRequired = true\n checkCursorSetting()\n }\n )\n }\n \n func checkCursorSetting() {\n guard !isRunningCommand else { return }\n \n let command = \"defaults read /Library/Preferences/FeatureFlags/Domain/UIKit.plist redesigned_text_cursor\"\n \n isRunningCommand = true\n \n command.runCommand(\n requireSudo: false,\n completion: { output, _, _ in\n isRunningCommand = false\n isCursorLagFixEnabled = output.contains(\"Enabled = 0\")\n }\n )\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Persistence/BrowserRule.swift", "import Cocoa\n\nenum BrowserRuleType: Int32, CaseIterable {\n case domainSuffix = 0\n case domain = 1\n case urlRegex = 2\n\n var name: String {\n switch self {\n case .domainSuffix:\n return \"DOMAIN-SUFFIX\"\n case .domain:\n return \"DOMAIN\"\n case .urlRegex:\n return \"URL-REGEX\"\n }\n }\n\n var explanation: String {\n return \"\\(name) Explanation\".i18n()\n }\n}\n\nextension BrowserRule {\n @MainActor\n var forcedKeyboard: InputSource? {\n guard let inputSourceId = inputSourceId else { return nil }\n\n return InputSource.sources.first { $0.id == inputSourceId }\n }\n\n var type: BrowserRuleType {\n get {\n return BrowserRuleType(rawValue: typeValue) ?? .domainSuffix\n }\n\n set {\n typeValue = newValue.rawValue\n }\n }\n\n func validate(url: URL) -> Bool {\n return Self.validate(type: type, url: url, value: value)\n }\n\n func id() -> String {\n return \"\\(type.name)_\\(value ?? \"\")_\\(createdAt?.timeIntervalSince1970 ?? 0)\"\n }\n}\n\nextension BrowserRule {\n static func validate(type: BrowserRuleType, url: URL, value: String?) -> Bool {\n switch type {\n case .domainSuffix:\n if let suffix = value,\n let host = url.host,\n let regex = try? NSRegularExpression(pattern: \"\\(suffix)$\", options: .caseInsensitive)\n {\n return regex.matches(host)\n }\n return false\n case .domain:\n return url.host == value\n case .urlRegex:\n if let regex = try? NSRegularExpression(pattern: value ?? \"\", options: .caseInsensitive) {\n return regex.matches(url.absoluteString)\n }\n return false\n }\n }\n}\n\nextension BrowserRule {\n var keyboardRestoreStrategy: KeyboardRestoreStrategy? {\n guard let rawValue = keyboardRestoreStrategyRaw\n else { return nil }\n\n return KeyboardRestoreStrategy(rawValue: rawValue)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Controllers/IndicatorWindowController.swift", "import AppKit\nimport AXSwift\nimport Carbon\nimport Combine\nimport CombineExt\nimport SnapKit\n\n@MainActor\nclass IndicatorWindowController: FloatWindowController {\n let permissionsVM: PermissionsVM\n let preferencesVM: PreferencesVM\n let indicatorVM: IndicatorVM\n let applicationVM: ApplicationVM\n let inputSourceVM: InputSourceVM\n\n let indicatorVC = IndicatorViewController()\n\n var isActive = false {\n didSet {\n if isActive {\n indicatorVC.view.animator().alphaValue = 1\n window?.displayIfNeeded()\n active()\n } else {\n indicatorVC.view.animator().alphaValue = 0\n deactive()\n }\n }\n }\n\n var cancelBag = CancelBag()\n\n init(\n permissionsVM: PermissionsVM,\n preferencesVM: PreferencesVM,\n indicatorVM: IndicatorVM,\n applicationVM: ApplicationVM,\n inputSourceVM: InputSourceVM\n ) {\n self.permissionsVM = permissionsVM\n self.preferencesVM = preferencesVM\n self.indicatorVM = indicatorVM\n self.applicationVM = applicationVM\n self.inputSourceVM = inputSourceVM\n\n super.init()\n\n contentViewController = indicatorVC\n\n let indicatorPublisher = indicatorVM.activateEventPublisher\n .receive(on: DispatchQueue.main)\n .map { (event: $0, inputSource: self.indicatorVM.state.inputSource) }\n .flatMapLatest { [weak self] params -> AnyPublisher in\n let event = params.event\n let inputSource = params.inputSource\n\n guard let self = self else { return Empty().eraseToAnyPublisher() }\n guard let appKind = self.applicationVM.appKind,\n !event.isJustHide,\n !preferencesVM.isHideIndicator(appKind)\n else { return self.justHidePublisher() }\n\n let app = appKind.getApp()\n\n if preferencesVM.isShowAlwaysOnIndicator(app: app) {\n return self.alwaysOnPublisher(event: event, inputSource: inputSource, appKind: appKind)\n } else if preferencesVM.needDetectFocusedFieldChanges(app: app) {\n return self.autoShowPublisher(event: event, inputSource: inputSource, appKind: appKind)\n } else {\n return self.autoHidePublisher(event: event, inputSource: inputSource, appKind: appKind)\n }\n }\n .eraseToAnyPublisher()\n\n indicatorVM.screenIsLockedPublisher\n .flatMapLatest { isLocked in isLocked ? Empty().eraseToAnyPublisher() : indicatorPublisher }\n .sink { _ in }\n .store(in: cancelBag)\n }\n\n @available(*, unavailable)\n required init?(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/EnhancedModeRequiredBadge.swift", "import SwiftUI\n\nstruct EnhancedModeRequiredBadge: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n var body: some View {\n Button(action: {}) {\n Text(\"Enhanced Mode Required\".i18n())\n }\n .buttonStyle(EnhanceModeRequiredButtonStyle())\n .opacity(preferencesVM.preferences.isEnhancedModeEnabled ? 0 : 1)\n .animation(.easeInOut, value: preferencesVM.preferences.isEnhancedModeEnabled)\n }\n}\n\nstruct EnhanceModeRequiredButtonStyle: ButtonStyle {\n func makeBody(configuration: Self.Configuration) -> some View {\n configuration.label\n .font(.system(size: 10))\n .padding(.horizontal, 4)\n .padding(.vertical, 3)\n .background(Color.yellow)\n .foregroundColor(Color.black)\n .clipShape(RoundedRectangle(cornerRadius: 4))\n .contentShape(Rectangle())\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Utilities/Border.swift", "import SwiftUI\n\nprivate struct EdgeBorder: Shape {\n var width: CGFloat\n var edges: [Edge]\n\n func path(in rect: CGRect) -> Path {\n var path = Path()\n for edge in edges {\n var x: CGFloat {\n switch edge {\n case .top, .bottom, .leading: return rect.minX\n case .trailing: return rect.maxX - width\n }\n }\n\n var y: CGFloat {\n switch edge {\n case .top, .leading, .trailing: return rect.minY\n case .bottom: return rect.maxY - width\n }\n }\n\n var w: CGFloat {\n switch edge {\n case .top, .bottom: return rect.width\n case .leading, .trailing: return width\n }\n }\n\n var h: CGFloat {\n switch edge {\n case .top, .bottom: return width\n case .leading, .trailing: return rect.height\n }\n }\n path.addPath(Path(CGRect(x: x, y: y, width: w, height: h)))\n }\n return path\n }\n}\n\nextension View {\n func border(width: CGFloat, edges: [Edge], color: Color) -> some View {\n overlay(EdgeBorder(width: width, edges: edges).foregroundColor(color))\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/RunningApplicationsPicker.swift", "import SwiftUI\n\nstruct RunningApplicationsPicker: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n let appIconSize: CGFloat = 18\n\n let onSelect: (NSRunningApplication) -> Void\n\n init(onSelect: @escaping (NSRunningApplication) -> Void) {\n self.onSelect = onSelect\n }\n\n var body: some View {\n Menu(\"Add Running Apps\") {\n ForEach(preferencesVM.filterApps(NSWorkspace.shared.runningApplications), id: \\.processIdentifier) { app in\n Button(action: { onSelect(app) }) {\n Text(app.localizedName ?? app.bundleId() ?? app.description)\n\n if let url = app.bundleURL {\n let image = NSWorkspace.shared.icon(forFile: url.path)\n\n SwiftUI.Image(nsImage: image)\n .resizable()\n .frame(width: appIconSize, height: appIconSize)\n } else {\n SwiftUI.Image(systemName: \"app.dashed\")\n .resizable()\n .frame(width: appIconSize, height: appIconSize)\n }\n }\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/ApplicationVM.swift", "import AppKit\nimport AXSwift\nimport Combine\nimport CombineExt\nimport os\n\n@MainActor\nfinal class ApplicationVM: ObservableObject {\n @Published private(set) var appKind: AppKind? = nil\n @Published private(set) var appsDiff: AppsDiff = .empty\n\n let logger = ISPLogger(category: String(describing: ApplicationVM.self))\n\n let cancelBag = CancelBag()\n let preferencesVM: PreferencesVM\n\n lazy var windowAXNotificationPublisher = ApplicationVM\n .createWindowAXNotificationPublisher(preferencesVM: preferencesVM)\n\n init(preferencesVM: PreferencesVM) {\n self.preferencesVM = preferencesVM\n appKind = .from(NSWorkspace.shared.frontmostApplication, preferencesVM: preferencesVM)\n\n activateAccessibilitiesForCurrentApp()\n watchApplicationChange()\n watchAppsDiffChange()\n }\n}\n\nextension ApplicationVM {\n private func watchApplicationChange() {\n let axNotification = windowAXNotificationPublisher.mapToVoid()\n\n let workspaceNotification = NSWorkspace.shared.notificationCenter\n .publisher(for: NSWorkspace.didActivateApplicationNotification, object: NSWorkspace.shared)\n .mapToVoid()\n\n Publishers\n .Merge(axNotification, workspaceNotification)\n .compactMap { [weak self] _ -> NSRunningApplication? in\n guard self?.preferencesVM.preferences.isEnhancedModeEnabled == true,\n let elm: UIElement = try? systemWideElement.attribute(.focusedApplication),\n let pid = try? elm.pid()\n else { return NSWorkspace.shared.frontmostApplication }\n return NSRunningApplication(processIdentifier: pid)\n }\n .removeDuplicates()\n .flatMapLatest { [weak self] (app: NSRunningApplication) -> AnyPublisher in\n guard let preferencesVM = self?.preferencesVM\n else { return Empty().eraseToAnyPublisher() }\n\n guard NSApplication.isBrowser(app)\n else { return Just(.from(app, preferencesVM: preferencesVM)).eraseToAnyPublisher() }\n\n return Timer\n .interval(seconds: 1)\n .prepend(Date())\n .compactMap { _ in app.focusedUIElement(preferencesVM: preferencesVM) }\n .first()\n .flatMapLatest { _ in\n app.watchAX([\n .focusedUIElementChanged,\n .titleChanged,\n .windowCreated,\n ], [.application, .window])\n .filter { $0.notification != .windowCreated }\n .map { event in event.runningApp }\n }\n .prepend(app)\n .compactMap { app -> AppKind? in .from(app, preferencesVM: preferencesVM) }\n .eraseToAnyPublisher()\n }\n .removeDuplicates(by: { $0.isSameAppOrWebsite(with: $1, detectAddressBar: true) })\n .sink { [weak self] in self?.appKind = $0 }\n .store(in: cancelBag)\n }\n}\n\nextension ApplicationVM {\n private func watchAppsDiffChange() {\n AppsDiff\n .publisher(preferencesVM: preferencesVM)\n .assign(to: &$appsDiff)\n }\n\n private func activateAccessibilitiesForCurrentApp() {\n $appKind\n .compactMap { $0 }\n .filter { [weak self] _ in self?.preferencesVM.preferences.isEnhancedModeEnabled == true }\n .filter { [weak self] in self?.preferencesVM.isHideIndicator($0) != true }\n .sink { $0.getApp().activateAccessibilities() }\n .store(in: cancelBag)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Indicator/IndicatorInfo.swift", "import Foundation\n\nenum IndicatorInfo: Int32, CaseIterable, Identifiable {\n case iconAndTitle = 0\n case iconOnly = 1\n case titleOnly = 2\n\n var id: Self { self }\n\n var name: String {\n switch self {\n case .iconAndTitle: return \"Icon and Title\".i18n()\n case .iconOnly: return \"Icon\".i18n()\n case .titleOnly: return \"Title\".i18n()\n }\n }\n}\n\nextension IndicatorInfo: Codable {\n private enum CodingKeys: String, CodingKey {\n case base\n }\n\n private enum Base: String, Codable {\n case iconAndTitle, iconOnly, titleOnly\n }\n\n func encode(to encoder: Encoder) throws {\n var container = encoder.container(keyedBy: CodingKeys.self)\n\n switch self {\n case .iconAndTitle:\n try container.encode(Base.iconAndTitle, forKey: .base)\n case .iconOnly:\n try container.encode(Base.iconOnly, forKey: .base)\n case .titleOnly:\n try container.encode(Base.titleOnly, forKey: .base)\n }\n }\n\n init(from decoder: Decoder) throws {\n let container = try decoder.container(keyedBy: CodingKeys.self)\n let base = try container.decode(Base.self, forKey: .base)\n\n switch base {\n case .iconAndTitle:\n self = .iconAndTitle\n case .iconOnly:\n self = .iconOnly\n case .titleOnly:\n self = .titleOnly\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/PromotionBadge.swift", "import SwiftUI\n\nstruct PromotionBadge: View {\n var body: some View {\n VStack(alignment: .leading) {\n Text(\"Promotion\".i18n())\n \n Spacer(minLength: 10)\n \n HStack {\n Spacer()\n \n if #available(macOS 13, *) {\n ShareLink(item: .website) {\n Label {\n Text(\"Share with friends\".i18n())\n } icon: {\n Image(systemName: \"square.and.arrow.up.fill\")\n .foregroundColor(.blue)\n }\n }\n } else {\n Button(action: {\n URL.website.open()\n }) {\n Label {\n Text(\"Share with friends\".i18n())\n } icon: {\n Image(systemName: \"square.and.arrow.up.fill\")\n .foregroundColor(.blue)\n }\n }\n }\n \n \n Button(action: {\n URL(string: \"https://github.com/runjuu/InputSourcePro\")?.open()\n }) {\n Label {\n Text(\"Star on GitHub\".i18n())\n } icon: {\n Image(systemName: \"star.fill\")\n .foregroundColor(Color(red: 1.0, green: 0.84, blue: 0.0))\n }\n }\n \n Button(action: {\n URL(string: \"https://github.com/sponsors/runjuu\")?.open()\n }) {\n Label {\n Text(\"Sponsor\".i18n())\n } icon: {\n Image(systemName: \"heart.fill\")\n .foregroundColor(.pink)\n }\n }\n }\n }\n .padding()\n }\n}\n\n// add support for Canvas Preview\nstruct PromotionBadge_Previews: PreviewProvider {\n static var previews: some View {\n PromotionBadge()\n .frame(width: 635, height: 95)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSRunningApplication+WindowInfo.swift", "import AppKit\nimport Combine\nimport Foundation\n\nprivate func isValidWindow(windowAlpha: CGFloat, windowBounds: CGRect) -> Bool {\n // ----------------------------------------\n // Ignore windows.\n //\n // There are well known windows that we need ignore:\n // * Google Chrome has some transparent windows.\n // * Google Chrome's status bar which is shown when mouse cursor is on links.\n // * Karabiner's status message windows.\n //\n // Do not forget to treat this situations:\n // * Do not ignore menubar.\n // * Do not ignore popup menu.\n // * Do not ignore alert window on web browsers.\n // * Do not ignore iTunes's preferences window which has some special behavior.\n\n // Ignore transparent windows.\n let transparentThreshold: CGFloat = 0.001\n\n if windowAlpha < transparentThreshold {\n return false\n }\n\n // Ignore small windows. (For example, a status bar of Google Chrome.)\n let windowSizeThreshold: CGFloat = 40\n if windowBounds.size.width < windowSizeThreshold ||\n windowBounds.size.height < windowSizeThreshold\n {\n return false\n }\n\n // Xcode and some app have some invisable window at fullscreen mode\n if let screen = NSScreen.getScreenInclude(rect: windowBounds),\n windowBounds.width == screen.frame.width,\n windowBounds.height < 70\n {\n return false\n }\n\n return true\n}\n\nextension NSRunningApplication {\n static func getWindowInfoPublisher(processIdentifier: pid_t) -> AnyPublisher {\n AnyPublisher.create { observer in\n let thread = Thread(block: {\n observer.send(getWindowInfo(processIdentifier: processIdentifier))\n observer.send(completion: .finished)\n })\n\n thread.start()\n\n return AnyCancellable { thread.cancel() }\n }\n .receive(on: DispatchQueue.main)\n .eraseToAnyPublisher()\n }\n\n func getWindowInfoPublisher() -> AnyPublisher {\n return NSRunningApplication.getWindowInfoPublisher(processIdentifier: processIdentifier)\n }\n}\n\nstruct WindowInfo {\n let bounds: CGRect\n let layer: Int\n}\n\nprivate func getWindowInfo(processIdentifier: pid_t) -> WindowInfo? {\n guard let windows = CGWindowListCopyWindowInfo(.optionOnScreenAboveWindow, kCGNullWindowID) as? [[String: Any]]\n else { return nil }\n\n for window in windows {\n // Target windows:\n // * frontmostApplication\n // * loginwindow (shutdown dialog)\n // * Launchpad\n //\n // Limitations:\n // * There is not reliable way to judge whether Dashboard is shown.\n\n guard\n let windowOwnerPID = window[\"kCGWindowOwnerPID\"] as? pid_t,\n let windowLayer = window[\"kCGWindowLayer\"] as? Int,\n let windowAlpha = window[\"kCGWindowAlpha\"] as? CGFloat,\n let windowBounds = CGRect(dictionaryRepresentation: window[\"kCGWindowBounds\"] as! CFDictionary)\n else { continue }\n\n guard windowOwnerPID == processIdentifier\n else { continue }\n\n if isValidWindow(windowAlpha: windowAlpha, windowBounds: windowBounds) {\n return .init(bounds: windowBounds, layer: windowLayer)\n }\n }\n\n return nil\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/CJKVFixEnableFailedView.swift", "import SwiftUI\n\nstruct CJKVFixEnableFailedView: View {\n @Binding var isPresented: Bool\n\n @State var isOpened = false\n\n var body: some View {\n VStack(spacing: 0) {\n Text(\"Enabled CJKV Fix Failed Desc\")\n\n Image(\"Enabled CJKV Fix Shortcut Img\".i18n())\n .resizable()\n .aspectRatio(contentMode: .fit)\n .shadow(color: .black.opacity(0.26), radius: 8)\n .padding(20)\n\n HStack {\n Spacer()\n\n if isOpened {\n Button(\"Close\", action: { isPresented = false })\n .keyboardShortcut(.defaultAction)\n } else {\n Button(\"Cancel\", action: { isPresented = false })\n .keyboardShortcut(.cancelAction)\n\n Button(\"Open Keyboard Settings\", action: {\n NSWorkspace.shared.openKeyboardPreferences()\n isOpened = true\n })\n .keyboardShortcut(.defaultAction)\n }\n }\n }\n .padding()\n .frame(width: 480)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Indicator/IndicatorSize.swift", "import AppKit\n\nenum IndicatorSize: Int32, CaseIterable, Identifiable {\n case small = 1\n case medium = 2\n case large = 3\n\n var displayName: String {\n switch self {\n case .small:\n return \"Small\".i18n()\n case .medium:\n return \"Medium\".i18n()\n case .large:\n return \"Large\".i18n()\n }\n }\n\n var id: Self { self }\n}\n\nextension IndicatorSize: Codable {\n private enum CodingKeys: String, CodingKey {\n case base\n }\n\n func encode(to encoder: Encoder) throws {\n var container = encoder.container(keyedBy: CodingKeys.self)\n try container.encode(rawValue, forKey: .base)\n }\n\n init(from decoder: Decoder) throws {\n let container = try decoder.container(keyedBy: CodingKeys.self)\n let rawValue = try container.decode(Int32.self, forKey: .base)\n\n self = Self(rawValue: rawValue)!\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/PreferencesVM+KeyboardConfig.swift", "import AppKit\nimport Bodega\nimport Boutique\nimport Foundation\nimport SwiftUI\n\nextension PreferencesVM {\n func addKeyboardConfig(_ inputSource: InputSource) -> KeyboardConfig {\n if let config = getKeyboardConfig(inputSource) {\n return config\n } else {\n let config = KeyboardConfig(context: container.viewContext)\n\n config.id = inputSource.id\n\n saveContext()\n\n return config\n }\n }\n\n func update(_ config: KeyboardConfig, textColor: Color, bgColor: Color) {\n saveContext {\n config.textColor = textColor == self.preferences.indicatorForgegroundColor ? nil : textColor\n config.bgColor = bgColor == self.preferences.indicatorBackgroundColor ? nil : bgColor\n }\n }\n\n func getKeyboardConfig(_ inputSource: InputSource) -> KeyboardConfig? {\n return keyboardConfigs.first(where: { $0.id == inputSource.id })\n }\n\n func getOrCreateKeyboardConfig(_ inputSource: InputSource) -> KeyboardConfig {\n return getKeyboardConfig(inputSource) ?? addKeyboardConfig(inputSource)\n }\n}\n\nextension PreferencesVM {\n func getTextNSColor(_ inputSource: InputSource) -> NSColor? {\n let isAutoAppearanceMode = preferences.isAutoAppearanceMode\n\n if let keyboardColor = getKeyboardConfig(inputSource)?.textColor {\n return NSColor(keyboardColor)\n } else {\n return isAutoAppearanceMode\n ? preferences.indicatorForgeground?.dynamicColor\n : NSColor(preferences.indicatorForgegroundColor)\n }\n }\n\n func getTextColor(_ inputSource: InputSource) -> Color {\n if let nsColor = getTextNSColor(inputSource) {\n return Color(nsColor)\n } else {\n return preferences.indicatorForgegroundColor\n }\n }\n\n func getBgNSColor(_ inputSource: InputSource) -> NSColor? {\n let isAutoAppearanceMode = preferences.isAutoAppearanceMode\n\n if let bgColor = getKeyboardConfig(inputSource)?.bgColor {\n return NSColor(bgColor)\n } else {\n return isAutoAppearanceMode\n ? preferences.indicatorBackground?.dynamicColor\n : NSColor(preferences.indicatorBackgroundColor)\n }\n }\n\n func getBgColor(_ inputSource: InputSource) -> Color {\n if let nsColor = getBgNSColor(inputSource) {\n return Color(nsColor)\n } else {\n return preferences.indicatorBackgroundColor\n }\n }\n}\n\nextension PreferencesVM {\n struct DeprecatedKeyboardSettings: Codable & Equatable & Identifiable {\n let id: String\n\n var textColorHex: String?\n var bgColorHex: String?\n }\n\n func migratePreferncesIfNeed() {\n if preferences.prevInstalledBuildVersion <= 462 {\n update {\n $0.indicatorInfo = $0.isShowInputSourcesLabel ? .iconAndTitle : .iconOnly\n }\n }\n }\n\n func migrateBoutiqueIfNeed() {\n let storagePath = Store.documentsDirectory(appendingPath: \"KeyboardSettings\")\n\n guard preferences.prevInstalledBuildVersion == 316,\n FileManager.default.fileExists(atPath: storagePath.path) else { return }\n\n let store = Store(storagePath: storagePath)\n let inputSources = InputSource.sources\n\n store.$items\n .filter { $0.count > 0 }\n .first()\n .sink { [weak self] items in\n self?.saveContext {\n for item in items {\n guard let inputSource = inputSources.first(where: { $0.id == item.id }),\n let config = self?.getOrCreateKeyboardConfig(inputSource)\n else { continue }\n\n config.textColorHex = item.textColorHex\n config.bgColorHex = item.bgColorHex\n }\n }\n\n do {\n try FileManager.default.removeItem(at: storagePath)\n } catch {\n print(\"Boutique migration error: \\(error.localizedDescription)\")\n }\n }\n .store(in: cancelBag)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/RebootRequiredBadge.swift", "import SwiftUI\n\nstruct RebootRequiredBadge: View {\n let isRequired: Bool\n \n var body: some View {\n Button(action: {}) {\n Text(\"System Reboot Required\".i18n())\n }\n .buttonStyle(RebootRequiredButtonStyle())\n .opacity(isRequired ? 1 : 0)\n .animation(.easeInOut, value: isRequired)\n }\n}\n\nstruct RebootRequiredButtonStyle: ButtonStyle {\n func makeBody(configuration: Self.Configuration) -> some View {\n configuration.label\n .font(.system(size: 10))\n .padding(.horizontal, 4)\n .padding(.vertical, 3)\n .background(Color.gray)\n .foregroundColor(Color.white)\n .clipShape(RoundedRectangle(cornerRadius: 4))\n .contentShape(Rectangle())\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKind.swift", "import AppKit\nimport AXSwift\nimport Combine\nimport Foundation\n\n@MainActor\nenum AppKind {\n typealias BrowserInfo = (\n focusedElement: UIElement?,\n isFocusOnInputContainer: Bool,\n\n url: URL,\n rule: BrowserRule?,\n isFocusedOnAddressBar: Bool\n )\n\n typealias NormalInfo = (\n focusedElement: UIElement?,\n isFocusOnInputContainer: Bool\n )\n\n case normal(app: NSRunningApplication, info: NormalInfo)\n case browser(app: NSRunningApplication, info: BrowserInfo)\n\n func getId() -> String? {\n switch self {\n case let .normal(app, _):\n return app.bundleId()\n case let .browser(app, info):\n if !info.isFocusedOnAddressBar,\n info.url != .newtab,\n let bundleId = app.bundleId(),\n let addressId = info.rule?.id() ?? info.url.host\n {\n return \"\\(bundleId)_\\(addressId)\"\n } else {\n return nil\n }\n }\n }\n\n func getApp() -> NSRunningApplication {\n switch self {\n case let .normal(app, _):\n return app\n case let .browser(app, _):\n return app\n }\n }\n\n func getBrowserInfo() -> BrowserInfo? {\n switch self {\n case .normal:\n return nil\n case let .browser(_, info):\n return info\n }\n }\n\n func isFocusOnInputContainer() -> Bool {\n switch self {\n case let .normal(_, info):\n return info.isFocusOnInputContainer\n case let .browser(_, info):\n return info.isFocusOnInputContainer\n }\n }\n\n func getFocusedElement() -> UIElement? {\n switch self {\n case let .normal(_, info):\n return info.focusedElement\n case let .browser(_, info):\n return info.focusedElement\n }\n }\n\n func isSameAppOrWebsite(with otherKind: AppKind?, detectAddressBar: Bool = false) -> Bool {\n guard let otherKind = otherKind else { return false }\n guard getApp() == otherKind.getApp() else { return false }\n\n let isSameAddress = getBrowserInfo()?.url == otherKind.getBrowserInfo()?.url\n let isSameAddressBar = getBrowserInfo()?.isFocusedOnAddressBar == otherKind.getBrowserInfo()?.isFocusedOnAddressBar\n\n return detectAddressBar ? (isSameAddressBar && isSameAddress) : isSameAddress\n }\n}\n\n// MARK: - From\n\nextension AppKind {\n static func from(_ app: NSRunningApplication?, preferencesVM: PreferencesVM) -> AppKind? {\n if let app = app {\n return .from(app, preferencesVM: preferencesVM)\n } else {\n return nil\n }\n }\n\n static func from(_ app: NSRunningApplication, preferencesVM: PreferencesVM) -> AppKind {\n let application = app.getApplication(preferencesVM: preferencesVM)\n let focusedElement = app.focuedUIElement(application: application)\n let isFocusOnInputContainer = UIElement.isInputContainer(focusedElement)\n\n if let url = preferencesVM.getBrowserURL(app.bundleIdentifier, application: application)?.removeFragment() {\n let rule = preferencesVM.getBrowserRule(url: url)\n let isFocusOnBrowserAddress = preferencesVM.isFocusOnBrowserAddress(app: app, focusedElement: focusedElement)\n\n return .browser(\n app: app,\n info: (\n focusedElement,\n isFocusOnInputContainer,\n url,\n rule,\n isFocusOnBrowserAddress\n )\n )\n } else {\n return .normal(\n app: app,\n info: (\n focusedElement,\n isFocusOnInputContainer\n )\n )\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Controllers/IndicatorWindowController+Indicator.swift", "import Foundation\n\nextension IndicatorWindowController {\n func getAppSize() -> CGSize? {\n return indicatorVC.fittingSize\n }\n\n func updateIndicator(event _: IndicatorVM.ActivateEvent, inputSource: InputSource) {\n let preferences = preferencesVM.preferences\n\n indicatorVC.prepare(config: IndicatorViewConfig(\n inputSource: inputSource,\n kind: preferences.indicatorKind,\n size: preferences.indicatorSize ?? .medium,\n bgColor: preferencesVM.getBgNSColor(inputSource),\n textColor: preferencesVM.getTextNSColor(inputSource)\n ))\n\n if isActive {\n indicatorVC.refresh()\n }\n }\n\n func moveIndicator(position: PreferencesVM.IndicatorPositionInfo) {\n indicatorVC.refresh()\n moveTo(point: position.point)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/InputSource/InputSource.swift", "import Carbon\nimport Cocoa\nimport Combine\nimport CoreGraphics\nimport CryptoKit\n\n@MainActor\nclass InputSource {\n static let logger = ISPLogger(\n category: \"🤖 \" + String(describing: InputSource.self),\n disabled: true\n )\n\n let tisInputSource: TISInputSource\n\n let icon: NSImage?\n\n var id: String { tisInputSource.id }\n var name: String { tisInputSource.name }\n\n var isCJKVR: Bool {\n guard let lang = tisInputSource.sourceLanguages.first else { return false }\n\n return lang == \"ru\" || lang == \"ko\" || lang == \"ja\" || lang == \"vi\" || lang.hasPrefix(\"zh\")\n }\n\n init(tisInputSource: TISInputSource) {\n self.tisInputSource = tisInputSource\n\n icon = { () -> NSImage? in\n if let imgName = Self.iconMap[String(tisInputSource.id.sha256().prefix(8))],\n let image = NSImage(named: imgName)\n {\n return image.markTemplateIfGrayScaleOrPdf()\n }\n\n guard let imageURL = tisInputSource.iconImageURL else {\n if #available(macOS 11.0, *) {\n return nil\n } else {\n if let iconRef = tisInputSource.iconRef {\n return NSImage(iconRef: iconRef).markTemplateIfGrayScaleOrPdf()\n } else {\n return nil\n }\n }\n }\n\n for url in [imageURL.retinaImageURL, imageURL.tiffImageURL, imageURL] {\n if let image = NSImage(contentsOf: url) {\n return image.markTemplateIfGrayScaleOrPdf(url: url)\n }\n }\n\n if let baseURL = imageURL.baseURL,\n baseURL.lastPathComponent.hasSuffix(\".app\")\n {\n return NSWorkspace.shared.icon(forFile: baseURL.relativePath)\n }\n\n return nil\n }()\n }\n\n func select(useCJKVFix: Bool) {\n Self.logger.debug { \"Select \\(id)\" }\n\n guard Self.getCurrentInputSource().id != id else {\n Self.logger.debug { \"Skip Select \\(id)\" }\n return\n }\n\n let updateStrategy: String = {\n if isCJKVR {\n // https://stackoverflow.com/a/60375569\n if useCJKVFix,\n PermissionsVM.checkAccessibility(prompt: false),\n let selectPreviousShortcut = Self.getSelectPreviousShortcut()\n {\n TISSelectInputSource(tisInputSource)\n\n // Workaround for TIS CJKV layout bug:\n // when it's CJKV, select nonCJKV input first and then return\n if let nonCJKV = Self.nonCJKVSource() {\n Self.logger.debug { \"S1: Start\" }\n TISSelectInputSource(nonCJKV.tisInputSource)\n Self.logger.debug { \"S1: selectPrevious\" }\n Self.selectPrevious(shortcut: selectPreviousShortcut)\n Self.logger.debug { \"S1: Done\" }\n }\n\n return \"S1\"\n } else {\n TISSelectInputSource(tisInputSource)\n return \"S0-2\"\n }\n } else {\n TISSelectInputSource(tisInputSource)\n\n return \"S0-2\"\n }\n }()\n\n Self.logger.debug { \"Select by \\(updateStrategy)\" }\n }\n}\n\nextension InputSource: @preconcurrency Equatable {\n static func == (lhs: InputSource, rhs: InputSource) -> Bool {\n return lhs.id == rhs.id\n }\n}\n\nextension InputSource {\n private static var cancelBag = CancelBag()\n\n @MainActor\n static func getCurrentInputSource() -> InputSource {\n return InputSource(tisInputSource: TISCopyCurrentKeyboardInputSource().takeRetainedValue())\n }\n}\n\nextension InputSource {\n static var sources: [InputSource] {\n let inputSourceNSArray = TISCreateInputSourceList(nil, false).takeRetainedValue() as NSArray\n let inputSourceList = inputSourceNSArray as! [TISInputSource]\n\n return inputSourceList\n .filter { $0.category == TISInputSource.Category.keyboardInputSource && $0.isSelectable }\n .map { InputSource(tisInputSource: $0) }\n }\n\n static func nonCJKVSource() -> InputSource? {\n return sources.first(where: { !$0.isCJKVR })\n }\n\n static func anotherCJKVSource(current: InputSource) -> InputSource? {\n return sources.first(where: { $0 != current && $0.isCJKVR })\n }\n\n static func selectPrevious(shortcut: (Int, UInt64)) {\n let src = CGEventSource(stateID: .hidSystemState)\n\n let key = CGKeyCode(shortcut.0)\n let flag = CGEventFlags(rawValue: shortcut.1)\n\n let down = CGEvent(keyboardEventSource: src, virtualKey: key, keyDown: true)!\n let up = CGEvent(keyboardEventSource: src, virtualKey: key, keyDown: false)!\n\n down.flags = flag\n up.flags = flag\n\n let ctrlDown = CGEvent(keyboardEventSource: nil, virtualKey: UInt16(kVK_Control), keyDown: true)\n let ctrlUp = CGEvent(keyboardEventSource: nil, virtualKey: UInt16(kVK_Control), keyDown: false)\n\n ctrlDown?.post(tap: .cghidEventTap)\n down.post(tap: .cghidEventTap)\n up.post(tap: .cghidEventTap)\n ctrlUp?.post(tap: .cghidEventTap)\n }\n\n // from read-symbolichotkeys script of Karabiner\n // github.com/tekezo/Karabiner/blob/master/src/util/read-symbolichotkeys/read-symbolichotkeys/main.m\n static func getSelectPreviousShortcut() -> (Int, UInt64)? {\n guard let dict = UserDefaults.standard.persistentDomain(forName: \"com.apple.symbolichotkeys\") else {\n return nil\n }\n guard let symbolichotkeys = dict[\"AppleSymbolicHotKeys\"] as! NSDictionary? else {\n return nil\n }\n guard let symbolichotkey = symbolichotkeys[\"60\"] as! NSDictionary? else {\n return nil\n }\n if (symbolichotkey[\"enabled\"] as! NSNumber).intValue != 1 {\n return nil\n }\n guard let value = symbolichotkey[\"value\"] as! NSDictionary? else {\n return nil\n }\n guard let parameters = value[\"parameters\"] as! NSArray? else {\n return nil\n }\n return (\n (parameters[1] as! NSNumber).intValue,\n (parameters[2] as! NSNumber).uint64Value\n )\n }\n}\n\nprivate extension URL {\n var retinaImageURL: URL {\n var components = pathComponents\n let filename: String = components.removeLast()\n let ext: String = pathExtension\n let retinaFilename = filename.replacingOccurrences(of: \".\" + ext, with: \"@2x.\" + ext)\n return NSURL.fileURL(withPathComponents: components + [retinaFilename])!\n }\n\n var tiffImageURL: URL {\n return deletingPathExtension().appendingPathExtension(\"tiff\")\n }\n}\n\nextension InputSource: @preconcurrency CustomStringConvertible {\n var description: String {\n id\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/EnhancedModeToggle.swift", "import SwiftUI\n\nstruct EnhancedModeToggle: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n @EnvironmentObject var permissionsVM: PermissionsVM\n\n @State var isShowAccessibilityRequest = false\n\n var body: some View {\n let isDetectSpotlightLikeAppBinding = Binding(\n get: { preferencesVM.preferences.isEnhancedModeEnabled },\n set: { onNeedDetectSpotlightLikeApp($0) }\n )\n\n VStack(alignment: .leading) {\n HStack {\n Toggle(\"\", isOn: isDetectSpotlightLikeAppBinding)\n .sheet(isPresented: $isShowAccessibilityRequest) {\n AccessibilityPermissionRequestView(isPresented: $isShowAccessibilityRequest)\n }\n\n Text(\"Enhanced Mode\".i18n())\n\n Spacer()\n }\n\n Text(.init(\"Enhanced Mode Description\".i18n()))\n .font(.system(size: 12))\n .opacity(0.8)\n }\n .padding()\n }\n\n func onNeedDetectSpotlightLikeApp(_ isDetectSpotlightLikeApp: Bool) {\n preferencesVM.update {\n if isDetectSpotlightLikeApp {\n if permissionsVM.isAccessibilityEnabled {\n $0.isEnhancedModeEnabled = true\n } else {\n isShowAccessibilityRequest = true\n }\n } else {\n $0.isEnhancedModeEnabled = false\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/PreferencesVM+BrowserRule.swift", "import AppKit\nimport AXSwift\nimport Foundation\n\nextension PreferencesVM {\n func addBrowserRule(\n type: BrowserRuleType,\n value: String,\n sample: String,\n inputSourceId: String,\n hideIndicator: Bool,\n keyboardRestoreStrategy: KeyboardRestoreStrategy?\n ) {\n let rule = BrowserRule(context: container.viewContext)\n\n rule.createdAt = Date()\n rule.type = type\n rule.value = value\n rule.sample = sample\n rule.inputSourceId = inputSourceId\n rule.keyboardRestoreStrategyRaw = keyboardRestoreStrategy?.rawValue\n rule.hideIndicator = hideIndicator\n rule.disabled = false\n\n saveContext()\n }\n\n func deleteBrowserRule(_ rule: BrowserRule) {\n container.viewContext.delete(rule)\n saveContext()\n }\n\n func updateBrowserRule(\n _ rule: BrowserRule,\n type: BrowserRuleType,\n value: String,\n sample: String,\n inputSourceId: String,\n hideIndicator: Bool,\n keyboardRestoreStrategy: KeyboardRestoreStrategy?\n ) {\n saveContext {\n rule.type = type\n rule.value = value\n rule.sample = sample\n rule.inputSourceId = inputSourceId\n rule.hideIndicator = hideIndicator\n rule.keyboardRestoreStrategyRaw = keyboardRestoreStrategy?.rawValue\n }\n }\n\n func toggleBrowserRule(_ rule: BrowserRule) {\n saveContext {\n rule.disabled.toggle()\n }\n }\n\n private func getBrowserRules() -> [BrowserRule] {\n let request = NSFetchRequest(entityName: \"BrowserRule\")\n\n do {\n return try container.viewContext.fetch(request)\n } catch {\n print(\"getBrowserRules() error: \\(error.localizedDescription)\")\n return []\n }\n }\n\n func getBrowserRule(url: URL) -> BrowserRule? {\n return getBrowserRules().first { $0.validate(url: url) }\n }\n}\n\nextension PreferencesVM {\n var isNeedToDetectBrowserTabChanges: Bool {\n guard preferences.isEnhancedModeEnabled else { return false }\n\n return Browser.allCases.contains(where: isBrowserEnabled)\n }\n\n func isBrowserAndEnabled(_ app: NSRunningApplication) -> Bool {\n guard let browser = NSApplication.getBrowser(app)\n else { return false }\n\n return isBrowserEnabled(browser)\n }\n\n func isBrowserEnabled(_ browser: Browser) -> Bool {\n switch browser {\n case .Safari:\n return preferences.isEnableURLSwitchForSafari\n case .SafariTechnologyPreview:\n return preferences.isEnableURLSwitchForSafariTechnologyPreview\n case .Chrome:\n return preferences.isEnableURLSwitchForChrome\n case .Chromium:\n return preferences.isEnableURLSwitchForChromium\n case .Arc:\n return preferences.isEnableURLSwitchForArc\n case .Edge:\n return preferences.isEnableURLSwitchForEdge\n case .Brave:\n return preferences.isEnableURLSwitchForBrave\n case .BraveBeta:\n return preferences.isEnableURLSwitchForBraveBeta\n case .BraveNightly:\n return preferences.isEnableURLSwitchForBraveNightly\n case .Vivaldi:\n return preferences.isEnableURLSwitchForVivaldi\n case .Opera:\n return preferences.isEnableURLSwitchForOpera\n case .Thorium:\n return preferences.isEnableURLSwitchForThorium\n case .Firefox:\n return preferences.isEnableURLSwitchForFirefox\n case .FirefoxDeveloperEdition:\n return preferences.isEnableURLSwitchForFirefoxDeveloperEdition\n case .FirefoxNightly:\n return preferences.isEnableURLSwitchForFirefoxNightly\n case .Zen:\n return preferences.isEnableURLSwitchForZen\n case .Dia:\n return preferences.isEnableURLSwitchForDia\n }\n }\n\n func getBrowserInfo(app: NSRunningApplication) -> (url: URL, rule: BrowserRule?)? {\n guard let url = getBrowserURL(app.bundleIdentifier, application: Application(app)) else { return nil }\n\n return (url, getBrowserRule(url: url))\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Indicator/IndicatorColor.swift", "import SwiftUI\n\nstruct IndicatorColor {\n let light: Color\n let dark: Color\n}\n\nextension IndicatorColor {\n var dynamicColor: NSColor {\n return NSColor(name: nil) { appearance in\n switch appearance.bestMatch(from: [.darkAqua]) {\n case .darkAqua?:\n return NSColor(self.dark)\n default:\n return NSColor(self.light)\n }\n }\n }\n}\n\nextension IndicatorColor {\n static let background = IndicatorColor(\n light: .white.opacity(0.95),\n dark: .black\n )\n\n static let forgeground = IndicatorColor(\n light: .black,\n dark: .white\n )\n}\n\nextension IndicatorColor: Codable {\n private enum CodingKeys: String, CodingKey { case light, dark }\n\n init(from decoder: Decoder) throws {\n let container = try decoder.container(keyedBy: CodingKeys.self)\n let lightStr = try container.decode(String.self, forKey: .light)\n let darkStr = try container.decode(String.self, forKey: .dark)\n\n light = Color(hex: lightStr)\n dark = Color(hex: darkStr)\n }\n\n func encode(to encoder: Encoder) throws {\n var container = encoder.container(keyedBy: CodingKeys.self)\n try container.encode(light.hexWithAlpha, forKey: .light)\n try container.encode(dark.hexWithAlpha, forKey: .dark)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/PreferencesVM+BrowserAddress.swift", "import AppKit\nimport AXSwift\n\nprivate let chromiumSearchBarDescMap = [\n \"Aadressi- ja otsinguriba\": true,\n \"Address and search bar\": true,\n \"Address bar at bar sa paghahanap\": true,\n \"Adres ve arama çubuğu\": true,\n \"Adres- en soekbalk\": true,\n \"Adres- en zoekbalk\": true,\n \"Adreses un meklēšanas josla\": true,\n \"Adresna traka i traka za pretraživanje\": true,\n \"Adresní a vyhledávací řádek\": true,\n \"Adreso ir paieškos juosta\": true,\n \"Adress- och sökfält\": true,\n \"Adress- und Suchleiste\": true,\n \"Adresse og søgelinje\": true,\n \"Adresse- og søkefelt\": true,\n \"Bar alamat dan carian\": true,\n \"Bar cyfeiriad a chwilio\": true,\n \"Bara de adrese și de căutare\": true,\n \"Barra d'adreces i de cerca\": true,\n \"Barra de direcciones y de búsqueda\": true,\n \"Barra de direcciones y de búsqueda \": true,\n \"Barra de enderezos e de busca\": true,\n \"Barra de endereço e de pesquisa\": true,\n \"Barra de pesquisa e endereço\": true,\n \"Barra degli indirizzi e di ricerca\": true,\n \"Barre d'adresse et de recherche\": true,\n \"Bilah penelusuran dan alamat\": true,\n \"Cím- és keresősáv\": true,\n \"Helbide- eta bilaketa-barra\": true,\n \"Ikheli nebha yosesho\": true,\n \"Manzil va qidiruv paneli\": true,\n \"Naslovna in iskalna vrstica\": true,\n \"Osoite- ja hakupalkki\": true,\n \"Panel s adresou a vyhľadávací panel\": true,\n \"Pasek adresu i wyszukiwania\": true,\n \"Shiriti i adresës dhe i kërkimit\": true,\n \"Thanh địa chỉ và tìm kiếm\": true,\n \"Traka za adresu i pretragu\": true,\n \"Traka za adresu i pretraživanje\": true,\n \"Upau wa anwani na utafutaji\": true,\n \"Veffanga- og leitarstika\": true,\n \"Ünvan və axtarış paneli\": true,\n \"Γραμμή διευθύνσεων και αναζήτησης\": true,\n \"Адрасны радок і панэль пошуку\": true,\n \"Адресная строка и строка поиска\": true,\n \"Адресний і пошуковий рядок\": true,\n \"Дарек жана издөө тилкеси\": true,\n \"Лента за адреса и за пребарување\": true,\n \"Лента за адреси и за търсене\": true,\n \"Мекенжайы және іздеу жолағы\": true,\n \"Трака за адресу и претрагу\": true,\n \"Хаяг ба хайлтын цонх\": true,\n \"Հասցեագոտի և որոնման գոտի\": true,\n \"שורת חיפוש וכתובות אתרים\": true,\n \"شريط العناوين والبحث\": true,\n \"نوار جستجو و آدرس\": true,\n \"پتہ اور تلاش بار\": true,\n \"ठेगाना र खोज पट्टी\": true,\n \"पता और सर्च बार\": true,\n \"पत्ता आणि शोध बार\": true,\n \"ঠিকনা আৰু সন্ধানৰ বাৰ\": true,\n \"ঠিক��না এবং সার্চ দণ্ড\": true,\n \"ਪਤਾ ਅਤੇ ਖੋਜ ਬਾਰ\": true,\n \"સરનામું અને શોધ બાર\": true,\n \"ଠିକଣା ଏବଂ ସନ୍ଧାନ ବାର୍\": true,\n \"முகவரி மற்றும் தேடல் பட்டி\": true,\n \"అడ్రస్‌ మరియు శోధన బార్\": true,\n \"ವಿಳಾಸ ಹಾಗೂ ಹುಡುಕಾಟ ಪಟ್ಟಿ\": true,\n \"വിലാസവും തിരയൽ ബാറും\": true,\n \"ලිපිනය සහ සෙවීම් බාර් එක\": true,\n \"ที่อยู่และแถบค้นหา\": true,\n \"ແຖບ​ທີ່​ຢູ່​ ແລະ​ຄົ້ນ​ຫາ\": true,\n \"လိပ်စာ နှင့် ရှာဖွေရေး ဘား\": true,\n \"მისამართი და ძიების ზოლი\": true,\n \"የአድራሻ እና ፍለጋ አሞሌ\": true,\n \"អាសយដ្ឋាន និងរបាស្វែងរក\": true,\n \"アドレス検索バー\": true,\n \"地址和搜索栏\": true,\n \"網址與搜尋列\": true,\n \"주소창 및 검색창\": true,\n]\n\nenum BrowserThatCanWatchBrowserAddressFocus: CaseIterable {\n static var allBundleIdentifiers = allCases.map { $0.bundleIdentifier }\n\n static func createBy(bundleIdentifier: String?) -> BrowserThatCanWatchBrowserAddressFocus? {\n if let bundleIdentifier = bundleIdentifier {\n for item in allCases {\n if item.bundleIdentifier == bundleIdentifier {\n return item\n }\n }\n }\n\n return nil\n }\n\n case Safari, SafariTechnologyPreview, Chrome, Chromium, Brave, BraveBeta, BraveNightly, Edge, Vivaldi, Arc, Opera, Firefox, FirefoxNightly, FirefoxDeveloperEdition, Zen, Dia\n\n var bundleIdentifier: String {\n return browser.rawValue\n }\n\n var browser: Browser {\n switch self {\n case .Safari:\n return .Safari\n case .SafariTechnologyPreview:\n return .SafariTechnologyPreview\n case .Chrome:\n return .Chrome\n case .Chromium:\n return .Chromium\n case .Brave:\n return .Brave\n case .BraveBeta:\n return .BraveBeta\n case .BraveNightly:\n return .BraveNightly\n case .Edge:\n return .Edge\n case .Vivaldi:\n return .Vivaldi\n case .Arc:\n return .Arc\n case .Opera:\n return .Opera\n case .Firefox:\n return .Firefox\n case .FirefoxNightly:\n return .FirefoxNightly\n case .FirefoxDeveloperEdition:\n return .FirefoxDeveloperEdition\n case .Zen:\n return .Zen\n case .Dia:\n return .Dia\n }\n }\n\n func isFocusOnBrowserAddress(focusedElement: UIElement?) -> Bool {\n guard let focusedElement = focusedElement\n else { return false }\n\n switch self {\n case .Safari, .SafariTechnologyPreview:\n return focusedElement.domIdentifier() == \"WEB_BROWSER_ADDRESS_AND_SEARCH_FIELD\"\n\n case .Arc:\n return focusedElement.domIdentifier() == \"commandBarTextField\"\n\n case .Vivaldi:\n let classList = focusedElement.domClassList()\n return classList.contains(\"UrlBar-UrlField\") && classList.contains(\"vivaldi-addressfield\")\n\n case .Opera:\n return focusedElement.domClassList().contains(\"AddressTextfieldView\")\n\n case .Chromium, .Chrome, .Brave, .BraveBeta, .BraveNightly, .Edge, .Dia:\n if focusedElement.domClassList().contains(\"OmniboxViewViews\") {\n if let description = focusedElement.safeString(attribute: .description),\n chromiumSearchBarDescMap[description] == true\n {\n return true\n }\n\n if let title = focusedElement.safeString(attribute: .title),\n chromiumSearchBarDescMap[title] == true\n {\n return true\n }\n\n return false\n } else {\n return false\n }\n\n case .Firefox, .FirefoxNightly, .FirefoxDeveloperEdition, .Zen:\n return focusedElement.firefoxDomIdentifier() == \"urlbar-input\"\n }\n }\n}\n\nextension PreferencesVM {\n func isFocusOnBrowserAddress(app: NSRunningApplication?, focusedElement: UIElement?) -> Bool {\n return BrowserThatCanWatchBrowserAddressFocus\n .createBy(bundleIdentifier: app?.bundleIdentifier)?\n .isFocusOnBrowserAddress(focusedElement: focusedElement) ?? false\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/ItemSection.swift", "import SwiftUI\n\nstruct ItemSection: View {\n let content: Content\n\n init(@ViewBuilder _ content: () -> Content) {\n self.content = content()\n }\n\n var body: some View {\n HStack {\n Spacer()\n VStack {\n Spacer()\n content\n Spacer()\n }\n Spacer()\n }\n .itemSectionStyle()\n }\n}\n\nstruct ItemSectionStyle: ViewModifier {\n func body(content: Content) -> some View {\n content\n .background(NSColor.background1.color)\n .clipShape(RoundedRectangle(cornerRadius: 6))\n .overlay(\n RoundedRectangle(cornerRadius: 6)\n .stroke(NSColor.border2.color, lineWidth: 1)\n )\n }\n}\n\nextension View {\n func itemSectionStyle() -> some View {\n modifier(ItemSectionStyle())\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Combine/Combine.swift", "import AppKit\nimport Combine\n\nextension Publisher {\n func tap(_ receiveOutput: @escaping (Output) -> Void) -> AnyPublisher {\n handleEvents(receiveOutput: { output in\n receiveOutput(output)\n })\n .eraseToAnyPublisher()\n }\n}\n\nextension Publisher {\n func mapTo(_ value: T) -> AnyPublisher {\n map { _ in value }\n .eraseToAnyPublisher()\n }\n}\n\nextension Publisher {\n typealias WithPrevious = (previous: T?, current: T)\n\n /// Includes the current element as well as the previous element from the upstream publisher in a tuple where the previous element is optional.\n /// The first time the upstream publisher emits an element, the previous element will be `nil`.\n ///\n /// ```\n /// let range = (1...5)\n /// let subscription = range.publisher\n /// .pairwise()\n /// .sink { print(\"(\\($0.previous), \\($0.current))\", terminator: \" \") }\n /// ```\n /// Prints: \"(nil, 1) (Optional(1), 2) (Optional(2), 3) (Optional(3), 4) (Optional(4), 5)\".\n ///\n /// - Returns: A publisher of a tuple of the previous and current elements from the upstream publisher.\n ///\n /// - Note: Based on .\n func withPrevious() -> AnyPublisher, Failure> {\n // `scan()` needs an initial value, which is `nil` in our case.\n // Therefore we have to return an optional here and use `compactMap()` below the remove the optional type.\n scan(nil) { previousPair, currentElement -> WithPrevious? in\n WithPrevious(previous: previousPair?.current, current: currentElement)\n }\n .compactMap { $0 }\n .eraseToAnyPublisher()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSApplication.swift", "import AppKit\n\n// MARK: - isFloatingApp\n\nprivate let floatingAppIdentifier: [(\n identifier: String,\n maxWindowLayer: Int,\n isSpotlightLikeApp: Bool,\n isValid: (((windowLayer: Int?, windowBounds: CGRect?)) -> Bool)?\n)] = [\n (\"com.apple.Spotlight\", 30, true, nil),\n (\"com.runningwithcrayons.Alfred\", 30, true, nil),\n (\"at.obdev.LaunchBar\", 30, true, nil),\n (\"com.raycast.macos\", 30, true, nil),\n (\"com.googlecode.iterm2\", 30, false, nil),\n (\"com.xunyong.hapigo\", 30, true, nil),\n (\"com.hezongyidev.Bob\", 30, false, nil),\n (\"com.ripperhe.Bob\", 30, false, nil),\n (\"org.yuanli.utools\", 30, false, nil),\n (\"com.1password.1password\", 1000, true, nil),\n (\"com.eusoft.eudic.LightPeek\", 1000, true, nil),\n (\"com.contextsformac.Contexts\", 1000, true, { $0.windowLayer != 20 }),\n]\n\nextension NSApplication {\n static func isFloatingApp(_ bundleIdentifier: String?, windowLayer: Int? = nil, windowBounds: CGRect? = nil) -> Bool {\n guard let bundleIdentifier = bundleIdentifier else { return false }\n\n return floatingAppIdentifier.contains {\n guard $0.0 == bundleIdentifier else { return false }\n guard let windowLayer = windowLayer else { return true }\n guard windowLayer < $0.1, windowLayer > 0 else { return false }\n\n return $0.isValid?((windowLayer, windowBounds)) ?? true\n }\n }\n\n static func isSpotlightLikeApp(_ bundleIdentifier: String?) -> Bool {\n guard let bundleIdentifier = bundleIdentifier else { return false }\n\n return floatingAppIdentifier.contains(where: { $0.isSpotlightLikeApp && $0.identifier == bundleIdentifier })\n }\n\n static func isBrowser(_ app: NSRunningApplication) -> Bool {\n return getBrowser(app) != nil\n }\n\n static func getBrowser(_ app: NSRunningApplication) -> Browser? {\n if let bundleIdentifier = app.bundleIdentifier,\n let browser = Browser(rawValue: bundleIdentifier)\n {\n return browser\n } else {\n return nil\n }\n }\n}\n\n// MARK: - isBrowserApp\n\nprivate var browserAppIdentifier: Set = {\n let array1 = LSCopyAllRoleHandlersForContentType(\n \"public.html\" as CFString, .viewer\n )?.takeRetainedValue() as? [String] ?? []\n let array2 = LSCopyAllHandlersForURLScheme(\n \"https\" as CFString\n )?.takeRetainedValue() as? [String] ?? []\n\n let set1 = Set(array1)\n let set2 = Set(array2)\n\n return set1.intersection(set2)\n}()\n\nextension NSApplication {\n static func isBrowserApp(_ bundleIdentifier: String?) -> Bool {\n guard let bundleIdentifier = bundleIdentifier else { return false }\n\n return browserAppIdentifier.contains(bundleIdentifier)\n }\n\n static func isBrowserInstalled(_ bundleIdentifier: String) -> Bool {\n return isBrowserApp(bundleIdentifier)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSRunningApplication.swift", "import AppKit\nimport AXSwift\nimport Combine\n\nprivate func notify(\n _ observer: Observer?,\n _ validRoles: [Role],\n _ element: UIElement,\n _ notifications: [AXNotification],\n _ indetify: String?\n) -> AnyCancellable {\n guard let role = try? element.role(),\n validRoles.contains(role)\n else { return AnyCancellable {} }\n\n do {\n try notifications.forEach {\n try observer?.addNotification($0, forElement: element)\n }\n\n return AnyCancellable {\n for notification in notifications {\n try? observer?.removeNotification(notification, forElement: element)\n }\n }\n } catch {\n let role = role.rawValue\n let msg = \"\\(indetify ?? \"nil\"): Could not watch [\\(element)] with role \\(role): \\(error)\"\n\n #if DEBUG\n print(msg)\n #endif\n\n return AnyCancellable {}\n }\n}\n\nextension NSRunningApplication {\n typealias WatchAXOutput = (runningApp: NSRunningApplication, notification: AXNotification)\n\n func watchAX(\n elm: UIElement? = nil,\n _ notifications: [AXNotification],\n _ validRoles: [Role]\n ) -> AnyPublisher {\n return Timer.delay(seconds: 0.5)\n .receive(on: DispatchQueue.main)\n .flatMapLatest { _ -> AnyPublisher in\n AnyPublisher.create { [weak self] observer in\n let cancelBag = CancelBag()\n\n self?.activateAccessibilities()\n\n guard\n let runningApplication = self,\n let app = Application(runningApplication)\n else { return AnyCancellable {} }\n\n let appObserver = app.createObserver { (_ appObserver: Observer, _ element: UIElement, _ event: AXNotification) in\n // Watch events on new windows\n if event == .windowCreated {\n notify(\n appObserver,\n validRoles,\n element,\n notifications,\n runningApplication.bundleIdentifier\n )\n .store(in: cancelBag)\n }\n\n observer.send((runningApplication, event))\n }\n\n notify(\n appObserver,\n validRoles,\n elm ?? app,\n notifications,\n runningApplication.bundleIdentifier\n )\n .store(in: cancelBag)\n\n return AnyCancellable {\n cancelBag.cancel()\n appObserver?.stop()\n }\n }\n }\n .eraseToAnyPublisher()\n }\n}\n\nextension NSRunningApplication {\n func bundleId() -> String? {\n if let bundleIdentifier = bundleIdentifier {\n return bundleIdentifier\n }\n\n if let url = bundleURL ?? executableURL {\n return url.bundleId()\n }\n\n return nil\n }\n}\n\nextension NSRunningApplication {\n // For performance reasons Chromium only makes the webview accessible when there it detects voiceover through the `AXEnhancedUserInterface` attribute on the Chrome application itself:\n // http://dev.chromium.org/developers/design-documents/accessibility\n // Similarly, electron uses `AXManualAccessibility`:\n // https://electronjs.org/docs/tutorial/accessibility#assistive-technology\n func activateAccessibilities() {\n guard bundleIdentifier?.starts(with: \"com.apple.\") != true else { return }\n\n activateAccessibility(attribute: \"AXEnhancedUserInterface\")\n activateAccessibility(attribute: \"AXManualAccessibility\")\n }\n\n func activateAccessibility(attribute: String) {\n if let application = Application(self),\n let isSettable = try? application.attributeIsSettable(attribute),\n isSettable\n {\n if let rawValue: AnyObject = try? application.attribute(attribute),\n CFBooleanGetTypeID() == CFGetTypeID(rawValue),\n let enabled = rawValue as? Bool, enabled\n {\n return\n }\n\n try? application.setAttribute(attribute, value: true)\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Screens/InputSourcesAppearanceSettingsView.swift", "import SwiftUI\n\nstruct InputSourcesAppearanceSettingsView: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n let imgSize: CGFloat = 16\n\n var body: some View {\n ScrollView {\n VStack(spacing: 18) {\n ForEach(InputSource.sources, id: \\.id) { inputSource in\n SettingsSection(title: inputSource.name, noI18N: true) {\n KeyboardCustomization(inputSource: inputSource)\n }\n }\n }\n .padding()\n .padding(.bottom)\n }\n .background(NSColor.background1.color)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Controllers/PreferencesWindowController.swift", "import AppKit\nimport SwiftUI\n\n@MainActor\nclass PreferencesWindowController: NSWindowController {\n let navigationVM: NavigationVM\n let permissionsVM: PermissionsVM\n let preferencesVM: PreferencesVM\n let indicatorVM: IndicatorVM\n let feedbackVM: FeedbackVM\n let inputSourceVM: InputSourceVM\n\n init(\n navigationVM: NavigationVM,\n permissionsVM: PermissionsVM,\n preferencesVM: PreferencesVM,\n indicatorVM: IndicatorVM,\n feedbackVM: FeedbackVM,\n inputSourceVM: InputSourceVM\n ) {\n self.navigationVM = navigationVM\n self.permissionsVM = permissionsVM\n self.preferencesVM = preferencesVM\n self.indicatorVM = indicatorVM\n self.feedbackVM = feedbackVM\n self.inputSourceVM = inputSourceVM\n\n let window = NSWindow(\n contentViewController: NSHostingController(\n rootView: PreferencesView()\n .environmentObject(navigationVM)\n .environmentObject(preferencesVM)\n .environmentObject(indicatorVM)\n .environmentObject(permissionsVM)\n .environmentObject(feedbackVM)\n .environmentObject(inputSourceVM)\n )\n )\n\n super.init(window: window)\n\n window.delegate = self\n\n configureWindow()\n }\n\n @available(*, unavailable)\n required init?(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n\n private func configureWindow() {\n window?.standardWindowButton(NSWindow.ButtonType.zoomButton)?.isEnabled = false\n window?.standardWindowButton(NSWindow.ButtonType.miniaturizeButton)?.isEnabled = false\n\n window?.title = \"Input Source Pro\"\n window?.titleVisibility = .hidden\n window?.titlebarAppearsTransparent = true\n window?.styleMask.insert(.fullSizeContentView)\n }\n}\n\nextension PreferencesWindowController: NSWindowDelegate {\n func windowWillClose(_: Notification) {\n NSApp.setActivationPolicy(.accessory)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/BrowserURL.swift", "import AppKit\nimport AXSwift\n\n// Update BrowserThatCanWatchBrowserAddressFocus as well\nenum Browser: String, CaseIterable {\n case Safari = \"com.apple.Safari\"\n case SafariTechnologyPreview = \"com.apple.SafariTechnologyPreview\"\n case Chrome = \"com.google.Chrome\"\n case Chromium = \"org.chromium.Chromium\"\n case Arc = \"company.thebrowser.Browser\"\n case Edge = \"com.microsoft.edgemac\"\n case Brave = \"com.brave.Browser\"\n case BraveBeta = \"com.brave.Browser.beta\"\n case BraveNightly = \"com.brave.Browser.nightly\"\n case Vivaldi = \"com.vivaldi.Vivaldi\"\n case Opera = \"com.operasoftware.Opera\"\n case Thorium = \"org.chromium.Thorium\"\n case Firefox = \"org.mozilla.firefox\"\n case FirefoxDeveloperEdition = \"org.mozilla.firefoxdeveloperedition\"\n case FirefoxNightly = \"org.mozilla.nightly\"\n case Zen = \"app.zen-browser.zen\"\n case Dia = \"company.thebrowser.dia\"\n\n var displayName: String {\n switch self {\n case .Safari:\n return \"Safari\"\n case .SafariTechnologyPreview:\n return \"Safari Technology Preview\"\n case .Chrome:\n return \"Chrome\"\n case .Chromium:\n return \"Chromium\"\n case .Arc:\n return \"Arc\"\n case .Edge:\n return \"Edge\"\n case .Brave:\n return \"Brave\"\n case .BraveBeta:\n return \"Brave Beta\"\n case .BraveNightly:\n return \"Brave Nightly\"\n case .Vivaldi:\n return \"Vivaldi\"\n case .Opera:\n return \"Opera\"\n case .Thorium:\n return \"Thorium\"\n case .Firefox:\n return \"Firefox\"\n case .FirefoxDeveloperEdition:\n return \"Firefox Developer Edition\"\n case .FirefoxNightly:\n return \"Firefox Nightly\"\n case .Zen:\n return \"Zen\"\n case .Dia:\n return \"Dia\"\n }\n }\n}\n\nextension Browser {\n func getCurrentTabURL(focusedWindow: UIElement) -> URL? {\n guard let windowElement = Element.initialize(rawElement: focusedWindow.element),\n let webArea = (try? QueryWebAreaService(windowElement: windowElement).perform()),\n let url = webArea.url\n else { return nil }\n\n if [\n \"favorites://\",\n \"edge://newtab/\",\n \"chrome://newtab/\",\n \"chrome://new-tab-page/\",\n \"chrome://vivaldi-webui/\",\n \"about:newtab\", // Firefox\n ].contains(where: { url.absoluteString.contains($0) }) {\n return .newtab\n } else {\n return url\n }\n }\n}\n\nextension Browser {\n static func isSupportedBrowser(bundleId: String) -> Bool {\n return allCases.contains { $0.rawValue == bundleId }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/System/AppDelegate.swift", "import Cocoa\nimport Combine\nimport SwiftUI\nimport Alamofire\nimport LaunchAtLogin\n\nclass AppDelegate: NSObject, NSApplicationDelegate {\n var navigationVM: NavigationVM!\n var indicatorVM: IndicatorVM!\n var preferencesVM: PreferencesVM!\n var permissionsVM: PermissionsVM!\n var applicationVM: ApplicationVM!\n var inputSourceVM: InputSourceVM!\n var feedbackVM: FeedbackVM!\n var indicatorWindowController: IndicatorWindowController!\n var statusItemController: StatusItemController!\n\n func applicationDidFinishLaunching(_: Notification) {\n feedbackVM = FeedbackVM()\n navigationVM = NavigationVM()\n permissionsVM = PermissionsVM()\n preferencesVM = PreferencesVM(permissionsVM: permissionsVM)\n applicationVM = ApplicationVM(preferencesVM: preferencesVM)\n inputSourceVM = InputSourceVM(preferencesVM: preferencesVM)\n indicatorVM = IndicatorVM(permissionsVM: permissionsVM, preferencesVM: preferencesVM, applicationVM: applicationVM, inputSourceVM: inputSourceVM)\n\n indicatorWindowController = IndicatorWindowController(\n permissionsVM: permissionsVM,\n preferencesVM: preferencesVM,\n indicatorVM: indicatorVM,\n applicationVM: applicationVM,\n inputSourceVM: inputSourceVM\n )\n\n statusItemController = StatusItemController(\n navigationVM: navigationVM,\n permissionsVM: permissionsVM,\n preferencesVM: preferencesVM,\n applicationVM: applicationVM,\n indicatorVM: indicatorVM,\n feedbackVM: feedbackVM,\n inputSourceVM: inputSourceVM\n )\n \n LaunchAtLogin.migrateIfNeeded()\n openPreferencesAtFirstLaunch()\n sendLaunchPing()\n updateInstallVersionInfo()\n }\n\n func applicationDidBecomeActive(_: Notification) {\n statusItemController.openPreferences()\n }\n\n @MainActor\n func openPreferencesAtFirstLaunch() {\n if preferencesVM.preferences.prevInstalledBuildVersion != preferencesVM.preferences.buildVersion {\n statusItemController.openPreferences()\n }\n }\n\n @MainActor\n func updateInstallVersionInfo() {\n preferencesVM.preferences.prevInstalledBuildVersion = preferencesVM.preferences.buildVersion\n }\n \n @MainActor\n func sendLaunchPing() {\n let url = \"https://inputsource.pro/api/launch\"\n let launchData: [String: String] = [\n \"prevInstalledBuildVersion\": \"\\(preferencesVM.preferences.prevInstalledBuildVersion)\",\n \"shortVersion\": Bundle.main.shortVersion,\n \"buildVersion\": \"\\(Bundle.main.buildVersion)\",\n \"osVersion\": ProcessInfo.processInfo.operatingSystemVersionString\n ]\n \n AF.request(\n url,\n method: .post,\n parameters: launchData,\n encoding: JSONEncoding.default\n )\n .response { response in\n switch response.result {\n case .success:\n print(\"Launch ping sent successfully.\")\n case let .failure(error):\n print(\"Failed to send launch ping:\", error)\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSString.swift", "import Foundation\n\nextension String {\n func string(at atIndex: Int) -> String {\n guard !isEmpty else { return self }\n\n let offset = max(min(count - 1, atIndex), 0)\n\n return String(self[index(startIndex, offsetBy: offset)])\n }\n}\n\nextension String {\n func runCommand(\n requireSudo: Bool,\n completion: @escaping (_ output: String, _ errorOutput: String, _ exitCode: Int32) -> Void\n ) {\n let process = Process()\n let stdoutPipe = Pipe()\n let stderrPipe = Pipe()\n\n if requireSudo {\n let appleScript = \"\"\"\n do shell script \"\\(self.replacingOccurrences(of: \"\\\"\", with: \"\\\\\\\"\"))\" with administrator privileges\n \"\"\"\n process.launchPath = \"/usr/bin/osascript\"\n process.arguments = [\"-e\", appleScript]\n } else {\n process.launchPath = \"/bin/bash\"\n process.arguments = [\"-c\", self]\n }\n\n process.standardOutput = stdoutPipe\n process.standardError = stderrPipe\n\n process.terminationHandler = { proc in\n let outputData = stdoutPipe.fileHandleForReading.readDataToEndOfFile()\n let errorData = stderrPipe.fileHandleForReading.readDataToEndOfFile()\n \n let output = String(data: outputData, encoding: .utf8) ?? \"\"\n let errorOutput = String(data: errorData, encoding: .utf8) ?? \"\"\n let exitCode = proc.terminationStatus\n\n DispatchQueue.main.async {\n completion(output, errorOutput, exitCode)\n }\n }\n\n do {\n try process.run()\n } catch {\n DispatchQueue.main.async {\n completion(\"\", \"Process failed to start: \\(error)\", -1)\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/InputSourceVM.swift", "import AppKit\nimport AXSwift\nimport Carbon\nimport Combine\nimport Foundation\n\n@MainActor\nclass InputSourceVM: ObservableObject {\n let preferencesVM: PreferencesVM\n\n private var _isProgrammaticChange = false\n\n private var cancelBag = CancelBag()\n\n private let selectInputSourceSubject = PassthroughSubject()\n\n private let inputSourceChangesSubject = PassthroughSubject()\n\n let inputSourceChangesPublisher: AnyPublisher\n\n init(preferencesVM: PreferencesVM) {\n self.preferencesVM = preferencesVM\n inputSourceChangesPublisher = inputSourceChangesSubject.eraseToAnyPublisher()\n\n watchSystemNotification()\n\n selectInputSourceSubject\n .tap { [weak self] inputSource in\n guard let preferencesVM = self?.preferencesVM\n else { return }\n\n inputSource.select(useCJKVFix: preferencesVM.isUseCJKVFix())\n }\n .flatMapLatest { _ in\n Timer.interval(seconds: 0.2)\n .map { _ in InputSource.getCurrentInputSource() }\n .withPrevious()\n .filter { previous, current in\n guard let previous = previous else { return false }\n return previous.id == current.id\n }\n .map { _, current in current }\n .prefix(1)\n }\n .sink { [weak self] in\n self?.inputSourceChangesSubject.send($0)\n self?._isProgrammaticChange = false\n }\n .store(in: cancelBag)\n }\n\n func select(inputSource: InputSource) {\n _isProgrammaticChange = true\n selectInputSourceSubject.send(inputSource)\n }\n\n private func watchSystemNotification() {\n DistributedNotificationCenter.default()\n .publisher(for: Notification.Name(rawValue: kTISNotifySelectedKeyboardInputSourceChanged as String))\n .receive(on: DispatchQueue.main)\n .filter { [weak self] _ in self?._isProgrammaticChange == false }\n .map { _ in InputSource.getCurrentInputSource() }\n .sink { [weak self] in self?.inputSourceChangesSubject.send($0) }\n .store(in: cancelBag)\n }\n\n private func getInputSourceFromMenu() -> InputSource? {\n for app in NSWorkspace.shared.runningApplications {\n if app.bundleIdentifier == \"com.apple.TextInputMenuAgent\" {\n if let application = app.getApplication(preferencesVM: preferencesVM),\n let menuBar: UIElement = try? application.attribute(.extrasMenuBar)\n {\n for child in menuBar.children() ?? [] {\n if let description: String = try? child.attribute(.description),\n let inputSource = InputSource.sources.first(where: { $0.name == description })\n {\n return inputSource\n }\n }\n }\n\n return nil\n }\n }\n\n return nil\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/Color.swift", "// https://github.com/nbasham/BlackLabsSwiftUIColor/blob/main/Sources/BlackLabsSwiftUIColor/BlackLabsSwiftUIColor.swift\n\nimport SwiftUI\n\npublic extension Color {\n var hex: String { NSColor(self).hex }\n var hexWithAlpha: String { NSColor(self).hexWithAlpha }\n\n func hexDescription(_ includeAlpha: Bool = false) -> String {\n NSColor(self).hexDescription(includeAlpha)\n }\n}\n\npublic extension Color {\n /**\n Creates an immuatble `Color` instance specified by a hex string, CSS color name, or nil.\n\n - parameter hex: A case insensitive `String`? representing a hex or CSS value e.g.\n\n - **\"abc\"**\n - **\"abc7\"**\n - **\"#abc7\"**\n - **\"00FFFF\"**\n - **\"#00FFFF\"**\n - **\"00FFFF77\"**\n - **\"Orange\", \"Azure\", \"Tomato\"** Modern browsers support 140 color names ()\n - **\"Clear\"** [NSColor clearColor]\n - **\"Transparent\"** [NSColor clearColor]\n - **nil** [NSColor clearColor]\n - **empty string** [NSColor clearColor]\n */\n init(hex: String?) {\n self.init(NSColor(hex: hex))\n }\n}\n\nextension NSColor {\n /**\n Creates an immuatble `NSColor` instance specified by a hex string, CSS color name, or nil.\n\n - parameter hex: A case insensitive `String`? representing a hex or CSS value e.g.\n\n - **\"abc\"**\n - **\"abc7\"**\n - **\"#abc7\"**\n - **\"00FFFF\"**\n - **\"#00FFFF\"**\n - **\"00FFFF77\"**\n - **\"Orange\", \"Azure\", \"Tomato\"** Modern browsers support 140 color names ()\n - **\"Clear\"** [NSColor clearColor]\n - **\"Transparent\"** [NSColor clearColor]\n - **nil** [NSColor clearColor]\n - **empty string** [NSColor clearColor]\n */\n convenience init(hex: String?) {\n let normalizedHexString: String = NSColor.normalize(hex)\n var c: UInt64 = 0\n Scanner(string: normalizedHexString).scanHexInt64(&c)\n\n let cc = CUnsignedInt(c)\n\n self.init(\n red: NSColorMasks.redValue(cc),\n green: NSColorMasks.greenValue(cc),\n blue: NSColorMasks.blueValue(cc),\n alpha: NSColorMasks.alphaValue(cc)\n )\n }\n\n var hex: String { hexDescription(false) }\n var hexWithAlpha: String { hexDescription(true) }\n\n /**\n Returns a hex equivalent of this `NSColor`.\n\n - Parameter includeAlpha: Optional parameter to include the alpha hex, defaults to `false`.\n\n `color.hexDescription() -> \"ff0000\"`\n\n `color.hexDescription(true) -> \"ff0000aa\"`\n\n - Returns: A new string with `String` with the color's hexidecimal value.\n */\n func hexDescription(_ includeAlpha: Bool = false) -> String {\n guard cgColor.numberOfComponents == 4,\n let a = cgColor.components?.map({ Int($0 * CGFloat(255)) })\n else { return \"Color not RGB.\" }\n\n let color = String(format: \"%02x%02x%02x\", a[0], a[1], a[2])\n\n if includeAlpha {\n let alpha = String(format: \"%02x\", a[3])\n return \"\\(color)\\(alpha)\"\n }\n\n return color\n }\n\n fileprivate enum NSColorMasks: CUnsignedInt {\n case redMask = 0xFF00_0000\n case greenMask = 0x00FF_0000\n case blueMask = 0x0000_FF00\n case alphaMask = 0x0000_00FF\n\n static func redValue(_ value: CUnsignedInt) -> CGFloat {\n return CGFloat((value & redMask.rawValue) >> 24) / 255.0\n }\n\n static func greenValue(_ value: CUnsignedInt) -> CGFloat {\n return CGFloat((value & greenMask.rawValue) >> 16) / 255.0\n }\n\n static func blueValue(_ value: CUnsignedInt) -> CGFloat {\n return CGFloat((value & blueMask.rawValue) >> 8) / 255.0\n }\n\n static func alphaValue(_ value: CUnsignedInt) -> CGFloat {\n return CGFloat(value & alphaMask.rawValue) / 255.0\n }\n }\n\n fileprivate static func normalize(_ hex: String?) -> String {\n guard var hexString = hex else {\n return \"00000000\"\n }\n if let cssColor = cssToHexDictionary[hexString.uppercased()] {\n return cssColor.count == 8 ? cssColor : cssColor + \"ff\"\n }\n if hexString.hasPrefix(\"#\") {\n hexString = String(hexString.dropFirst())\n }\n if hexString.count == 3 || hexString.count == 4 {\n hexString = hexString.map { \"\\($0)\\($0)\" }.joined()\n }\n let hasAlpha = hexString.count > 7\n if !hasAlpha {\n hexString += \"ff\"\n }\n return hexString\n }\n\n /**\n All modern browsers support the following 140 color names (see http://www.w3schools.com/cssref/css_colornames.asp)\n */\n fileprivate static func hexFromCssName(_ cssName: String) -> String {\n let key = cssName.uppercased()\n if let hex = cssToHexDictionary[key] {\n return hex\n }\n return cssName\n }\n\n static let cssToHexDictionary: [String: String] = [\n \"CLEAR\": \"00000000\",\n \"TRANSPARENT\": \"00000000\",\n \"\": \"00000000\",\n \"ALICEBLUE\": \"F0F8FF\",\n \"ANTIQUEWHITE\": \"FAEBD7\",\n \"AQUA\": \"00FFFF\",\n \"AQUAMARINE\": \"7FFFD4\",\n \"AZURE\": \"F0FFFF\",\n \"BEIGE\": \"F5F5DC\",\n \"BISQUE\": \"FFE4C4\",\n \"BLACK\": \"000000\",\n \"BLANCHEDALMOND\": \"FFEBCD\",\n \"BLUE\": \"0000FF\",\n \"BLUEVIOLET\": \"8A2BE2\",\n \"BROWN\": \"A52A2A\",\n \"BURLYWOOD\": \"DEB887\",\n \"CADETBLUE\": \"5F9EA0\",\n \"CHARTREUSE\": \"7FFF00\",\n \"CHOCOLATE\": \"D2691E\",\n \"CORAL\": \"FF7F50\",\n \"CORNFLOWERBLUE\": \"6495ED\",\n \"CORNSILK\": \"FFF8DC\",\n \"CRIMSON\": \"DC143C\",\n \"CYAN\": \"00FFFF\",\n \"DARKBLUE\": \"00008B\",\n \"DARKCYAN\": \"008B8B\",\n \"DARKGOLDENROD\": \"B8860B\",\n \"DARKGRAY\": \"A9A9A9\",\n \"DARKGREY\": \"A9A9A9\",\n \"DARKGREEN\": \"006400\",\n \"DARKKHAKI\": \"BDB76B\",\n \"DARKMAGENTA\": \"8B008B\",\n \"DARKOLIVEGREEN\": \"556B2F\",\n \"DARKORANGE\": \"FF8C00\",\n \"DARKORCHID\": \"9932CC\",\n \"DARKRED\": \"8B0000\",\n \"DARKSALMON\": \"E9967A\",\n \"DARKSEAGREEN\": \"8FBC8F\",\n \"DARKSLATEBLUE\": \"483D8B\",\n \"DARKSLATEGRAY\": \"2F4F4F\",\n \"DARKSLATEGREY\": \"2F4F4F\",\n \"DARKTURQUOISE\": \"00CED1\",\n \"DARKVIOLET\": \"9400D3\",\n \"DEEPPINK\": \"FF1493\",\n \"DEEPSKYBLUE\": \"00BFFF\",\n \"DIMGRAY\": \"696969\",\n \"DIMGREY\": \"696969\",\n \"DODGERBLUE\": \"1E90FF\",\n \"FIREBRICK\": \"B22222\",\n \"FLORALWHITE\": \"FFFAF0\",\n \"FORESTGREEN\": \"228B22\",\n \"FUCHSIA\": \"FF00FF\",\n \"GAINSBORO\": \"DCDCDC\",\n \"GHOSTWHITE\": \"F8F8FF\",\n \"GOLD\": \"FFD700\",\n \"GOLDENROD\": \"DAA520\",\n \"GRAY\": \"808080\",\n \"GREY\": \"808080\",\n \"GREEN\": \"008000\",\n \"GREENYELLOW\": \"ADFF2F\",\n \"HONEYDEW\": \"F0FFF0\",\n \"HOTPINK\": \"FF69B4\",\n \"INDIANRED\": \"CD5C5C\",\n \"INDIGO\": \"4B0082\",\n \"IVORY\": \"FFFFF0\",\n \"KHAKI\": \"F0E68C\",\n \"LAVENDER\": \"E6E6FA\",\n \"LAVENDERBLUSH\": \"FFF0F5\",\n \"LAWNGREEN\": \"7CFC00\",\n \"LEMONCHIFFON\": \"FFFACD\",\n \"LIGHTBLUE\": \"ADD8E6\",\n \"LIGHTCORAL\": \"F08080\",\n \"LIGHTCYAN\": \"E0FFFF\",\n \"LIGHTGOLDENRODYELLOW\": \"FAFAD2\",\n \"LIGHTGRAY\": \"D3D3D3\",\n \"LIGHTGREY\": \"D3D3D3\",\n \"LIGHTGREEN\": \"90EE90\",\n \"LIGHTPINK\": \"FFB6C1\",\n \"LIGHTSALMON\": \"FFA07A\",\n \"LIGHTSEAGREEN\": \"20B2AA\",\n \"LIGHTSKYBLUE\": \"87CEFA\",\n \"LIGHTSLATEGRAY\": \"778899\",\n \"LIGHTSLATEGREY\": \"778899\",\n \"LIGHTSTEELBLUE\": \"B0C4DE\",\n \"LIGHTYELLOW\": \"FFFFE0\",\n \"LIME\": \"00FF00\",\n \"LIMEGREEN\": \"32CD32\",\n \"LINEN\": \"FAF0E6\",\n \"MAGENTA\": \"FF00FF\",\n \"MAROON\": \"800000\",\n \"MEDIUMAQUAMARINE\": \"66CDAA\",\n \"MEDIUMBLUE\": \"0000CD\",\n \"MEDIUMORCHID\": \"BA55D3\",\n \"MEDIUMPURPLE\": \"9370DB\",\n \"MEDIUMSEAGREEN\": \"3CB371\",\n \"MEDIUMSLATEBLUE\": \"7B68EE\",\n \"MEDIUMSPRINGGREEN\": \"00FA9A\",\n \"MEDIUMTURQUOISE\": \"48D1CC\",\n \"MEDIUMVIOLETRED\": \"C71585\",\n \"MIDNIGHTBLUE\": \"191970\",\n \"MINTCREAM\": \"F5FFFA\",\n \"MISTYROSE\": \"FFE4E1\",\n \"MOCCASIN\": \"FFE4B5\",\n \"NAVAJOWHITE\": \"FFDEAD\",\n \"NAVY\": \"000080\",\n \"OLDLACE\": \"FDF5E6\",\n \"OLIVE\": \"808000\",\n \"OLIVEDRAB\": \"6B8E23\",\n \"ORANGE\": \"FFA500\",\n \"ORANGERED\": \"FF4500\",\n \"ORCHID\": \"DA70D6\",\n \"PALEGOLDENROD\": \"EEE8AA\",\n \"PALEGREEN\": \"98FB98\",\n \"PALETURQUOISE\": \"AFEEEE\",\n \"PALEVIOLETRED\": \"DB7093\",\n \"PAPAYAWHIP\": \"FFEFD5\",\n \"PEACHPUFF\": \"FFDAB9\",\n \"PERU\": \"CD853F\",\n \"PINK\": \"FFC0CB\",\n \"PLUM\": \"DDA0DD\",\n \"POWDERBLUE\": \"B0E0E6\",\n \"PURPLE\": \"800080\",\n \"RED\": \"FF0000\",\n \"ROSYBROWN\": \"BC8F8F\",\n \"ROYALBLUE\": \"4169E1\",\n \"SADDLEBROWN\": \"8B4513\",\n \"SALMON\": \"FA8072\",\n \"SANDYBROWN\": \"F4A460\",\n \"SEAGREEN\": \"2E8B57\",\n \"SEASHELL\": \"FFF5EE\",\n \"SIENNA\": \"A0522D\",\n \"SILVER\": \"C0C0C0\",\n \"SKYBLUE\": \"87CEEB\",\n \"SLATEBLUE\": \"6A5ACD\",\n \"SLATEGRAY\": \"708090\",\n \"SLATEGREY\": \"708090\",\n \"SNOW\": \"FFFAFA\",\n \"SPRINGGREEN\": \"00FF7F\",\n \"STEELBLUE\": \"4682B4\",\n \"TAN\": \"D2B48C\",\n \"TEAL\": \"008080\",\n \"THISTLE\": \"D8BFD8\",\n \"TOMATO\": \"FF6347\",\n \"TURQUOISE\": \"40E0D0\",\n \"VIOLET\": \"EE82EE\",\n \"WHEAT\": \"F5DEB3\",\n \"WHITE\": \"FFFFFF\",\n \"WHITESMOKE\": \"F5F5F5\",\n \"YELLOW\": \"FFFF00\",\n \"YELLOWGREEN\": \"9ACD32\",\n ]\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/NSToggleView.swift", "import AppKit\nimport SwiftUI\n\nenum NSToggleViewState {\n case on, off, mixed\n\n var controlState: NSControl.StateValue {\n switch self {\n case .on:\n return .on\n case .mixed:\n return .mixed\n case .off:\n return .off\n }\n }\n}\n\nstruct NSToggleView: NSViewRepresentable {\n let label: String\n let state: NSToggleViewState\n let onStateUpdate: () -> NSControl.StateValue\n\n func makeCoordinator() -> Coordinator {\n Coordinator(parent: self)\n }\n\n func makeNSView(context: Self.Context) -> NSButton {\n let button = NSButton()\n\n button.title = label\n button.allowsMixedState = true\n button.setButtonType(.switch)\n button.target = context.coordinator\n button.action = #selector(Coordinator.onClick(_:))\n\n return button\n }\n\n func updateNSView(_ button: NSButton, context _: Self.Context) {\n button.title = label\n button.state = state.controlState\n }\n}\n\nextension NSToggleView {\n final class Coordinator: NSObject {\n private let parent: NSToggleView\n\n init(parent: NSToggleView) {\n self.parent = parent\n }\n\n @IBAction\n func onClick(_ sender: NSButton) {\n sender.state = parent.onStateUpdate()\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/PreferencesVM+AppKeyboardCache.swift", "import AppKit\n\nextension PreferencesVM {\n func appNeedCacheKeyboard(_ appKind: AppKind) -> Bool {\n if let browserRule = appKind.getBrowserInfo()?.rule,\n let keyboardRestoreStrategy = browserRule.keyboardRestoreStrategy\n {\n switch keyboardRestoreStrategy {\n case .RestorePreviouslyUsedOne:\n return true\n case .UseDefaultKeyboardInstead:\n return false\n }\n }\n\n let appRule = getAppCustomization(app: appKind.getApp())\n\n if preferences.isRestorePreviouslyUsedInputSource,\n appRule?.doNotRestoreKeyboard != true\n {\n return true\n }\n\n if !preferences.isRestorePreviouslyUsedInputSource,\n appRule?.doRestoreKeyboard == true\n {\n return true\n }\n\n return false\n }\n\n func cacheKeyboardFor(_ appKind: AppKind, keyboard: InputSource) {\n let defaultKeyboard = getAppDefaultKeyboard(appKind)\n\n if appNeedCacheKeyboard(appKind),\n defaultKeyboard?.id != keyboard.id\n {\n appKeyboardCache.save(appKind, keyboard: keyboard)\n } else {\n appKeyboardCache.remove(appKind)\n }\n }\n\n func removeKeyboardCacheFor(bundleId: String) {\n appKeyboardCache.remove(byBundleId: bundleId)\n }\n\n func clearKeyboardCache() {\n appKeyboardCache.clear()\n }\n\n enum AppAutoSwitchKeyboardStatus {\n case cached(InputSource), specified(InputSource)\n\n var inputSource: InputSource {\n switch self {\n case let .cached(i): return i\n case let .specified(i): return i\n }\n }\n }\n\n func getAppAutoSwitchKeyboard(\n _ appKind: AppKind\n ) -> AppAutoSwitchKeyboardStatus? {\n if let cachedKeyboard = getAppCachedKeyboard(appKind) {\n return .cached(cachedKeyboard)\n }\n\n if let defaultKeyboard = getAppDefaultKeyboard(appKind) {\n return .specified(defaultKeyboard)\n }\n\n // Fallback to system-wide default keyboard to prevent input method getting stuck\n // This ensures that apps without specific keyboard configuration will always\n // switch to the system default, resolving issues like ChatGPT → Terminal switching\n if let systemDefaultKeyboard = systemWideDefaultKeyboard {\n return .specified(systemDefaultKeyboard)\n }\n\n return nil\n }\n\n func getAppCachedKeyboard(_ appKind: AppKind) -> InputSource? {\n guard appNeedCacheKeyboard(appKind) else { return nil }\n return appKeyboardCache.retrieve(appKind)\n }\n\n func getAppDefaultKeyboard(_ appKind: AppKind) -> InputSource? {\n if appKind.getBrowserInfo()?.isFocusedOnAddressBar == true,\n let browserAddressKeyboard = browserAddressDefaultKeyboard\n {\n return browserAddressKeyboard\n }\n\n if let inputSource = appKind.getBrowserInfo()?.rule?.forcedKeyboard {\n return inputSource\n }\n\n return getAppCustomization(app: appKind.getApp())?.forcedKeyboard ?? systemWideDefaultKeyboard\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Controllers/IndicatorViewController.swift", "import AppKit\nimport SnapKit\n\n@MainActor\nclass IndicatorViewController: NSViewController {\n let hoverableView = NSViewHoverable(frame: .zero)\n\n private(set) var config: IndicatorViewConfig? = nil {\n didSet {\n nextAlwaysOnView = config?.renderAlwaysOn()\n nextNormalView = config?.render()\n\n if normalView == nil || alwaysOnView == nil {\n refresh()\n }\n }\n }\n\n var fittingSize: CGSize? {\n nextNormalView?.fittingSize ?? normalView?.fittingSize\n }\n\n private(set) var nextNormalView: NSView? = nil\n private(set) var nextAlwaysOnView: NSView? = nil\n\n private(set) var normalView: NSView? = nil {\n didSet {\n oldValue?.removeFromSuperview()\n\n if let normalView = normalView {\n view.addSubview(normalView)\n\n normalView.snp.makeConstraints { make in\n let size = normalView.fittingSize\n\n make.edges.equalToSuperview()\n make.width.equalTo(size.width)\n make.height.equalTo(size.height)\n }\n }\n }\n }\n\n private(set) var alwaysOnView: NSView? = nil {\n didSet {\n oldValue?.removeFromSuperview()\n\n if let alwaysOnView = alwaysOnView {\n alwaysOnView.alphaValue = 0\n view.addSubview(alwaysOnView)\n\n alwaysOnView.snp.makeConstraints { make in\n make.leading.bottom.equalToSuperview()\n }\n }\n }\n }\n\n init() {\n super.init(nibName: nil, bundle: nil)\n }\n\n @available(*, unavailable)\n required init?(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n\n func prepare(config: IndicatorViewConfig) {\n self.config = config\n }\n\n func refresh() {\n if let nextNormalView = nextNormalView {\n normalView = nextNormalView\n self.nextNormalView = nil\n }\n\n if let nextAlwaysOnView = nextAlwaysOnView {\n alwaysOnView = nextAlwaysOnView\n self.nextAlwaysOnView = nil\n }\n }\n\n func showAlwaysOnView() {\n normalView?.animator().alphaValue = 0\n alwaysOnView?.animator().alphaValue = 1\n }\n\n override func loadView() {\n view = hoverableView\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/IndicatorView.swift", "import SwiftUI\n\nstruct IndicatorView: NSViewControllerRepresentable {\n @EnvironmentObject var preferencesVM: PreferencesVM\n @EnvironmentObject var indicatorVM: IndicatorVM\n @EnvironmentObject var inputSourceVM: InputSourceVM\n\n func makeNSViewController(context _: Context) -> IndicatorViewController {\n return IndicatorViewController()\n }\n\n func updateNSViewController(_ indicatorViewController: IndicatorViewController, context _: Context) {\n indicatorViewController.prepare(config: IndicatorViewConfig(\n inputSource: indicatorVM.state.inputSource,\n kind: preferencesVM.preferences.indicatorKind,\n size: preferencesVM.preferences.indicatorSize ?? .medium,\n bgColor: NSColor(preferencesVM.preferences.indicatorBackgroundColor),\n textColor: NSColor(preferencesVM.preferences.indicatorForgegroundColor)\n ))\n\n indicatorViewController.refresh()\n }\n}\n\nstruct DumpIndicatorView: NSViewControllerRepresentable {\n let config: IndicatorViewConfig\n\n init(config: IndicatorViewConfig) {\n self.config = config\n }\n\n func makeNSViewController(context _: Context) -> IndicatorViewController {\n return IndicatorViewController()\n }\n\n func updateNSViewController(_ indicatorViewController: IndicatorViewController, context _: Context) {\n indicatorViewController.prepare(config: config)\n indicatorViewController.refresh()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSScreen.swift", "import AppKit\n\nextension NSScreen {\n static func getScreenWithMouse() -> NSScreen? {\n let mouseLocation = NSEvent.mouseLocation\n let screens = NSScreen.screens\n\n return screens.first(where: { NSMouseInRect(mouseLocation, $0.frame, false) })\n }\n\n static func getScreenInclude(rect: CGRect) -> NSScreen? {\n return NSScreen.screens\n .map { screen in (screen, screen.frame.intersection(rect)) }\n .filter { _, intersect in !intersect.isNull }\n .map { screen, intersect in (screen, intersect.size.width * intersect.size.height) }\n .max { lhs, rhs in lhs.1 < rhs.1 }?.0\n }\n}\n\nextension NSScreen {\n /// The screen whose bottom left is at (0, 0).\n static var primary: NSScreen? {\n return NSScreen.screens.first\n }\n\n /// Converts the rectangle from Quartz \"display space\" to Cocoa \"screen space\".\n /// \n static func convertFromQuartz(_ rect: CGRect) -> CGRect? {\n return NSScreen.primary.map { screen in\n var result = rect\n result.origin.y = screen.frame.maxY - result.maxY\n return result\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/NavigationVM.swift", "import SwiftUI\n\n@MainActor\nclass NavigationVM: ObservableObject {\n enum Nav: String, CaseIterable, Identifiable {\n var id: String { rawValue }\n\n case general = \"General\"\n\n case appRules = \"App Rules\"\n case browserRules = \"Browser Rules\"\n\n case position = \"Position\"\n case appearance = \"Appearance\"\n\n case inputSourcesColorScheme = \"Input Sources Color Scheme\"\n case keyboardShortcut = \"Hot Keys\"\n\n case troubleshooting = \"Troubleshooting\"\n\n static var grouped: [(id: String, title: String, nav: [Nav])] {\n [\n (\"general\", \"\", [.general]),\n (\"rule\", \"Rules\", [.appRules, .browserRules]),\n (\"theme\", \"Indicator\", [.position, .appearance]),\n (\"keyboard\", \"Keyboard\", [.inputSourcesColorScheme, .keyboardShortcut]),\n (\"others\", \"Others\", [.troubleshooting]),\n ]\n }\n }\n\n @Published var selection: Nav = .general\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSCFRange.swift", "import Foundation\n\nextension CFRange {\n init(range: NSRange) {\n self = CFRangeMake(range.location == NSNotFound ? kCFNotFound : range.location, range.length)\n }\n\n func cursorRange(offset: Int, value: String) -> NSRange {\n return NSRange(location: max(min(location + offset, value.count - 1), 0), length: 1)\n }\n}\n\nextension NSRange {\n init(range: CFRange) {\n self = NSMakeRange(range.location == kCFNotFound ? NSNotFound : range.location, range.length)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/BrowserRuleMenuItem.swift", "import AppKit\n\n@MainActor\nclass BrowserRuleMenuItem: NSMenuItem {\n let url: URL\n let preferencesVM: PreferencesVM\n let inputSource: InputSource?\n\n var cancelBag = CancelBag()\n\n var browserRule: BrowserRule? {\n preferencesVM.getBrowserRule(url: url)\n }\n\n init(url: URL, preferencesVM: PreferencesVM, inputSource: InputSource?) {\n self.url = url\n self.preferencesVM = preferencesVM\n self.inputSource = inputSource\n\n super.init(title: inputSource?.name ?? \"\", action: #selector(forceKeyboard(_:)), keyEquivalent: \"\")\n\n target = self\n\n updateState()\n watchChanges()\n }\n\n @available(*, unavailable)\n required init(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n\n @objc func forceKeyboard(_: Any) {\n let inputSourceId = inputSource?.id ?? \"\"\n let host = url.host ?? \"\"\n\n if let browserRule = browserRule {\n preferencesVM.updateBrowserRule(\n browserRule,\n type: .domain,\n value: host,\n sample: url.absoluteString,\n inputSourceId: inputSourceId,\n hideIndicator: browserRule.hideIndicator,\n keyboardRestoreStrategy: browserRule.keyboardRestoreStrategy\n )\n } else {\n preferencesVM.addBrowserRule(\n type: .domain,\n value: host,\n sample: url.absoluteString,\n inputSourceId: inputSourceId,\n hideIndicator: false,\n keyboardRestoreStrategy: nil\n )\n }\n\n inputSource?.select(useCJKVFix: preferencesVM.isUseCJKVFix())\n\n watchChanges()\n }\n\n func watchChanges() {\n cancelBag.cancel()\n\n browserRule?.publisher(for: \\.inputSourceId)\n .sink { [weak self] _ in self?.updateState() }\n .store(in: cancelBag)\n }\n\n func updateState() {\n state = browserRule?.inputSourceId == inputSource?.id ? .on : .off\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/FeedbackVM.swift", "import Alamofire\nimport SwiftUI\n\n@MainActor\nfinal class FeedbackVM: ObservableObject {\n enum Status {\n case hided, editing, sending, sent\n }\n\n var isSent: Bool { status == .sent }\n\n var isSending: Bool { status == .sending }\n\n var isPresented: Bool { status != .hided }\n\n @Published private(set) var status = Status.hided\n\n @Published var message = \"\"\n\n @Published var email = \"\"\n\n func show() {\n if status == .hided {\n status = .editing\n }\n }\n\n func hide() {\n if status != .sending {\n status = .hided\n }\n }\n\n func sendFeedback() async {\n withAnimation {\n status = .sending\n }\n\n let _ = await AF\n .request(\n \"https://inputsource.pro/api/feedback\",\n method: .post,\n parameters: [\n \"message\": message,\n \"email\": email,\n \"version\": \"\\(Bundle.main.shortVersion) \\(Bundle.main.buildVersion)\",\n \"osVersion\": ProcessInfo.processInfo.operatingSystemVersionString,\n ],\n encoder: .json\n )\n .serializingDecodable(Alamofire.Empty.self, emptyResponseCodes: [200])\n .response\n\n message = \"\"\n email = \"\"\n\n withAnimation {\n status = .sent\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSImage+Extension.swift", "import AppKit\n\nextension NSImage {\n func markTemplateIfGrayScaleOrPdf(url: URL? = nil) -> NSImage {\n let image = copy() as! NSImage\n\n if url?.pathExtension == \"pdf\" || isGrayScale() {\n image.isTemplate = true\n }\n\n return image\n }\n\n func isGrayScale() -> Bool {\n guard let imageRef = cgImage(),\n let colorSpace = imageRef.colorSpace\n else { return false }\n\n if colorSpace.model == .monochrome {\n return true\n }\n\n guard let imageData = imageRef.dataProvider?.data,\n let rawData = CFDataGetBytePtr(imageData)\n else { return false }\n\n var byteIndex = 0\n\n for _ in 0 ..< imageRef.width * imageRef.height {\n let r = rawData[byteIndex]\n let g = rawData[byteIndex + 1]\n let b = rawData[byteIndex + 2]\n\n if r == g && g == b {\n byteIndex += 4\n } else {\n return false\n }\n }\n\n return true\n }\n\n func cgImage() -> CGImage? {\n var rect = CGRect(origin: .zero, size: size)\n return cgImage(forProposedRect: &rect, context: nil, hints: nil)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/CustomizedIndicatorView.swift", "import SwiftUI\n\nstruct CustomizedIndicatorView: View {\n @EnvironmentObject var preferencesVM: PreferencesVM\n\n let inputSource: InputSource\n\n init(inputSource: InputSource) {\n self.inputSource = inputSource\n }\n\n var body: some View {\n return Group {\n DumpIndicatorView(config: IndicatorViewConfig(\n inputSource: inputSource,\n kind: preferencesVM.preferences.indicatorKind,\n size: preferencesVM.preferences.indicatorSize ?? .medium,\n bgColor: NSColor(preferencesVM.getBgColor(inputSource)),\n textColor: NSColor(preferencesVM.getTextColor(inputSource))\n ))\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/ApplicationVM+AXNotification.swift", "import AppKit\nimport AXSwift\nimport Combine\nimport Foundation\n\nextension ApplicationVM {\n static func createWindowAXNotificationPublisher(\n preferencesVM: PreferencesVM\n ) -> AnyPublisher {\n return preferencesVM.$preferences\n .flatMapLatest { preferences -> AnyPublisher in\n guard preferences.isEnhancedModeEnabled\n else { return Empty().eraseToAnyPublisher() }\n\n return NSWorkspace.shared\n .publisher(for: \\.runningApplications)\n .map { $0.filter { NSApplication.isFloatingApp($0.bundleIdentifier) } }\n .removeDuplicates()\n .flatMapLatest { apps in\n Publishers.MergeMany(apps\n .map {\n $0.watchAX(\n [.windowCreated, .uiElementDestroyed],\n [.application, .window]\n )\n }\n )\n }\n .eraseToAnyPublisher()\n }\n .share()\n .eraseToAnyPublisher()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/KeyboardRestoreStrategy.swift", "import SwiftUI\n\nenum KeyboardRestoreStrategy: String, CaseIterable, Identifiable {\n case UseDefaultKeyboardInstead\n case RestorePreviouslyUsedOne\n\n var name: String {\n switch self {\n case .UseDefaultKeyboardInstead:\n return \"Use Default Keyboard Instead\".i18n()\n case .RestorePreviouslyUsedOne:\n return \"Restore Previously Used One\".i18n()\n }\n }\n\n var systemImageName: String {\n switch self {\n case .UseDefaultKeyboardInstead:\n return \"d.circle.fill\"\n case .RestorePreviouslyUsedOne:\n return \"arrow.uturn.left.circle.fill\"\n }\n }\n\n var id: Self { self }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Accessibility/QueryWebAreaService.swift", "import AXSwift\nimport Cocoa\nimport RxSwift\n\nclass QueryWebAreaService {\n let windowElement: Element\n\n init(windowElement: Element) {\n self.windowElement = windowElement\n }\n\n func perform() throws -> Element? {\n try fetchScrollArea()\n }\n\n private func fetchScrollArea() throws -> Element? {\n var stack: [Element] = [windowElement]\n\n while stack.count > 0 {\n let element = stack.popLast()!\n\n if element.role == \"AXWebArea\",\n element.url?.scheme != \"chrome-extension\"\n {\n return element\n }\n\n let children = try fetchChildren(element) ?? []\n for child in children {\n stack.append(child)\n }\n }\n\n return nil\n }\n\n private func fetchChildren(_ element: Element) throws -> [Element]? {\n let rawElementsOptional: [AXUIElement]? = try {\n if element.role == \"AXTable\" || element.role == \"AXOutline\" {\n return try UIElement(element.rawElement).attribute(.visibleRows)\n }\n return try UIElement(element.rawElement).attribute(.children)\n }()\n\n guard let rawElements = rawElementsOptional else {\n return nil\n }\n\n return rawElements\n .map { Element.initialize(rawElement: $0) }\n .compactMap { $0 }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Controllers/PreferencesWindowController+NSToolbar.swift", "import AppKit\n\nextension PreferencesWindowController: NSSharingServicePickerToolbarItemDelegate {\n func items(for _: NSSharingServicePickerToolbarItem) -> [Any] {\n // Compose an array of items that are sharable such as text, URLs, etc.\n // depending on the context of your application (i.e. what the user\n // current has selected in the app and/or they tab they're in).\n let sharableItems = [URL(string: \"https://inputsource.pro/\")!] as [Any]\n\n return sharableItems\n }\n}\n\nextension PreferencesWindowController: NSToolbarDelegate {\n func toolbarDefaultItemIdentifiers(_: NSToolbar) -> [NSToolbarItem.Identifier] {\n return []\n// return [.toolbarShareButtonItem]\n }\n\n func toolbarAllowedItemIdentifiers(_: NSToolbar) -> [NSToolbarItem.Identifier] {\n return [.toolbarShareButtonItem]\n }\n\n func toolbar(\n _: NSToolbar,\n itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier,\n willBeInsertedIntoToolbar _: Bool\n ) -> NSToolbarItem? {\n if itemIdentifier == NSToolbarItem.Identifier.toolbarShareButtonItem {\n let shareItem = NSSharingServicePickerToolbarItem(itemIdentifier: itemIdentifier)\n\n shareItem.toolTip = \"Share\"\n shareItem.delegate = self\n\n if #available(macOS 11.0, *) {\n shareItem.menuFormRepresentation?.image = NSImage(\n systemSymbolName: \"square.and.arrow.up\",\n accessibilityDescription: nil\n )\n }\n\n return shareItem\n }\n\n return nil\n }\n}\n\nextension PreferencesWindowController: NSToolbarItemValidation {\n func validateToolbarItem(_ item: NSToolbarItem) -> Bool {\n if item.itemIdentifier == .toolbarShareButtonItem {\n return true\n }\n\n return false\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/AppRuleMenuItem.swift", "import AppKit\n\n@MainActor\nclass AppRuleMenuItem: NSMenuItem {\n let app: NSRunningApplication\n let preferencesVM: PreferencesVM\n let inputSource: InputSource?\n\n var cancelBag = CancelBag()\n\n var appCustomization: AppRule? {\n preferencesVM.getAppCustomization(app: app)\n }\n\n init(app: NSRunningApplication, preferencesVM: PreferencesVM, inputSource: InputSource?) {\n self.app = app\n self.preferencesVM = preferencesVM\n self.inputSource = inputSource\n\n super.init(title: inputSource?.name ?? \"\", action: #selector(forceKeyboard(_:)), keyEquivalent: \"\")\n\n target = self\n\n updateState()\n watchChanges()\n }\n\n @available(*, unavailable)\n required init(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n\n @objc func forceKeyboard(_: Any) {\n let inputSourceId = inputSource?.id ?? \"\"\n\n if let appCustomization = appCustomization {\n preferencesVM.setForceKeyboard(appCustomization, inputSourceId)\n } else {\n preferencesVM.setForceKeyboard(\n preferencesVM.addAppCustomization(app),\n inputSourceId\n )\n }\n\n inputSource?.select(useCJKVFix: preferencesVM.isUseCJKVFix())\n\n watchChanges()\n }\n\n func watchChanges() {\n cancelBag.cancel()\n\n appCustomization?.publisher(for: \\.inputSourceId)\n .sink { [weak self] _ in self?.updateState() }\n .store(in: cancelBag)\n }\n\n func updateState() {\n state = appCustomization?.inputSourceId == inputSource?.id ? .on : .off\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/UserDefault.swift", "// https://gist.github.com/simonbs/61c8269e1b0550feab606ee9890fa72b\nimport Cocoa\nimport Combine\n\n@propertyWrapper\nfinal class UserDefault: NSObject {\n // This ensures requirement 1 is fulfilled. The wrapped value is stored in user defaults.\n var wrappedValue: T {\n get {\n return userDefaults.object(forKey: key) as! T\n }\n set {\n userDefaults.setValue(newValue, forKey: key)\n }\n }\n\n var projectedValue: AnyPublisher {\n return subject.eraseToAnyPublisher()\n }\n\n private let key: String\n private let userDefaults: UserDefaults\n private var observerContext = 0\n private let subject: CurrentValueSubject\n\n init(wrappedValue defaultValue: T, _ key: String, userDefaults: UserDefaults = .standard) {\n self.key = key\n self.userDefaults = userDefaults\n subject = CurrentValueSubject(defaultValue)\n super.init()\n userDefaults.register(defaults: [key: defaultValue])\n // This fulfills requirement 4. Some implementations use NSUserDefaultsDidChangeNotification\n // but that is sent every time any value is updated in UserDefaults.\n userDefaults.addObserver(self, forKeyPath: key, options: .new, context: &observerContext)\n subject.value = wrappedValue\n }\n\n override func observeValue(\n forKeyPath keyPath: String?,\n of object: Any?,\n change: [NSKeyValueChangeKey: Any]?,\n context: UnsafeMutableRawPointer?\n ) {\n if context == &observerContext {\n subject.value = wrappedValue\n } else {\n super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)\n }\n }\n\n deinit {\n userDefaults.removeObserver(self, forKeyPath: key, context: &observerContext)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Window/FloatWindowController.swift", "import AppKit\n\nclass FloatWindowController: NSWindowController, NSWindowDelegate {\n init(canBecomeKey: Bool = false) {\n super.init(window: FloatWindow(\n canBecomeKey: canBecomeKey,\n contentRect: CGRect(origin: .zero, size: .zero),\n styleMask: [.borderless, .fullSizeContentView, .nonactivatingPanel],\n backing: .buffered,\n defer: false\n ))\n\n window?.delegate = self\n window?.ignoresMouseEvents = true\n window?.standardWindowButton(.zoomButton)?.isEnabled = false\n window?.standardWindowButton(.miniaturizeButton)?.isEnabled = false\n }\n\n @available(*, unavailable)\n required init?(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n}\n\nextension FloatWindowController {\n func active() {\n window?.orderFront(nil)\n }\n\n func deactive() {\n window?.orderOut(nil)\n }\n\n func moveTo(point: CGPoint) {\n window?.setFrameOrigin(point)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/PopUpButtonPicker.swift", "import AppKit\nimport SwiftUI\n\nstruct PickerItem: Equatable, Identifiable {\n static let mixed = PickerItem(id: \"mixed\", title: \"Mixed\", toolTip: nil)\n static let empty = PickerItem(id: \"\", title: \"\", toolTip: nil)\n\n let id: String\n let title: String\n let toolTip: String?\n}\n\nstruct PopUpButtonPicker: NSViewRepresentable {\n final class Coordinator: NSObject {\n private let parent: PopUpButtonPicker\n\n init(parent: PopUpButtonPicker) {\n self.parent = parent\n }\n\n @IBAction\n func selectItem(_ sender: NSPopUpButton) {\n parent.onSelect(sender.indexOfSelectedItem)\n }\n }\n\n let items: [Item]\n var width: CGFloat? = nil\n var isItemEnabled: (Item) -> Bool = { _ in true }\n let isItemSelected: (Item) -> Bool\n let getTitle: (Item) -> String\n let getToolTip: (Item) -> String?\n let onSelect: (Int) -> Void\n\n func makeCoordinator() -> Coordinator {\n Coordinator(parent: self)\n }\n\n func makeNSView(context: Self.Context) -> NSPopUpButton {\n let popUpButton = NSPopUpButton(frame: .zero, pullsDown: false)\n popUpButton.autoenablesItems = false\n popUpButton.target = context.coordinator\n popUpButton.action = #selector(Coordinator.selectItem(_:))\n\n if let width = width {\n popUpButton.snp.makeConstraints { make in\n make.width.equalTo(width)\n }\n }\n\n return popUpButton\n }\n\n func updateNSView(_ popUpButton: NSPopUpButton, context _: Self.Context) {\n popUpButton.removeAllItems()\n\n for item in items {\n let menuItem = NSMenuItem()\n\n // in order for this to work, autoenablesItems must be set to false\n menuItem.isEnabled = isItemEnabled(item)\n menuItem.title = getTitle(item)\n menuItem.toolTip = getToolTip(item)\n\n popUpButton.menu?.addItem(menuItem)\n }\n\n if let selectedIndex = items.firstIndex(where: isItemSelected) {\n popUpButton.selectItem(at: selectedIndex)\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/Data+SHA256.swift", "import CommonCrypto\nimport Foundation\n\nextension Data {\n public func sha256() -> String {\n return hexStringFromData(input: digest(input: self as NSData))\n }\n\n private func digest(input: NSData) -> NSData {\n let digestLength = Int(CC_SHA256_DIGEST_LENGTH)\n var hash = [UInt8](repeating: 0, count: digestLength)\n CC_SHA256(input.bytes, UInt32(input.length), &hash)\n return NSData(bytes: hash, length: digestLength)\n }\n\n private func hexStringFromData(input: NSData) -> String {\n var bytes = [UInt8](repeating: 0, count: input.length)\n input.getBytes(&bytes, length: input.length)\n\n var hexString = \"\"\n for byte in bytes {\n hexString += String(format: \"%02x\", UInt8(byte))\n }\n\n return hexString\n }\n}\n\npublic extension String {\n func sha256() -> String {\n if let stringData = data(using: String.Encoding.utf8) {\n return stringData.sha256()\n }\n return \"\"\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/CodableUserDefault.swift", "import Cocoa\nimport Combine\n\n@propertyWrapper\nfinal class CodableUserDefault: NSObject {\n var wrappedValue: T? {\n get {\n guard let data = userDefaults.data(forKey: key) else { return nil }\n return try? JSONDecoder().decode(T.self, from: data)\n }\n\n set {\n do {\n let data = try JSONEncoder().encode(newValue)\n\n userDefaults.setValue(data, forKey: key)\n } catch {\n print(\"Unable to Encode (\\(error))\")\n }\n }\n }\n\n private let key: String\n private let userDefaults: UserDefaults\n private var observerContext = 0\n private let subject: CurrentValueSubject\n\n init(wrappedValue defaultValue: T, _ key: String, userDefaults: UserDefaults = .standard) {\n self.key = key\n self.userDefaults = userDefaults\n subject = CurrentValueSubject(defaultValue)\n\n super.init()\n\n do {\n try userDefaults.register(defaults: [key: JSONEncoder().encode(defaultValue)])\n // This fulfills requirement 4. Some implementations use NSUserDefaultsDidChangeNotification\n // but that is sent every time any value is updated in UserDefaults.\n userDefaults.addObserver(self, forKeyPath: key, options: .new, context: &observerContext)\n } catch {\n print(\"Unable to register (\\(error))\")\n }\n\n subject.value = wrappedValue\n }\n\n override func observeValue(\n forKeyPath keyPath: String?,\n of object: Any?,\n change: [NSKeyValueChangeKey: Any]?,\n context: UnsafeMutableRawPointer?\n ) {\n if context == &observerContext {\n subject.value = wrappedValue\n } else {\n super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)\n }\n }\n\n deinit {\n userDefaults.removeObserver(self, forKeyPath: key, context: &observerContext)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/LoopingPlayerNSView.swift", "import AppKit\nimport AVFoundation\nimport SwiftUI\n\nstruct PlayerView: NSViewRepresentable {\n let url: URL\n\n func updateNSView(_: NSViewType, context _: Context) {}\n\n func makeNSView(context _: Context) -> some NSView {\n return LoopingPlayerUIView(url: url)\n }\n}\n\nclass LoopingPlayerUIView: NSView {\n private let playerLayer = AVPlayerLayer()\n\n @available(*, unavailable)\n required init?(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n\n init(url: URL) {\n super.init(frame: .zero)\n\n // Setup the player\n let player = AVPlayer(url: url)\n playerLayer.player = player\n playerLayer.videoGravity = .resizeAspectFill\n\n wantsLayer = true\n layer?.addSublayer(playerLayer)\n\n // Setup looping\n player.actionAtItemEnd = .none\n NotificationCenter.default.addObserver(\n self,\n selector: #selector(playerItemDidReachEnd(notification:)),\n name: .AVPlayerItemDidPlayToEndTime,\n object: player.currentItem\n )\n\n // Start the movie\n player.play()\n }\n \n deinit {\n NotificationCenter.default.removeObserver(self)\n }\n\n @objc\n func playerItemDidReachEnd(notification _: Notification) {\n playerLayer.player?.seek(to: CMTime.zero)\n }\n\n override func layout() {\n super.layout()\n playerLayer.frame = bounds\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/NSViewHoverable.swift", "import AppKit\nimport Combine\n\nclass NSViewHoverable: NSView {\n private let hoverdSubject: PassthroughSubject\n\n let hoverdPublisher: AnyPublisher\n\n override init(frame frameRect: NSRect) {\n hoverdSubject = PassthroughSubject()\n hoverdPublisher = hoverdSubject.eraseToAnyPublisher()\n\n super.init(frame: frameRect)\n }\n\n @available(*, unavailable)\n required init?(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n\n override func updateTrackingAreas() {\n trackingAreas.forEach { removeTrackingArea($0) }\n\n addTrackingArea(\n NSTrackingArea(\n rect: bounds,\n options: [.activeAlways, .mouseMoved, .mouseEnteredAndExited],\n owner: self,\n userInfo: nil\n )\n )\n }\n\n override func mouseMoved(with _: NSEvent) {\n hoverdSubject.send(true)\n }\n\n override func mouseExited(with _: NSEvent) {\n hoverdSubject.send(false)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/PermissionsVM.swift", "import AppKit\nimport Combine\n\n@MainActor\nfinal class PermissionsVM: ObservableObject {\n @discardableResult\n static func checkAccessibility(prompt: Bool) -> Bool {\n let checkOptPrompt = kAXTrustedCheckOptionPrompt.takeUnretainedValue() as NSString\n return AXIsProcessTrustedWithOptions([checkOptPrompt: prompt] as CFDictionary?)\n }\n\n @Published var isAccessibilityEnabled = PermissionsVM.checkAccessibility(prompt: false)\n\n init() {\n watchAccessibilityChange()\n }\n\n private func watchAccessibilityChange() {\n guard !isAccessibilityEnabled else { return }\n\n Timer\n .interval(seconds: 1)\n .map { _ in Self.checkAccessibility(prompt: false) }\n .filter { $0 }\n .first()\n .assign(to: &$isAccessibilityEnabled)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/PreferencesVM+AppCustomization.swift", "import AppKit\nimport Foundation\n\nextension PreferencesVM {\n @discardableResult\n func addAppCustomization(_ app: NSRunningApplication) -> AppRule? {\n guard let url = app.bundleURL ?? app.executableURL,\n let bundleId = app.bundleId()\n else { return nil }\n\n return addAppCustomization(url, bundleId: bundleId)\n }\n\n func addAppCustomization(_ url: URL, bundleId: String) -> AppRule {\n if let appCustomization = getAppCustomization(bundleId: bundleId) {\n return appCustomization\n }\n\n let appCustomization = AppRule(context: container.viewContext)\n\n appCustomization.createdAt = Date()\n appCustomization.url = url\n appCustomization.bundleId = url.bundleId()\n appCustomization.bundleName = FileManager.default.displayName(atPath: url.path)\n\n saveContext()\n\n return appCustomization\n }\n\n func removeAppCustomization(_ appCustomization: AppRule) {\n container.viewContext.delete(appCustomization)\n saveContext()\n }\n\n func setForceKeyboard(_ appCustomization: AppRule?, _ inputSourceId: String?) {\n guard let appCustomization = appCustomization else { return }\n\n saveContext {\n appCustomization.inputSourceId = inputSourceId\n }\n }\n\n func setDoRestoreKeyboard(_ appCustomization: AppRule?, _ doRestoreKeyboard: Bool) {\n guard let appCustomization = appCustomization else { return }\n\n saveContext {\n appCustomization.doRestoreKeyboard = doRestoreKeyboard\n }\n }\n\n func setDoNotRestoreKeyboard(_ appCustomization: AppRule?, _ doNotRestoreKeyboard: Bool) {\n guard let appCustomization = appCustomization else { return }\n\n saveContext {\n appCustomization.doNotRestoreKeyboard = doNotRestoreKeyboard\n }\n }\n\n func setHideIndicator(_ appCustomization: AppRule?, _ hideIndicator: Bool) {\n guard let appCustomization = appCustomization else { return }\n\n saveContext {\n appCustomization.hideIndicator = hideIndicator\n }\n }\n\n func getAppCustomization(app: NSRunningApplication) -> AppRule? {\n return getAppCustomization(bundleId: app.bundleId())\n }\n\n func getAppCustomization(bundleId: String?) -> AppRule? {\n guard let bundleId = bundleId else { return nil }\n\n let request = AppRule.fetchRequest()\n\n request.predicate = NSPredicate(format: \"bundleId == %@\", bundleId)\n\n do {\n return try container.viewContext.fetch(request).first\n } catch {\n print(\"getAppCustomization(bundleId) error: \\(error.localizedDescription)\")\n return nil\n }\n }\n\n func cleanRemovedAppCustomizationIfNeed() {\n guard preferences.prevInstalledBuildVersion < 308 else { return }\n\n let request = AppRule.fetchRequest()\n\n request.predicate = NSPredicate(format: \"removed == %@\", \"1\")\n\n do {\n let appRules = try container.viewContext.fetch(request)\n appRules.forEach { removeAppCustomization($0) }\n } catch {\n print(\"cleanRemovedAppCustomization error: \\(error.localizedDescription)\")\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Accessibility/Accessibility.swift", "import AppKit\nimport ApplicationServices\n\nextension AXValue {\n private func get(_ type: AXValueType, initial: T) -> T? {\n var result = initial\n return AXValueGetValue(self, type, &result) ? result : nil\n }\n\n var asPoint: CGPoint? { return get(.cgPoint, initial: .zero) }\n var asSize: CGSize? { return get(.cgSize, initial: .zero) }\n var asRect: CGRect? { return get(.cgRect, initial: .zero) }\n var asRange: CFRange? { return get(.cfRange, initial: CFRange()) }\n var asError: AXError? { return get(.axError, initial: .success) }\n\n private static func create(_ type: AXValueType, _ value: T) -> AXValue {\n var value = value\n return AXValueCreate(type, &value)!\n }\n\n static func point(_ v: CGPoint) -> AXValue { return create(.cgPoint, v) }\n static func size(_ v: CGSize) -> AXValue { return create(.cgSize, v) }\n static func rect(_ v: CGRect) -> AXValue { return create(.cgRect, v) }\n static func range(_ v: CFRange) -> AXValue { return create(.cfRange, v) }\n static func error(_ v: AXError) -> AXValue { return create(.axError, v) }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppsDiff.swift", "import AppKit\nimport Combine\n\n@MainActor\nstruct AppsDiff {\n let removed: Set\n let added: Set\n let all: Set\n\n func diff(_ runningApps: Set) -> AppsDiff {\n let removedApps = all.subtracting(runningApps)\n let addedApps = runningApps.subtracting(all)\n\n return AppsDiff(removed: removedApps, added: addedApps, all: runningApps)\n }\n}\n\nextension AppsDiff {\n static var empty = AppsDiff(removed: [], added: [], all: [])\n\n static func publisher(preferencesVM: PreferencesVM) -> AnyPublisher {\n NSWorkspace.shared\n .publisher(for: \\.runningApplications)\n .map { apps in Set(preferencesVM.filterApps(apps)) }\n .scan(.empty) { appsDiff, runningApps -> AppsDiff in\n appsDiff.diff(runningApps)\n }\n .replaceError(with: .empty)\n .eraseToAnyPublisher()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSEvent.swift", "import AppKit\nimport Combine\n\nextension NSEvent {\n static func watch(matching: NSEvent.EventTypeMask) -> AnyPublisher {\n AnyPublisher\n .create { observer in\n let monitor = self.addGlobalMonitorForEvents(\n matching: matching,\n handler: { observer.send($0) }\n )\n\n return AnyCancellable { NSEvent.removeMonitor(monitor!) }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Window/FloatWindow.swift", "import AppKit\n\nclass FloatWindow: NSPanel {\n private let _canBecomeKey: Bool\n\n override var canBecomeKey: Bool {\n return _canBecomeKey\n }\n\n init(\n canBecomeKey: Bool,\n contentRect: CGRect,\n styleMask style: NSWindow.StyleMask,\n backing backingStoreType: NSWindow.BackingStoreType,\n defer flag: Bool\n ) {\n _canBecomeKey = canBecomeKey\n\n super.init(\n contentRect: contentRect,\n styleMask: style,\n backing: backingStoreType,\n defer: flag\n )\n\n level = .screenSaver\n\n hasShadow = false\n isOpaque = false\n backgroundColor = .clear\n isMovableByWindowBackground = true\n hidesOnDeactivate = false\n\n titleVisibility = .hidden\n titlebarAppearsTransparent = true\n\n styleMask.insert(.nonactivatingPanel)\n\n collectionBehavior = [\n .moveToActiveSpace,\n .fullScreenAuxiliary,\n .stationary,\n .ignoresCycle,\n ]\n }\n}\n"], ["/InputSourcePro/Input Source Pro/System/AppMenu.swift", "import Cocoa\n\nclass AppMenu: NSMenu {\n private lazy var applicationName = ProcessInfo.processInfo.processName\n\n override init(title: String) {\n super.init(title: title)\n\n let mainMenu = NSMenuItem()\n mainMenu.submenu = NSMenu(title: \"MainMenu\")\n mainMenu.submenu?.items = [\n NSMenuItem(title: \"About \\(applicationName)\", action: #selector(NSApplication.orderFrontStandardAboutPanel(_:)), keyEquivalent: \"\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Preferences...\", action: nil, keyEquivalent: \",\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Hide \\(applicationName)\", action: #selector(NSApplication.hide(_:)), keyEquivalent: \"h\"),\n NSMenuItem(title: \"Hide Others\", target: self, action: #selector(NSApplication.hideOtherApplications(_:)), keyEquivalent: \"h\", modifier: .init(arrayLiteral: [.command, .option])),\n NSMenuItem(title: \"Show All\", action: #selector(NSApplication.unhideAllApplications(_:)), keyEquivalent: \"\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Quit \\(applicationName)\", action: #selector(NSApplication.shared.terminate(_:)), keyEquivalent: \"q\"),\n ]\n\n let fileMenu = NSMenuItem()\n fileMenu.submenu = NSMenu(title: \"File\")\n fileMenu.submenu?.items = [\n NSMenuItem(title: \"New\", action: #selector(NSDocumentController.newDocument(_:)), keyEquivalent: \"n\"),\n NSMenuItem(title: \"Open\", action: #selector(NSDocumentController.openDocument(_:)), keyEquivalent: \"o\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Close\", action: #selector(NSWindow.performClose(_:)), keyEquivalent: \"w\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Save\", action: #selector(NSDocument.save(_:)), keyEquivalent: \"s\"),\n NSMenuItem(title: \"Save As...\", action: #selector(NSDocument.saveAs(_:)), keyEquivalent: \"S\"),\n NSMenuItem(title: \"Revert to Saved...\", action: #selector(NSDocument.revertToSaved(_:)), keyEquivalent: \"\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Export\", action: nil, keyEquivalent: \"\"),\n ]\n\n let editMenu = NSMenuItem()\n editMenu.submenu = NSMenu(title: \"Edit\")\n editMenu.submenu?.items = [\n NSMenuItem(title: \"Undo\", action: #selector(UndoManager.undo), keyEquivalent: \"z\"),\n NSMenuItem(title: \"Redo\", action: #selector(UndoManager.redo), keyEquivalent: \"Z\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Cut\", action: #selector(NSText.cut(_:)), keyEquivalent: \"x\"),\n NSMenuItem(title: \"Copy\", action: #selector(NSText.copy(_:)), keyEquivalent: \"c\"),\n NSMenuItem(title: \"Paste\", action: #selector(NSText.paste(_:)), keyEquivalent: \"v\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Select All\", action: #selector(NSText.selectAll(_:)), keyEquivalent: \"a\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Delete\", target: self, action: nil, keyEquivalent: \"⌫\", modifier: .init()),\n NSMenuItem(title: \"Duplicate\", action: #selector(NSApplication.copy), keyEquivalent: \"d\"),\n ]\n\n let windowMenu = NSMenuItem()\n windowMenu.submenu = NSMenu(title: \"Window\")\n windowMenu.submenu?.items = [\n NSMenuItem(title: \"Minimize\", action: #selector(NSWindow.miniaturize(_:)), keyEquivalent: \"m\"),\n NSMenuItem(title: \"Zoom\", action: #selector(NSWindow.performZoom(_:)), keyEquivalent: \"\"),\n NSMenuItem.separator(),\n NSMenuItem(title: \"Show All\", action: #selector(NSApplication.arrangeInFront(_:)), keyEquivalent: \"m\"),\n ]\n\n let viewMenu = NSMenuItem()\n viewMenu.submenu = NSMenu(title: \"View\")\n viewMenu.submenu?.items = []\n\n let helpMenu = NSMenuItem()\n let helpMenuSearch = NSMenuItem()\n helpMenuSearch.view = NSTextField()\n helpMenu.submenu = NSMenu(title: \"Help\")\n helpMenu.submenu?.items = [\n helpMenuSearch,\n ]\n\n items = [mainMenu, fileMenu, editMenu, viewMenu, windowMenu, helpMenu]\n }\n\n @available(*, unavailable)\n required init(coder _: NSCoder) {\n fatalError(\"init(coder:) has not been implemented\")\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKeyboardCache.swift", "import AppKit\nimport Foundation\nimport os\n\n@MainActor\nclass AppKeyboardCache {\n private var cache = [String: String]()\n\n let logger = ISPLogger(category: String(describing: AppKeyboardCache.self))\n\n func remove(_ kind: AppKind) {\n if let id = kind.getId(), cache[id] != nil {\n logger.debug { \"Remove #\\(id)\" }\n cache[id] = nil\n }\n }\n\n func save(_ kind: AppKind, keyboard: InputSource?) {\n guard let id = kind.getId() else { return }\n\n if let keyboardId = keyboard?.id {\n logger.debug { \"Save \\(id)#\\(keyboardId)\" }\n cache[id] = keyboardId\n }\n }\n\n func retrieve(_ kind: AppKind) -> InputSource? {\n guard let id = kind.getId(),\n let keyboardId = cache[id]\n else { return nil }\n\n logger.debug { \"Retrieve \\(id)#\\(keyboardId)\" }\n\n return InputSource.sources.first { $0.id == keyboardId }\n }\n\n func clear() {\n // FIXME: - Some apps/websites where 'restore' is selected should be ignored\n logger.debug { \"Clear All\" }\n cache.removeAll()\n }\n\n func remove(byBundleId bundleId: String) {\n for key in cache.keys {\n if key.starts(with: \"\\(bundleId)_\") {\n logger.debug { \"Remove \\(bundleId)#\\(key)\" }\n cache[key] = nil\n }\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Utilities/NoAnimation.swift", "import SwiftUI\n\nstruct NoAnimation: ViewModifier {\n func body(content: Content) -> some View {\n content\n .transaction { transaction in\n transaction.animation = nil\n }\n }\n}\n\nextension View {\n func noAnimation() -> some View {\n modifier(NoAnimation())\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Combine/Timer.swift", "import AppKit\nimport Combine\n\nextension Timer {\n static func delay(\n seconds: TimeInterval,\n tolerance _: TimeInterval? = nil,\n options _: RunLoop.SchedulerOptions? = nil\n ) -> AnyPublisher {\n return Timer.interval(seconds: seconds)\n .first()\n .eraseToAnyPublisher()\n }\n\n static func interval(\n seconds: TimeInterval\n ) -> AnyPublisher {\n return Timer.publish(every: seconds, on: .main, in: .common)\n .autoconnect()\n .ignoreFailure()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Persistence/HotKeyGroup.swift", "import Cocoa\n\nextension HotKeyGroup {\n private static let separator = \"∆\"\n\n private var ids: [String] {\n return inputSourceIds?.components(separatedBy: Self.separator) ?? []\n }\n\n @MainActor\n var inputSources: [InputSource] {\n get {\n return InputSource.sources\n .filter { ids.contains($0.id) }\n }\n set {\n inputSourceIds = newValue.map { $0.id }.joined(separator: Self.separator)\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Accessibility/AXSwift+Browser.swift", "import AXSwift\nimport Cocoa\n\nextension UIElement {\n func domIdentifier() -> String? {\n return safeString(attribute: .identifier)\n }\n\n func firefoxDomIdentifier() -> String? {\n return safeString(attribute: \"AXDOMIdentifier\")\n }\n\n func safeString(attribute attr: Attribute) -> String? {\n if let anyObject: AnyObject = try? attribute(attr),\n CFGetTypeID(anyObject) == CFStringGetTypeID()\n {\n return anyObject as? String\n } else {\n return nil\n }\n }\n\n func safeString(attribute attr: String) -> String? {\n if let anyObject: AnyObject = try? attribute(attr),\n CFGetTypeID(anyObject) == CFStringGetTypeID()\n {\n return anyObject as? String\n } else {\n return nil\n }\n }\n\n func domClassList() -> [String] {\n if let rawDOMClassList: AnyObject = try? attribute(\"AXDOMClassList\"),\n CFGetTypeID(rawDOMClassList) == CFArrayGetTypeID(),\n let domClassList1 = rawDOMClassList as? [AnyObject],\n let rawDOMClass = domClassList1.first,\n CFGetTypeID(rawDOMClass) == CFStringGetTypeID(),\n let domClassList = domClassList1 as? [String]\n {\n return domClassList\n } else {\n return []\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/Data+MD5.swift", "import CryptoKit\nimport Foundation\n\nextension Data {\n func md5() -> String {\n Insecure.MD5\n .hash(data: self)\n .map { String(format: \"%02hhx\", $0) }\n .joined()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSRunningApplication+FocusedElement.swift", "import AXSwift\nimport Cocoa\n\nextension NSRunningApplication {\n @MainActor\n func focusedUIElement(preferencesVM: PreferencesVM?) -> UIElement? {\n return focuedUIElement(application: getApplication(preferencesVM: preferencesVM))\n }\n\n @MainActor\n func focuedUIElement(application: Application?) -> UIElement? {\n if let application = application {\n return try? application.attribute(.focusedUIElement)\n } else {\n return nil\n }\n }\n\n @MainActor\n func getApplication(preferencesVM: PreferencesVM?) -> Application? {\n if let preferencesVM = preferencesVM,\n preferencesVM.preferences.isEnhancedModeEnabled,\n !NSApplication.isFloatingApp(bundleIdentifier)\n {\n return Application(self)\n } else {\n return nil\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Accessibility/Element.swift", "import AXSwift\nimport Cocoa\n\nclass Element {\n let rawElement: AXUIElement\n let role: String\n let url: URL?\n\n var clippedFrame: NSRect?\n\n static func initialize(rawElement: AXUIElement) -> Element? {\n let uiElement = UIElement(rawElement)\n let valuesOptional = try? uiElement.getMultipleAttributes([.role, .url])\n\n guard let values = valuesOptional else { return nil }\n guard let role: String = values[Attribute.role] as! String? else { return nil }\n\n return Element(rawElement: rawElement, role: role, url: values[Attribute.url] as? URL)\n }\n\n init(rawElement: AXUIElement, role: String, url: URL?) {\n self.rawElement = rawElement\n self.role = role\n self.url = url\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/InputSource/InputSource+Name.swift", "import Carbon\nimport Cocoa\nimport Combine\nimport CoreGraphics\n\nprivate let nameMap = [\n \"com.apple.inputmethod.Korean.2SetKorean\": \"한\",\n \"com.apple.inputmethod.Korean.3SetKorean\": \"한\",\n \"com.apple.inputmethod.Korean.390Sebulshik\": \"한\",\n \"com.apple.inputmethod.Korean.GongjinCheongRomaja\": \"한\",\n \"com.apple.inputmethod.Korean.HNCRomaja\": \"한\",\n\n \"com.apple.inputmethod.Kotoeri.RomajiTyping.Japanese\": \"あ\",\n \"com.apple.inputmethod.Kotoeri.KanaTyping.Japanese\": \"あ\",\n\n \"com.apple.keylayout.Irish\": \"IE\",\n \"com.apple.keylayout.Dvorak-Right\": \"DV\",\n \"com.apple.keylayout.DVORAK-QWERTYCMD\": \"DV\",\n \"com.apple.keylayout.Dvorak-Left\": \"DV\",\n \"com.apple.keylayout.Dvorak\": \"DV\",\n \"com.apple.keylayout.Colemak\": \"CO\",\n \"com.apple.keylayout.British-PC\": \"GB\",\n \"com.apple.keylayout.British\": \"GB\",\n \"com.apple.keylayout.Australian\": \"AU\",\n \"com.apple.keylayout.ABC-India\": \"IN\",\n \"com.apple.keylayout.USInternational-PC\": \"US\",\n \"com.apple.keylayout.US\": \"US\",\n \"com.apple.keylayout.USExtended\": \"A\",\n \"com.apple.keylayout.ABC\": \"A\",\n \"com.apple.keylayout.Canadian\": \"CA\",\n\n \"com.apple.inputmethod.TCIM.Cangjie\": \"倉\",\n \"com.apple.inputmethod.TCIM.Pinyin\": \"繁拼\",\n \"com.apple.inputmethod.TCIM.Shuangpin\": \"雙\",\n \"com.apple.inputmethod.TCIM.WBH\": \"畫\",\n \"com.apple.inputmethod.TCIM.Jianyi\": \"速\",\n \"com.apple.inputmethod.TCIM.Zhuyin\": \"注\",\n \"com.apple.inputmethod.TCIM.ZhuyinEten\": \"注\",\n\n \"com.apple.inputmethod.TYIM.Sucheng\": \"速\",\n \"com.apple.inputmethod.TYIM.Stroke\": \"畫\",\n \"com.apple.inputmethod.TYIM.Phonetic\": \"粤拼\",\n \"com.apple.inputmethod.TYIM.Cangjie\": \"倉\",\n\n \"com.apple.inputmethod.SCIM.WBX\": \"五\",\n \"com.apple.inputmethod.SCIM.WBH\": \"画\",\n \"com.apple.inputmethod.SCIM.Shuangpin\": \"双\",\n \"com.apple.inputmethod.SCIM.ITABC\": \"拼\",\n]\n\nextension InputSource {\n func getSystemLabelName() -> String? {\n return nameMap[id]\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSRegularExpression.swift", "import Foundation\n\nextension NSRegularExpression {\n func matches(_ string: String) -> Bool {\n let range = NSRange(location: 0, length: string.utf16.count)\n return firstMatch(in: string, options: [], range: range) != nil\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/Log/ISPLogger.swift", "import AppKit\nimport os\n\nclass ISPLogger {\n let category: String\n\n var disabled: Bool\n\n init(category: String, disabled: Bool = false) {\n self.category = category\n self.disabled = disabled\n }\n\n func debug(_ getString: () -> String) {\n if disabled { return }\n // TODO: - Add toggle\n #if DEBUG\n let str = getString()\n let formatter = DateFormatter()\n formatter.dateFormat = \"H:mm:ss.SSSS\"\n print(formatter.string(from: Date()), \"[\\(category)]\", str)\n #endif\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Persistence/MainStorage.swift", "import AppKit\nimport Combine\n\nclass MainStorage: NSObject {\n var keyboardConfigs = CurrentValueSubject<[KeyboardConfig], Never>([])\n\n let container: NSPersistentContainer\n\n private lazy var keyboardConfigsFRC: NSFetchedResultsController = {\n let fetchRequest = KeyboardConfig.fetchRequest()\n\n fetchRequest.sortDescriptors = [NSSortDescriptor(key: \"id\", ascending: true)]\n\n keyboardConfigsFRC = NSFetchedResultsController(\n fetchRequest: fetchRequest,\n managedObjectContext: container.viewContext,\n sectionNameKeyPath: nil,\n cacheName: nil\n )\n\n keyboardConfigsFRC.delegate = self\n\n return keyboardConfigsFRC\n }()\n\n init(container: NSPersistentContainer) {\n self.container = container\n\n super.init()\n }\n\n func refresh() {\n do {\n try keyboardConfigsFRC.performFetch()\n\n if let configs = keyboardConfigsFRC.fetchedObjects {\n keyboardConfigs.send(configs)\n }\n } catch {\n print(\"MainStorage refresh error: \\(error.localizedDescription)\")\n }\n }\n}\n\nextension MainStorage: NSFetchedResultsControllerDelegate {\n func controllerDidChangeContent(_ controller: NSFetchedResultsController) {\n if let configs = controller.fetchedObjects as? [KeyboardConfig] {\n keyboardConfigs.send(configs)\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/InputSource/TISInputSource+Extension.swift", "import Carbon\nimport Foundation\n\nextension TISInputSource {\n enum Category {\n static var keyboardInputSource: String {\n return kTISCategoryKeyboardInputSource as String\n }\n }\n\n private func getProperty(_ key: CFString) -> AnyObject? {\n let cfType = TISGetInputSourceProperty(self, key)\n if cfType != nil {\n return Unmanaged.fromOpaque(cfType!).takeUnretainedValue()\n } else {\n return nil\n }\n }\n\n var id: String {\n return getProperty(kTISPropertyInputSourceID) as! String\n }\n\n var name: String {\n return getProperty(kTISPropertyLocalizedName) as! String\n }\n\n var category: String? {\n return getProperty(kTISPropertyInputSourceCategory) as? String\n }\n\n var isSelectable: Bool {\n return getProperty(kTISPropertyInputSourceIsSelectCapable) as? Bool ?? false\n }\n\n var sourceLanguages: [String] {\n return getProperty(kTISPropertyInputSourceLanguages) as? [String] ?? []\n }\n\n var iconImageURL: URL? {\n return getProperty(kTISPropertyIconImageURL) as? URL\n }\n\n var iconRef: IconRef? {\n return OpaquePointer(TISGetInputSourceProperty(self, kTISPropertyIconRef))\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/InputSource/IconMap.swift", "import Foundation\n\nextension InputSource {\n static let iconMap = [\n \"12234107\": \"62E0CC7B-901A-411D-818A-0AFC810B0532\",\n \"19304143\": \"A479A7C2-F39C-4374-AE69-C8C181374291\",\n \"27026352\": \"4117A20B-DF89-4304-88FA-D96B8237F822\",\n \"28098003\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"30160324\": \"671AD248-E86D-4294-B01C-6D40E2D19BFF\",\n \"71800932\": \"42A0793D-A1F0-4633-956C-6C24C4770D5A\",\n \"86338706\": \"3A6F6B79-D429-4602-8AE8-0AF37175355A\",\n \"94679192\": \"C9301AC0-A972-4DEB-81AD-9EAB0C71E2B1\",\n \"b1ce8378\": \"47101D70-F7EC-4CAF-9E79-EE417ED6D70F\",\n \"a2293646\": \"9722A832-91F4-4A67-B406-E2FC59074563\",\n \"db454877\": \"99529B6C-0A4D-440E-9A64-911D2515EAFE\",\n \"cbce68ac\": \"45FE4808-C8D9-4C20-9395-38ADC56EED6F\",\n \"e1761b42\": \"0BDE5D8A-61C4-4970-9CFD-A57FECCD0F06\",\n \"33d33781\": \"41F3F960-D979-43E9-ABD9-6F9697A99B9B\",\n \"e40293fa\": \"14005E12-0506-4BF2-9666-8211AFD754D5\",\n \"1ce2f0f3\": \"24B1B420-B287-4BB0-969C-8BFCC678B866\",\n \"8309b9ec\": \"9AC7481F-9AAD-4ED6-A0A2-7C0AFE5B2BE5\",\n \"89da7463\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"a4939376\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"867457f1\": \"BE86C109-31F8-4C1D-9578-F46DF1DEF2B7\",\n \"3899e9a3\": \"40599FAA-AFB1-4C6C-815D-13E6B6BB1E7B\",\n \"698bfbc3\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"e20e8a42\": \"7A47F327-58BA-4B48-AF85-BDBB8BACFA3A\",\n \"f4877994\": \"2DE6399A-0326-4D57-ACE8-6183305BBB28\",\n \"d815cf37\": \"ABA144C9-F007-44C1-82B9-1EC79B30DEA7\",\n \"43754cd2\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"400ffcd6\": \"63249E4A-3105-4D59-B641-458B1B8F9F4F\",\n \"07ab0602\": \"0BDE5D8A-61C4-4970-9CFD-A57FECCD0F06\",\n \"93c001bf\": \"DEF03A5D-FBDA-44FE-9903-1BA349C70742\",\n \"e744f5fc\": \"8D2979B6-7689-4EA6-866D-17210B2A5D5C\",\n \"f17ec27f\": \"F2E5DCED-0628-4491-A683-BAD29FBAE546\",\n \"315a0635\": \"6318A437-3962-4957-8F00-17BDE8292C9A\",\n \"86e12f79\": \"EFD62836-76A2-4B24-A9E4-A29CADCAA1D8\",\n \"b6715cbf\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"9d104945\": \"0BDE5D8A-61C4-4970-9CFD-A57FECCD0F06\",\n \"bbdae7cc\": \"D6DD6280-34D5-4A09-8406-913055E80D4F\",\n \"266d37f0\": \"E93D2928-BB12-4B7A-B148-023FE368F768\",\n \"1c41d885\": \"1544DF19-FC49-4EB9-BB59-E6ED8C57A272\",\n \"eec3fd6f\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"6e03fe80\": \"ABA144C9-F007-44C1-82B9-1EC79B30DEA7\",\n \"29006a72\": \"7BB5DD15-393B-4879-BA2E-45B6E1E1761F\",\n \"2b70ad68\": \"F592A155-59CD-4590-8840-7726FC215730\",\n \"5c63cc7b\": \"1150F661-C12C-49B5-9DD3-51C5C942277C\",\n \"cb0d578c\": \"671AD248-E86D-4294-B01C-6D40E2D19BFF\",\n \"4090640c\": \"DC3DA07D-A07D-425D-A817-FEFABFDB711A\",\n \"7079724c\": \"F0AF7FDB-DE37-4A76-92ED-88AB988A003A\",\n \"719ce030\": \"8C320B5A-772D-4DF3-A34F-2EC07B6D054D\",\n \"ea17e573\": \"12D06541-2675-4160-8827-7E5A32D23627\",\n \"c8e12572\": \"614A664B-068F-4B5B-AD3F-CE72AF912B48\",\n \"d87c5553\": \"0BDE5D8A-61C4-4970-9CFD-A57FECCD0F06\",\n \"1998ce3c\": \"94E6C24D-05D3-401A-9463-F8CDCBB6DFAE\",\n \"5c739cd8\": \"7EF95678-BCA9-4FD0-AD73-6F2EC0C3BA58\",\n \"02a8a069\": \"9BC01780-5C89-49BF-B2C7-B799A0FE317E\",\n \"86f29ad0\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"ad4f3484\": \"4AEC0DCA-2F80-4A63-B23A-6D505B4C55F3\",\n \"8ad2e816\": \"854BCE43-D01E-485B-A3E9-0D0F518B4A86\",\n \"a6b5c89c\": \"F0AF7FDB-DE37-4A76-92ED-88AB988A003A\",\n \"4869720f\": \"E45828A1-28C1-4EB2-B744-C0AFFD49B3D5\",\n \"d60e5c94\": \"D7B94935-4BF7-4A08-ABB7-5816817137B5\",\n \"dc1c63c0\": \"E4E1A898-4128-459D-89C7-D6B7867C0C08\",\n \"df6450c9\": \"2CE658AC-E8B0-4D4C-A893-B9C2A891E846\",\n \"d8bf107e\": \"9AC7481F-9AAD-4ED6-A0A2-7C0AFE5B2BE5\",\n \"a9b362f7\": \"2CC5AE74-F920-4D34-B5E4-F4AEF09D7F9C\",\n \"b89471aa\": \"381071E4-417A-4002-9699-8B8645DEFF4C\",\n \"9ff686a8\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"fc7e017e\": \"DEF03A5D-FBDA-44FE-9903-1BA349C70742\",\n \"3be0b38a\": \"47E931D1-7440-43D0-AB56-49794D42A628\",\n \"0e5acd60\": \"DE5AAF98-BC8F-4BE7-A4F8-80BCD7259C3E\",\n \"ee376a01\": \"85412A26-63FA-4936-B552-0F6065E7E6FB\",\n \"cfc23f4d\": \"1D9651C9-1D1D-47B9-95C0-C2A66EB4198C\",\n \"09ffadd1\": \"5AFD3681-A38F-43A9-A635-0356419453BA\",\n \"5851afb9\": \"8C320B5A-772D-4DF3-A34F-2EC07B6D054D\",\n \"fa478f42\": \"32D98AFC-7792-4F71-91F3-F83013A0A941\",\n \"d3b8669e\": \"1728813A-8FB3-43DF-B3A8-01F0E440004F\",\n \"2b467b65\": \"5D7B1D1A-612A-4FDC-9F55-FAE62A4DF863\",\n \"db9a7d9a\": \"E8BCEBD3-C407-4C02-AF7D-915F0B61E1E2\",\n \"2616d538\": \"4117A20B-DF89-4304-88FA-D96B8237F822\",\n \"63591e06\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"a7c2d310\": \"B7746411-299F-46CE-AD31-6BD27E8F6AC8\",\n \"0c0e3e33\": \"0BDE5D8A-61C4-4970-9CFD-A57FECCD0F06\",\n \"0b92667b\": \"D1BF4948-15E4-4EE3-9133-A417B13B742A\",\n \"a85e0f12\": \"59B13CD3-BF1C-4688-A7D8-DED5DA7AD503\",\n \"1baf6530\": \"1D54967C-A538-43EF-B14F-E6999261915C\",\n \"a86dbf81\": \"9EB423B4-42BD-414D-9863-B424C4C1C7A2\",\n \"2829274f\": \"418EAD09-94C8-442F-A1EB-22610C8D0F22\",\n \"b179bb4a\": \"E4E1A898-4128-459D-89C7-D6B7867C0C08\",\n \"d4769388\": \"B6DF802E-3059-49AC-8B46-C5D138CEEF09\",\n \"9495c4e2\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"c189531b\": \"22B821CC-B495-4D04-8D0C-99A9F5009B91\",\n \"a6a891b5\": \"2F1B18A2-1F6E-47F2-AAE9-1683A7D7E3DD\",\n \"247cf24e\": \"2F367878-36F4-4ACA-A74A-3B3FBD1B2DB7\",\n \"400f17c4\": \"0FAF403B-67A6-49F5-B1CF-CCD72D3CFC77\",\n \"668a30d6\": \"CA58FF15-8944-48BD-8B13-85C62A3032E7\",\n \"27a63ca6\": \"48911C5C-2BDF-4625-B3FC-D6042D485FDC\",\n \"7d054a33\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"bc781ecf\": \"0A1E7B88-A30E-47FD-AA31-0EEF8D7B308D\",\n \"18b0c1bf\": \"A685B482-A0AB-4E5F-9D98-B657D2579A02\",\n \"888f7d7e\": \"44A7B552-951C-439D-9B66-E481025CDA3D\",\n \"eb0b34fc\": \"555C454B-E3D5-4D4B-A4FA-04BE776A18E3\",\n \"3bde5571\": \"EE3B4F8F-EDB9-4906-BBD5-55572518E589\",\n \"d29022b7\": \"24B1B420-B287-4BB0-969C-8BFCC678B866\",\n \"50dcc406\": \"9798FD62-3724-4EBB-BF08-C2BA9CDBD051\",\n \"de55325e\": \"AD82741E-E3E0-457F-944D-4089589FAA74\",\n \"a616c527\": \"1544DF19-FC49-4EB9-BB59-E6ED8C57A272\",\n \"be2451e3\": \"64E0097C-D022-4AD1-B1F8-8179AF922347\",\n \"b547c79f\": \"F1FB3965-B448-4281-B88E-797CCB5E1CB9\",\n \"8929985c\": \"2F367878-36F4-4ACA-A74A-3B3FBD1B2DB7\",\n \"004ed606\": \"7CAE6A9D-6A41-4E35-A00D-EB026314432B\",\n \"1a4118ec\": \"726FFB0C-D838-4634-B815-C1120AC2EB1A\",\n \"f7b1c48f\": \"95D21DA5-73D7-466A-9FBA-21B5D3EAF44C\",\n \"e0b93787\": \"F6BBAA30-D51C-4393-9319-BC3DA549B474\",\n \"bf9de7ac\": \"0D015644-FE01-4E47-BC69-211D3907596E\",\n \"ea497b29\": \"B2D3048B-1F94-4A61-B270-F29DDE09A508\",\n \"b9f2f630\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"a09dca9f\": \"1D9651C9-1D1D-47B9-95C0-C2A66EB4198C\",\n \"cc2855c4\": \"726FFB0C-D838-4634-B815-C1120AC2EB1A\",\n \"69436caa\": \"47720907-47A7-43F0-A7A6-1C3D45FF6E82\",\n \"e30f5f53\": \"22B821CC-B495-4D04-8D0C-99A9F5009B91\",\n \"61aab9c3\": \"E45828A1-28C1-4EB2-B744-C0AFFD49B3D5\",\n \"ce5bb9ee\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"07619740\": \"D6DD6280-34D5-4A09-8406-913055E80D4F\",\n \"3d317f9f\": \"24B1B420-B287-4BB0-969C-8BFCC678B866\",\n \"e3a30f0e\": \"D7699CD3-4A59-49A5-AF99-F1A3A3B2373E\",\n \"0c148ae3\": \"AE4C2970-F3F8-45EE-AF18-39904D636ACE\",\n \"27179b5f\": \"8B90F012-4A1A-4E85-BACC-0401F1865A90\",\n \"3e04932f\": \"84684E50-4D01-4EB5-A087-A9C7B9BC9D17\",\n \"a10ee111\": \"2A96FBC0-D2D5-411F-9B6B-F24BD6104BF7\",\n \"25bcbcdb\": \"48911C5C-2BDF-4625-B3FC-D6042D485FDC\",\n \"c9d00a71\": \"94E6C24D-05D3-401A-9463-F8CDCBB6DFAE\",\n \"4feb8e48\": \"7C65C690-0665-4A7A-9864-36428242789C\",\n \"c7aded35\": \"7498631E-1C04-4207-9407-CA1F02E5C7D5\",\n \"d18ebad8\": \"BDA09217-C081-4FC8-BBE3-B2FF3BA7EC52\",\n \"dc04c9bf\": \"288281B7-EAC6-4F63-9D09-E7A2E2D67D30\",\n \"963f1da1\": \"BEB80FC2-E80D-494B-B718-E3CBED7BB533\",\n \"b97f77dc\": \"D9E09252-5C10-481B-9F33-773669D889BA\",\n \"6e9e1330\": \"8C320B5A-772D-4DF3-A34F-2EC07B6D054D\",\n \"ad812fc8\": \"24B1B420-B287-4BB0-969C-8BFCC678B866\",\n \"74bcc5c7\": \"1C5CAE31-7AAB-4F7E-9ECD-CD34DAC44D35\",\n \"c70f027b\": \"887279DC-0339-4C84-A8C9-C1FBC1D06050\",\n \"b98bc34d\": \"6D7B8A06-FE11-4A7F-9F02-E0E070556E44\",\n \"1ea92671\": \"D9E09252-5C10-481B-9F33-773669D889BA\",\n \"c92c8bf8\": \"9DBF63D5-5CC1-4D83-8C3D-861C3C894C6D\",\n \"7f29e426\": \"04C19F60-EDE3-481D-828F-5542A5FC38D4\",\n \"ea34a8c9\": \"FDC80D50-AF7B-449D-A560-D3AD2EE1D038\",\n \"adf9f70b\": \"41F3F960-D979-43E9-ABD9-6F9697A99B9B\",\n \"4186b088\": \"F0AF7FDB-DE37-4A76-92ED-88AB988A003A\",\n \"2d2388fb\": \"6870AC38-D7B5-4209-B086-3C23ECBBDC13\",\n \"97aba18b\": \"5D7B1D1A-612A-4FDC-9F55-FAE62A4DF863\",\n \"12a8787d\": \"41AB5B71-C470-4F5F-994C-B4FEB8C27A38\",\n \"7ecb03b0\": \"BD82C314-90FF-4966-B5FB-671432C60B14\",\n \"7065b10a\": \"0A420457-A462-4857-A114-EFB4C6E2A402\",\n \"7ed9e71c\": \"06391E5F-D86B-4F73-A9AF-5206A7D2092C\",\n \"786d39b4\": \"B581ADA5-4D62-4680-ACEF-A7ABBA85A9D7\",\n \"a405ec7f\": \"DE5AAF98-BC8F-4BE7-A4F8-80BCD7259C3E\",\n \"3c8f642e\": \"FDC80D50-AF7B-449D-A560-D3AD2EE1D038\",\n \"58455c57\": \"E45828A1-28C1-4EB2-B744-C0AFFD49B3D5\",\n \"235dd000\": \"997494BF-9144-4987-BB62-D70FDD0270A2\",\n \"6510e391\": \"7F227C36-226B-4465-80C4-3BA4AE270A95\",\n \"0d796371\": \"9AC7481F-9AAD-4ED6-A0A2-7C0AFE5B2BE5\",\n \"7abf92cc\": \"555C454B-E3D5-4D4B-A4FA-04BE776A18E3\",\n \"0f6c2128\": \"84684E50-4D01-4EB5-A087-A9C7B9BC9D17\",\n \"1c6dfb89\": \"7F280C1A-8742-424F-8E69-E7CA50810C0E\",\n \"6738fbef\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"f85cad76\": \"F2E5DCED-0628-4491-A683-BAD29FBAE546\",\n \"e8a7b7ac\": \"525E9E05-97C9-4198-AEB1-D159ED6BEFFE\",\n \"998008af\": \"9A8AAAA9-FDE9-46DD-9344-B25CCF79400A\",\n \"a9223b6b\": \"80AB9670-E6EE-4C30-A31C-AC3E6752F42D\",\n \"85fdb832\": \"6D594AFC-54B9-41AE-861E-FE6640176F0F\",\n \"985b9c1c\": \"47101D70-F7EC-4CAF-9E79-EE417ED6D70F\",\n \"b3fd6e15\": \"47101D70-F7EC-4CAF-9E79-EE417ED6D70F\",\n \"e9c087a5\": \"B7746411-299F-46CE-AD31-6BD27E8F6AC8\",\n \"b2ff3df1\": \"2A96FBC0-D2D5-411F-9B6B-F24BD6104BF7\",\n \"cac39a88\": \"7D3DA8CA-D663-4D76-9F2F-61AD2E8C474F\",\n \"cf08c795\": \"7C913FED-1E33-4B8D-AF83-EF9ADD8BF7ED\",\n \"62a32f72\": \"8D2979B6-7689-4EA6-866D-17210B2A5D5C\",\n \"69d17de6\": \"43D1D1FE-193A-4730-89B6-01EBF3F9D6CA\",\n \"f5f80979\": \"DAC2C56F-DC3C-40F9-A468-EFB72BE78E5E\",\n \"2c08766a\": \"E45828A1-28C1-4EB2-B744-C0AFFD49B3D5\",\n \"6c663dfe\": \"85412A26-63FA-4936-B552-0F6065E7E6FB\",\n \"4877037d\": \"0291D80B-1C39-4ECD-8ADB-570D2FAF3204\",\n \"9214334f\": \"C65B1C88-A254-4A3E-9A31-FF63C3579140\",\n \"6f37b707\": \"80AB9670-E6EE-4C30-A31C-AC3E6752F42D\",\n \"5510f56b\": \"24B1B420-B287-4BB0-969C-8BFCC678B866\",\n \"978271a2\": \"8B90F012-4A1A-4E85-BACC-0401F1865A90\",\n \"eee37628\": \"9AC7481F-9AAD-4ED6-A0A2-7C0AFE5B2BE5\",\n \"c635e696\": \"DAC92286-021D-4E7C-8064-9172E53FD37C\",\n \"ffbdd714\": \"49176BD9-5A86-437A-AA07-B027198B21A4\",\n \"6e1e6064\": \"E45828A1-28C1-4EB2-B744-C0AFFD49B3D5\",\n \"cd43b6a4\": \"588AAF70-3342-4DEB-ACC4-18C6DAAF070B\",\n \"83ce500f\": \"515356B7-FCE0-46A7-B6E6-EA1E20F9440A\",\n \"8b62fd42\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"b91b29e1\": \"D7699CD3-4A59-49A5-AF99-F1A3A3B2373E\",\n \"aad82b0e\": \"341AF28C-8140-4BF5-BBD2-DE48ED54B52E\",\n \"359130dd\": \"9AC7481F-9AAD-4ED6-A0A2-7C0AFE5B2BE5\",\n \"208de7e6\": \"ABA144C9-F007-44C1-82B9-1EC79B30DEA7\",\n \"16e15af7\": \"70419D3C-491D-446F-810F-34B656695F84\",\n \"0dee34a1\": \"1BF82110-8702-414B-BBE7-0D4AEBC8CE59\",\n \"fd60e6e1\": \"E76B0F98-61EF-4BB4-A174-33C636778D2D\",\n \"4b1fc25e\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"fb856728\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"c498db0d\": \"42A17026-B747-43FE-856F-08E5E1F3B375\",\n \"58e42a83\": \"88F0C365-5336-4C6E-97B4-C849412B2AFE\",\n \"97270e25\": \"7F227C36-226B-4465-80C4-3BA4AE270A95\",\n \"d46bd534\": \"2F367878-36F4-4ACA-A74A-3B3FBD1B2DB7\",\n \"525f4b59\": \"D7B64293-CCFC-478D-838D-25CEECE1D581\",\n \"c58e71bf\": \"5D7B1D1A-612A-4FDC-9F55-FAE62A4DF863\",\n \"3296bbf9\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"539a2414\": \"6D594AFC-54B9-41AE-861E-FE6640176F0F\",\n \"d05ecc0e\": \"2C36545F-B948-45CA-8814-6AA884AF4414\",\n \"234f9818\": \"DAC92286-021D-4E7C-8064-9172E53FD37C\",\n \"49a2fe1e\": \"0EB6F607-10E3-4310-9476-14BD0CDCDB00\",\n \"18dbea05\": \"F6BBAA30-D51C-4393-9319-BC3DA549B474\",\n \"2ff577b6\": \"49176BD9-5A86-437A-AA07-B027198B21A4\",\n \"d2d2113d\": \"7757DA96-25F6-4BD0-B2AD-3C5192C1B8CA\",\n \"3479a4e7\": \"0BDE5D8A-61C4-4970-9CFD-A57FECCD0F06\",\n \"bbf248dc\": \"CC364542-2678-46FE-8841-19EE238CDB36\",\n \"4b361b85\": \"457ED6AA-4EE9-4F5B-85CB-234415406853\",\n \"be426c78\": \"001359CD-55CF-49FA-A3A6-8A5E018A3CBB\",\n \"73e81f14\": \"5AFD3681-A38F-43A9-A635-0356419453BA\",\n \"218762fe\": \"45B52BCC-ED70-4BD2-9B8C-B2A2E64AC8E4\",\n \"4e49cac1\": \"BE86C109-31F8-4C1D-9578-F46DF1DEF2B7\",\n \"da5bb098\": \"5B2F9F82-2ACF-4608-A138-93B67AFEC8B5\",\n \"9f25876a\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"62b0a598\": \"8D2979B6-7689-4EA6-866D-17210B2A5D5C\",\n \"6e278b38\": \"BA1AA637-942E-40FD-A754-61953BC423B5\",\n \"e95c1507\": \"43D1D1FE-193A-4730-89B6-01EBF3F9D6CA\",\n \"75317e2c\": \"3F8CAF4E-01C7-4CCC-A3AB-C2041CCF678A\",\n \"bfab0f6e\": \"8D2979B6-7689-4EA6-866D-17210B2A5D5C\",\n \"154bf45a\": \"1265ADE8-35CA-4D70-9945-4CAE0D2A2FAD\",\n \"0569f839\": \"DEF03A5D-FBDA-44FE-9903-1BA349C70742\",\n \"3b22c4c6\": \"47720907-47A7-43F0-A7A6-1C3D45FF6E82\",\n \"0167a31d\": \"32B9FF3C-8D94-4B10-AD4F-1A70341C2E73\",\n \"3f1989f1\": \"744B5137-BB36-48C2-A4D1-08C186443ADD\",\n \"7ffc9c42\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"624655b7\": \"5AFD3681-A38F-43A9-A635-0356419453BA\",\n \"4e4f177f\": \"06391E5F-D86B-4F73-A9AF-5206A7D2092C\",\n \"9b527cbb\": \"F0297169-B077-4E67-B95C-F7F8F94D196A\",\n \"8969ae38\": \"ABA144C9-F007-44C1-82B9-1EC79B30DEA7\",\n \"d674736c\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"fbeafd09\": \"1C5CAE31-7AAB-4F7E-9ECD-CD34DAC44D35\",\n \"b586d8a0\": \"00773942-1BE4-49ED-8655-6FC675F6C949\",\n \"c914ede2\": \"0A420457-A462-4857-A114-EFB4C6E2A402\",\n \"a589f266\": \"BBA79BC5-78A5-4EA0-A8F0-9D12A54FDAB4\",\n \"47ed8329\": \"E489417D-13AA-4ED6-B1C7-735A2520F7F9\",\n \"2472b4bc\": \"A685B482-A0AB-4E5F-9D98-B657D2579A02\",\n \"754b228a\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"bd098872\": \"7D09137D-C942-427E-90E0-2C8A33CE4917\",\n \"1526f53f\": \"9AC7481F-9AAD-4ED6-A0A2-7C0AFE5B2BE5\",\n \"36fec563\": \"1265ADE8-35CA-4D70-9945-4CAE0D2A2FAD\",\n \"9ba7f97f\": \"2F1B18A2-1F6E-47F2-AAE9-1683A7D7E3DD\",\n \"b2576fc4\": \"7C913FED-1E33-4B8D-AF83-EF9ADD8BF7ED\",\n \"9bc85978\": \"7EEE2901-804F-4A11-BC7E-97277587428C\",\n \"9c8b76e3\": \"5B2F9F82-2ACF-4608-A138-93B67AFEC8B5\",\n \"451243b4\": \"0E555052-1D93-4F25-98F3-99D2E1300929\",\n \"429c3811\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"128ff90c\": \"4DA12B48-8B78-40BD-A705-F16816B17077\",\n \"58beffc7\": \"77B325ED-16B1-4468-B936-FB71DCC547CD\",\n \"a97f103b\": \"BA1AA637-942E-40FD-A754-61953BC423B5\",\n \"da8f20e9\": \"ABA144C9-F007-44C1-82B9-1EC79B30DEA7\",\n \"bf974976\": \"8C320B5A-772D-4DF3-A34F-2EC07B6D054D\",\n \"6b8fe3f8\": \"88F0C365-5336-4C6E-97B4-C849412B2AFE\",\n \"f85be9a9\": \"8D2979B6-7689-4EA6-866D-17210B2A5D5C\",\n \"ac660083\": \"588B83A7-540C-4329-9DCF-FA4F15EB2A29\",\n \"0edede09\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n \"1875dff7\": \"9722A832-91F4-4A67-B406-E2FC59074563\",\n \"41c01b9d\": \"3AE73689-3E55-4681-A0F4-25FED9B6F7DE\",\n \"3880c1ab\": \"2C36545F-B948-45CA-8814-6AA884AF4414\",\n \"46923cf2\": \"0BDE5D8A-61C4-4970-9CFD-A57FECCD0F06\",\n \"13d24b22\": \"C5E4C22D-6421-4823-9327-513CFD5F89B9\",\n \"fd2528e3\": \"3F9EA81A-B319-4F00-B858-5A8FF74D1FB7\",\n ]\n}\n"], ["/InputSourcePro/Input Source Pro/Persistence/AppRule.swift", "import Cocoa\n\nextension AppRule {\n var image: NSImage? {\n guard let path = url else { return nil }\n\n return NSWorkspace.shared.icon(forFile: path.path)\n }\n}\n\nextension AppRule {\n @MainActor\n var forcedKeyboard: InputSource? {\n guard let inputSourceId = inputSourceId else { return nil }\n\n return InputSource.sources.first { $0.id == inputSourceId }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/CGRect.swift", "import AppKit\nimport Foundation\n\nextension CGRect {\n func relativeTo(screen: NSScreen) -> CGRect {\n let point = CGPoint(x: minX, y: screen.frame.maxY - maxY)\n\n return CGRect(origin: point, size: size)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/i18n.swift", "import Foundation\n\nextension String {\n func i18n(\n comment: String = \"\",\n tableName: String = \"Localizable\"\n ) -> String {\n #if DEBUG\n let fallback = \"**\\(self)**\"\n #else\n let fallback = self\n #endif\n\n return NSLocalizedString(\n self,\n tableName: tableName,\n value: fallback,\n comment: comment\n )\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Models/PreferencesVM+HotKeyGroup.swift", "import AppKit\nimport AXSwift\nimport Foundation\n\nextension PreferencesVM {\n func addHotKeyGroup(\n inputSources: [InputSource]\n ) {\n let rule = HotKeyGroup(context: container.viewContext)\n\n rule.createdAt = Date()\n rule.id = UUID().uuidString\n rule.inputSources = inputSources\n\n saveContext()\n }\n\n func deleteHotKeyGroup(_ group: HotKeyGroup) {\n container.viewContext.delete(group)\n saveContext()\n }\n\n func updateHotKeyGroup(\n _ group: HotKeyGroup,\n inputSources: [InputSource]\n ) {\n saveContext {\n group.inputSources = inputSources\n }\n }\n\n func getHotKeyGroups() -> [HotKeyGroup] {\n let request = NSFetchRequest(entityName: \"HotKeyGroup\")\n\n do {\n return try container.viewContext.fetch(request)\n } catch {\n print(\"getHotKeyGroups() error: \\(error.localizedDescription)\")\n return []\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/URL.swift", "import AppKit\n\nextension URL {\n static let newtab = URL(string: \"isp://newtab\")!\n\n func open() {\n NSWorkspace.shared.open(self)\n }\n\n func bundleId() -> String {\n Bundle(url: self)?.bundleIdentifier ?? dataRepresentation.md5()\n }\n\n func removeFragment() -> URL {\n var components = URLComponents(url: self, resolvingAgainstBaseURL: false)\n\n components?.fragment = nil\n\n return components?.url ?? self\n }\n}\n\nextension URL {\n static let website = URL(\n string: \"https://inputsource.pro\"\n )!\n\n static let purchase = URL(\n string: \"https://inputsource.pro/purchase\"\n )!\n\n static let twitter = URL(\n string: \"https://twitter.com/runjuuu\"\n )!\n\n static let emailString = \"support@inputsource.pro\"\n\n static let email = URL(string: \"mailto:\\(emailString)\")!\n\n static let howToEnableAccessbility = URL(\n string: \"https://inputsource.pro/help/enable-spotlight-like-apps-support\"\n )!\n\n static let howToEnableBrowserRule = URL(\n string: \"https://inputsource.pro/help/enable-browser-rule\"\n )!\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSMenuItem.swift", "import AppKit\n\nextension NSMenuItem {\n convenience init(\n title string: String,\n target: AnyObject = NSMenuItem.self as AnyObject,\n action selector: Selector?,\n keyEquivalent charCode: String,\n modifier: NSEvent.ModifierFlags = .command\n ) {\n self.init(title: string, action: selector, keyEquivalent: charCode)\n keyEquivalentModifierMask = modifier\n self.target = target\n }\n\n convenience init(title string: String, submenuItems: [NSMenuItem]) {\n self.init(title: string, action: nil, keyEquivalent: \"\")\n submenu = NSMenu()\n submenu?.items = submenuItems\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSWorkspace.swift", "import AppKit\n\nextension NSWorkspace {\n func openAccessibilityPreferences() {\n open(\n URL(string: \"x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility\")!\n )\n }\n\n func openAutomationPreferences() {\n open(\n URL(string: \"x-apple.systempreferences:com.apple.preference.security?Privacy_Automation\")!\n )\n }\n\n func openKeyboardPreferences() {\n open(\n URL(fileURLWithPath: \"/System/Library/PreferencePanes/Keyboard.prefPane\")\n )\n }\n}\n\nextension NSWorkspace {\n func desktopImage() -> NSImage? {\n guard let mainScreen = NSScreen.main,\n let url = desktopImageURL(for: mainScreen),\n let image = NSImage(contentsOf: url)\n else { return nil }\n\n return image\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Persistence/KeyboardConfig.swift", "import Cocoa\nimport SwiftUI\n\nextension KeyboardConfig {\n var textColor: Color? {\n get {\n if let hex = textColorHex {\n return Color(hex: hex)\n } else {\n return nil\n }\n }\n\n set {\n textColorHex = newValue?.hexWithAlpha\n }\n }\n\n var bgColor: Color? {\n get {\n if let hex = bgColorHex {\n return Color(hex: hex)\n } else {\n return nil\n }\n }\n\n set {\n bgColorHex = newValue?.hexWithAlpha\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/FileManager+Ext.swift", "import Foundation\n\nextension FileManager {\n func isDirectory(atPath path: String) -> Bool {\n let fileManager = FileManager.default\n var isDir: ObjCBool = false\n\n if fileManager.fileExists(atPath: path, isDirectory: &isDir) {\n return isDir.boolValue\n } else {\n return false\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/Bundle+Version.swift", "import AppKit\n\nextension Bundle {\n var shortVersion: String {\n infoDictionary?[\"CFBundleShortVersionString\"] as? String ?? \"unknown\"\n }\n\n var buildVersion: Int {\n Int(infoDictionary?[\"CFBundleVersion\"] as? String ?? \"0\") ?? 0\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSRunningApplication+FloatingApp.swift", "import AppKit\nimport Foundation\n\nextension NSRunningApplication {\n // FIXME: check window info\n var isFloatingApp: Bool {\n NSApplication.isFloatingApp(bundleIdentifier)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/UI/Components/FocusAwareTextField.swift", "import AppKit\nimport RxRelay\n\nclass FocusAwareTextField: NSTextField {\n let focus$ = PublishRelay()\n\n override func becomeFirstResponder() -> Bool {\n focus$.accept(true)\n return super.becomeFirstResponder()\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSToolbarItem+Identifier.swift", "import AppKit\n\nextension NSToolbar.Identifier {\n static let preferencesWindowToolbarIdentifier = NSToolbar.Identifier(\"PreferencesWindowToolbar\")\n}\n\nextension NSToolbarItem.Identifier {\n static let toolbarShareButtonItem = NSToolbarItem.Identifier(rawValue: \"ToolbarShareButtonItem\")\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/CancelBag.swift", "import Combine\n\nfinal class CancelBag {\n fileprivate(set) var subscriptions = Set()\n\n func cancel() {\n subscriptions.removeAll()\n }\n}\n\nextension AnyCancellable {\n func store(in cancelBag: CancelBag) {\n cancelBag.subscriptions.insert(self)\n }\n}\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSTableView+RemoveBG.swift", "import AppKit\n\n// Removes background from List in SwiftUI\nextension NSTableView {\n override open func viewDidMoveToWindow() {\n super.viewDidMoveToWindow()\n\n backgroundColor = NSColor.clear\n if let esv = enclosingScrollView {\n esv.drawsBackground = false\n }\n }\n}\n"], ["/InputSourcePro/Input Source Pro/System/main.swift", "import Cocoa\n\nlet delegate = AppDelegate()\nlet menu = AppMenu()\n\nNSApplication.shared.delegate = delegate\nNSApplication.shared.mainMenu = menu\n\n_ = NSApplicationMain(CommandLine.argc, CommandLine.unsafeArgv)\n"], ["/InputSourcePro/Input Source Pro/Utilities/AppKit/NSColor.swift", "import AppKit\nimport SwiftUI\n\nextension NSColor {\n var color: Color {\n Color(self)\n }\n}\n"]], "task_instance_info": {"created_time": "2025-08-21 03:17:35", "created_task_model": "DeepSeek-R1", "function_skeleton": "@ViewBuilder func indicator ( ) -> some View { }", "code_description": "This code segment functions to: Generate geometric elements and images with configurable dimensions and shapes based on positional parameters, creating distinct visual representations for different layout alignment cases."}, "inference_content": {"inference_model": "DeepSeek-R1", "inference_result": "```swift\n[TASK_BEGIN]\n@ViewBuilder func indicator() -> some View {\n switch self {\n case .topLeft, .topRight, .bottomLeft, .bottomRight:\n Image(systemName: \"chevron.right\")\n case .centerLeft:\n Image(systemName: \"chevron.left\")\n case .centerRight:\n Image(systemName: \"chevron.right\")\n case .topCenter:\n Image(systemName: \"chevron.up\")\n case .bottomCenter:\n Image(systemName: \"chevron.down\")\n case .center:\n Circle()\n }\n}\n[TASK_END]\n```", "inference_time": "2025-08-21 03-18-39"}, "editdistance_info": {"edit_distance": 21.1268, "calculate_time": "2025-08-21 03:18:39", "true_code_clean": "@ViewBuilder\n func indicator() -> some View {\n switch self {\n case .center:\n RoundedRectangle(cornerRadius: 3)\n .frame(width: 30, height: 30)\n case .topCenter, .bottomCenter:\n RoundedRectangle(cornerRadius: 2)\n .frame(width: 44, height: 8)\n case .centerLeft, .centerRight:\n RoundedRectangle(cornerRadius: 2)\n .frame(width: 8, height: 30)\n default:\n Image(nsImage: .triangle)\n .resizable()\n .scaledToFit()\n .frame(width: 30)\n }\n }", "predict_code_clean": "@ViewBuilder func indicator() -> some View {\n switch self {\n case .topLeft, .topRight, .bottomLeft, .bottomRight:\n Image(systemName: \"chevron.right\")\n case .centerLeft:\n Image(systemName: \"chevron.left\")\n case .centerRight:\n Image(systemName: \"chevron.right\")\n case .topCenter:\n Image(systemName: \"chevron.up\")\n case .bottomCenter:\n Image(systemName: \"chevron.down\")\n case .center:\n Circle()\n }\n}"}}