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

View file

@ -1,6 +1,6 @@
[package]
name = "powertools-rs"
version = "1.2.0-alpha"
version = "1.2.0-beta1"
edition = "2021"
authors = ["NGnius (Graham) <ngniusness@gmail.com>"]
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
[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_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 }
[features]
default = ["online"]
default = ["online", "decky"]
decky = ["usdpl-back/decky"]
crankshaft = ["usdpl-back/crankshaft"]
encrypt = ["usdpl-back/encrypt"]

View file

@ -244,6 +244,9 @@ impl ApiMessageHandler {
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());
if let Err(e) = crate::utility::chown_settings_dir() {
log::error!("Failed to change config dir permissions: {}", e);
}
} else {
if save_path.exists() {
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;
fn main() -> Result<(), ()> {
#[cfg(debug_assertions)]
let log_filepath = usdpl_back::api::dirs::home()
.unwrap_or_else(|| "/tmp/".into())
@ -46,6 +45,7 @@ fn main() -> Result<(), ()> {
},
Default::default(),
std::fs::File::create(&log_filepath).unwrap(),
//std::fs::File::create("/home/deck/powertools-rs.log").unwrap(),
)
.unwrap();
log::debug!("Logging to: {:?}.", log_filepath);
@ -55,6 +55,8 @@ fn main() -> Result<(), ()> {
log::info!("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();
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");
}
if let Err(e) = utility::chown_settings_dir() {
log::warn!("Failed to change config dir permissions: {}", e);
}
api_worker::spawn(loaded_settings, api_handler);
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::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 {
match result {
@ -29,3 +31,25 @@ pub fn settings_dir() -> std::path::PathBuf {
.unwrap_or_else(|| "/tmp/".into())
.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):
# startup
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(
[PARENT_DIR + "/bin/backend"],
env = {"LD_LIBRARY_PATH": ":"+PARENT_DIR+"/bin"})
env = env_proc)
while True:
await asyncio.sleep(1)

View file

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

View file

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

View file

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

View file

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

View file

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