PowerStatus: Add logic to automatically install in Deskbar.

Modeled after NetworkStatus. Also add it to
default_deskbar_items.sh.

Fixes #18748.
This commit is contained in:
Augustin Cavalier
2024-01-30 14:44:28 -05:00
parent 6a47944773
commit ef1427bb58
2 changed files with 35 additions and 9 deletions
@@ -1,8 +1,9 @@
#!/bin/sh #!/bin/sh
# install ProcessController, NetworkStatus & volume control in the Deskbar # install ProcessController, NetworkStatus, PowerStatus & volume control in the Deskbar
/boot/system/apps/ProcessController -deskbar /boot/system/apps/ProcessController -deskbar
/boot/system/apps/NetworkStatus --deskbar /boot/system/apps/NetworkStatus --deskbar
/boot/system/apps/PowerStatus --deskbar
/boot/system/bin/desklink --add-volume /boot/system/bin/desklink --add-volume
# install KeymapSwitcher for certain locales # install KeymapSwitcher for certain locales
+31 -6
View File
@@ -33,8 +33,12 @@ class PowerStatus : public BApplication {
PowerStatus(); PowerStatus();
virtual ~PowerStatus(); virtual ~PowerStatus();
virtual void ArgvReceived(int32 argc, char** argv);
virtual void ReadyToRun(); virtual void ReadyToRun();
virtual void AboutRequested(); virtual void AboutRequested();
private:
bool fAutoInstallInDeskbar;
}; };
@@ -61,7 +65,9 @@ our_image(image_info& image)
PowerStatus::PowerStatus() PowerStatus::PowerStatus()
: BApplication(kSignature) :
BApplication(kSignature),
fAutoInstallInDeskbar(false)
{ {
} }
@@ -71,6 +77,27 @@ PowerStatus::~PowerStatus()
} }
void
PowerStatus::ArgvReceived(int32 argc, char** argv)
{
if (argc <= 1)
return;
if (strcmp(argv[1], "--help") == 0
|| strcmp(argv[1], "-h") == 0) {
const char* str = "PowerStatus options:\n"
"\t--deskbar\tautomatically add replicant to Deskbar\n"
"\t--help\t\tprint this info and exit";
puts(str);
Quit();
return;
}
if (strcmp(argv[1], "--deskbar") == 0)
fAutoInstallInDeskbar = true;
}
void void
PowerStatus::ReadyToRun() PowerStatus::ReadyToRun()
{ {
@@ -83,6 +110,7 @@ PowerStatus::ReadyToRun()
B_TRANSLATE("No supported battery detected. PowerStatus " B_TRANSLATE("No supported battery detected. PowerStatus "
"cannot be used on your system."), B_TRANSLATE("Too bad!"), "cannot be used on your system."), B_TRANSLATE("Too bad!"),
NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
if (!fAutoInstallInDeskbar)
alert->Go(); alert->Go();
Quit(); Quit();
return; return;
@@ -93,9 +121,7 @@ PowerStatus::ReadyToRun()
// if the Deskbar is not alive at this point, it might be after having // if the Deskbar is not alive at this point, it might be after having
// acknowledged the requester below // acknowledged the requester below
BDeskbar deskbar; BDeskbar deskbar;
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
isDeskbarRunning = deskbar.IsRunning(); isDeskbarRunning = deskbar.IsRunning();
#endif
isInstalled = deskbar.HasItem(kDeskbarItemName); isInstalled = deskbar.HasItem(kDeskbarItemName);
} }
@@ -106,7 +132,7 @@ PowerStatus::ReadyToRun()
B_TRANSLATE("Install in Deskbar"), NULL, B_WIDTH_AS_USUAL, B_TRANSLATE("Install in Deskbar"), NULL, B_WIDTH_AS_USUAL,
B_WARNING_ALERT); B_WARNING_ALERT);
if (alert->Go()) { if (fAutoInstallInDeskbar || alert->Go()) {
image_info info; image_info info;
entry_ref ref; entry_ref ref;
@@ -147,11 +173,10 @@ PowerStatus::AboutRequested()
int int
main(int, char**) main(int argc, char* argv[])
{ {
PowerStatus app; PowerStatus app;
app.Run(); app.Run();
return 0; return 0;
} }