diff --git a/MacPowerAlert.xcodeproj/project.pbxproj b/MacPowerAlert.xcodeproj/project.pbxproj index 5d50f0d..8e588f6 100644 --- a/MacPowerAlert.xcodeproj/project.pbxproj +++ b/MacPowerAlert.xcodeproj/project.pbxproj @@ -7,19 +7,19 @@ objects = { /* Begin PBXBuildFile section */ - D36A49A52B44A9C5005E1573 /* MacPowerAlertApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = D36A49A42B44A9C5005E1573 /* MacPowerAlertApp.swift */; }; - D36A49A72B44A9C5005E1573 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D36A49A62B44A9C5005E1573 /* ContentView.swift */; }; D36A49A92B44A9C6005E1573 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D36A49A82B44A9C6005E1573 /* Assets.xcassets */; }; D36A49AC2B44A9C6005E1573 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D36A49AB2B44A9C6005E1573 /* Preview Assets.xcassets */; }; + D36A49BA2B44B2B5005E1573 /* MacPowerAlertApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = D36A49B92B44B2B5005E1573 /* MacPowerAlertApp.swift */; }; + D36A49BC2B44B2EA005E1573 /* BackgroundService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D36A49BB2B44B2EA005E1573 /* BackgroundService.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ D36A49A12B44A9C5005E1573 /* MacPowerAlert.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MacPowerAlert.app; sourceTree = BUILT_PRODUCTS_DIR; }; - D36A49A42B44A9C5005E1573 /* MacPowerAlertApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacPowerAlertApp.swift; sourceTree = ""; }; - D36A49A62B44A9C5005E1573 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; D36A49A82B44A9C6005E1573 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; D36A49AB2B44A9C6005E1573 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; D36A49AD2B44A9C6005E1573 /* MacPowerAlert.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MacPowerAlert.entitlements; sourceTree = ""; }; + D36A49B92B44B2B5005E1573 /* MacPowerAlertApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacPowerAlertApp.swift; sourceTree = ""; }; + D36A49BB2B44B2EA005E1573 /* BackgroundService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundService.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -52,10 +52,10 @@ D36A49A32B44A9C5005E1573 /* MacPowerAlert */ = { isa = PBXGroup; children = ( - D36A49A42B44A9C5005E1573 /* MacPowerAlertApp.swift */, - D36A49A62B44A9C5005E1573 /* ContentView.swift */, D36A49A82B44A9C6005E1573 /* Assets.xcassets */, D36A49AD2B44A9C6005E1573 /* MacPowerAlert.entitlements */, + D36A49B92B44B2B5005E1573 /* MacPowerAlertApp.swift */, + D36A49BB2B44B2EA005E1573 /* BackgroundService.swift */, D36A49AA2B44A9C6005E1573 /* Preview Content */, ); path = MacPowerAlert; @@ -101,6 +101,7 @@ TargetAttributes = { D36A49A02B44A9C5005E1573 = { CreatedOnToolsVersion = 15.1; + LastSwiftMigration = 1510; }; }; }; @@ -139,8 +140,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - D36A49A72B44A9C5005E1573 /* ContentView.swift in Sources */, - D36A49A52B44A9C5005E1573 /* MacPowerAlertApp.swift in Sources */, + D36A49BA2B44B2B5005E1573 /* MacPowerAlertApp.swift in Sources */, + D36A49BC2B44B2EA005E1573 /* BackgroundService.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -269,7 +270,10 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + "ASSETCATALOG_COMPILER_APPICON_NAME[sdk=macosx*]" = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES; + CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = MacPowerAlert/MacPowerAlert.entitlements; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; @@ -279,6 +283,9 @@ ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_CFBundleDisplayName = MacPowerAlert; + INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities"; + INFOPLIST_KEY_LSUIElement = YES; INFOPLIST_KEY_NSHumanReadableCopyright = ""; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -288,6 +295,7 @@ PRODUCT_BUNDLE_IDENTIFIER = TMBConsulinfo.MacPowerAlert; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; }; name = Debug; @@ -296,7 +304,10 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + "ASSETCATALOG_COMPILER_APPICON_NAME[sdk=macosx*]" = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES; + CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = MacPowerAlert/MacPowerAlert.entitlements; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; @@ -306,6 +317,9 @@ ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_CFBundleDisplayName = MacPowerAlert; + INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities"; + INFOPLIST_KEY_LSUIElement = YES; INFOPLIST_KEY_NSHumanReadableCopyright = ""; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", diff --git a/MacPowerAlert/Assets.xcassets/AccentColor.colorset/Contents.json b/MacPowerAlert/Assets.xcassets/AccentColor.colorset/Contents.json deleted file mode 100644 index eb87897..0000000 --- a/MacPowerAlert/Assets.xcassets/AccentColor.colorset/Contents.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "colors" : [ - { - "idiom" : "universal" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - } -} diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/100.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/100.png new file mode 100644 index 0000000..779947f Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/100.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/1024.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/1024.png new file mode 100644 index 0000000..51df6d2 Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/1024.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/114.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/114.png new file mode 100644 index 0000000..83a3cdf Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/114.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/120.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/120.png new file mode 100644 index 0000000..c2ef574 Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/120.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/128.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/128.png new file mode 100644 index 0000000..d0dc88a Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/128.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/144.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/144.png new file mode 100644 index 0000000..dab5d2e Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/144.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/152.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/152.png new file mode 100644 index 0000000..a30ccb6 Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/152.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/16.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/16.png new file mode 100644 index 0000000..ee1796b Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/16.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/167.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/167.png new file mode 100644 index 0000000..249ee7d Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/167.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/172.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/172.png new file mode 100644 index 0000000..2cd0eed Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/172.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/180.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/180.png new file mode 100644 index 0000000..e155cf3 Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/180.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/196.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/196.png new file mode 100644 index 0000000..14340b8 Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/196.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/20.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/20.png new file mode 100644 index 0000000..352c012 Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/20.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/216.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/216.png new file mode 100644 index 0000000..562432f Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/216.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/256.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/256.png new file mode 100644 index 0000000..994290c Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/256.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/29.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/29.png new file mode 100644 index 0000000..0ce2de4 Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/29.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/32.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/32.png new file mode 100644 index 0000000..b9fac17 Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/32.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/40.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/40.png new file mode 100644 index 0000000..a6a5166 Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/40.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/48.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/48.png new file mode 100644 index 0000000..493ec27 Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/48.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/50.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/50.png new file mode 100644 index 0000000..24ddbd7 Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/50.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/512.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/512.png new file mode 100644 index 0000000..183b863 Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/512.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/55.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/55.png new file mode 100644 index 0000000..92caad4 Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/55.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/57.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/57.png new file mode 100644 index 0000000..e7a39ad Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/57.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/58.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/58.png new file mode 100644 index 0000000..9bc62c9 Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/58.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/60.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/60.png new file mode 100644 index 0000000..a63fab6 Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/60.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/64.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/64.png new file mode 100644 index 0000000..f41e859 Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/64.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/66.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/66.png new file mode 100644 index 0000000..0b43621 Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/66.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/72.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/72.png new file mode 100644 index 0000000..db7d4d6 Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/72.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/76.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/76.png new file mode 100644 index 0000000..5348a86 Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/76.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/80.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/80.png new file mode 100644 index 0000000..87a1ed8 Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/80.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/87.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/87.png new file mode 100644 index 0000000..1454893 Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/87.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/88.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/88.png new file mode 100644 index 0000000..226e190 Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/88.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/92.png b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/92.png new file mode 100644 index 0000000..f4a23e4 Binary files /dev/null and b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/92.png differ diff --git a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/Contents.json b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/Contents.json index 3f00db4..8e70699 100644 --- a/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/MacPowerAlert/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,54 +1,342 @@ { "images" : [ { + "filename" : "40.png", + "idiom" : "iphone", + "scale" : "2x", + "size" : "20x20" + }, + { + "filename" : "60.png", + "idiom" : "iphone", + "scale" : "3x", + "size" : "20x20" + }, + { + "filename" : "29.png", + "idiom" : "iphone", + "scale" : "1x", + "size" : "29x29" + }, + { + "filename" : "58.png", + "idiom" : "iphone", + "scale" : "2x", + "size" : "29x29" + }, + { + "filename" : "87.png", + "idiom" : "iphone", + "scale" : "3x", + "size" : "29x29" + }, + { + "filename" : "80.png", + "idiom" : "iphone", + "scale" : "2x", + "size" : "40x40" + }, + { + "filename" : "120.png", + "idiom" : "iphone", + "scale" : "3x", + "size" : "40x40" + }, + { + "filename" : "57.png", + "idiom" : "iphone", + "scale" : "1x", + "size" : "57x57" + }, + { + "filename" : "114.png", + "idiom" : "iphone", + "scale" : "2x", + "size" : "57x57" + }, + { + "filename" : "120.png", + "idiom" : "iphone", + "scale" : "2x", + "size" : "60x60" + }, + { + "filename" : "180.png", + "idiom" : "iphone", + "scale" : "3x", + "size" : "60x60" + }, + { + "filename" : "20.png", + "idiom" : "ipad", + "scale" : "1x", + "size" : "20x20" + }, + { + "filename" : "40.png", + "idiom" : "ipad", + "scale" : "2x", + "size" : "20x20" + }, + { + "filename" : "29.png", + "idiom" : "ipad", + "scale" : "1x", + "size" : "29x29" + }, + { + "filename" : "58.png", + "idiom" : "ipad", + "scale" : "2x", + "size" : "29x29" + }, + { + "filename" : "40.png", + "idiom" : "ipad", + "scale" : "1x", + "size" : "40x40" + }, + { + "filename" : "80.png", + "idiom" : "ipad", + "scale" : "2x", + "size" : "40x40" + }, + { + "filename" : "50.png", + "idiom" : "ipad", + "scale" : "1x", + "size" : "50x50" + }, + { + "filename" : "100.png", + "idiom" : "ipad", + "scale" : "2x", + "size" : "50x50" + }, + { + "filename" : "72.png", + "idiom" : "ipad", + "scale" : "1x", + "size" : "72x72" + }, + { + "filename" : "144.png", + "idiom" : "ipad", + "scale" : "2x", + "size" : "72x72" + }, + { + "filename" : "76.png", + "idiom" : "ipad", + "scale" : "1x", + "size" : "76x76" + }, + { + "filename" : "152.png", + "idiom" : "ipad", + "scale" : "2x", + "size" : "76x76" + }, + { + "filename" : "167.png", + "idiom" : "ipad", + "scale" : "2x", + "size" : "83.5x83.5" + }, + { + "filename" : "1024.png", + "idiom" : "ios-marketing", + "scale" : "1x", + "size" : "1024x1024" + }, + { + "filename" : "16.png", "idiom" : "mac", "scale" : "1x", "size" : "16x16" }, { + "filename" : "32.png", "idiom" : "mac", "scale" : "2x", "size" : "16x16" }, { + "filename" : "32.png", "idiom" : "mac", "scale" : "1x", "size" : "32x32" }, { + "filename" : "64.png", "idiom" : "mac", "scale" : "2x", "size" : "32x32" }, { + "filename" : "128.png", "idiom" : "mac", "scale" : "1x", "size" : "128x128" }, { + "filename" : "256.png", "idiom" : "mac", "scale" : "2x", "size" : "128x128" }, { + "filename" : "256.png", "idiom" : "mac", "scale" : "1x", "size" : "256x256" }, { + "filename" : "512.png", "idiom" : "mac", "scale" : "2x", "size" : "256x256" }, { + "filename" : "512.png", "idiom" : "mac", "scale" : "1x", "size" : "512x512" }, { + "filename" : "1024.png", "idiom" : "mac", "scale" : "2x", "size" : "512x512" + }, + { + "filename" : "48.png", + "idiom" : "watch", + "role" : "notificationCenter", + "scale" : "2x", + "size" : "24x24", + "subtype" : "38mm" + }, + { + "filename" : "55.png", + "idiom" : "watch", + "role" : "notificationCenter", + "scale" : "2x", + "size" : "27.5x27.5", + "subtype" : "42mm" + }, + { + "filename" : "58.png", + "idiom" : "watch", + "role" : "companionSettings", + "scale" : "2x", + "size" : "29x29" + }, + { + "filename" : "87.png", + "idiom" : "watch", + "role" : "companionSettings", + "scale" : "3x", + "size" : "29x29" + }, + { + "filename" : "66.png", + "idiom" : "watch", + "role" : "notificationCenter", + "scale" : "2x", + "size" : "33x33", + "subtype" : "45mm" + }, + { + "filename" : "80.png", + "idiom" : "watch", + "role" : "appLauncher", + "scale" : "2x", + "size" : "40x40", + "subtype" : "38mm" + }, + { + "filename" : "88.png", + "idiom" : "watch", + "role" : "appLauncher", + "scale" : "2x", + "size" : "44x44", + "subtype" : "40mm" + }, + { + "filename" : "92.png", + "idiom" : "watch", + "role" : "appLauncher", + "scale" : "2x", + "size" : "46x46", + "subtype" : "41mm" + }, + { + "filename" : "100.png", + "idiom" : "watch", + "role" : "appLauncher", + "scale" : "2x", + "size" : "50x50", + "subtype" : "44mm" + }, + { + "idiom" : "watch", + "role" : "appLauncher", + "scale" : "2x", + "size" : "51x51", + "subtype" : "45mm" + }, + { + "idiom" : "watch", + "role" : "appLauncher", + "scale" : "2x", + "size" : "54x54", + "subtype" : "49mm" + }, + { + "filename" : "172.png", + "idiom" : "watch", + "role" : "quickLook", + "scale" : "2x", + "size" : "86x86", + "subtype" : "38mm" + }, + { + "filename" : "196.png", + "idiom" : "watch", + "role" : "quickLook", + "scale" : "2x", + "size" : "98x98", + "subtype" : "42mm" + }, + { + "filename" : "216.png", + "idiom" : "watch", + "role" : "quickLook", + "scale" : "2x", + "size" : "108x108", + "subtype" : "44mm" + }, + { + "idiom" : "watch", + "role" : "quickLook", + "scale" : "2x", + "size" : "117x117", + "subtype" : "45mm" + }, + { + "idiom" : "watch", + "role" : "quickLook", + "scale" : "2x", + "size" : "129x129", + "subtype" : "49mm" + }, + { + "filename" : "1024.png", + "idiom" : "watch-marketing", + "scale" : "1x", + "size" : "1024x1024" } ], "info" : { diff --git a/MacPowerAlert/BackgroundService.swift b/MacPowerAlert/BackgroundService.swift new file mode 100644 index 0000000..943e6ea --- /dev/null +++ b/MacPowerAlert/BackgroundService.swift @@ -0,0 +1,85 @@ +import Foundation +import UserNotifications +import IOKit.ps + +class BackgroundService: ObservableObject { + static let shared = BackgroundService() + + private var lowBatteryNotificationCount = 0 + private var highBatteryNotificationCount = 0 + + internal init() { + startMonitoring() + } + + func startMonitoring() { + let timer = Timer.scheduledTimer(timeInterval: 10, target: self, selector: #selector(checkBatteryLevel), userInfo: nil, repeats: true) + timer.fire() + } + + @objc func checkBatteryLevel() { + let currentLevel = getCurrentBatteryLevel() + let isCharging = isCharging() + + if currentLevel <= 20 && !isCharging { + if lowBatteryNotificationCount < 3 { + showNotification(message: "È il momento di mettere in carica il Mac, la percentuale della tua batteria è al \(currentLevel)%") + lowBatteryNotificationCount += 1 + } + } else { + lowBatteryNotificationCount = 0 // Resetta il conteggio quando rientra nel range + } + + if currentLevel >= 80 && isCharging { + if highBatteryNotificationCount < 3 { + showNotification(message: "Scollega il Mac, la batteria è al \(currentLevel)%") + highBatteryNotificationCount += 1 + } + } else { + highBatteryNotificationCount = 0 // Resetta il conteggio quando rientra nel range + } + } + + + func getCurrentBatteryLevel() -> Int { + let snapshot = IOPSCopyPowerSourcesInfo().takeRetainedValue() + let sources = IOPSCopyPowerSourcesList(snapshot).takeRetainedValue() as Array + + if let sourceData = IOPSGetPowerSourceDescription(snapshot, sources[0]).takeUnretainedValue() as? [String: AnyObject], + let currentCapacity = sourceData[kIOPSCurrentCapacityKey] as? Int { + return currentCapacity + } + + return 0 + } + + func isCharging() -> Bool { + let snapshot = IOPSCopyPowerSourcesInfo().takeRetainedValue() + let sources = IOPSCopyPowerSourcesList(snapshot).takeRetainedValue() as Array + + for source in sources { + if let sourceData = IOPSGetPowerSourceDescription(snapshot, source).takeUnretainedValue() as? [String: AnyObject] { + if let isPresent = sourceData[kIOPSIsPresentKey] as? Bool, + let state = sourceData[kIOPSPowerSourceStateKey] as? String, + isPresent { + let isCharging = state == "AC Power" + return isCharging + } + } + } + + return false + } + + + func showNotification(message: String) { + let content = UNMutableNotificationContent() + content.title = "MacPowerAlert" + content.body = message + content.sound = UNNotificationSound.default + + let request = UNNotificationRequest(identifier: "BatteryNotification", content: content, trigger: nil) + UNUserNotificationCenter.current().add(request, withCompletionHandler: nil) + } + +} diff --git a/MacPowerAlert/ContentView.swift b/MacPowerAlert/ContentView.swift deleted file mode 100644 index 1a6d075..0000000 --- a/MacPowerAlert/ContentView.swift +++ /dev/null @@ -1,24 +0,0 @@ -// -// ContentView.swift -// MacPowerAlert -// -// Created by Davide Tamburrelli on 02/01/24. -// - -import SwiftUI - -struct ContentView: View { - var body: some View { - VStack { - Image(systemName: "globe") - .imageScale(.large) - .foregroundStyle(.tint) - Text("Hello, world!") - } - .padding() - } -} - -#Preview { - ContentView() -} diff --git a/MacPowerAlert/MacPowerAlert.entitlements b/MacPowerAlert/MacPowerAlert.entitlements index 18aff0c..0c67376 100644 --- a/MacPowerAlert/MacPowerAlert.entitlements +++ b/MacPowerAlert/MacPowerAlert.entitlements @@ -1,10 +1,5 @@ - - com.apple.security.app-sandbox - - com.apple.security.files.user-selected.read-only - - + diff --git a/MacPowerAlert/MacPowerAlertApp.swift b/MacPowerAlert/MacPowerAlertApp.swift index 6f2991d..4ede990 100644 --- a/MacPowerAlert/MacPowerAlertApp.swift +++ b/MacPowerAlert/MacPowerAlertApp.swift @@ -1,17 +1,34 @@ -// -// MacPowerAlertApp.swift -// MacPowerAlert -// -// Created by Davide Tamburrelli on 02/01/24. -// - import SwiftUI +import UserNotifications @main struct MacPowerAlertApp: App { + @StateObject private var backgroundService = BackgroundService() + + init() { + // Richiesta autorizzazione notifiche + requestNotificationAuthorization() + + // Inizia il servizio di background + backgroundService.startMonitoring() + } + + func requestNotificationAuthorization() { + UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in + if granted { + print("Autorizzazione alle notifiche ottenuta") + } else if let error = error { + print("Errore nell'ottenere l'autorizzazione alle notifiche:", error) + } else { + print("Autorizzazione alle notifiche non ottenuta") + } + } + } + var body: some Scene { - WindowGroup { - ContentView() + // Non includere alcuna finestra principale + Settings { + EmptyView() } } } diff --git a/README.md b/README.md index 4e21393..51712d3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,22 @@ MacPowerAlert is a macOS application that monitors your Mac's battery status and notifies you when the battery is at 20% or 80%. -## Installation +## Why avoid discharging below 20% and charging above 80% + +Keeping your Mac's battery between 20% and 80% charge can help extend the battery's lifespan. Recharging the battery when it's around 20% and stopping the charge when it reaches 80% can reduce stress on the battery and slow down the aging process. + +## Installation + +Downlaod the app, copy to Applications folder, right click and select open, then select open anyway + +## Autostart Activation via Mac System Preferences + +To enable MacPowerAlert to start automatically with your Mac, follow these steps: + +1. Go to "System Preferences" on your Mac. +2. In the "Login Items" tab, add MacPowerAlert to the list of login items. + +## Setup Project 1. Make sure you have [Xcode](https://developer.apple.com/xcode/) installed on your system. 2. Clone the repository: `git clone https://github.com/your-username/MacPowerAlert.git` @@ -16,19 +31,6 @@ MacPowerAlert is a macOS application that monitors your Mac's battery status and 2. The app will start monitoring the battery status every minute. 3. You'll receive notifications when the battery is at 20% or 80%. -## Why avoid discharging below 20% and charging above 80% - -Keeping your Mac's battery between 20% and 80% charge can help extend the battery's lifespan. Recharging the battery when it's around 20% and stopping the charge when it reaches 80% can reduce stress on the battery and slow down the aging process. - -## Autostart Activation via Mac System Preferences - -To enable MacPowerAlert to start automatically with your Mac, follow these steps: - -1. Go to "System Preferences" on your Mac. -2. Select "Users & Groups." -3. In the "Login Items" tab, add MacPowerAlert to the list of login items. -4. Ensure the added application is checked in the "Hide" column. - ## Contribute If you want to contribute to this project, follow these steps: @@ -42,5 +44,4 @@ If you want to contribute to this project, follow these steps: ## Contact - Davide Tamburrelli - [tambu.dt@gmail.com](mailto:tambu.dt@gmail.com) -- [Other Contacts or Social Media]