1
0

Improved extensibility of nickel_setting, split browser stuff into nickel_browser action (closes #59) (#60)

* Split browser actions from nickel_extra into nickel_browser

* Improved extensibility of nickel_setting action

Instead of nickel_setting:<setting> for toggling a setting and
nickel_setting:<setting>:<bool> for setting it explicitly, use
nickel_setting:<action>:<setting>.
This commit is contained in:
Patrick Gaskin
2020-07-02 00:25:00 -04:00
committed by GitHub
parent 7019745ff7
commit cb2caff551
3 changed files with 146 additions and 145 deletions

33
res/doc
View File

@@ -29,6 +29,7 @@
# kfmon - triggers a kfmon action
# nickel_setting - toggles a boolean setting
# nickel_extras - opens one of the beta features
# nickel_browser - opens the browser
# nickel_misc - other stuff which isn't significant enough for its own category
# nickel_open - opens a view
# nickel_wifi - controls wifi (note: it doesn't wait for it to connect or disconnect, neither does it check for success)
@@ -46,27 +47,29 @@
# kfmon - the filename of the KFMon watched item to launch.
# This is actually the basename of the watch's filename as specified in its KFMon config (i.e., the png).
# You can also check the output of the 'list' command via the kfmon-ipc tool.
# nickel_setting - one of:
# invert - toggles FeatureSettings.InvertScreen
# invert:<value> - ^ same, but sets it to 'true'/'enabled'/'yes'/'on'/'1' or 'false'/'disabled'/'no'/'off'/'0'
# lockscreen - toggles PowerSettings.UnlockEnabled (4.12.12111+)
# lockscreen:<value> - ^ ...
# screenshots - toggles FeatureSettings.Screenshots
# screenshots:<value> - ^ ...
# force_wifi - toggles DeveloperSettings.ForceWifiOn (note: the setting doesn't apply until you toggle WiFi)
# force_wifi:<value> - ^ ...
# nickel_setting - <action>:<setting>
# action if one of:
# toggle - toggles between true/false
# enable - sets to true
# disable - sets to false
# setting is one of:
# invert - FeatureSettings.InvertScreen
# lockscreen - PowerSettings.UnlockEnabled (4.12.12111+)
# screenshots - FeatureSettings.Screenshots
# force_wifi - DeveloperSettings.ForceWifiOn (note: the setting doesn't apply until you toggle WiFi)
# nickel_extras - the mimetype of the plugin, or one of:
# web_browser - opens the web browser to the default homepage
# web_browser:<url> - opens the web browser to the specified URL
# web_browser:<url> <css> - opens the web browser to the specified URL and injects the specified CSS (which can contain spaces and colons) into all pages
# web_browser:modal - opens the web browser to the default homepage as a pop-up window
# web_browser:modal:<url> - see above
# web_browser:modal:<url> <css> - see above
# unblock_it
# sketch_pad
# solitaire
# sudoku
# word_scramble
# nickel_browser - one of:
# - opens the web browser to the default homepage (note that the line should end with a colon even though the argument is blank)
# <url> - opens the web browser to the specified URL
# <url> <css> - opens the web browser to the specified URL and injects the specified CSS (which can contain spaces and colons) into all pages
# modal - opens the web browser to the default homepage as a pop-up window
# modal:<url> - see above
# modal:<url> <css> - see above
# nickel_misc - one of:
# home - goes to the home screen
# force_usb_connection - forces a usb connection dialog to be shown

View File

@@ -43,6 +43,7 @@ void nm_action_result_free(nm_action_result_t *res);
X(kfmon_id) \
X(nickel_setting) \
X(nickel_extras) \
X(nickel_browser) \
X(nickel_misc) \
X(nickel_open) \
X(nickel_wifi) \

View File

@@ -126,6 +126,26 @@ NM_ACTION_(nickel_open) {
NM_ACTION_(nickel_setting) {
#define NM_ERR_RET nullptr
enum {
mode_toggle,
mode_enable,
mode_disable,
} mode;
char *tmp1 = strdupa(arg); // strsep and strtrim will modify it
char *arg1 = strtrim(strsep(&tmp1, ":"));
char *arg2 = strtrim(tmp1);
NM_ASSERT(arg2, "could not find a : in the argument");
if (!strcmp(arg1, "toggle"))
mode = mode_toggle;
else if (!strcmp(arg1, "enable"))
mode = mode_enable;
else if (!strcmp(arg1, "disable"))
mode = mode_disable;
else
NM_RETURN_ERR("unknown action '%s' for nickel_setting: expected 'toggle', 'enable', or 'disable'", arg1);
//libnickel 4.6 * _ZN6Device16getCurrentDeviceEv
Device *(*Device_getCurrentDevice)();
reinterpret_cast<void*&>(Device_getCurrentDevice) = dlsym(RTLD_DEFAULT, "_ZN6Device16getCurrentDeviceEv");
@@ -188,30 +208,15 @@ NM_ACTION_(nickel_setting) {
NM_ASSERT(Settings_vtable, "could not dlsym the vtable for Settings");
NM_ASSERT(vtable_ptr(settings) == vtable_target(Settings_vtable), "unexpected vtable layout (expected class to start with a pointer to 8 bytes into the vtable)");
bool v = false;
bool v = mode == mode_disable; // this gets inverted
char *tmp1 = strdupa(arg); // strsep and strtrim will modify it
char *arg1 = strtrim(strsep(&tmp1, ":"));
char *arg2 = strtrim(tmp1);
if (arg2) {
// note: v gets inverted when setting the setting below
if (!strcmp(arg2, "true") || !strcmp(arg2, "enabled") || !strcmp(arg2, "yes") || !strcmp(arg2, "on") || !strcmp(arg2, "1")) {
v = false;
} else if (!strcmp(arg2, "false") || !strcmp(arg2, "disabled") || !strcmp(arg2, "no") || !strcmp(arg2, "off") || !strcmp(arg2, "0")) {
v = true;
} else {
NM_RETURN_ERR("invalid value '%s' for setting '%s', must be 'true'/'enabled'/'yes'/'on'/'1' or 'false'/'disabled'/'no'/'off'/'0' (arg: '%s')", arg2, arg1, arg);
}
}
if (!strcmp(arg1, "invert") || !strcmp(arg1, "screenshots")) {
if (!strcmp(arg2, "invert") || !strcmp(arg2, "screenshots")) {
//libnickel 4.6 * _ZTV15FeatureSettings
void *FeatureSettings_vtable = dlsym(RTLD_DEFAULT, "_ZTV15FeatureSettings");
NM_ASSERT(FeatureSettings_vtable, "could not dlsym the vtable for FeatureSettings");
vtable_ptr(settings) = vtable_target(FeatureSettings_vtable);
if (!strcmp(arg1, "invert")) {
if (!strcmp(arg2, "invert")) {
//libnickel 4.6 * _ZN15FeatureSettings12invertScreenEv
bool (*FeatureSettings_invertScreen)(Settings*);
reinterpret_cast<void*&>(FeatureSettings_invertScreen) = dlsym(RTLD_DEFAULT, "_ZN15FeatureSettings12invertScreenEv");
@@ -222,7 +227,7 @@ NM_ACTION_(nickel_setting) {
reinterpret_cast<void*&>(FeatureSettings_setInvertScreen) = dlsym(RTLD_DEFAULT, "_ZN15FeatureSettings15setInvertScreenEb");
NM_ASSERT(FeatureSettings_setInvertScreen, "could not dlsym FeatureSettings::setInvertScreen");
if (!arg2) {
if (mode == mode_toggle) {
v = FeatureSettings_invertScreen(settings);
vtable_ptr(settings) = vtable_target(FeatureSettings_vtable);
}
@@ -237,8 +242,8 @@ NM_ACTION_(nickel_setting) {
NM_LOG("updating top-level window %p after invert", w);
if (w)
w->update(); // TODO: figure out how to make it update _after_ the menu item redraws itself
} else if (!strcmp(arg1, "screenshots")) {
if (!arg2) {
} else if (!strcmp(arg2, "screenshots")) {
if (mode == mode_toggle) {
QVariant v1 = Settings_getSetting(settings, QStringLiteral("Screenshots"), QVariant(false));
vtable_ptr(settings) = vtable_target(FeatureSettings_vtable);
v = v1.toBool();
@@ -250,12 +255,11 @@ NM_ACTION_(nickel_setting) {
QVariant v2 = Settings_getSetting(settings, QStringLiteral("Screenshots"), QVariant(false));
vtable_ptr(settings) = vtable_target(FeatureSettings_vtable);
}
} else if (!strcmp(arg1, "lockscreen")) {
} else if (!strcmp(arg2, "lockscreen")) {
void *PowerSettings_vtable = dlsym(RTLD_DEFAULT, "_ZTV13PowerSettings");
NM_ASSERT(PowerSettings_vtable, "could not dlsym the vtable for PowerSettings");
vtable_ptr(settings) = vtable_target(PowerSettings_vtable);
if (!strcmp(arg1, "lockscreen")) {
//libnickel 4.12.12111 * _ZN13PowerSettings16getUnlockEnabledEv
bool (*PowerSettings__getUnlockEnabled)(Settings*);
reinterpret_cast<void*&>(PowerSettings__getUnlockEnabled) = dlsym(RTLD_DEFAULT, "_ZN13PowerSettings16getUnlockEnabledEv");
@@ -266,7 +270,7 @@ NM_ACTION_(nickel_setting) {
reinterpret_cast<void*&>(PowerSettings__setUnlockEnabled) = dlsym(RTLD_DEFAULT, "_ZN13PowerSettings16setUnlockEnabledEb");
NM_ASSERT(PowerSettings__setUnlockEnabled, "could not dlsym PowerSettings::setUnlockEnabled");
if (!arg2) {
if (mode == mode_toggle) {
v = PowerSettings__getUnlockEnabled(settings);
vtable_ptr(settings) = vtable_target(PowerSettings_vtable);
}
@@ -276,15 +280,13 @@ NM_ACTION_(nickel_setting) {
NM_ASSERT(PowerSettings__getUnlockEnabled(settings) == !v, "failed to set setting");
vtable_ptr(settings) = vtable_target(PowerSettings_vtable);
}
} else if (!strcmp(arg1, "force_wifi")) {
} else if (!strcmp(arg2, "force_wifi")) {
//libnickel 4.6 * _ZTV11DevSettings
void *PowerSettings_vtable = dlsym(RTLD_DEFAULT, "_ZTV11DevSettings");
NM_ASSERT(PowerSettings_vtable, "could not dlsym the vtable for DevSettings");
vtable_ptr(settings) = vtable_target(PowerSettings_vtable);
if (!strcmp(arg1, "force_wifi")) {
if (!arg2) {
if (mode == mode_toggle) {
QVariant v1 = Settings_getSetting(settings, QStringLiteral("ForceWifiOn"), QVariant(false));
vtable_ptr(settings) = vtable_target(PowerSettings_vtable);
v = v1.toBool();
@@ -295,9 +297,8 @@ NM_ACTION_(nickel_setting) {
QVariant v2 = Settings_getSetting(settings, QStringLiteral("ForceWifiOn"), QVariant(false));
vtable_ptr(settings) = vtable_target(PowerSettings_vtable);
}
} else {
// TODO: more settings
// TODO: more settings?
Settings_SettingsD(settings);
NM_RETURN_ERR("unknown setting name '%s' (arg: '%s')", arg1, arg);
}
@@ -307,7 +308,7 @@ NM_ACTION_(nickel_setting) {
Settings_SettingsD(settings);
NM_RETURN_OK(strcmp(arg1, "invert") // invert is obvious
NM_RETURN_OK(strcmp(arg2, "invert") // invert is obvious
? nm_action_result_toast("%s %s", v ? "disabled" : "enabled", arg1)
: nm_action_result_silent());
#undef NM_ERR_RET
@@ -316,24 +317,38 @@ NM_ACTION_(nickel_setting) {
NM_ACTION_(nickel_extras) {
#define NM_ERR_RET nullptr
if (!strncmp(arg, "web_browser", 11)) {
const char* mimetype;
if (strchr(arg, '/')) mimetype = arg;
else if (!strcmp(arg, "unblock_it")) mimetype = "application/x-games-RushHour";
else if (!strcmp(arg, "sketch_pad")) mimetype = "application/x-games-Scribble";
else if (!strcmp(arg, "solitaire")) mimetype = "application/x-games-Solitaire";
else if (!strcmp(arg, "sudoku")) mimetype = "application/x-games-Sudoku";
else if (!strcmp(arg, "word_scramble")) mimetype = "application/x-games-Boggle";
else NM_RETURN_ERR("unknown beta feature name or plugin mimetype '%s'", arg);
//libnickel 4.6 * _ZN18ExtrasPluginLoader10loadPluginEPKc
void (*ExtrasPluginLoader_loadPlugin)(const char*);
reinterpret_cast<void*&>(ExtrasPluginLoader_loadPlugin) = dlsym(RTLD_DEFAULT, "_ZN18ExtrasPluginLoader10loadPluginEPKc");
NM_ASSERT(ExtrasPluginLoader_loadPlugin, "could not dlsym ExtrasPluginLoader::loadPlugin");
ExtrasPluginLoader_loadPlugin(mimetype);
NM_RETURN_OK(nm_action_result_silent());
#undef NM_ERR_RET
}
NM_ACTION_(nickel_browser) {
#define NM_ERR_RET nullptr
bool modal;
QUrl *url;
QString *css;
if (!strcmp(arg, "web_browser")) {
if (!arg || !*arg) {
modal = false;
url = new QUrl();
css = new QString("");
} else {
char *tmp1 = strdupa(arg); // strsep and strtrim will modify it
char *arg1 = strtrim(strsep(&tmp1, ":"));
char *arg2 = strtrim(tmp1);
if (!arg2 || strcmp(arg1, "web_browser"))
NM_RETURN_ERR("unknown beta feature name or plugin mimetype '%s' (split: '%s')", arg, arg1);
QString tmp = QString::fromUtf8(arg2).trimmed();
QString tmp = QString::fromUtf8(arg).trimmed();
if (tmp.section(':', 0, 0).trimmed() == "modal") {
modal = true;
@@ -389,24 +404,6 @@ NM_ACTION_(nickel_extras) {
BrowserWorkflowManager_openBrowser(bwm, modal, url, css);
NM_RETURN_OK(nm_action_result_silent());
}
const char* mimetype;
if (strchr(arg, '/')) mimetype = arg;
else if (!strcmp(arg, "unblock_it")) mimetype = "application/x-games-RushHour";
else if (!strcmp(arg, "sketch_pad")) mimetype = "application/x-games-Scribble";
else if (!strcmp(arg, "solitaire")) mimetype = "application/x-games-Solitaire";
else if (!strcmp(arg, "sudoku")) mimetype = "application/x-games-Sudoku";
else if (!strcmp(arg, "word_scramble")) mimetype = "application/x-games-Boggle";
else NM_RETURN_ERR("unknown beta feature name or plugin mimetype '%s'", arg);
//libnickel 4.6 * _ZN18ExtrasPluginLoader10loadPluginEPKc
void (*ExtrasPluginLoader_loadPlugin)(const char*);
reinterpret_cast<void*&>(ExtrasPluginLoader_loadPlugin) = dlsym(RTLD_DEFAULT, "_ZN18ExtrasPluginLoader10loadPluginEPKc");
NM_ASSERT(ExtrasPluginLoader_loadPlugin, "could not dlsym ExtrasPluginLoader::loadPlugin");
ExtrasPluginLoader_loadPlugin(mimetype);
NM_RETURN_OK(nm_action_result_silent());
#undef NM_ERR_RET
}