Skip to content

Commit

Permalink
Launching at login
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnpn committed Jul 7, 2022
1 parent 9b8a57f commit c1e1fdc
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 18 deletions.
57 changes: 53 additions & 4 deletions Urusai.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
1789588828770DD3005B45FF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1789588728770DD3005B45FF /* Assets.xcassets */; };
1789588B28770DD3005B45FF /* Preferences.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1789588928770DD3005B45FF /* Preferences.storyboard */; };
178958E32877725B005B45FF /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 178958E12877725B005B45FF /* Main.storyboard */; };
178958E6287777D4005B45FF /* LaunchAtLogin in Frameworks */ = {isa = PBXBuildFile; productRef = 178958E5287777D4005B45FF /* LaunchAtLogin */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -30,6 +31,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
178958E6287777D4005B45FF /* LaunchAtLogin in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -76,12 +78,16 @@
1789587C28770DD0005B45FF /* Sources */,
1789587D28770DD0005B45FF /* Frameworks */,
1789587E28770DD0005B45FF /* Resources */,
178958E728777AC9005B45FF /* Copy “Launch at Login Helper” */,
);
buildRules = (
);
dependencies = (
);
name = Urusai;
packageProductDependencies = (
178958E5287777D4005B45FF /* LaunchAtLogin */,
);
productName = Urusai;
productReference = 1789588028770DD0005B45FF /* Urusai.app */;
productType = "com.apple.product-type.application";
Expand Down Expand Up @@ -110,6 +116,9 @@
Base,
);
mainGroup = 1789587728770DD0005B45FF;
packageReferences = (
178958E4287777D4005B45FF /* XCRemoteSwiftPackageReference "LaunchAtLogin" */,
);
productRefGroup = 1789588128770DD0005B45FF /* Products */;
projectDirPath = "";
projectRoot = "";
Expand All @@ -132,6 +141,27 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
178958E728777AC9005B45FF /* Copy “Launch at Login Helper” */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "Copy “Launch at Login Helper”";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${BUILT_PRODUCTS_DIR}/LaunchAtLogin_LaunchAtLogin.bundle/Contents/Resources/copy-helper-swiftpm.sh\"\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
1789587C28770DD0005B45FF /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down Expand Up @@ -285,7 +315,7 @@
CODE_SIGN_ENTITLEMENTS = Urusai/Urusai.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = 35BSP6SUG9;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -298,7 +328,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.0;
MARKETING_VERSION = 1.1;
PRODUCT_BUNDLE_IDENTIFIER = dev.mnpn.Urusai;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -314,7 +344,7 @@
CODE_SIGN_ENTITLEMENTS = Urusai/Urusai.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = 35BSP6SUG9;
ENABLE_HARDENED_RUNTIME = YES;
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -327,7 +357,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 1.0;
MARKETING_VERSION = 1.1;
PRODUCT_BUNDLE_IDENTIFIER = dev.mnpn.Urusai;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -357,6 +387,25 @@
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
178958E4287777D4005B45FF /* XCRemoteSwiftPackageReference "LaunchAtLogin" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/sindresorhus/LaunchAtLogin";
requirement = {
branch = main;
kind = branch;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
178958E5287777D4005B45FF /* LaunchAtLogin */ = {
isa = XCSwiftPackageProductDependency;
package = 178958E4287777D4005B45FF /* XCRemoteSwiftPackageReference "LaunchAtLogin" */;
productName = LaunchAtLogin;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 1789587828770DD0005B45FF /* Project object */;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "launchatlogin",
"kind" : "remoteSourceControl",
"location" : "https://github.com/sindresorhus/LaunchAtLogin",
"state" : {
"branch" : "main",
"revision" : "e8171b3e38a2816f579f58f3dac1522aa39efe41"
}
}
],
"version" : 2
}
11 changes: 2 additions & 9 deletions Urusai/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
mElement: kAudioObjectPropertyElementMain)

func applicationDidFinishLaunching(_ aNotification: Notification) {
// set default UserDefaults if they do not exist
UserDefaults.standard.register(
defaults: [
"should_launch_at_startup": true,
"should_show_menubar_item": true
]
)
UserDefaults.standard.register(defaults: ["should_show_menubar_item": true])

addListenerBlock(listenerBlock: audioObjectPropertyListenerBlock,
onAudioObjectID: AudioObjectID(bitPattern: kAudioObjectSystemObject),
Expand All @@ -58,7 +52,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
menu.addItem(NSMenuItem(title: "Preferences…", action: #selector(openPreferences), keyEquivalent: ","))
menu.addItem(NSMenuItem(title: "Quit Urusai", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q"))
statusItem.menu = menu
openPreferences()
}

func applicationWillTerminate(_ aNotification: Notification) { }
Expand Down Expand Up @@ -87,7 +80,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
lastDevice = device
}
default:
print("We didn't expect this!")
print("pain, there's no default device?")
}
index += 1
}
Expand Down
9 changes: 6 additions & 3 deletions Urusai/Base.lproj/Preferences.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,15 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="k8U-Gd-2G8">
<rect key="frame" x="18" y="60" width="315" height="18"/>
<rect key="frame" x="18" y="60" width="296" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Launch Urusai automatically on system start-up" bezelStyle="regularSquare" imagePosition="left" enabled="NO" inset="2" id="FkZ-rc-dLF">
<buttonCell key="cell" type="check" title="Launch Urusai automatically when logging in" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="FkZ-rc-dLF">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<binding destination="XfG-lQ-9wD" name="value" keyPath="launchAtLogin.isEnabled" id="HlY-Cs-aJt"/>
</connections>
</button>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Xym-S7-Fec">
<rect key="frame" x="18" y="38" width="200" height="18"/>
Expand Down Expand Up @@ -126,13 +129,13 @@
</subviews>
</view>
<connections>
<outlet property="autolaunchToggle" destination="k8U-Gd-2G8" id="DFj-hU-FAq"/>
<outlet property="link" destination="vI3-UN-Pdy" id="iaJ-Bz-1fs"/>
<outlet property="menubarToggle" destination="Xym-S7-Fec" id="fZL-KB-Fbd"/>
<outlet property="versionLabel" destination="aKr-kL-Rye" id="Box-KW-uqX"/>
</connections>
</viewController>
<customObject id="rPt-NT-nkU" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
<userDefaultsController representsSharedInstance="YES" id="8GZ-zj-pP5"/>
</objects>
<point key="canvasLocation" x="75" y="552.5"/>
</scene>
Expand Down
4 changes: 2 additions & 2 deletions Urusai/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
//

import Cocoa
import LaunchAtLogin

class ViewController: NSViewController {
@IBOutlet weak var autolaunchToggle: NSButton!
@IBOutlet weak var menubarToggle: NSButton!
@IBOutlet weak var versionLabel: NSTextField!
@IBOutlet var link: NSTextView!

let df = UserDefaults.standard
@objc dynamic var launchAtLogin = LaunchAtLogin.kvo

override func viewDidLoad() {
super.viewDidLoad()
autolaunchToggle?.state = df.bool(forKey: "should_launch_at_startup") ? NSControl.StateValue.on : NSControl.StateValue.off
menubarToggle?.state = df.bool(forKey: "should_show_menubar_item") ? NSControl.StateValue.on : NSControl.StateValue.off

// https://stackoverflow.com/questions/3015796
Expand Down

0 comments on commit c1e1fdc

Please sign in to comment.