Skip to content

Commit

Permalink
experimental launch at login module
Browse files Browse the repository at this point in the history
  • Loading branch information
insanj committed Mar 12, 2021
1 parent 784f6ba commit 5bd65b3
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 4 deletions.
50 changes: 49 additions & 1 deletion whilom.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 52;
objects = {

/* Begin PBXBuildFile section */
1E396DC525FB4C26008E2122 /* NSImage+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E396DC425FB4C26008E2122 /* NSImage+Extension.swift */; };
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 */
Expand Down Expand Up @@ -55,6 +56,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
1E5B4DE525FC24CA00092422 /* LaunchAtLogin in Frameworks */,
1E5B4D6A25FBFE4B00092422 /* Cocoa.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -149,6 +155,9 @@
Base,
);
mainGroup = 1EE4E20124F97E240097C32C;
packageReferences = (
1E5B4DE325FC24CA00092422 /* XCRemoteSwiftPackageReference "LaunchAtLogin" */,
);
productRefGroup = 1EE4E20B24F97E240097C32C /* Products */;
projectDirPath = "";
projectRoot = "";
Expand All @@ -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;
Expand Down Expand Up @@ -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 */;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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
}
28 changes: 26 additions & 2 deletions whilom/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -128,8 +140,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {

enableSleepScript = buildEnableSleepScript()
disableSleepScript = buildDisableSleepScript()

showPasswordRememberAlert()

if !hasShownRememberPasswordAlert { // TODO
hasShownRememberPasswordAlert = true
showPasswordRememberAlert()
}
}

func applicationWillTerminate(_ aNotification: Notification) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5bd65b3

Please sign in to comment.