Implemented power:shutdown and power:reboot actions (closes #14)
This commit is contained in:
4
res/doc
4
res/doc
@@ -27,6 +27,7 @@
|
||||
# nickel_setting - toggles a boolean setting
|
||||
# nickel_extras - opens one of the beta features
|
||||
# nickel_misc - other stuff which isn't significant enough for its own category
|
||||
# power - gracefully controls the power state
|
||||
# cmd_spawn - starts another process or script in the background
|
||||
# cmd_output - runs a command and displays the output
|
||||
# <arg> the argument passed to the action:
|
||||
@@ -53,6 +54,9 @@
|
||||
# force_usb_connection - forces a usb connection dialog to be shown
|
||||
# rescan_books - forces nickel to rescan books
|
||||
# rescan_books_full - forces a full usb connect/disconnect cycle
|
||||
# power - one of:
|
||||
# shutdown
|
||||
# reboot
|
||||
# cmd_spawn - the command line to pass to /bin/sh -c (started in /)
|
||||
# cmd_output - the timeout in milliseconds (0 < t < 10000), a colon, then the command line to pass to /bin/sh -c (started in /)
|
||||
#
|
||||
|
||||
@@ -41,6 +41,7 @@ void nm_action_result_free(nm_action_result_t *res);
|
||||
X(nickel_setting) \
|
||||
X(nickel_extras) \
|
||||
X(nickel_misc) \
|
||||
X(power) \
|
||||
X(cmd_spawn) \
|
||||
X(cmd_output)
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ typedef void Settings;
|
||||
typedef void PlugWorkflowManager;
|
||||
typedef void BrowserWorkflowManager;
|
||||
typedef void N3SettingsExtrasController;
|
||||
typedef void N3PowerWorkflowManager;
|
||||
|
||||
NM_ACTION_(nickel_setting) {
|
||||
#define NM_ERR_RET nullptr
|
||||
@@ -312,6 +313,38 @@ NM_ACTION_(nickel_misc) {
|
||||
#undef NM_ERR_RET
|
||||
}
|
||||
|
||||
NM_ACTION_(power) {
|
||||
#define NM_ERR_RET nullptr
|
||||
if (!strcmp(arg, "shutdown") || !strcmp(arg, "reboot")) {
|
||||
N3PowerWorkflowManager *(*N3PowerWorkflowManager_sharedInstance)();
|
||||
reinterpret_cast<void*&>(N3PowerWorkflowManager_sharedInstance) = dlsym(RTLD_DEFAULT, "_ZN22N3PowerWorkflowManager14sharedInstanceEv");
|
||||
NM_ASSERT(N3PowerWorkflowManager_sharedInstance, "could not dlsym N3PowerWorkflowManager::sharedInstance, so cannot perform action cleanly (if you must, report a bug and use cmd_spawn instead)");
|
||||
|
||||
N3PowerWorkflowManager *pwm = N3PowerWorkflowManager_sharedInstance();
|
||||
NM_ASSERT(pwm, "could not get shared power manager pointer");
|
||||
|
||||
if (!strcmp(arg, "shutdown")) {
|
||||
void (*N3PowerWorkflowManager_powerOff)(N3PowerWorkflowManager*, bool); // bool is for if it's due to low battery
|
||||
reinterpret_cast<void*&>(N3PowerWorkflowManager_powerOff) = dlsym(RTLD_DEFAULT, "_ZN22N3PowerWorkflowManager8powerOffEb");
|
||||
NM_ASSERT(N3PowerWorkflowManager_powerOff, "could not dlsym N3PowerWorkflowManager::powerOff");
|
||||
|
||||
N3PowerWorkflowManager_powerOff(pwm, false);
|
||||
NM_RETURN_OK(nm_action_result_toast("Shutting down..."));
|
||||
} else if (!strcmp(arg, "reboot")) {
|
||||
void (*N3PowerWorkflowManager_reboot)(N3PowerWorkflowManager*);
|
||||
reinterpret_cast<void*&>(N3PowerWorkflowManager_reboot) = dlsym(RTLD_DEFAULT, "_ZN22N3PowerWorkflowManager6rebootEv");
|
||||
NM_ASSERT(N3PowerWorkflowManager_reboot, "could not dlsym N3PowerWorkflowManager::reboot");
|
||||
|
||||
N3PowerWorkflowManager_reboot(pwm);
|
||||
NM_RETURN_OK(nm_action_result_toast("Rebooting..."));
|
||||
}
|
||||
} else {
|
||||
NM_RETURN_ERR("unknown power action '%s'", arg);
|
||||
}
|
||||
NM_RETURN_OK(nm_action_result_silent());
|
||||
#undef NM_ERR_RET
|
||||
}
|
||||
|
||||
NM_ACTION_(cmd_spawn) {
|
||||
#define NM_ERR_RET nullptr
|
||||
QProcess proc;
|
||||
|
||||
Reference in New Issue
Block a user