diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c188a2d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +xcuserdata/ +Carthage diff --git a/.swiftlint.yml b/.swiftlint.yml new file mode 100644 index 0000000..31fd86d --- /dev/null +++ b/.swiftlint.yml @@ -0,0 +1,2 @@ +excluded: + - Carthage diff --git a/Bluesnooze.xcodeproj/project.pbxproj b/Bluesnooze.xcodeproj/project.pbxproj new file mode 100644 index 0000000..014fe98 --- /dev/null +++ b/Bluesnooze.xcodeproj/project.pbxproj @@ -0,0 +1,425 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + 4F229ABE243CC29500B1784C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F229ABD243CC29500B1784C /* AppDelegate.swift */; }; + 4F229AC0243CC29600B1784C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4F229ABF243CC29600B1784C /* Assets.xcassets */; }; + 4F229AC3243CC29600B1784C /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4F229AC1243CC29600B1784C /* MainMenu.xib */; }; + 4FDC9C13243DCC0300FB0C4E /* LaunchAtLogin.framework.dSYM in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4FDC9C12243DCC0300FB0C4E /* LaunchAtLogin.framework.dSYM */; }; + 4FDC9C14243DCC6B00FB0C4E /* LaunchAtLogin.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4FDC9C0E243DCB7B00FB0C4E /* LaunchAtLogin.framework */; }; + 4FDC9C15243DCC6B00FB0C4E /* LaunchAtLogin.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4FDC9C0E243DCB7B00FB0C4E /* LaunchAtLogin.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 4FDC9C0C243DCB0B00FB0C4E /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 16; + files = ( + 4FDC9C13243DCC0300FB0C4E /* LaunchAtLogin.framework.dSYM in CopyFiles */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 4FDC9C16243DCC6B00FB0C4E /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + 4FDC9C15243DCC6B00FB0C4E /* LaunchAtLogin.framework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 4F229ABA243CC29500B1784C /* Bluesnooze.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Bluesnooze.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 4F229ABD243CC29500B1784C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 4F229ABF243CC29600B1784C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 4F229AC2243CC29600B1784C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; + 4F229AC4243CC29600B1784C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 4F229AC5243CC29600B1784C /* Bluesnooze.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Bluesnooze.entitlements; sourceTree = ""; }; + 4F229ACB243CC72800B1784C /* Bluesnooze-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Bluesnooze-Bridging-Header.h"; sourceTree = ""; }; + 4FDC9C0E243DCB7B00FB0C4E /* LaunchAtLogin.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = LaunchAtLogin.framework; path = Carthage/Build/Mac/LaunchAtLogin.framework; sourceTree = ""; }; + 4FDC9C12243DCC0300FB0C4E /* LaunchAtLogin.framework.dSYM */ = {isa = PBXFileReference; lastKnownFileType = wrapper.dsym; name = LaunchAtLogin.framework.dSYM; path = Carthage/Build/Mac/LaunchAtLogin.framework.dSYM; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 4F229AB7243CC29500B1784C /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 4FDC9C14243DCC6B00FB0C4E /* LaunchAtLogin.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 4F229AB1243CC29500B1784C = { + isa = PBXGroup; + children = ( + 4F229ABC243CC29500B1784C /* Bluesnooze */, + 4F229ABB243CC29500B1784C /* Products */, + 4FDC9C0D243DCB7B00FB0C4E /* Frameworks */, + ); + sourceTree = ""; + }; + 4F229ABB243CC29500B1784C /* Products */ = { + isa = PBXGroup; + children = ( + 4F229ABA243CC29500B1784C /* Bluesnooze.app */, + ); + name = Products; + sourceTree = ""; + }; + 4F229ABC243CC29500B1784C /* Bluesnooze */ = { + isa = PBXGroup; + children = ( + 4F229ABD243CC29500B1784C /* AppDelegate.swift */, + 4F229ABF243CC29600B1784C /* Assets.xcassets */, + 4F229AC1243CC29600B1784C /* MainMenu.xib */, + 4F229AC4243CC29600B1784C /* Info.plist */, + 4F229AC5243CC29600B1784C /* Bluesnooze.entitlements */, + 4F229ACB243CC72800B1784C /* Bluesnooze-Bridging-Header.h */, + ); + path = Bluesnooze; + sourceTree = ""; + }; + 4FDC9C0D243DCB7B00FB0C4E /* Frameworks */ = { + isa = PBXGroup; + children = ( + 4FDC9C12243DCC0300FB0C4E /* LaunchAtLogin.framework.dSYM */, + 4FDC9C0E243DCB7B00FB0C4E /* LaunchAtLogin.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 4F229AB9243CC29500B1784C /* Bluesnooze */ = { + isa = PBXNativeTarget; + buildConfigurationList = 4F229AC8243CC29600B1784C /* Build configuration list for PBXNativeTarget "Bluesnooze" */; + buildPhases = ( + 4F707EAE243DC8DA00CBAE8A /* ShellScript */, + 4F229AB6243CC29500B1784C /* Sources */, + 4F229AB7243CC29500B1784C /* Frameworks */, + 4F229AB8243CC29500B1784C /* Resources */, + 4FDC9C0C243DCB0B00FB0C4E /* CopyFiles */, + 4FDC9C16243DCC6B00FB0C4E /* Embed Frameworks */, + 4FDC9C11243DCBD700FB0C4E /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Bluesnooze; + productName = Bluesnooze; + productReference = 4F229ABA243CC29500B1784C /* Bluesnooze.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 4F229AB2243CC29500B1784C /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1110; + LastUpgradeCheck = 1110; + ORGANIZATIONNAME = "Oliver Peate"; + TargetAttributes = { + 4F229AB9243CC29500B1784C = { + CreatedOnToolsVersion = 11.1; + LastSwiftMigration = 1110; + }; + }; + }; + buildConfigurationList = 4F229AB5243CC29500B1784C /* Build configuration list for PBXProject "Bluesnooze" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 4F229AB1243CC29500B1784C; + productRefGroup = 4F229ABB243CC29500B1784C /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 4F229AB9243CC29500B1784C /* Bluesnooze */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 4F229AB8243CC29500B1784C /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4F229AC0243CC29600B1784C /* Assets.xcassets in Resources */, + 4F229AC3243CC29600B1784C /* MainMenu.xib in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 4F707EAE243DC8DA00CBAE8A /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; + }; + 4FDC9C11243DCBD700FB0C4E /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PROJECT_DIR}/Carthage/Build/Mac/LaunchAtLogin.framework/Resources/copy-helper.sh\"\n"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 4F229AB6243CC29500B1784C /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4F229ABE243CC29500B1784C /* AppDelegate.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 4F229AC1243CC29600B1784C /* MainMenu.xib */ = { + isa = PBXVariantGroup; + children = ( + 4F229AC2243CC29600B1784C /* Base */, + ); + name = MainMenu.xib; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 4F229AC6243CC29600B1784C /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.14; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 4F229AC7243CC29600B1784C /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.14; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + 4F229AC9243CC29600B1784C /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Bluesnooze/Bluesnooze.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEVELOPMENT_TEAM = 7X3FR535W8; + ENABLE_HARDENED_RUNTIME = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/Mac", + ); + INFOPLIST_FILE = Bluesnooze/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.oliverpeate.Bluesnooze; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Bluesnooze/Bluesnooze-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 4F229ACA243CC29600B1784C /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Bluesnooze/Bluesnooze.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEVELOPMENT_TEAM = 7X3FR535W8; + ENABLE_HARDENED_RUNTIME = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/Mac", + ); + INFOPLIST_FILE = Bluesnooze/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.oliverpeate.Bluesnooze; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "Bluesnooze/Bluesnooze-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 4F229AB5243CC29500B1784C /* Build configuration list for PBXProject "Bluesnooze" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4F229AC6243CC29600B1784C /* Debug */, + 4F229AC7243CC29600B1784C /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 4F229AC8243CC29600B1784C /* Build configuration list for PBXNativeTarget "Bluesnooze" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4F229AC9243CC29600B1784C /* Debug */, + 4F229ACA243CC29600B1784C /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 4F229AB2243CC29500B1784C /* Project object */; +} diff --git a/Bluesnooze.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Bluesnooze.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..83f6636 --- /dev/null +++ b/Bluesnooze.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Bluesnooze.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Bluesnooze.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Bluesnooze.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Bluesnooze.xcodeproj/xcshareddata/xcschemes/Bluesnooze.xcscheme b/Bluesnooze.xcodeproj/xcshareddata/xcschemes/Bluesnooze.xcscheme new file mode 100644 index 0000000..b1c0aa5 --- /dev/null +++ b/Bluesnooze.xcodeproj/xcshareddata/xcschemes/Bluesnooze.xcscheme @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Bluesnooze/AppDelegate.swift b/Bluesnooze/AppDelegate.swift new file mode 100644 index 0000000..c186358 --- /dev/null +++ b/Bluesnooze/AppDelegate.swift @@ -0,0 +1,73 @@ +// +// AppDelegate.swift +// Bluesnooze +// +// Created by Oliver Peate on 07/04/2020. +// Copyright © 2020 Oliver Peate. All rights reserved. +// + +import Cocoa +import IOBluetooth +import LaunchAtLogin + +@NSApplicationMain +class AppDelegate: NSObject, NSApplicationDelegate { + + @IBOutlet weak var statusMenu: NSMenu! + @IBOutlet weak var launchAtLoginMenuItem: NSMenuItem! + + private let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength) + + func applicationDidFinishLaunching(_ aNotification: Notification) { + initStatusItem() + setLaunchAtLoginState() + NSWorkspace.shared.notificationCenter.addObserver( + self, selector: #selector(onSleepNote(note:)), name: NSWorkspace.willSleepNotification, object: nil + ) + NSWorkspace.shared.notificationCenter.addObserver( + self, selector: #selector(onWakeNote(note:)), name: NSWorkspace.didWakeNotification, object: nil + ) + } + + // MARK: Click handlers + + @IBAction func launchAtLoginClicked(_ sender: NSMenuItem) { + LaunchAtLogin.isEnabled = !LaunchAtLogin.isEnabled + setLaunchAtLoginState() + } + + @IBAction func quitClicked(_ sender: NSMenuItem) { + NSApplication.shared.terminate(self) + } + + // MARK: Notification handlers + + @objc func onSleepNote(note: NSNotification) { + setBluetooth(powerOn: false) + } + + @objc func onWakeNote(note: NSNotification) { + setBluetooth(powerOn: true) + } + + private func setBluetooth(powerOn: Bool) { + IOBluetoothPreferenceSetControllerPowerState(powerOn ? 1 : 0) + } + + // MARK: UI state + + private func initStatusItem() { + if let icon = NSImage(named: "bluesnooze") { + icon.isTemplate = true + statusItem.button?.image = icon + } else { + statusItem.button?.title = "Bluesnooze" + } + statusItem.menu = statusMenu + } + + private func setLaunchAtLoginState() { + let state = LaunchAtLogin.isEnabled ? NSControl.StateValue.on : NSControl.StateValue.off + launchAtLoginMenuItem.state = state + } +} diff --git a/Bluesnooze/Assets.xcassets/AppIcon.appiconset/Contents.json b/Bluesnooze/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..8e19de9 --- /dev/null +++ b/Bluesnooze/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,68 @@ +{ + "images" : [ + { + "size" : "16x16", + "idiom" : "mac", + "filename" : "icon.png", + "scale" : "1x" + }, + { + "size" : "16x16", + "idiom" : "mac", + "filename" : "icon@2x.png", + "scale" : "2x" + }, + { + "size" : "32x32", + "idiom" : "mac", + "filename" : "icon@2x-1.png", + "scale" : "1x" + }, + { + "size" : "32x32", + "idiom" : "mac", + "filename" : "icon-1.png", + "scale" : "2x" + }, + { + "size" : "128x128", + "idiom" : "mac", + "filename" : "icon@2x-2.png", + "scale" : "1x" + }, + { + "size" : "128x128", + "idiom" : "mac", + "filename" : "icon@4x.png", + "scale" : "2x" + }, + { + "size" : "256x256", + "idiom" : "mac", + "filename" : "icon@4x-1.png", + "scale" : "1x" + }, + { + "size" : "256x256", + "idiom" : "mac", + "filename" : "icon-2.png", + "scale" : "2x" + }, + { + "size" : "512x512", + "idiom" : "mac", + "filename" : "icon-3.png", + "scale" : "1x" + }, + { + "size" : "512x512", + "idiom" : "mac", + "filename" : "icon@2x-3.png", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon-1.png b/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon-1.png new file mode 100644 index 0000000..9ba8990 Binary files /dev/null and b/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon-1.png differ diff --git a/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon-2.png b/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon-2.png new file mode 100644 index 0000000..bedf302 Binary files /dev/null and b/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon-2.png differ diff --git a/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon-3.png b/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon-3.png new file mode 100644 index 0000000..bedf302 Binary files /dev/null and b/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon-3.png differ diff --git a/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon.png b/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon.png new file mode 100644 index 0000000..d794e75 Binary files /dev/null and b/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon.png differ diff --git a/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon@2x-1.png b/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon@2x-1.png new file mode 100644 index 0000000..8d4e2b0 Binary files /dev/null and b/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon@2x-1.png differ diff --git a/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon@2x-2.png b/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon@2x-2.png new file mode 100644 index 0000000..de63246 Binary files /dev/null and b/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon@2x-2.png differ diff --git a/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon@2x-3.png b/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon@2x-3.png new file mode 100644 index 0000000..9c0f200 Binary files /dev/null and b/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon@2x-3.png differ diff --git a/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon@2x.png b/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon@2x.png new file mode 100644 index 0000000..8d4e2b0 Binary files /dev/null and b/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon@2x.png differ diff --git a/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon@4x-1.png b/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon@4x-1.png new file mode 100644 index 0000000..388e55e Binary files /dev/null and b/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon@4x-1.png differ diff --git a/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon@4x.png b/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon@4x.png new file mode 100644 index 0000000..388e55e Binary files /dev/null and b/Bluesnooze/Assets.xcassets/AppIcon.appiconset/icon@4x.png differ diff --git a/Bluesnooze/Assets.xcassets/Contents.json b/Bluesnooze/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/Bluesnooze/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Bluesnooze/Assets.xcassets/bluesnooze.imageset/Contents.json b/Bluesnooze/Assets.xcassets/bluesnooze.imageset/Contents.json new file mode 100644 index 0000000..28cd1f1 --- /dev/null +++ b/Bluesnooze/Assets.xcassets/bluesnooze.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "bluesnooze.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "bluesnooze@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "bluesnooze@3x.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Bluesnooze/Assets.xcassets/bluesnooze.imageset/bluesnooze.png b/Bluesnooze/Assets.xcassets/bluesnooze.imageset/bluesnooze.png new file mode 100644 index 0000000..2302914 Binary files /dev/null and b/Bluesnooze/Assets.xcassets/bluesnooze.imageset/bluesnooze.png differ diff --git a/Bluesnooze/Assets.xcassets/bluesnooze.imageset/bluesnooze@2x.png b/Bluesnooze/Assets.xcassets/bluesnooze.imageset/bluesnooze@2x.png new file mode 100644 index 0000000..7cb5330 Binary files /dev/null and b/Bluesnooze/Assets.xcassets/bluesnooze.imageset/bluesnooze@2x.png differ diff --git a/Bluesnooze/Assets.xcassets/bluesnooze.imageset/bluesnooze@3x.png b/Bluesnooze/Assets.xcassets/bluesnooze.imageset/bluesnooze@3x.png new file mode 100644 index 0000000..f02147b Binary files /dev/null and b/Bluesnooze/Assets.xcassets/bluesnooze.imageset/bluesnooze@3x.png differ diff --git a/Bluesnooze/Base.lproj/MainMenu.xib b/Bluesnooze/Base.lproj/MainMenu.xib new file mode 100644 index 0000000..06fc27c --- /dev/null +++ b/Bluesnooze/Base.lproj/MainMenu.xib @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Bluesnooze/Bluesnooze-Bridging-Header.h b/Bluesnooze/Bluesnooze-Bridging-Header.h new file mode 100644 index 0000000..aa5af92 --- /dev/null +++ b/Bluesnooze/Bluesnooze-Bridging-Header.h @@ -0,0 +1,5 @@ +// +// Use this file to import your target's public headers that you would like to expose to Swift. +// + +void IOBluetoothPreferenceSetControllerPowerState(int); diff --git a/Bluesnooze/Bluesnooze.entitlements b/Bluesnooze/Bluesnooze.entitlements new file mode 100644 index 0000000..e9da8e1 --- /dev/null +++ b/Bluesnooze/Bluesnooze.entitlements @@ -0,0 +1,12 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.device.bluetooth + + com.apple.security.files.user-selected.read-only + + + diff --git a/Bluesnooze/Info.plist b/Bluesnooze/Info.plist new file mode 100644 index 0000000..207273a --- /dev/null +++ b/Bluesnooze/Info.plist @@ -0,0 +1,40 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSApplicationCategoryType + public.app-category.utilities + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + LSUIElement + + NSHumanReadableCopyright + Copyright © 2020 Oliver Peate. All rights reserved. + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + NSSupportsAutomaticTermination + + NSSupportsSuddenTermination + + + diff --git a/Cartfile b/Cartfile new file mode 100644 index 0000000..3819bb8 --- /dev/null +++ b/Cartfile @@ -0,0 +1 @@ +github "sindresorhus/LaunchAtLogin" diff --git a/Cartfile.resolved b/Cartfile.resolved new file mode 100644 index 0000000..bc0bf77 --- /dev/null +++ b/Cartfile.resolved @@ -0,0 +1 @@ +github "sindresorhus/LaunchAtLogin" "v3.0.0"