Fixing login helper
This commit is contained in:
parent
8f23c05e97
commit
fdea9ddcb1
|
|
@ -277,14 +277,16 @@ static NSTimeInterval updateSystemVolumeInterval=0.1f;
|
||||||
[NSApp terminate:nil];
|
[NSApp terminate:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
// In AppDelegate.m -> setStartAtLogin:
|
- (void)updateStartAtLoginMenuItem
|
||||||
- (void)setStartAtLogin:(bool)enabled savePreferences:(bool)savePreferences
|
|
||||||
{
|
{
|
||||||
|
BOOL enabled = [self StartAtLogin];
|
||||||
NSMenuItem* menuItem = [self.statusMenu itemWithTag:START_AT_LOGIN_ID];
|
NSMenuItem* menuItem = [self.statusMenu itemWithTag:START_AT_LOGIN_ID];
|
||||||
[menuItem setState:enabled ? NSControlStateValueOn : NSControlStateValueOff];
|
[menuItem setState:enabled ? NSControlStateValueOn : NSControlStateValueOff];
|
||||||
|
}
|
||||||
|
|
||||||
if (!savePreferences) return;
|
|
||||||
|
|
||||||
|
- (void)setStartAtLogin:(BOOL)enabled savePreferences:(BOOL)savePreferences
|
||||||
|
{
|
||||||
NSString *helperBundleID = @"io.alberti42.VolumeControlHelper";
|
NSString *helperBundleID = @"io.alberti42.VolumeControlHelper";
|
||||||
|
|
||||||
if (@available(macOS 13.0, *)) {
|
if (@available(macOS 13.0, *)) {
|
||||||
|
|
@ -294,34 +296,41 @@ static NSTimeInterval updateSystemVolumeInterval=0.1f;
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
if (service.status != SMAppServiceStatusEnabled) {
|
if (service.status != SMAppServiceStatusEnabled) {
|
||||||
if (![service registerAndReturnError:&error]) {
|
if (![service registerAndReturnError:&error]) {
|
||||||
NSLog(@"[Volume Control] Error registering login item: %@", error.localizedDescription);
|
NSLog(@"Error registering login item: %@", error.localizedDescription);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (service.status == SMAppServiceStatusEnabled) {
|
if (service.status != SMAppServiceStatusNotRegistered) {
|
||||||
if (![service unregisterAndReturnError:&error]) {
|
if (![service unregisterAndReturnError:&error]) {
|
||||||
NSLog(@"[Volume Control] Error unregistering login item: %@", error.localizedDescription);
|
NSLog(@"Error unregistering login item: %@", error.localizedDescription);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Legacy fallback
|
// Fallback
|
||||||
NSLog(@"[Volume Control] loginItemServiceWithIdentifier not supported by this version of macOS.");
|
NSLog(@"[Volume Control] loginItemServiceWithIdentifier not supported by this version of macOS.");
|
||||||
|
if (savePreferences) {
|
||||||
|
[preferences setBool:NO forKey:@"StartAtLoginPreference"];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[self updateStartAtLoginMenuItem];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (bool)StartAtLogin
|
- (bool)StartAtLogin
|
||||||
{
|
{
|
||||||
NSString *helperBundleID = @"io.alberti42.VolumeControl.VolumeControlHelper";
|
NSString *helperBundleID = @"io.alberti42.VolumeControlHelper";
|
||||||
|
|
||||||
if (@available(macOS 13.0, *)) {
|
if (@available(macOS 13.0, *)) {
|
||||||
SMAppService *service = [SMAppService loginItemServiceWithIdentifier:helperBundleID];
|
SMAppService *service = [SMAppService loginItemServiceWithIdentifier:helperBundleID];
|
||||||
return service.status == SMAppServiceStatusEnabled;
|
return (service.status == SMAppServiceStatusEnabled ||
|
||||||
|
service.status == SMAppServiceStatusRequiresApproval);
|
||||||
} else {
|
} else {
|
||||||
return [preferences boolForKey:@"StartAtLoginPreference"];
|
return NO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void)wasAuthorized
|
- (void)wasAuthorized
|
||||||
{
|
{
|
||||||
[accessibilityDialog close];
|
[accessibilityDialog close];
|
||||||
|
|
@ -766,15 +775,11 @@ static NSTimeInterval updateSystemVolumeInterval=0.1f;
|
||||||
_PlaySoundFeedback=enabled;
|
_PlaySoundFeedback=enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
// You will also need to update your toggle action method
|
|
||||||
- (IBAction)toggleStartAtLogin:(id)sender
|
- (IBAction)toggleStartAtLogin:(id)sender
|
||||||
{
|
{
|
||||||
// Use a stored preference as the source of truth for the current state
|
BOOL currentlyEnabled = [self StartAtLogin];
|
||||||
bool newState = ![[NSUserDefaults standardUserDefaults] boolForKey:@"StartAtLoginPreference"];
|
[self setStartAtLogin:!currentlyEnabled savePreferences:YES];
|
||||||
[[NSUserDefaults standardUserDefaults] setBool:newState forKey:@"StartAtLoginPreference"];
|
[self updateStartAtLoginMenuItem];
|
||||||
|
|
||||||
// Now call the method to apply the change
|
|
||||||
[self setStartAtLogin:newState savePreferences:true];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setUseAppleCMDModifier:(bool)enabled
|
- (void) setUseAppleCMDModifier:(bool)enabled
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,23 @@
|
||||||
65996E09267EB0FF0080A9A5 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 65996E08267EB0FF0080A9A5 /* main.m */; };
|
65996E09267EB0FF0080A9A5 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 65996E08267EB0FF0080A9A5 /* main.m */; };
|
||||||
65996E1A267EB14F0080A9A5 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 65996E13267EB14F0080A9A5 /* AppDelegate.m */; };
|
65996E1A267EB14F0080A9A5 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 65996E13267EB14F0080A9A5 /* AppDelegate.m */; };
|
||||||
65996E1B267EB14F0080A9A5 /* SystemVolume.m in Sources */ = {isa = PBXBuildFile; fileRef = 65996E16267EB14F0080A9A5 /* SystemVolume.m */; };
|
65996E1B267EB14F0080A9A5 /* SystemVolume.m in Sources */ = {isa = PBXBuildFile; fileRef = 65996E16267EB14F0080A9A5 /* SystemVolume.m */; };
|
||||||
65DBBEEF2E89E08100752329 /* Volume Control Helper.app in Embed Login Items */ = {isa = PBXBuildFile; fileRef = 65DBBEDA2E89DE1800752329 /* Volume Control Helper.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
|
65DBBEF22E89EB6000752329 /* Volume Control Helper.app in Embed Login Helper */ = {isa = PBXBuildFile; fileRef = 65DBBEDA2E89DE1800752329 /* Volume Control Helper.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
|
||||||
65EF8F5A2E888C9500AAE7B7 /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65EF8F582E888C6B00AAE7B7 /* Sparkle.framework */; };
|
65EF8F5A2E888C9500AAE7B7 /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 65EF8F582E888C6B00AAE7B7 /* Sparkle.framework */; };
|
||||||
65EF8F5B2E888C9500AAE7B7 /* Sparkle.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 65EF8F582E888C6B00AAE7B7 /* Sparkle.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
65EF8F5B2E888C9500AAE7B7 /* Sparkle.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 65EF8F582E888C6B00AAE7B7 /* Sparkle.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXCopyFilesBuildPhase section */
|
/* Begin PBXCopyFilesBuildPhase section */
|
||||||
|
65DBBEF12E89EB4D00752329 /* Embed Login Helper */ = {
|
||||||
|
isa = PBXCopyFilesBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
dstPath = Contents/Library/LoginItems;
|
||||||
|
dstSubfolderSpec = 1;
|
||||||
|
files = (
|
||||||
|
65DBBEF22E89EB6000752329 /* Volume Control Helper.app in Embed Login Helper */,
|
||||||
|
);
|
||||||
|
name = "Embed Login Helper";
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
};
|
||||||
65EF8F5C2E888C9500AAE7B7 /* Embed Frameworks */ = {
|
65EF8F5C2E888C9500AAE7B7 /* Embed Frameworks */ = {
|
||||||
isa = PBXCopyFilesBuildPhase;
|
isa = PBXCopyFilesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
|
|
@ -39,17 +50,6 @@
|
||||||
name = "Embed Frameworks";
|
name = "Embed Frameworks";
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
65EF8F5E2E88969C00AAE7B7 /* Embed Login Items */ = {
|
|
||||||
isa = PBXCopyFilesBuildPhase;
|
|
||||||
buildActionMask = 2147483647;
|
|
||||||
dstPath = Contents/Library/LoginItems;
|
|
||||||
dstSubfolderSpec = 1;
|
|
||||||
files = (
|
|
||||||
65DBBEEF2E89E08100752329 /* Volume Control Helper.app in Embed Login Items */,
|
|
||||||
);
|
|
||||||
name = "Embed Login Items";
|
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
|
||||||
};
|
|
||||||
/* End PBXCopyFilesBuildPhase section */
|
/* End PBXCopyFilesBuildPhase section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
|
|
@ -359,7 +359,7 @@
|
||||||
65996C52267EA86A0080A9A5 /* Frameworks */,
|
65996C52267EA86A0080A9A5 /* Frameworks */,
|
||||||
65996C53267EA86A0080A9A5 /* Resources */,
|
65996C53267EA86A0080A9A5 /* Resources */,
|
||||||
65EF8F5C2E888C9500AAE7B7 /* Embed Frameworks */,
|
65EF8F5C2E888C9500AAE7B7 /* Embed Frameworks */,
|
||||||
65EF8F5E2E88969C00AAE7B7 /* Embed Login Items */,
|
65DBBEF12E89EB4D00752329 /* Embed Login Helper */,
|
||||||
);
|
);
|
||||||
buildRules = (
|
buildRules = (
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue