From 5bd65b31dd687691d5c7bf1c1836a23856f2b71a Mon Sep 17 00:00:00 2001 From: Julian Weiss Date: Fri, 12 Mar 2021 17:44:16 -0500 Subject: [PATCH] experimental launch at login module --- whilom.xcodeproj/project.pbxproj | 50 ++++++++++++++++++- .../contents.xcworkspacedata | 2 +- .../xcshareddata/swiftpm/Package.resolved | 16 ++++++ whilom/AppDelegate.swift | 28 ++++++++++- 4 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 whilom.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved diff --git a/whilom.xcodeproj/project.pbxproj b/whilom.xcodeproj/project.pbxproj index 2205f79..d0ae8e2 100644 --- a/whilom.xcodeproj/project.pbxproj +++ b/whilom.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 50; + objectVersion = 52; objects = { /* Begin PBXBuildFile section */ @@ -11,6 +11,7 @@ 1E5B4D0825FB779900092422 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1E5B4D0725FB779900092422 /* Main.storyboard */; }; 1E5B4D6A25FBFE4B00092422 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1E5B4D6925FBFE4B00092422 /* Cocoa.framework */; }; 1E5B4DD625FC0DBF00092422 /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E5B4DD525FC0DBF00092422 /* String+Extension.swift */; }; + 1E5B4DE525FC24CA00092422 /* LaunchAtLogin in Frameworks */ = {isa = PBXBuildFile; productRef = 1E5B4DE425FC24CA00092422 /* LaunchAtLogin */; }; 1EE4E20E24F97E240097C32C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EE4E20D24F97E240097C32C /* AppDelegate.swift */; }; 1EE4E21224F97E250097C32C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1EE4E21124F97E250097C32C /* Assets.xcassets */; }; /* End PBXBuildFile section */ @@ -55,6 +56,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 1E5B4DE525FC24CA00092422 /* LaunchAtLogin in Frameworks */, 1E5B4D6A25FBFE4B00092422 /* Cocoa.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -114,12 +116,16 @@ 1EE4E20824F97E240097C32C /* Resources */, 1E5B4D3625FBFC4000092422 /* Embed XPC Services */, 1E5B4D6E25FBFE9100092422 /* CopyFiles */, + 1E5B4DE725FC25B000092422 /* ShellScript */, ); buildRules = ( ); dependencies = ( ); name = whilom; + packageProductDependencies = ( + 1E5B4DE425FC24CA00092422 /* LaunchAtLogin */, + ); productName = keysmith; productReference = 1EE4E20A24F97E240097C32C /* whilom.app */; productType = "com.apple.product-type.application"; @@ -149,6 +155,9 @@ Base, ); mainGroup = 1EE4E20124F97E240097C32C; + packageReferences = ( + 1E5B4DE325FC24CA00092422 /* XCRemoteSwiftPackageReference "LaunchAtLogin" */, + ); productRefGroup = 1EE4E20B24F97E240097C32C /* Products */; projectDirPath = ""; projectRoot = ""; @@ -170,6 +179,26 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 1E5B4DE725FC25B000092422 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "# Type a script or drag a script file from your workspace to insert its path.\n\"${BUILT_PRODUCTS_DIR}/LaunchAtLogin_LaunchAtLogin.bundle/Contents/Resources/copy-helper-swiftpm.sh\"\n"; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 1EE4E20624F97E240097C32C /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -378,6 +407,25 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + 1E5B4DE325FC24CA00092422 /* XCRemoteSwiftPackageReference "LaunchAtLogin" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/sindresorhus/LaunchAtLogin"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 4.0.0; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 1E5B4DE425FC24CA00092422 /* LaunchAtLogin */ = { + isa = XCSwiftPackageProductDependency; + package = 1E5B4DE325FC24CA00092422 /* XCRemoteSwiftPackageReference "LaunchAtLogin" */; + productName = LaunchAtLogin; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = 1EE4E20224F97E240097C32C /* Project object */; } diff --git a/whilom.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/whilom.xcodeproj/project.xcworkspace/contents.xcworkspacedata index b019bb7..919434a 100644 --- a/whilom.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/whilom.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "self:"> diff --git a/whilom.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/whilom.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 0000000..c88b7a8 --- /dev/null +++ b/whilom.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,16 @@ +{ + "object": { + "pins": [ + { + "package": "LaunchAtLogin", + "repositoryURL": "https://github.com/sindresorhus/LaunchAtLogin", + "state": { + "branch": null, + "revision": "0f39982b9d6993eef253b81219d3c39ba1e680f3", + "version": "4.0.0" + } + } + ] + }, + "version": 1 +} diff --git a/whilom/AppDelegate.swift b/whilom/AppDelegate.swift index 7c7eddd..98dc575 100644 --- a/whilom/AppDelegate.swift +++ b/whilom/AppDelegate.swift @@ -7,12 +7,14 @@ // import Cocoa +import LaunchAtLogin @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { // MARK: - properties // MARK: state private var rememberedPassword: String? + private var hasShownRememberPasswordAlert: Bool = false // MARK: modals that need to be referenced twice private var passwordRememberAlert: NSAlert? @@ -58,6 +60,16 @@ class AppDelegate: NSObject, NSApplicationDelegate { quitMenuItem.title = "About" return quitMenuItem }() + + let launchAtLoginItem: NSMenuItem = { + let startItem = NSMenuItem() + startItem.title = AppDelegate.launchAtLoginTitle + return startItem + }() + + private static var launchAtLoginTitle: String { + return "\(LaunchAtLogin.isEnabled ? "✔ " : "")Start at login" + } let quitMenuItem: NSMenuItem = { let quitMenuItem = NSMenuItem() @@ -128,8 +140,11 @@ class AppDelegate: NSObject, NSApplicationDelegate { enableSleepScript = buildEnableSleepScript() disableSleepScript = buildDisableSleepScript() - - showPasswordRememberAlert() + + if !hasShownRememberPasswordAlert { // TODO + hasShownRememberPasswordAlert = true + showPasswordRememberAlert() + } } func applicationWillTerminate(_ aNotification: Notification) { @@ -161,6 +176,10 @@ class AppDelegate: NSObject, NSApplicationDelegate { aboutMenuItem.target = self menu.addItem(aboutMenuItem) + launchAtLoginItem.action = #selector(launchAtLoginWhilom(_:)) + launchAtLoginItem.target = self + menu.addItem(launchAtLoginItem) + quitMenuItem.action = #selector(quitWhilom(_:)) quitMenuItem.target = self menu.addItem(quitMenuItem) @@ -188,6 +207,11 @@ class AppDelegate: NSObject, NSApplicationDelegate { aboutAlert.runModal() } + @objc func launchAtLoginWhilom(_ sender: Any) { + LaunchAtLogin.isEnabled = !LaunchAtLogin.isEnabled + launchAtLoginItem.title = AppDelegate.launchAtLoginTitle + } + @objc func quitWhilom(_ sender: Any) -> Bool { NSApplication.shared.terminate(self) return true