Update to usdpl v0.10 and change ~/.config/powertools to not require su perms

This commit is contained in:
NGnius (Graham) 2023-02-21 21:28:59 -05:00
parent d79ab91a04
commit 37f96a5cdd
15 changed files with 112 additions and 91 deletions

10
backend/Cargo.lock generated
View file

@ -826,7 +826,7 @@ dependencies = [
[[package]] [[package]]
name = "powertools-rs" name = "powertools-rs"
version = "1.2.0-alpha" version = "1.2.0-beta1"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"limits_core", "limits_core",
@ -1375,9 +1375,9 @@ dependencies = [
[[package]] [[package]]
name = "usdpl-back" name = "usdpl-back"
version = "0.9.1" version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2938cb40ba84ebea44658ebb1e4e0045fca54a562873bacab2ae094abab61ff" checksum = "2d185cc6e3f5d305e6e97f1b5cadf1da78bac6b62ea3457802d250708c315306"
dependencies = [ dependencies = [
"async-recursion", "async-recursion",
"async-trait", "async-trait",
@ -1393,9 +1393,9 @@ dependencies = [
[[package]] [[package]]
name = "usdpl-core" name = "usdpl-core"
version = "0.9.0" version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3904ca38aca189c68a6bc876cf73de7cc60003476b4e118012ae7eb783c1700" checksum = "bd73bec3df5bed5862cab15aaa645d76c388e00128a14c372806907e2f331960"
dependencies = [ dependencies = [
"aes-gcm-siv", "aes-gcm-siv",
"base64", "base64",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "powertools-rs" name = "powertools-rs"
version = "1.2.0-alpha" version = "1.2.0-beta1"
edition = "2021" edition = "2021"
authors = ["NGnius (Graham) <ngniusness@gmail.com>"] authors = ["NGnius (Graham) <ngniusness@gmail.com>"]
description = "Backend (superuser) functionality for PowerTools" description = "Backend (superuser) functionality for PowerTools"
@ -12,7 +12,7 @@ readme = "../README.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
usdpl-back = { version = "0.9.1", features = ["blocking"] }#, path = "../../usdpl-rs/usdpl-back"} usdpl-back = { version = "0.10.1", features = ["blocking"] }#, path = "../../usdpl-rs/usdpl-back"}
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
@ -32,7 +32,7 @@ ryzenadj-rs = { version = "0.1" }
ureq = { version = "2.5", features = ["json", "gzip", "brotli", "charset"], default-features = false, optional = true } ureq = { version = "2.5", features = ["json", "gzip", "brotli", "charset"], default-features = false, optional = true }
[features] [features]
default = ["online"] default = ["online", "decky"]
decky = ["usdpl-back/decky"] decky = ["usdpl-back/decky"]
crankshaft = ["usdpl-back/crankshaft"] crankshaft = ["usdpl-back/crankshaft"]
encrypt = ["usdpl-back/encrypt"] encrypt = ["usdpl-back/encrypt"]

View file

@ -244,6 +244,9 @@ impl ApiMessageHandler {
let save_json: SettingsJson = settings_clone.into(); let save_json: SettingsJson = settings_clone.into();
unwrap_maybe_fatal(save_json.save(&save_path), "Failed to save settings"); unwrap_maybe_fatal(save_json.save(&save_path), "Failed to save settings");
log::debug!("Saved settings to {}", save_path.display()); log::debug!("Saved settings to {}", save_path.display());
if let Err(e) = crate::utility::chown_settings_dir() {
log::error!("Failed to change config dir permissions: {}", e);
}
} else { } else {
if save_path.exists() { if save_path.exists() {
if let Err(e) = std::fs::remove_file(&save_path) { if let Err(e) = std::fs::remove_file(&save_path) {

View file

@ -18,7 +18,6 @@ use usdpl_back::core::serdes::Primitive;
use usdpl_back::Instance; use usdpl_back::Instance;
fn main() -> Result<(), ()> { fn main() -> Result<(), ()> {
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
let log_filepath = usdpl_back::api::dirs::home() let log_filepath = usdpl_back::api::dirs::home()
.unwrap_or_else(|| "/tmp/".into()) .unwrap_or_else(|| "/tmp/".into())
@ -46,6 +45,7 @@ fn main() -> Result<(), ()> {
}, },
Default::default(), Default::default(),
std::fs::File::create(&log_filepath).unwrap(), std::fs::File::create(&log_filepath).unwrap(),
//std::fs::File::create("/home/deck/powertools-rs.log").unwrap(),
) )
.unwrap(); .unwrap();
log::debug!("Logging to: {:?}.", log_filepath); log::debug!("Logging to: {:?}.", log_filepath);
@ -55,6 +55,8 @@ fn main() -> Result<(), ()> {
log::info!("Current dir `{}`", std::env::current_dir().unwrap().display()); log::info!("Current dir `{}`", std::env::current_dir().unwrap().display());
println!("Current dir `{}`", std::env::current_dir().unwrap().display()); println!("Current dir `{}`", std::env::current_dir().unwrap().display());
log::info!("home dir: {:?}", usdpl_back::api::dirs::home());
let _limits_handle = crate::settings::limits_worker_spawn(); let _limits_handle = crate::settings::limits_worker_spawn();
log::info!("Detected device automatically, starting with driver: {:?} (This can be overriden)", crate::settings::auto_detect_provider()); log::info!("Detected device automatically, starting with driver: {:?} (This can be overriden)", crate::settings::auto_detect_provider());
@ -227,6 +229,10 @@ fn main() -> Result<(), ()> {
log::info!("Startup Settings.on_set() success"); log::info!("Startup Settings.on_set() success");
} }
if let Err(e) = utility::chown_settings_dir() {
log::warn!("Failed to change config dir permissions: {}", e);
}
api_worker::spawn(loaded_settings, api_handler); api_worker::spawn(loaded_settings, api_handler);
instance instance

View file

@ -1,29 +0,0 @@
use std::sync::mpsc::{self, Receiver, Sender};
use std::thread::{self, JoinHandle};
use crate::persist::SettingsJson;
use crate::settings::Settings;
use crate::utility::{unwrap_lock, unwrap_maybe_fatal};
pub fn spawn(settings: Settings) -> (JoinHandle<()>, Sender<()>) {
let (sender, receiver): (Sender<()>, Receiver<()>) = mpsc::channel();
let worker = thread::spawn(move || {
log::info!("save_worker starting...");
for _ in receiver.iter() {
log::debug!("save_worker is saving...");
let is_persistent = unwrap_lock(settings.general.lock(), "general").persistent.clone();
if is_persistent {
let save_path = crate::utility::settings_dir()
.join(unwrap_lock(settings.general.lock(), "general").path.clone());
let settings_clone = settings.clone();
let save_json: SettingsJson = settings_clone.into();
unwrap_maybe_fatal(save_json.save(&save_path), "Failed to save settings");
log::debug!("Saved settings to {}", save_path.display());
} else {
log::debug!("Ignored save request for non-persistent settings");
}
}
log::warn!("save_worker completed!");
});
(worker, sender)
}

View file

@ -1,5 +1,7 @@
use std::fmt::Display; use std::fmt::Display;
//use std::sync::{LockResult, MutexGuard}; //use std::sync::{LockResult, MutexGuard};
//use std::fs::{Permissions, metadata};
use std::os::unix::fs::PermissionsExt;
pub fn unwrap_maybe_fatal<T: Sized, E: Display>(result: Result<T, E>, message: &str) -> T { pub fn unwrap_maybe_fatal<T: Sized, E: Display>(result: Result<T, E>, message: &str) -> T {
match result { match result {
@ -29,3 +31,25 @@ pub fn settings_dir() -> std::path::PathBuf {
.unwrap_or_else(|| "/tmp/".into()) .unwrap_or_else(|| "/tmp/".into())
.join(".config/powertools/") .join(".config/powertools/")
} }
pub fn chown_settings_dir() -> std::io::Result<()> {
let dir = settings_dir();
#[cfg(feature = "decky")]
let deck_user = usdpl_back::api::decky::user().map_err(|_| std::io::Error::new(std::io::ErrorKind::NotFound, "Decky missing deck user's username"))?;
#[cfg(not(feature = "decky"))]
let deck_user = "deck".to_owned();
// FIXME this shouldn't need to invoke a command
let output = std::process::Command::new("id")
.args(["-u", &deck_user])
.output()?;
let uid: u32 = String::from_utf8_lossy(&output.stdout).parse().unwrap_or(1000);
log::info!("chmod/chown ~/.config/powertools for user `{}` ({})", deck_user, uid);
let permissions = PermissionsExt::from_mode(0o655);
std::fs::set_permissions(&dir, permissions)?;
// FIXME once merged into stable https://github.com/rust-lang/rust/issues/88989
//std::os::unix::fs::chown(&dir, Some(uid), None)
std::process::Command::new("chown")
.args(["-R", &format!("{}:{}", deck_user, deck_user), &dir.to_str().unwrap_or(".")])
.output()?;
Ok(())
}

View file

@ -12,9 +12,14 @@ class Plugin:
async def _main(self): async def _main(self):
# startup # startup
print("PowerTools starting...") print("PowerTools starting...")
env_proc = dict(os.environ)
if "LD_LIBRARY_PATH" in env_proc:
env_proc["LD_LIBRARY_PATH"] += ":"+PARENT_DIR+"/bin"
else:
env_proc["LD_LIBRARY_PATH"] = ":"+PARENT_DIR+"/bin"
self.backend_proc = subprocess.Popen( self.backend_proc = subprocess.Popen(
[PARENT_DIR + "/bin/backend"], [PARENT_DIR + "/bin/backend"],
env = {"LD_LIBRARY_PATH": ":"+PARENT_DIR+"/bin"}) env = env_proc)
while True: while True:
await asyncio.sleep(1) await asyncio.sleep(1)

View file

@ -1,6 +1,6 @@
{ {
"name": "PowerTools", "name": "PowerTools",
"version": "1.2.0-alpha", "version": "1.2.0-beta1",
"description": "Power tweaks for power users", "description": "Power tweaks for power users",
"scripts": { "scripts": {
"build": "shx rm -rf dist && rollup -c", "build": "shx rm -rf dist && rollup -c",

View file

@ -381,7 +381,7 @@ packages:
hasBin: true hasBin: true
dependencies: dependencies:
caniuse-lite: 1.0.30001457 caniuse-lite: 1.0.30001457
electron-to-chromium: 1.4.303 electron-to-chromium: 1.4.305
node-releases: 2.0.10 node-releases: 2.0.10
update-browserslist-db: 1.0.10_browserslist@4.21.5 update-browserslist-db: 1.0.10_browserslist@4.21.5
dev: true dev: true
@ -429,8 +429,8 @@ packages:
engines: {node: '>=0.10.0'} engines: {node: '>=0.10.0'}
dev: true dev: true
/electron-to-chromium/1.4.303: /electron-to-chromium/1.4.305:
resolution: {integrity: sha512-XaqiQhVsGO5ymf/Lg6XEGpv2h8b5AFqQDQ9fQckolNP2VtD2VL1pn1TIx1SSYsf0srfXVi2Sm7n/K3slJSX3ig==} resolution: {integrity: sha512-WETy6tG0CT5gm1O+xCbyapWNsCcmIvrn4NHViIGYo2AT8FV2qUCXdaB+WqYxSv/vS5mFqhBYnfZAAkVArjBmUg==}
dev: true dev: true
/enhanced-resolve/5.12.0: /enhanced-resolve/5.12.0:
@ -927,5 +927,5 @@ packages:
file:src/usdpl_front: file:src/usdpl_front:
resolution: {directory: src/usdpl_front, type: directory} resolution: {directory: src/usdpl_front, type: directory}
name: usdpl-front name: usdpl-front
version: 0.9.1 version: 0.10.0
dev: false dev: false

View file

@ -35,8 +35,8 @@ export async function initBackend() {
? navigator.languages[0] ? navigator.languages[0]
: navigator.language; : navigator.language;
console.log("POWERTOOLS: locale", user_locale); console.log("POWERTOOLS: locale", user_locale);
let mo_path = "../plugins/PowerTools/translations/" + user_locale.toString() + ".mo"; //let mo_path = "../plugins/PowerTools/translations/" + user_locale.toString() + ".mo";
await init_tr(mo_path); await init_tr(user_locale);
//await init_tr("../plugins/PowerTools/translations/test.mo"); //await init_tr("../plugins/PowerTools/translations/test.mo");
//setReady(true); //setReady(true);
} }

View file

@ -290,7 +290,7 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({}) => {
export default definePlugin((serverApi: ServerAPI) => { export default definePlugin((serverApi: ServerAPI) => {
return { return {
title: <div className={staticClasses.Title}>PowerTools</div>, title: <div className={staticClasses.Title}>PowerTools 300</div>,
content: <Content serverAPI={serverApi} />, content: <Content serverAPI={serverApi} />,
icon: <GiDrill />, icon: <GiDrill />,
onDismount() { onDismount() {

View file

@ -4,7 +4,7 @@
"NGnius (Graham) <ngniusness@gmail.com>" "NGnius (Graham) <ngniusness@gmail.com>"
], ],
"description": "Universal Steam Deck Plugin Library front-end designed for WASM", "description": "Universal Steam Deck Plugin Library front-end designed for WASM",
"version": "0.9.1", "version": "0.10.0",
"license": "GPL-3.0-only", "license": "GPL-3.0-only",
"repository": { "repository": {
"type": "git", "type": "git",

13
src/usdpl_front/rebuild.sh Executable file
View file

@ -0,0 +1,13 @@
#!/bin/bash
git clone https://github.com/NGnius/usdpl-rs usdpl-rs
cd usdpl-rs/usdpl-front/
./build.sh $1 $2
cd ../..
cp -f ./usdpl-rs/usdpl-front/pkg/* ./
#rm ./.gitignore
rm -rf ./usdpl-rs

File diff suppressed because one or more lines are too long

Binary file not shown.