Compare commits
12 commits
Author | SHA1 | Date | |
---|---|---|---|
|
e13f87f81f | ||
|
db371d8d8f | ||
|
627708e0d9 | ||
|
bb9fa9f170 | ||
|
326a727a2f | ||
|
529664fadc | ||
|
4816279f9e | ||
|
da5d2a9673 | ||
|
6379853307 | ||
|
db6da81a3f | ||
|
d22df0639a | ||
|
ae7810702a |
21 changed files with 244 additions and 198 deletions
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
|
@ -1,2 +0,0 @@
|
|||
github: NGnius
|
||||
liberapay: NGnius
|
26
.github/ISSUE_TEMPLATE/bug-report.md
vendored
Normal file
26
.github/ISSUE_TEMPLATE/bug-report.md
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
---
|
||||
name: Bug Report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Expected Behaviour**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Actual Behaviour**
|
||||
A clear and concise description of what actually happened.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Screenshots, etc.**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
Please include the log (located at `/tmp/powertools.log`) if possible.
|
||||
Note: the log is deleted when the device is restarted.
|
72
.github/ISSUE_TEMPLATE/bug-report.yml
vendored
72
.github/ISSUE_TEMPLATE/bug-report.yml
vendored
|
@ -1,72 +0,0 @@
|
|||
name: "Bug Report"
|
||||
description: "Report an issue with PowerTools"
|
||||
labels: "bug"
|
||||
body:
|
||||
- type: textarea
|
||||
id: expected-behaviour
|
||||
attributes:
|
||||
label: Expected Behaviour
|
||||
description: A clear and concise description of what you expected to happen.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: actual-behaviour
|
||||
attributes:
|
||||
label: Actual Behaviour
|
||||
description: A clear and concise description of what actually happened.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: reproduction
|
||||
attributes:
|
||||
label: Steps To Reproduce
|
||||
description: Steps to reproduce the behaviour.
|
||||
placeholder: |
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '.....'
|
||||
4. See error......
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: extras
|
||||
attributes:
|
||||
label: Anything else?
|
||||
description: |
|
||||
Screenshots? Logs? limits_overrides.ron? limits_cache.ron? Anything that will give more context about the problem!
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
Please include the log (located at `/tmp/powertools.log`) if possible.
|
||||
Note: the log is deleted when the device is restarted.
|
||||
|
||||
Tip: You can attach files by clicking this area to highlight it and then dragging them in.
|
||||
validations:
|
||||
required: false
|
||||
- type: input
|
||||
id: version
|
||||
attributes:
|
||||
label: Version
|
||||
description: What version of PowerTools are you using? This is the version beside `Native` near the bottom of the plugin's UI.
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: platform
|
||||
attributes:
|
||||
label: Platform
|
||||
description: What driver is PowerTools using?
|
||||
value: SteamDeck
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
id: operating-system
|
||||
attributes:
|
||||
label: OS
|
||||
description: On which operating system are you running PowerTools?
|
||||
options:
|
||||
- _
|
||||
- SteamOS 3 (Stable)
|
||||
- SteamOS 3 (Preview/Beta)
|
||||
- SteamOS 3 (Main)
|
||||
- HoloISO
|
||||
- Not listed
|
||||
validations:
|
||||
required: true
|
5
.github/ISSUE_TEMPLATE/config.yml
vendored
5
.github/ISSUE_TEMPLATE/config.yml
vendored
|
@ -1,5 +0,0 @@
|
|||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: NGnius
|
||||
url: https://git.ngni.us/sys/website/wiki#contact-information
|
||||
about: Repository owner
|
17
.github/ISSUE_TEMPLATE/feature-request.md
vendored
Normal file
17
.github/ISSUE_TEMPLATE/feature-request.md
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
name: Feature Request
|
||||
about: Suggest a tool to add
|
||||
title: ''
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe what you'd like to be able to do**
|
||||
A clear and concise description of what you want. E.g. I'd like to be able to select how many CPU cores are enabled.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternatives you've considered. E.g. Enabling and disabling CPU cores with another computer connected over SSH.
|
||||
|
||||
**Additional context**
|
||||
Description of how can this be done. E.g. This can be accomplished with `echo {0 or 1} > /sys/devices/system/cpu/cpu{cpu_number}/online`.
|
32
.github/ISSUE_TEMPLATE/feature-request.yml
vendored
32
.github/ISSUE_TEMPLATE/feature-request.yml
vendored
|
@ -1,32 +0,0 @@
|
|||
name: Feature Request
|
||||
description: Suggest functionality to add
|
||||
labels: "enhancement"
|
||||
body:
|
||||
- type: textarea
|
||||
id: feature-description
|
||||
attributes:
|
||||
label: Describe what you'd like to be able to do
|
||||
description: A clear and concise description of what you want.
|
||||
placeholder: I'd like to be able to ...
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: alternatives
|
||||
attributes:
|
||||
label: Describe alternatives you've considered
|
||||
description: A clear and concise description of any alternatives you've considered.
|
||||
placeholder: This can also be done by ... but ...
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: extras
|
||||
attributes:
|
||||
label: Anything else?
|
||||
description: |
|
||||
Description of how this can be achieved, or other additional context.
|
||||
If this is related to the UI, consider adding a picture.
|
||||
|
||||
Tip: You can attach files by clicking this area to highlight it and then dragging them in.
|
||||
placeholder: This can be accomplished by doing ...
|
||||
validations:
|
||||
required: false
|
23
.github/ISSUE_TEMPLATE/question.yml
vendored
23
.github/ISSUE_TEMPLATE/question.yml
vendored
|
@ -1,23 +0,0 @@
|
|||
name: "Question"
|
||||
description: "Ask for more information about PowerTools"
|
||||
labels: "question"
|
||||
body:
|
||||
- type: textarea
|
||||
id: question-elaboration
|
||||
attributes:
|
||||
label: Question
|
||||
description: |
|
||||
A clear and concise description of what you'd like to know.
|
||||
Please check the wiki and closed issues to avoid waiting for an answer when you didn't need to.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: extras
|
||||
attributes:
|
||||
label: Extra Info
|
||||
description: |
|
||||
Additional context or information which may be helpful when answering your question.
|
||||
|
||||
Tip: You can attach files by clicking this area to highlight it and then dragging them in.
|
||||
validations:
|
||||
required: false
|
13
.github/pull_request_template.md
vendored
13
.github/pull_request_template.md
vendored
|
@ -1,13 +0,0 @@
|
|||
## Description
|
||||
|
||||
A short description of what the PR changes.
|
||||
If this is a minor change and the commit message(s) explains it well, feel free to delete this section.
|
||||
|
||||
## Motivation
|
||||
|
||||
Why did you write this PR and/or why should it be accepted.
|
||||
|
||||
## Fixes
|
||||
|
||||
Please indicate issues that this fixes or addresses here.
|
||||
If this is a bugfix with no pre-existing issue, please describe the bug here instead.
|
28
README.md
28
README.md
|
@ -1,12 +1,12 @@
|
|||
# PowerTools
|
||||
<!-- TODO Update badges for new git repo location -->
|
||||
[![Decky store](https://img.shields.io/badge/dynamic/json?color=blue&label=release&query=%24%5B%3F%28%40.name%3D%3D%27PowerTools%27%29%5D.versions%5B0%5D.name&url=https%3A%2F%2Fplugins.deckbrew.xyz%2Fplugins&style=flat-square)](https://plugins.deckbrew.xyz/)
|
||||
[![Custom store](https://img.shields.io/badge/dynamic/json?color=blue&label=preview&query=%24%5B%3F%28%40.name%3D%3D%27PowerTools%27%29%5D.versions%5B0%5D.name&url=https%3A%2F%2Fnot-decky-alpha.ngni.us%2Fplugins&style=flat-square)](https://git.ngni.us/NG-SD-Plugins/PowerTools/wiki)
|
||||
[![Custom store](https://img.shields.io/badge/dynamic/json?color=blue&label=preview&query=%24%5B%3F%28%40.name%3D%3D%27PowerTools%27%29%5D.versions%5B0%5D.name&url=https%3A%2F%2Fnot-decky-alpha.ngni.us%2Fplugins&style=flat-square)](https://github.com/NGnius/PowerTools/wiki)
|
||||
[![GitHub package.json version](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgit.ngni.us%2FNG-SD-Plugins%2FPowerTools%2Fraw%2Fbranch%2Fmain%2Fpackage.json&query=%24.version&style=flat-square&label=local&cacheSeconds=600)](https://git.ngni.us/NG-SD-Plugins/PowerTools/src/branch/main/package.json)
|
||||
|
||||
[![Liberapay](https://img.shields.io/liberapay/patrons/NGnius?style=flat-square)](https://liberapay.com/NGnius)
|
||||
[![GitHub](https://img.shields.io/badge/GPL--3.0-orange?style=flat-square&label=license&cacheSeconds=600)](https://git.ngni.us/NG-SD-Plugins/PowerTools/blob/main/LICENSE)
|
||||
[![GitHub package.json dependency version (local)](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgit.ngni.us%2FNG-SD-Plugins%2FPowerTools%2Fraw%2Fbranch%2Fmain%2Fpackage.json&query=%24..%5B'decky-frontend-lib'%5D&style=flat-square&label=decky-frontend-lib&cacheSeconds=600)](https://git.ngni.us/NG-SD-Plugins/PowerTools/blob/main/pnpm-lock.yaml)
|
||||
[![GitHub](https://img.shields.io/badge/GPL--3.0-orange?style=flat-square&label=license&cacheSeconds=600)](https://github.com/NGnius/PowerTools/blob/main/LICENSE)
|
||||
[![GitHub package.json dependency version (local)](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fgit.ngni.us%2FNG-SD-Plugins%2FPowerTools%2Fraw%2Fbranch%2Fmain%2Fpackage.json&query=%24..%5B'decky-frontend-lib'%5D&style=flat-square&label=decky-frontend-lib&cacheSeconds=600)](https://github.com/NGnius/PowerTools/blob/main/pnpm-lock.yaml)
|
||||
|
||||
![plugin_demo](./assets/ui.png)
|
||||
|
||||
|
@ -20,38 +20,24 @@ You will need that installed for this plugin to work.
|
|||
- Enable & disable CPU threads & SMT
|
||||
- Set CPU frequencies
|
||||
- Set GPU frequencies and power (fastPPT & slowPPT)
|
||||
- Cap battery charge level
|
||||
- Cap battery charge rate (when awake)
|
||||
- Display supplementary battery info
|
||||
- Keep settings between restarts (stored in `~/homebrew/settings/PowerTools/<appId>.ron`)
|
||||
- Keep settings between restarts (stored in `~/.config/powertools/<gameId>.json`)
|
||||
|
||||
This plugin is tested on Steam Deck LCD/OLED, but is designed to work on other Linux devices as well. Unfortunately I am currently unable to test on most other devices.
|
||||
This plugin is tested on Steam Deck, but is designed to work on other Linux devices as well. Unfortunately I am currently unable to test on other devices.
|
||||
|
||||
## Install
|
||||
|
||||
Please use Decky's [built-in store](https://plugins.deckbrew.xyz/) to install official releases.
|
||||
If you want to test unstable versions, use [my custom store](https://not-decky-alpha.ngni.us/plugins). If you would like to use an in-development version, feel free to build PowerTools yourself.
|
||||
|
||||
## Build/Deploy
|
||||
## Build
|
||||
|
||||
0. Requirements: a functioning Rust toolchain for x86_64-unknown-linux-gnu (or -musl), pnpm, and some tech literacy
|
||||
1. In a terminal, navigate to the backend directory of this project and run `./build.sh`
|
||||
2. In the root of this project, run `pnpm run build`
|
||||
3. Transfer the project (especially dist/ and bin/) to a folder in your Steam Deck's `~/homebrew/plugins` directory
|
||||
4. Restart Decky with `sudo systemctl restart plugin_loader.service`
|
||||
|
||||
## License
|
||||
|
||||
This is licensed under GNU GPLv3.
|
||||
|
||||
## Contributing
|
||||
|
||||
All contributions are welcome!
|
||||
Anything from a comment on an issue to a new feature pull request will be appreciated by PowerTools's crack team of one (NGnius).
|
||||
|
||||
### Translations
|
||||
|
||||
Adding new languages and keeping existing language files up to date makes PowerTools more accessible to the majority of the world which doesn't speak English. Take a look at [this comment](https://git.ngni.us/NG-SD-Plugins/PowerTools/issues/9#issuecomment-345) (and the rest of that issue) to get started.
|
||||
|
||||
### Code
|
||||
|
||||
To prevent spam, this server does not allow regular users to create/fork repositories. Please open an issue [here](https://git.ngni.us/sys/website) to request permission. There's no pressure to actually do anything with that permission, though it may be revoked when the server is running low on space.
|
||||
|
|
20
backend/Cargo.lock
generated
20
backend/Cargo.lock
generated
|
@ -891,22 +891,22 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "libryzenadj-alt"
|
||||
version = "0.14.0"
|
||||
name = "libryzenadj"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0a8cc66a7f77b864c2ef014dd9f9a3b03305d9e7f130202ca4addde9bc71f8b"
|
||||
checksum = "c5bccdf07c3234c06c435648a53d8cb369f76d20e03bb8d2f8c24fb2330efc32"
|
||||
dependencies = [
|
||||
"errno",
|
||||
"libryzenadj-sys-alt",
|
||||
"libryzenadj-sys",
|
||||
"num_enum",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libryzenadj-sys-alt"
|
||||
version = "0.14.0"
|
||||
name = "libryzenadj-sys"
|
||||
version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb9de62ac92216770e51b5fa0628c22246a23c948e006f4ee65f6b96f6e0dd35"
|
||||
checksum = "b1de3621be974e892e12d4a07a6a2e32b6a05950759b062d94f5b54f78fabc3a"
|
||||
dependencies = [
|
||||
"bindgen",
|
||||
"cmake",
|
||||
|
@ -1170,14 +1170,14 @@ checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
|||
|
||||
[[package]]
|
||||
name = "powertools"
|
||||
version = "2.0.3"
|
||||
version = "2.0.3-alpha1"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"chrono",
|
||||
"clap",
|
||||
"community_settings_core",
|
||||
"libc",
|
||||
"libryzenadj-alt",
|
||||
"libryzenadj",
|
||||
"limits_core",
|
||||
"log",
|
||||
"regex",
|
||||
|
@ -1482,8 +1482,6 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "smokepatio"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3416e8c907d171c4334df3933873c32bff97ca5ad7ae0ee93e6268e04e2041ef"
|
||||
dependencies = [
|
||||
"embedded-io",
|
||||
"log",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "powertools"
|
||||
version = "2.0.3"
|
||||
version = "2.0.3-alpha1"
|
||||
edition = "2021"
|
||||
authors = ["NGnius (Graham) <ngniusness@gmail.com>"]
|
||||
description = "Backend (superuser) functionality for PowerTools"
|
||||
|
@ -31,7 +31,7 @@ limits_core = { version = "3", path = "./limits_core" }
|
|||
regex = "1"
|
||||
|
||||
# steam deck libs
|
||||
smokepatio = { version = "0.2", default-features = false }
|
||||
smokepatio = { version = "0.2", default-features = false, path = "../../smokepatio" }
|
||||
libc = "0.2"
|
||||
|
||||
# online settings
|
||||
|
@ -40,7 +40,7 @@ chrono = { version = "0.4", features = [ "serde" ] }
|
|||
|
||||
# hardware enablement
|
||||
#libryzenadj = { version = "0.14", path = "../../libryzenadj-rs-14" }
|
||||
libryzenadj-alt = { version = "0.14" }
|
||||
libryzenadj = { version = "0.13" }
|
||||
|
||||
# ureq's tls feature does not like musl targets
|
||||
ureq = { version = "2", features = ["json", "gzip", "brotli", "charset", "tls"], default-features = false, optional = true }
|
||||
|
|
|
@ -23,7 +23,7 @@ pub enum ApiMessage {
|
|||
OnChargeChange(f64), // battery fill amount: 0 = empty, 1 = full
|
||||
PowerVibeCheck,
|
||||
WaitForEmptyQueue(Callback<()>),
|
||||
LoadSettings(u64, String, u64, String), // (path, name, variant, variant name)
|
||||
LoadSettings(Option<(u64, String)>, Option<(u64, String, u64, String)>), // (legacy(game_id, name), current(path, name, variant, variant name))
|
||||
LoadVariant(u64, String), // (variant, variant name) -- path and name assumed to be for current profile
|
||||
LoadMainSettings,
|
||||
LoadSystemSettings,
|
||||
|
@ -45,13 +45,21 @@ impl core::fmt::Display for ApiMessage {
|
|||
Self::OnChargeChange(x) => write!(f, "OnChargeChange({:?})", x),
|
||||
Self::PowerVibeCheck => write!(f, "PowerVibeCheck"),
|
||||
Self::WaitForEmptyQueue(_) => write!(f, "WaitForEmptyQueue"),
|
||||
Self::LoadSettings(path, name, variant, variant_name) => write!(f, "LoadSettings({}, {}, {}, {})", path, name, variant, variant_name),
|
||||
Self::LoadVariant(variant, variant_name) => write!(f, "LoadVariant({}, {})", variant, variant_name),
|
||||
Self::LoadSettings(path, name, variant, variant_name) => write!(
|
||||
f,
|
||||
"LoadSettings({}, {}, {}, {})",
|
||||
path, name, variant, variant_name
|
||||
),
|
||||
Self::LoadVariant(variant, variant_name) => {
|
||||
write!(f, "LoadVariant({}, {})", variant, variant_name)
|
||||
}
|
||||
Self::LoadMainSettings => write!(f, "LoadMainSettings"),
|
||||
Self::LoadSystemSettings => write!(f, "LoadSystemSettings"),
|
||||
Self::GetLimits(_) => write!(f, "GetLimits"),
|
||||
Self::GetProvider(s, _) => write!(f, "GetProvider({})", s),
|
||||
Self::UploadCurrentVariant(id, user) => write!(f, "UploadCurrentVariant(id: {}, user: {})", id, user),
|
||||
Self::UploadCurrentVariant(id, user) => {
|
||||
write!(f, "UploadCurrentVariant(id: {}, user: {})", id, user)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -392,9 +400,7 @@ impl ApiMessageHandler {
|
|||
messages.push(msg.to_string());
|
||||
dirty |= self.process(settings, msg);
|
||||
}
|
||||
if dirty
|
||||
|| dirty_echo
|
||||
{
|
||||
if dirty || dirty_echo {
|
||||
dirty_echo = dirty; // echo only once
|
||||
print_messages(&messages);
|
||||
// run on_set
|
||||
|
@ -498,7 +504,61 @@ impl ApiMessageHandler {
|
|||
self.on_empty.push(callback);
|
||||
false
|
||||
}
|
||||
ApiMessage::LoadSettings(id, name, variant_id, variant_name) => {
|
||||
ApiMessage::LoadSettings(legacy_settings, current_settings) => {
|
||||
/* Migration steps:
|
||||
1. Modify to the frontend to send the game ID in this message (`id` here is the app
|
||||
ID).
|
||||
2. Change game ID to app ID.
|
||||
3. (Create and) call function to merge OldSettingsJson with existing FileJson, or
|
||||
use existing `From<OldSettingsJson> for FileJson` if this game doesn't have a
|
||||
save in the new format yet.
|
||||
4. Let the rest of the code below work its magic.
|
||||
*/
|
||||
|
||||
// ===== migration logic =====
|
||||
if legacy_settings.is_some() {
|
||||
let (legacy_game_id, legacy_name) = legacy_settings.unwrap();
|
||||
|
||||
let legacy_file_path = format!("{legacy_game_id}.json");
|
||||
let legacy_file = crate::persist::OldSettingsJson::open(legacy_file_path)
|
||||
.expect("should be able to deserialzie legacy savefile format"); // TODO: don't panic on fail.
|
||||
|
||||
if current_settings.is_some() {
|
||||
// A savefile in both the legacy and current format exist.
|
||||
let (id, name, variant_id, variant_name) = current_settings.unwrap();
|
||||
let path = format!("{}.ron", id);
|
||||
|
||||
// 1. Parse `legacy_file` to into a settings variant.
|
||||
let migrated_settings_variant: crate::persist::SettingsJson =
|
||||
legacy_file.into();
|
||||
// 2. Insert the variant into the current settings file.
|
||||
match settings.load_file(
|
||||
path.into(),
|
||||
id,
|
||||
name,
|
||||
variant_id,
|
||||
variant_name,
|
||||
false,
|
||||
) {
|
||||
Ok(success) => log::info!("Loaded settings file? {}", success),
|
||||
Err(e) => log::warn!("Load file err: {}", e),
|
||||
}
|
||||
settings.add_variant() //TODO: This.
|
||||
} else {
|
||||
// A savefile in the current format doesn't exist yet.
|
||||
// TODO: Parse it to the new format and save it.
|
||||
|
||||
let app_id_from_game_id: u64;
|
||||
let new_path = format!("{app_id_from_game_id}.ron");
|
||||
|
||||
let migrated_settings: crate::persist::FileJson = legacy_file.into();
|
||||
migrated_settings.save(new_path);
|
||||
}
|
||||
} else if current_settings.is_some() {
|
||||
// ...
|
||||
}
|
||||
// ===========================
|
||||
|
||||
let path = format!("{}.ron", id);
|
||||
if let Err(e) = settings.on_unload() {
|
||||
print_errors("LoadSettings on_unload()", e);
|
||||
|
|
|
@ -36,6 +36,14 @@ impl From<ron::error::Error> for RonError {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<serde_json::Error> for RonError {
|
||||
fn from(_value: serde_json::Error) -> Self {
|
||||
RonError::General(ron::Error::Message(String::from(
|
||||
"TODO: make error handling in migration logic good. Specifically, make it so a json error can be used as a RonError instead of just returning this string",
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ron::error::SpannedError> for RonError {
|
||||
fn from(value: ron::error::SpannedError) -> Self {
|
||||
Self::Spanned(value)
|
||||
|
|
4
backend/src/persist/migration.rs
Normal file
4
backend/src/persist/migration.rs
Normal file
|
@ -0,0 +1,4 @@
|
|||
pub mod gpu;
|
||||
pub mod settings;
|
||||
|
||||
pub const APP_ID_UNKNOWN: u64 = u64::MAX;
|
26
backend/src/persist/migration/gpu.rs
Normal file
26
backend/src/persist/migration/gpu.rs
Normal file
|
@ -0,0 +1,26 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::persist::{GpuJson, MinMaxJson};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct OldGpuJson {
|
||||
pub fast_ppt: Option<u64>,
|
||||
pub slow_ppt: Option<u64>,
|
||||
pub clock_limits: Option<MinMaxJson<u64>>,
|
||||
pub slow_memory: bool,
|
||||
pub root: Option<String>,
|
||||
}
|
||||
|
||||
impl From<OldGpuJson> for GpuJson {
|
||||
fn from(old_gpu: OldGpuJson) -> Self {
|
||||
Self {
|
||||
fast_ppt: old_gpu.fast_ppt,
|
||||
slow_ppt: old_gpu.slow_ppt,
|
||||
tdp: None,
|
||||
tdp_boost: None,
|
||||
clock_limits: old_gpu.clock_limits.clone(),
|
||||
memory_clock: None,
|
||||
root: old_gpu.root.clone(),
|
||||
}
|
||||
}
|
||||
}
|
67
backend/src/persist/migration/settings.rs
Normal file
67
backend/src/persist/migration/settings.rs
Normal file
|
@ -0,0 +1,67 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::persist::{
|
||||
BatteryJson, CpuJson, DriverJson, FileJson, SerdeError, SettingsJson, LATEST_VERSION,
|
||||
};
|
||||
|
||||
use super::gpu::OldGpuJson;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct OldOnEventJson {
|
||||
pub on_save: Option<String>,
|
||||
pub on_load: Option<String>,
|
||||
pub on_set: Option<String>,
|
||||
pub on_resume: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct OldSettingsJson {
|
||||
pub version: u64,
|
||||
pub name: String,
|
||||
pub persistent: bool,
|
||||
pub cpus: Vec<CpuJson>,
|
||||
pub gpu: OldGpuJson,
|
||||
pub battery: BatteryJson,
|
||||
pub provider: Option<DriverJson>,
|
||||
pub events: Option<OldOnEventJson>,
|
||||
}
|
||||
|
||||
impl From<OldSettingsJson> for SettingsJson {
|
||||
fn from(old_settings: OldSettingsJson) -> Self {
|
||||
Self {
|
||||
version: old_settings.version,
|
||||
name: format!("{} (migrated)", old_settings.name.clone()),
|
||||
variant: 0,
|
||||
persistent: old_settings.persistent,
|
||||
cpus: old_settings.cpus.clone(),
|
||||
gpu: old_settings.gpu.clone().into(),
|
||||
battery: old_settings.battery.clone(),
|
||||
provider: old_settings.provider.clone(),
|
||||
tags: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<OldSettingsJson> for FileJson {
|
||||
fn from(old_settings: OldSettingsJson) -> Self {
|
||||
let mut variants = HashMap::new();
|
||||
let variant = SettingsJson::from(old_settings.clone());
|
||||
variants.insert(0, variant);
|
||||
|
||||
Self {
|
||||
version: LATEST_VERSION,
|
||||
name: old_settings.name.clone(),
|
||||
app_id: super::APP_ID_UNKNOWN, // `u64::MAX`, sentinel value.
|
||||
variants,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl OldSettingsJson {
|
||||
pub fn open<P: AsRef<std::path::Path>>(path: P) -> Result<Self, SerdeError> {
|
||||
let mut file = std::fs::File::open(path).map_err(SerdeError::Io)?;
|
||||
serde_json::from_reader(&mut file).map_err(|e| SerdeError::Serde(e.into()))
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ mod error;
|
|||
mod file;
|
||||
mod general;
|
||||
mod gpu;
|
||||
mod migration;
|
||||
|
||||
pub use battery::{BatteryEventJson, BatteryJson};
|
||||
pub use cpu::CpuJson;
|
||||
|
@ -12,7 +13,8 @@ pub use driver::DriverJson;
|
|||
pub use file::FileJson;
|
||||
pub use general::{MinMaxJson, SettingsJson};
|
||||
pub use gpu::GpuJson;
|
||||
pub use migration::{gpu::*, settings::*};
|
||||
|
||||
pub use error::SerdeError;
|
||||
pub use error::{RonError, SerdeError};
|
||||
|
||||
pub const LATEST_VERSION: u64 = 0;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use libryzenadj_alt::RyzenAdj;
|
||||
use libryzenadj::RyzenAdj;
|
||||
use std::sync::Mutex;
|
||||
|
||||
use crate::persist::GpuJson;
|
||||
|
@ -22,9 +22,9 @@ fn msg_or_err<D: std::fmt::Display, E: std::fmt::Display>(
|
|||
fn log_capabilities(ryzenadj: &RyzenAdj) {
|
||||
log::info!(
|
||||
"RyzenAdj v{}.{}.{}",
|
||||
libryzenadj_alt::libryzenadj_sys::RYZENADJ_REVISION_VER,
|
||||
libryzenadj_alt::libryzenadj_sys::RYZENADJ_MAJOR_VER,
|
||||
libryzenadj_alt::libryzenadj_sys::RYZENADJ_MINIOR_VER
|
||||
libryzenadj::libryzenadj_sys::RYZENADJ_REVISION_VER,
|
||||
libryzenadj::libryzenadj_sys::RYZENADJ_MAJOR_VER,
|
||||
libryzenadj::libryzenadj_sys::RYZENADJ_MINIOR_VER
|
||||
);
|
||||
#[cfg(feature = "experimental")]
|
||||
if let Some(x) = ryzenadj.get_init_table_err() {
|
||||
|
|
|
@ -59,7 +59,6 @@ mod test {
|
|||
online: status,
|
||||
clock_limits: None,
|
||||
governor: "schedutil".to_owned(),
|
||||
root: Some("/".to_owned()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "PowerTools",
|
||||
"version": "2.0.3",
|
||||
"version": "2.0.3-alpha1",
|
||||
"description": "Power tweaks for power users",
|
||||
"scripts": {
|
||||
"build": "shx rm -rf dist && rollup -c",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "PowerTools",
|
||||
"author": "NGnius",
|
||||
"flags": ["root", "global-dfl"],
|
||||
"flags": ["root", "_debug", "global-dfl"],
|
||||
"publish": {
|
||||
"discord_id": "106537989684887552",
|
||||
"description": "Power tweaks for power users",
|
||||
|
|
Loading…
Reference in a new issue