Use profile filename instead of profile name to detect profile change

This commit is contained in:
NGnius (Graham) 2023-03-25 13:46:58 -04:00
parent 1175780951
commit 68e86c0778
7 changed files with 46 additions and 10 deletions

View file

@ -140,6 +140,28 @@ pub fn get_name(
} }
} }
/// Generate get current settings name
pub fn get_path(
sender: Sender<ApiMessage>,
) -> impl AsyncCallable {
let sender = Arc::new(Mutex::new(sender)); // Sender is not Sync; this is required for safety
let getter = move || {
let sender2 = sender.clone();
move || {
let (tx, rx) = mpsc::channel();
let callback = move |name: std::path::PathBuf| tx.send(name).expect("get_path callback send failed");
sender2.lock().unwrap().send(ApiMessage::General(GeneralMessage::GetPath(Box::new(callback)))).expect("get_name send failed");
rx.recv().expect("get_path callback recv failed")
}
};
super::async_utils::AsyncIshGetter {
set_get: getter,
trans_getter: |result| {
vec![result.to_string_lossy().to_string().into()]
}
}
}
/// Generate wait for all locks to be available web method /// Generate wait for all locks to be available web method
pub fn lock_unlock_all( pub fn lock_unlock_all(
sender: Sender<ApiMessage>, sender: Sender<ApiMessage>,

View file

@ -194,6 +194,7 @@ pub enum GeneralMessage {
SetPersistent(bool), SetPersistent(bool),
GetPersistent(Callback<bool>), GetPersistent(Callback<bool>),
GetCurrentProfileName(Callback<String>), GetCurrentProfileName(Callback<String>),
GetPath(Callback<std::path::PathBuf>),
ApplyNow, ApplyNow,
} }
@ -204,6 +205,7 @@ impl GeneralMessage {
Self::SetPersistent(val) => *settings.persistent() = val, Self::SetPersistent(val) => *settings.persistent() = val,
Self::GetPersistent(cb) => cb(*settings.persistent()), Self::GetPersistent(cb) => cb(*settings.persistent()),
Self::GetCurrentProfileName(cb) => cb(settings.get_name().to_owned()), Self::GetCurrentProfileName(cb) => cb(settings.get_name().to_owned()),
Self::GetPath(cb) => cb(settings.get_path().to_owned()),
Self::ApplyNow => {}, Self::ApplyNow => {},
} }
dirty dirty

View file

@ -215,6 +215,10 @@ fn main() -> Result<(), ()> {
"GENERAL_get_name", "GENERAL_get_name",
api::general::get_name(api_sender.clone()) api::general::get_name(api_sender.clone())
) )
.register_async(
"GENERAL_get_path",
api::general::get_path(api_sender.clone())
)
.register_async( .register_async(
"GENERAL_wait_for_unlocks", "GENERAL_wait_for_unlocks",
api::general::lock_unlock_all(api_sender.clone()) api::general::lock_unlock_all(api_sender.clone())

View file

@ -140,7 +140,7 @@ impl Settings {
} }
pub fn load_file(&mut self, filename: PathBuf, name: String, system_defaults: bool) -> Result<bool, SettingError> { pub fn load_file(&mut self, filename: PathBuf, name: String, system_defaults: bool) -> Result<bool, SettingError> {
let json_path = crate::utility::settings_dir().join(filename); let json_path = crate::utility::settings_dir().join(&filename);
if json_path.exists() { if json_path.exists() {
let settings_json = SettingsJson::open(&json_path).map_err(|e| SettingError { let settings_json = SettingsJson::open(&json_path).map_err(|e| SettingError {
msg: e.to_string(), msg: e.to_string(),
@ -176,7 +176,7 @@ impl Settings {
} }
*self.general.persistent() = false; *self.general.persistent() = false;
} }
self.general.path(json_path); self.general.path(filename);
Ok(*self.general.persistent()) Ok(*self.general.persistent())
} }

View file

@ -245,6 +245,10 @@ export async function getGeneralSettingsName(): Promise<string> {
return (await call_backend("GENERAL_get_name", []))[0]; return (await call_backend("GENERAL_get_name", []))[0];
} }
export async function getGeneralSettingsPath(): Promise<string> {
return (await call_backend("GENERAL_get_path", []))[0];
}
export async function waitForComplete(): Promise<boolean> { export async function waitForComplete(): Promise<boolean> {
return (await call_backend("GENERAL_wait_for_unlocks", []))[0]; return (await call_backend("GENERAL_wait_for_unlocks", []))[0];
} }

View file

@ -27,3 +27,5 @@ export const SLOW_MEMORY_GPU = "GPU_slow_memory";
export const PERSISTENT_GEN = "GENERAL_persistent"; export const PERSISTENT_GEN = "GENERAL_persistent";
export const NAME_GEN = "GENERAL_name"; export const NAME_GEN = "GENERAL_name";
export const PATH_GEN = "GENERAL_path";

View file

@ -21,6 +21,7 @@ import {
} from "decky-frontend-lib"; } from "decky-frontend-lib";
import { VFC, useState } from "react"; import { VFC, useState } from "react";
import { GiDrill, GiTimeBomb, GiTimeTrap, GiDynamite } from "react-icons/gi"; import { GiDrill, GiTimeBomb, GiTimeTrap, GiDynamite } from "react-icons/gi";
import { HiRefresh, HiTrash } from "react-icons/hi";
//import * as python from "./python"; //import * as python from "./python";
import * as backend from "./backend"; import * as backend from "./backend";
@ -54,6 +55,7 @@ import {
PERSISTENT_GEN, PERSISTENT_GEN,
NAME_GEN, NAME_GEN,
PATH_GEN,
} from "./consts"; } from "./consts";
import { set_value, get_value } from "usdpl-front"; import { set_value, get_value } from "usdpl-front";
import { Debug } from "./components/debug"; import { Debug } from "./components/debug";
@ -142,6 +144,7 @@ const reload = function() {
backend.resolve(backend.getGeneralPersistent(), (value: boolean) => { set_value(PERSISTENT_GEN, value) }); backend.resolve(backend.getGeneralPersistent(), (value: boolean) => { set_value(PERSISTENT_GEN, value) });
backend.resolve(backend.getGeneralSettingsName(), (name: string) => { set_value(NAME_GEN, name) }); backend.resolve(backend.getGeneralSettingsName(), (name: string) => { set_value(NAME_GEN, name) });
backend.resolve(backend.getGeneralSettingsPath(), (path: string) => { set_value(PATH_GEN, path) });
backend.resolve(backend.getInfo(), (info: string) => { set_value(BACKEND_INFO, info) }); backend.resolve(backend.getInfo(), (info: string) => { set_value(BACKEND_INFO, info) });
backend.resolve(backend.getDriverProviderName("gpu"), (driver: string) => { set_value(DRIVER_INFO, driver) }); backend.resolve(backend.getDriverProviderName("gpu"), (driver: string) => { set_value(DRIVER_INFO, driver) });
@ -151,7 +154,6 @@ const reload = function() {
(async function(){ (async function(){
await backend.initBackend(); await backend.initBackend();
usdplReady = true; usdplReady = true;
set_value(NAME_GEN, "Default");
reload(); // technically this is only a load reload(); // technically this is only a load
// register Steam callbacks // register Steam callbacks
@ -186,11 +188,11 @@ const periodicals = function() {
backend.resolve(backend.getBatteryChargeNow(), (rate: number) => { set_value(CHARGE_NOW_BATT, rate) }); backend.resolve(backend.getBatteryChargeNow(), (rate: number) => { set_value(CHARGE_NOW_BATT, rate) });
backend.resolve(backend.getBatteryChargeFull(), (rate: number) => { set_value(CHARGE_FULL_BATT, rate) }); backend.resolve(backend.getBatteryChargeFull(), (rate: number) => { set_value(CHARGE_FULL_BATT, rate) });
backend.resolve(backend.getGeneralPersistent(), (value: boolean) => { set_value(PERSISTENT_GEN, value) }); backend.resolve(backend.getGeneralSettingsPath(), (path: string) => {
backend.resolve(backend.getGeneralSettingsName(), (name: string) => { const oldValue = get_value(PATH_GEN);
const oldValue = get_value(NAME_GEN); set_value(PATH_GEN, path);
set_value(NAME_GEN, name); if (path != oldValue) {
if (name != oldValue) { backend.log(backend.LogLevel.Info, "Frontend values reload triggered by path change: " + oldValue + " -> " + path);
reload(); reload();
} }
}); });
@ -272,7 +274,7 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({}) => {
backend.forceApplySettings(); backend.forceApplySettings();
}} }}
> >
{tr("Reapply settings")} <HiRefresh /> {tr("Reapply settings")}
</ButtonItem> </ButtonItem>
</PanelSectionRow> </PanelSectionRow>
@ -293,7 +295,7 @@ const Content: VFC<{ serverAPI: ServerAPI }> = ({}) => {
); );
}} }}
> >
{tr("Defaults")} <HiTrash /> {tr("Defaults")}
</ButtonItem> </ButtonItem>
</PanelSectionRow> </PanelSectionRow>
</PanelSection> </PanelSection>