aerospace fork
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112import AppKitimport Commonimport Foundation
@MainActor public func initAppBundle() { Task.startUnstructured { initTerminationHandler() unsafe _isCli = false initServerArgs() await waitForAccessibilityPermission_nonCancellable() if isDebug { await toggleReleaseServerIfDebug(.off) interceptTermination(SIGINT) interceptTermination(SIGKILL) }
await bootstrapConfig_nonCancellable() _ = await reloadConfig_nonCancellable()
startUnixSocketServer() GlobalObserver.initObserver() Workspace.garbageCollectUnusedWorkspaces() // init workspaces _ = Workspace.all.first?.focusWorkspace() await runHeavyCompleteRefreshSession( .startup, // It's important for the first initialization to be non cancellable // to make sure that isStartup propagates to all places assumeCancellable: false, layoutWorkspaces: false, ) try await runLightSession(.startup, .forceRun) { smartLayoutAtStartup() _ = await config.afterStartupCommand.run(.defaultEnv, .emptyStdin) } }}
@MainActor private func bootstrapConfig_nonCancellable() async { let result = await reloadConfig_nonCancellable(forceConfigUrl: defaultConfigUrl) let msg = """ Can't load default config. Your installation is probably corrupted. Please don't modify \(defaultConfigUrl.description.singleQuoted)
\(result.stdout) """ check(result.isOk, msg)}
@MainActorprivate func smartLayoutAtStartup() { let workspace = focus.workspace let root = workspace.rootTilingContainer switch root.children.count <= 3 { case true: root.layout = .tiles case false: root.layout = .accordion }}
var isStartup: Bool { refreshSessionEvent?.isStartup == true }
struct ServerArgs: Sendable { var configLocation: String? = nil var isReadOnly: Bool = false}
private let serverHelp = """ USAGE: \(CommandLine.arguments.first ?? "DeeWM.app/Contents/MacOS/DeeWM") [<options>]
OPTIONS: -h, --help Print help -v, --version Print DeeWM.app version --config-path <path> Config path. It will take priority over ~/.deewm.toml and ${XDG_CONFIG_HOME}/deewm/deewm.toml --read-only Disable window management. Useful if you want to use only debug-windows or other query commands. """
nonisolated(unsafe) private var _serverArgs = ServerArgs()var serverArgs: ServerArgs { unsafe _serverArgs }private func initServerArgs() { let args = CommandLine.arguments.slice(1...) ?? [] if args.contains(where: { $0 == "-h" || $0 == "--help" }) { exit(EXIT_CODE_ZERO, out: serverHelp) } var index = 0 while index < args.count { let current = args[index] index += 1 switch current { case "--version", "-v": exit(EXIT_CODE_ZERO, out: "\(aeroSpaceAppVersion) \(gitHash)") case "--config-path": switch args.getOrNil(atIndex: index) { case let arg?: unsafe _serverArgs.configLocation = arg case nil: exit(EXIT_CODE_TWO, err: "Missing <path> in --config-path flag") } index += 1 case "--read-only": // todo rename to '--disabled' and unite with disabled feature unsafe _serverArgs.isReadOnly = true case "-NSDocumentRevisionsDebugMode" where isDebug: // Skip Xcode CLI args. // Usually it's '-NSDocumentRevisionsDebugMode NO'/'-NSDocumentRevisionsDebugMode YES' while args.getOrNil(atIndex: index)?.starts(with: "-") == false { index += 1 } default: exit(EXIT_CODE_TWO, err: "Unrecognized flag \(args.first.orDie().singleQuoted)") } } if let path = serverArgs.configLocation, !FileManager.default.fileExists(atPath: path) { exit(EXIT_CODE_TWO, err: "\(path) doesn't exist") }}