mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-11 01:18:39 +00:00
commit
6ca7f11a2b
@ -18,6 +18,7 @@
|
||||
36C2ECDD207C723B003CDA33 /* ParseConfigTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36C2ECDC207C723B003CDA33 /* ParseConfigTests.swift */; };
|
||||
36C2ECDE207C82DE003CDA33 /* ItemsParsing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36C2ECDA207C3FE7003CDA33 /* ItemsParsing.swift */; };
|
||||
36C2ECE0207CB1B0003CDA33 /* defaultPreset.json in Resources */ = {isa = PBXBuildFile; fileRef = 36C2ECDF207CB1B0003CDA33 /* defaultPreset.json */; };
|
||||
60173D3E20C0031B002C305F /* LaunchAtLoginController.m in Sources */ = {isa = PBXBuildFile; fileRef = 60173D3D20C0031B002C305F /* LaunchAtLoginController.m */; };
|
||||
6027D1B92080E52A004FFDC7 /* BrightnessViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6027D1B72080E52A004FFDC7 /* BrightnessViewController.swift */; };
|
||||
6027D1BA2080E52A004FFDC7 /* VolumeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6027D1B82080E52A004FFDC7 /* VolumeViewController.swift */; };
|
||||
6042B6A72083E03A00C525C8 /* AppScrubberTouchBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6042B6A62083E03A00C525C8 /* AppScrubberTouchBarItem.swift */; };
|
||||
@ -65,6 +66,8 @@
|
||||
36C2ECDA207C3FE7003CDA33 /* ItemsParsing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemsParsing.swift; sourceTree = "<group>"; };
|
||||
36C2ECDC207C723B003CDA33 /* ParseConfigTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseConfigTests.swift; sourceTree = "<group>"; };
|
||||
36C2ECDF207CB1B0003CDA33 /* defaultPreset.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = defaultPreset.json; sourceTree = "<group>"; };
|
||||
60173D3C20C0031B002C305F /* LaunchAtLoginController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LaunchAtLoginController.h; sourceTree = "<group>"; };
|
||||
60173D3D20C0031B002C305F /* LaunchAtLoginController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LaunchAtLoginController.m; sourceTree = "<group>"; };
|
||||
6027D1B72080E52A004FFDC7 /* BrightnessViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BrightnessViewController.swift; sourceTree = "<group>"; };
|
||||
6027D1B82080E52A004FFDC7 /* VolumeViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VolumeViewController.swift; sourceTree = "<group>"; };
|
||||
6042B6A62083E03A00C525C8 /* AppScrubberTouchBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppScrubberTouchBarItem.swift; sourceTree = "<group>"; };
|
||||
@ -222,6 +225,8 @@
|
||||
B0F8771B207AC92700D6E430 /* TouchBarSupport.h */,
|
||||
6042B6A82083E1F500C525C8 /* DeprecatedCarbonAPI.h */,
|
||||
6042B6A92083E27000C525C8 /* DeprecatedCarbonAPI.c */,
|
||||
60173D3C20C0031B002C305F /* LaunchAtLoginController.h */,
|
||||
60173D3D20C0031B002C305F /* LaunchAtLoginController.m */,
|
||||
);
|
||||
path = CBridge;
|
||||
sourceTree = "<group>";
|
||||
@ -367,6 +372,7 @@
|
||||
B082B253205C7D8000BC04DC /* AppDelegate.swift in Sources */,
|
||||
60C44AFD20A373A100C0EC91 /* MusicBarItem.swift in Sources */,
|
||||
B059D624205E04F3006E6B86 /* CustomButtonTouchBarItem.swift in Sources */,
|
||||
60173D3E20C0031B002C305F /* LaunchAtLoginController.m in Sources */,
|
||||
6027D1BA2080E52A004FFDC7 /* VolumeViewController.swift in Sources */,
|
||||
607EEA4B2087835F009DA5F0 /* WeatherBarItem.swift in Sources */,
|
||||
6042B6AA2083E27000C525C8 /* DeprecatedCarbonAPI.c in Sources */,
|
||||
|
||||
@ -89,6 +89,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
@objc func toggleStartAtLogin(_ sender: Any?) {
|
||||
LaunchAtLoginController().setLaunchAtLogin(!LaunchAtLoginController().launchAtLogin, for: NSURL.fileURL(withPath: Bundle.main.bundlePath))
|
||||
createMenu()
|
||||
}
|
||||
|
||||
func createMenu() {
|
||||
let menu = NSMenu()
|
||||
menu.addItem(withTitle: "Preferences", action: #selector(openPreferences(_:)), keyEquivalent: ",")
|
||||
@ -96,6 +101,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
menu.addItem(withTitle: "Open Preset", action: #selector(openPreset(_:)), keyEquivalent: "O")
|
||||
menu.addItem(withTitle: TouchBarController.shared.controlStripState ? "Hide Control Strip" : "Show Control Strip" , action: #selector(toggleControlStrip(_:)), keyEquivalent: "T")
|
||||
menu.addItem(withTitle: "Toggle blackList current app" , action: #selector(toggleBlackListedApp(_:)), keyEquivalent: "B")
|
||||
menu.addItem(withTitle: LaunchAtLoginController().launchAtLogin ? "Disable start at login" : "Enable start at login", action: #selector(toggleStartAtLogin(_:)), keyEquivalent: "L")
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
menu.addItem(withTitle: "Quit", action: #selector(NSApplication.terminate(_:)), keyEquivalent: "q")
|
||||
statusItem.menu = menu
|
||||
|
||||
35
MTMR/CBridge/LaunchAtLoginController.h
Normal file
35
MTMR/CBridge/LaunchAtLoginController.h
Normal file
@ -0,0 +1,35 @@
|
||||
//
|
||||
// LaunchAtLoginController.h
|
||||
//
|
||||
// Copyright 2011 Tomáš Znamenáček
|
||||
// Copyright 2010 Ben Clark-Robinson
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the ‘Software’),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
@import Foundation;
|
||||
@import CoreServices;
|
||||
|
||||
@interface LaunchAtLoginController : NSObject {}
|
||||
|
||||
@property(assign) BOOL launchAtLogin;
|
||||
|
||||
- (BOOL) willLaunchAtLogin: (NSURL*) itemURL;
|
||||
- (void) setLaunchAtLogin: (BOOL) enabled forURL: (NSURL*) itemURL;
|
||||
|
||||
@end
|
||||
128
MTMR/CBridge/LaunchAtLoginController.m
Normal file
128
MTMR/CBridge/LaunchAtLoginController.m
Normal file
@ -0,0 +1,128 @@
|
||||
//
|
||||
// LaunchAtLoginController.m
|
||||
//
|
||||
// Copyright 2011 Tomáš Znamenáček
|
||||
// Copyright 2010 Ben Clark-Robinson
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the ‘Software’),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
#import "LaunchAtLoginController.h"
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
|
||||
static NSString *const StartAtLoginKey = @"launchAtLogin";
|
||||
|
||||
@interface LaunchAtLoginController ()
|
||||
@property(assign) LSSharedFileListRef loginItems;
|
||||
@end
|
||||
|
||||
@implementation LaunchAtLoginController
|
||||
@synthesize loginItems;
|
||||
|
||||
#pragma mark Change Observing
|
||||
|
||||
void sharedFileListDidChange(LSSharedFileListRef inList, void *context)
|
||||
{
|
||||
LaunchAtLoginController *self = (__bridge id) context;
|
||||
[self willChangeValueForKey:StartAtLoginKey];
|
||||
[self didChangeValueForKey:StartAtLoginKey];
|
||||
}
|
||||
|
||||
#pragma mark Initialization
|
||||
|
||||
- (id) init
|
||||
{
|
||||
self = [super init];
|
||||
loginItems = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL);
|
||||
LSSharedFileListAddObserver(loginItems, CFRunLoopGetMain(),
|
||||
(CFStringRef)NSDefaultRunLoopMode, sharedFileListDidChange, (voidPtr)CFBridgingRetain(self));
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
LSSharedFileListRemoveObserver(loginItems, CFRunLoopGetMain(),
|
||||
(CFStringRef)NSDefaultRunLoopMode, sharedFileListDidChange, (__bridge void *)(self));
|
||||
CFRelease(loginItems);
|
||||
}
|
||||
|
||||
#pragma mark Launch List Control
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
LSSharedFileListItemRef copyItemWithURLinFileList(NSURL* wantedURL, LSSharedFileListRef fileList) {
|
||||
if (wantedURL == NULL || fileList == NULL)
|
||||
return NULL;
|
||||
|
||||
NSArray *listSnapshot = (__bridge_transfer NSArray *)LSSharedFileListCopySnapshot(fileList, NULL);
|
||||
for(NSUInteger i = 0; i< [listSnapshot count]; i++) {
|
||||
LSSharedFileListItemRef item = (__bridge LSSharedFileListItemRef)[listSnapshot objectAtIndex:i];
|
||||
UInt32 resolutionFlags = kLSSharedFileListNoUserInteraction | kLSSharedFileListDoNotMountVolumes;
|
||||
CFURLRef currentItemURL = NULL;
|
||||
LSSharedFileListItemResolve(item, resolutionFlags, ¤tItemURL, NULL);
|
||||
if (currentItemURL && [(__bridge_transfer NSURL*)currentItemURL isEqual:wantedURL]) {
|
||||
CFRetain(item);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
- (BOOL) willLaunchAtLogin: (NSURL*) itemURL
|
||||
{
|
||||
return !!copyItemWithURLinFileList(itemURL, loginItems);
|
||||
}
|
||||
|
||||
- (void) setLaunchAtLogin: (BOOL) enabled forURL: (NSURL*) itemURL
|
||||
{
|
||||
LSSharedFileListItemRef appItem = copyItemWithURLinFileList(itemURL, loginItems);
|
||||
if (enabled && !appItem) {
|
||||
LSSharedFileListInsertItemURL(loginItems, kLSSharedFileListItemBeforeFirst,
|
||||
NULL, NULL, (__bridge CFURLRef)itemURL, NULL, NULL);
|
||||
} else if (!enabled && appItem) {
|
||||
LSSharedFileListItemRemove(loginItems, appItem);
|
||||
}
|
||||
if (appItem) {
|
||||
CFRelease(appItem);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark Basic Interface
|
||||
|
||||
- (NSURL*) appURL
|
||||
{
|
||||
return [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
|
||||
}
|
||||
|
||||
- (void) setLaunchAtLogin: (BOOL) enabled
|
||||
{
|
||||
[self willChangeValueForKey:StartAtLoginKey];
|
||||
[self setLaunchAtLogin:enabled forURL:[self appURL]];
|
||||
[self didChangeValueForKey:StartAtLoginKey];
|
||||
}
|
||||
|
||||
- (BOOL) launchAtLogin
|
||||
{
|
||||
return [self willLaunchAtLogin:[self appURL]];
|
||||
}
|
||||
|
||||
@end
|
||||
#pragma clang diagnostic pop
|
||||
@ -9,6 +9,7 @@
|
||||
#import "TouchBarPrivateApi.h"
|
||||
#import "TouchBarSupport.h"
|
||||
#import "DeprecatedCarbonAPI.h"
|
||||
#include "LaunchAtLoginController.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
|
||||
@ -36,7 +36,7 @@ My the idea is to create the program like a platform for plugins for customizati
|
||||
|
||||
Settings:
|
||||
- [ ] Interface for plugins and export like presets
|
||||
- [ ] Startup at login
|
||||
- [x] Startup at login
|
||||
- [ ] Show on/off in Dock
|
||||
- [ ] Show on/off in StatusBar
|
||||
- [ ] On/off Haptic Feedback
|
||||
|
||||
Loading…
Reference in New Issue
Block a user