diff --git a/Clapet.xcodeproj/project.pbxproj b/Clapet.xcodeproj/project.pbxproj index 434931f..ae2b518 100644 --- a/Clapet.xcodeproj/project.pbxproj +++ b/Clapet.xcodeproj/project.pbxproj @@ -500,7 +500,7 @@ "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 3; + CURRENT_PROJECT_VERSION = 4; DEVELOPMENT_ASSET_PATHS = "\"Clapet/Preview Content\""; DEVELOPMENT_TEAM = 4STM42SPF5; ENABLE_HARDENED_RUNTIME = YES; @@ -515,7 +515,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 1.0.2; + MARKETING_VERSION = 1.0.3; PRODUCT_BUNDLE_IDENTIFIER = fr.mbenoukaiss.Clapet; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -535,7 +535,7 @@ "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 3; + CURRENT_PROJECT_VERSION = 4; DEVELOPMENT_ASSET_PATHS = "\"Clapet/Preview Content\""; DEVELOPMENT_TEAM = 4STM42SPF5; ENABLE_HARDENED_RUNTIME = YES; @@ -550,7 +550,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 1.0.2; + MARKETING_VERSION = 1.0.3; PRODUCT_BUNDLE_IDENTIFIER = fr.mbenoukaiss.Clapet; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/Clapet/AppDelegate.swift b/Clapet/AppDelegate.swift index 7a08a77..f49bfd4 100644 --- a/Clapet/AppDelegate.swift +++ b/Clapet/AppDelegate.swift @@ -44,7 +44,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate, Observable } static func hideApplication() { - NSApp.setActivationPolicy(.prohibited) + Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { + NSApp.setActivationPolicy(.prohibited); + $0.invalidate(); + } } } diff --git a/Clapet/Services/SleepService.swift b/Clapet/Services/SleepService.swift index f359af0..569402f 100644 --- a/Clapet/Services/SleepService.swift +++ b/Clapet/Services/SleepService.swift @@ -45,6 +45,25 @@ class SleepService: ObservableObject { Shell.run("sudo -n pmset -g") { self.pmsetAccessible = $0.success + if !self.pmsetAccessible! && self.alreadySetup { + AppDelegate.showApplication(bringToFront: true); + + let alert = NSAlert() + alert.messageText = "no-permission-title".localize() + alert.informativeText = "no-permission-content".localize() + alert.addButton(withTitle: "no-permission-open".localize()) + alert.addButton(withTitle: "cancel".localize()) + alert.alertStyle = .warning + + if alert.runModal() == .alertFirstButtonReturn { + if let url = URL(string: "https://github.com/mbenoukaiss/clapet#manual-configuration") { + NSWorkspace.shared.open(url) + } + + AppDelegate.hideApplication(); + } + } + //trigger automatic change after its value has been //loaded from app storage if self.alreadySetup { diff --git a/Clapet/en.lproj/Localizable.strings b/Clapet/en.lproj/Localizable.strings index a5ca067..e6869dc 100644 --- a/Clapet/en.lproj/Localizable.strings +++ b/Clapet/en.lproj/Localizable.strings @@ -1,9 +1,15 @@ +//updates "update-available" = "Update %1$@ available"; "update-available-description" = "A new update is available, click on the download link to see the changelog and download it !"; "remind-me-later" = "Remind me later"; "skip-version" = "Ignore version"; "download-version" = "Download"; +//errors +"no-permission-title" = "No permission to disable sleep"; +"no-permission-content" = "Clapet needs access to the pmset utility to enable and disable sleep. Please follow the configuration instructions on the GitHub page if you want to eliminate pop-ups requesting permissions. You may need to do this again after a new macOS update, as updates can sometimes erase the configuration."; +"no-permission-open" = "See instructions"; + //introduction "introduction" = "Introduction"; "clapet-description" = "Clapet is a utility that allows you to disable sleep completely so you can close your mac while on an external display even when on battery"; diff --git a/Clapet/fr.lproj/Localizable.strings b/Clapet/fr.lproj/Localizable.strings index fb44eee..2a0955c 100644 --- a/Clapet/fr.lproj/Localizable.strings +++ b/Clapet/fr.lproj/Localizable.strings @@ -1,9 +1,15 @@ +//updates "update-available" = "Mise à jour %1$@ disponible"; "update-available-description" = "Une nouvelle mise à jour est disponible, cliquez sur le lien de téléchargement pour voir les changements et la télécharger !"; "remind-me-later" = "Me le rappeler plus tard"; "skip-version" = "Ignorer cette version"; "download-version" = "Télécharger"; +//errors +"no-permission-title" = "Permissions manquantes"; +"no-permission-content" = "Clapet a besoin d'accéder à l'utilitaire pmset pour activer et désactiver le mode veille. Veuillez suivre les instructions de configuration sur la page GitHub si vous souhaitez éliminer les fenêtres contextuelles demandant des autorisations. Vous pourriez avoir à le refaire après une nouvelle mise à jour de macOS, car les mises à jour peuvent parfois effacer la configuration."; +"no-permission-open" = "Voir instructions"; + //introduction "introduction" = "Introduction"; "clapet-description" = "Clapet est un utilitaire qui permet de désactiver complètement la veille afin de fermer le macbook lorsqu'il sur batterie et connecté à un écran externe"; diff --git a/README.md b/README.md index 1424e9c..4f3ed13 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ When an external display is detected while on battery or power adapter, the appl disable sleep so you can use your computer with the lid closed, and as soon as the external display is unplugged, sleep will be enabled again to preserve battery. +**After macOS updates you may have to go through the _Manual configuration_ step again** + ## Features * Automatically disable sleep if an external display is connected * Disable sleep for a specified amount of time @@ -50,7 +52,8 @@ Then add the following line at the bottom of the file and replace `username` by username ALL = NOPASSWD : /usr/bin/pmset ``` -You should now be able to run `pmset` without entering your password +You should now be able to run `sudo pmset` without entering your password. The configuration in this step +may get erased after a macOS upate, you should do it again if the app starts asking for permissions again. ### Uninstalling