Skip to content

Commit

Permalink
Fix dock icon and add alert to setup pmset
Browse files Browse the repository at this point in the history
  • Loading branch information
mbenoukaiss committed Dec 21, 2023
1 parent aac2687 commit b9a048c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Clapet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = "";
Expand All @@ -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;
Expand All @@ -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 = "";
Expand Down
5 changes: 4 additions & 1 deletion Clapet/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

}
19 changes: 19 additions & 0 deletions Clapet/Services/SleepService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions Clapet/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
6 changes: 6 additions & 0 deletions Clapet/fr.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b9a048c

Please sign in to comment.