-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce DBus-powered x1plusd to manage settings (#223)
Continuing in the path of #196, we introduce a handful of infrastructure in this PR, and only a few tiny users :-) The core idea of this is that we introduce @riptidewave93 's `x1plusd` (and the associated `settings` service), but instead of binding it to DDS, we bind it to DBus using `jeepney` (which @jphannifan found after I spent a night unsuccessfully wrestling with the library dependencies for `dasbus` -- thanks!). The `x1plusd` registers a DBus bus name `x1plus.x1plusd` that has an object `/x1plus/settings`, which, in turn, exposes the following methods: * `x1plus.settings.GetSettings(json: string)` returns a JSON dictionary of all the current known X1Plus settings, loaded from the SD card's printer-specific X1Plus settings JSON. * `x1plus.settings.PutSettings(json: string)` updates the X1Plus settings with keys from the passed JSON dictionary. When a setting changes, it emits a signal: * `x1plus.settings.SettingsChanged(json: string)`, with a dictionary that has set in it only the keys that have changed. We also introduce a QML API, `X1Plus.Settings.get` / `X1Plus.Settings.put`. `X1Plus.Settings.get` works like a QML binding, and if used in a QML binding context, will dynamically retrigger the binding if the setting changes either internally to `bbl_screen` or externally, as part of another system user's DBus operation. Finally, we wire the lock screen's `locktype` and `passcode` variables to `X1Plus.Settings`, to store them in the `settings.json`, and we migrate these settings on boot if they exist. To show the live QML binding behavior, we introduce a `x1plus-test-settings.py` that commands the X1Plus daemon to change some settings. Test it by loading the lock screen configuration dialog, and then ssh'ing in and running something like: `$ /opt/x1plus-test-settings.py passcode=1337` or: `$ /opt/x1plus-test-settings.py locktype=1` You should see the settings change in real time on the display. --------- Co-authored-by: Chris Blake <chrisrblake93@gmail.com>
- Loading branch information
1 parent
5e9f724
commit facd79e
Showing
53 changed files
with
4,794 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
.pragma library | ||
|
||
/* Core logic to mirror x1plusd settings to QML bindings | ||
* | ||
* Copyright (c) 2024 Joshua Wise, and the X1Plus authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
var X1Plus = null; | ||
|
||
var _PutSettings = null; | ||
var _settings = {}; | ||
var _settingsBindings = {}; | ||
|
||
function _settingChanged(k, v) { | ||
_settings[k] = v; | ||
if (_settingsBindings[k]) { | ||
_settingsBindings[k][2 /* set */](v); | ||
} | ||
} | ||
|
||
function get(k, def) { | ||
if (!_settingsBindings[k]) { | ||
_settingsBindings[k] = X1Plus.Binding.makeBinding(_settings[k]); | ||
} | ||
var v = _settingsBindings[k][0 /* get */](); /* trigger the binding */ | ||
if (v === undefined || v === null) { | ||
return def; | ||
} else { | ||
return v; | ||
} | ||
} | ||
|
||
function put(k, v) { | ||
_settingChanged(k, v); | ||
_PutSettings({ [k]: v }); | ||
} | ||
|
||
function _migrate(k, newk) { | ||
var v = X1Plus.DeviceManager.getSetting(k, null); | ||
if (v !== null) { | ||
console.log(`X1Plus.Settings: migrating key ${k} -> ${newk}`); | ||
put(newk, v); | ||
DeviceManager.putSetting(k, null); | ||
} | ||
} | ||
|
||
function awaken() { | ||
X1Plus.DBus.onSignal("x1plus.settings", "SettingsChanged", (arg) => { | ||
for (const k in arg) { | ||
console.log(`x1plus.settings.SettingsChanged(${k})`); | ||
_settingChanged(k, arg[k]); | ||
} | ||
}); | ||
_settings = X1Plus.DBus.proxyFunction("x1plus.x1plusd", "/x1plus/settings", "x1plus.settings", "GetSettings")(); | ||
_PutSettings = X1Plus.DBus.proxyFunction("x1plus.x1plusd", "/x1plus/settings", "x1plus.settings", "PutSettings"); | ||
|
||
_migrate("cfw_passcode", "passcode"); | ||
_migrate("cfw_locktype", "locktype"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
/*.squashfs | ||
cfw/opt/python/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/sh | ||
|
||
# X1Plus Daemon, our Python do-it-all script that interfaces with DDS. | ||
|
||
start() { | ||
printf "Starting x1plusd: " | ||
start-stop-daemon -S -m -b -p /var/run/x1plusd.pid --exec /opt/python/bin/python3 -- /opt/x1plusd.py | ||
[ $? = 0 ] && echo "OK" || echo "FAIL" | ||
} | ||
stop() { | ||
printf "Stopping x1plusd: " | ||
start-stop-daemon -K -q -p /var/run/x1plusd.pid | ||
[ $? = 0 ] && echo "OK" || echo "FAIL" | ||
} | ||
restart() { | ||
stop | ||
sleep 5 | ||
start | ||
} | ||
|
||
case "$1" in | ||
start) | ||
start | ||
;; | ||
stop) | ||
stop | ||
;; | ||
restart|reload) | ||
restart | ||
;; | ||
*) | ||
echo "Usage: $0 {start|stop|restart}" | ||
exit 1 | ||
esac | ||
|
||
exit $? |
Oops, something went wrong.