+
Date: Wed, 19 Jun 2024 21:51:08 -0400
Subject: [PATCH 08/19] Simplify LibrarySyncState init code
---
src/helpers/libSyncState.ts | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/helpers/libSyncState.ts b/src/helpers/libSyncState.ts
index 5fbdb6f..6c38e56 100644
--- a/src/helpers/libSyncState.ts
+++ b/src/helpers/libSyncState.ts
@@ -49,10 +49,10 @@ class AppState {
const data = await serverApi.callPluginMethod<{}, LibrarySyncState>("get_library_sync_config", {});
if (data.success) {
- this.setState("Documents", { enabled: data.result.Documents.enabled, bisync: data.result.Documents.bisync, destination: data.result.Documents.destination });
- this.setState("Music", { enabled: data.result.Music.enabled, bisync: data.result.Music.bisync, destination: data.result.Music.destination });
- this.setState("Pictures", { enabled: data.result.Pictures.enabled, bisync: data.result.Pictures.bisync, destination: data.result.Pictures.destination });
- this.setState("Videos", { enabled: data.result.Videos.enabled, bisync: data.result.Videos.bisync, destination: data.result.Videos.destination });
+ this.setState("Documents", data.result.Documents);
+ this.setState("Music", data.result.Music);
+ this.setState("Pictures", data.result.Pictures);
+ this.setState("Videos", data.result.Videos);
} else {
Logger.error(data);
}
From a83890a9397b8675d80fcb4e93aafa660d48cc85 Mon Sep 17 00:00:00 2001
From: Akaza Renn <8340896+AkazaRenn@users.noreply.github.com>
Date: Thu, 20 Jun 2024 18:20:09 -0400
Subject: [PATCH 09/19] Migrate to json config
---
py_modules/plugin_config.py | 96 ++++++++++++----------
src/helpers/libSyncState.ts | 134 -------------------------------
src/helpers/state.ts | 56 +++++++++++--
src/pages/ConfigurePathsPage.tsx | 20 +++--
4 files changed, 111 insertions(+), 195 deletions(-)
delete mode 100644 src/helpers/libSyncState.ts
diff --git a/py_modules/plugin_config.py b/py_modules/plugin_config.py
index c1e74e3..02f73e3 100644
--- a/py_modules/plugin_config.py
+++ b/py_modules/plugin_config.py
@@ -13,24 +13,38 @@
cfg_syncpath_includes_file = config_dir / "sync_paths.txt"
cfg_syncpath_excludes_file = config_dir / "sync_paths_excludes.txt"
cfg_syncpath_filter_file = config_dir / "sync_paths_filter.txt"
-cfg_property_file = config_dir / "plugin.properties"
-library_sync_config = settings_manager(name="library_sync", settings_directory=decky_plugin.DECKY_PLUGIN_SETTINGS_DIR)
+config = settings_manager(name="config", settings_directory=decky_plugin.DECKY_PLUGIN_SETTINGS_DIR)
-def get_config():
+def get_cfg_property():
"""
- Reads and parses the plugin configuration file.
+ Reads and parses the plugin.properties.
+ This is only used for migration from legacy config file and should not be used for any other purpose.
Returns:
list: A list of key-value pairs representing the configuration.
"""
+ cfg_property_file = config_dir / "plugin.properties"
+ if not cfg_property_file.is_file():
+ return []
with open(cfg_property_file) as f:
lines = f.readlines()
lines = list(map(lambda x: x.strip().split('='), lines))
decky_plugin.logger.debug("config %s", lines)
+ cfg_property_file.unlink()
return lines
-def set_config(key: str, value: str):
+def get_config():
+ """
+ Retrieves the plugin configuration.
+
+ Returns:
+ dict: The plugin configuration.
+ """
+ config.read()
+ return config.settings
+
+def set_config(key: str, value):
"""
Sets a configuration key-value pair in the plugin configuration file.
@@ -38,20 +52,9 @@ def set_config(key: str, value: str):
key (str): The key to set.
value (str): The value to set for the key.
"""
- with open(cfg_property_file, "r") as f:
- lines = f.readlines()
- with open(cfg_property_file, "w") as f:
- found = False
- for line in lines:
- if line.startswith(key + '='):
- f.write(f"{key}={value}\n")
- found = True
- else:
- f.write(line)
- if not found:
- f.write(f"{key}={value}\n")
-
-def get_config_item(name: str, default: str = None):
+ config.setSetting(key, value)
+
+def get_config_item(name: str, default = None):
"""
Retrieves a configuration item by name.
@@ -62,7 +65,8 @@ def get_config_item(name: str, default: str = None):
Returns:
str: The value of the configuration item.
"""
- return next((x[1] for x in get_config() if x[0] == name), default)
+ config.read()
+ return config.getSetting(name, default)
def regenerate_filter_file():
"""
@@ -95,11 +99,11 @@ def get_library_sync_config(key: str = None):
Returns:
dict: The library sync configuration.
"""
- library_sync_config.read()
+ config.read()
if key:
- return library_sync_config.getSetting(key, {"enabled": False, "bisync": False, "destination": f"deck-libraries/{key}"})
+ return config.getSetting("library_sync", {}).get(key, {"enabled": False, "bisync": False, "destination": f"deck-libraries/{key}"})
else:
- return library_sync_config.settings
+ return config.getSetting("library_sync", {})
def set_library_sync_config(key: str, enabled: bool = None, bisync: bool = None, destination: str = None):
"""
@@ -110,15 +114,16 @@ def set_library_sync_config(key: str, enabled: bool = None, bisync: bool = None,
enabled (bool): Whether the key is enabled.
destination (str): The destination of the key.
"""
- library_sync_config.read()
+ config.read()
if enabled == None:
- enabled = library_sync_config.getSetting(key, {}).get("enabled", False)
+ enabled = get_library_sync_config(key).get("enabled", False)
if bisync == None:
- bisync = library_sync_config.getSetting(key, {}).get("bisync", False)
+ bisync = get_library_sync_config(key).get(key, {}).get("bisync", False)
if destination == None:
- destination = library_sync_config.getSetting(key, {}).get("destination", f"deck-libraries/{key}")
-
- library_sync_config.setSetting(key, {"enabled": enabled, "bisync": bisync, "destination": destination})
+ destination = get_library_sync_config(key).get(key, {}).get("destination", f"deck-libraries/{key}")
+ library_sync_config = get_library_sync_config()
+ library_sync_config.update({key: {"enabled": enabled, "bisync": bisync, "destination": destination}})
+ config.setSetting("library_sync", library_sync_config)
def migrate():
"""
@@ -130,24 +135,31 @@ def migrate():
cfg_syncpath_includes_file.touch()
if not cfg_syncpath_excludes_file.is_file():
cfg_syncpath_excludes_file.touch()
- if not cfg_property_file.is_file():
- cfg_property_file.touch()
if not cfg_syncpath_filter_file.is_file():
regenerate_filter_file()
- config = get_config()
- if not any(e[0] == "destination_directory" for e in config):
+ # Migrate from plugin.properties to config.json
+ config_pairs_list = get_cfg_property()
+ for pair in config_pairs_list:
+ if pair[1] == "true":
+ pair[1] = True
+ elif pair[1] == "false":
+ pair[1] = False
+ set_config(pair[0], pair[1])
+
+ # Set default configurations
+ current_config = get_config()
+ if not "destination_directory" in current_config:
set_config("destination_directory", "decky-cloud-save")
- if not any(e[0] == "bisync_enabled" for e in config):
- set_config("bisync_enabled", "false")
- if not any(e[0] == "log_level" for e in config):
+ if not "bisync_enabled" in current_config:
+ set_config("bisync_enabled", False)
+ if not "log_level" in current_config:
set_config("log_level", "INFO")
- if not any(e[0] == "sync_on_game_exit" for e in config):
- set_config("sync_on_game_exit", "true")
- if not any(e[0] == "toast_auto_sync" for e in config):
- set_config("toast_auto_sync", "true")
-
- if not get_library_sync_config():
+ if not "sync_on_game_exit" in current_config:
+ set_config("sync_on_game_exit", True)
+ if not "toast_auto_sync" in current_config:
+ set_config("toast_auto_sync", True)
+ if not "library_sync" in current_config:
set_library_sync_config("Documents")
set_library_sync_config("Music")
set_library_sync_config("Pictures")
diff --git a/src/helpers/libSyncState.ts b/src/helpers/libSyncState.ts
deleted file mode 100644
index 6c38e56..0000000
--- a/src/helpers/libSyncState.ts
+++ /dev/null
@@ -1,134 +0,0 @@
-import { ServerAPI } from "decky-frontend-lib";
-import { useEffect, useState } from "react";
-import { Logger } from "./logger";
-
-export type LibrarySyncState = {
- Documents: LibrarySyncStateEntry;
- Music: LibrarySyncStateEntry;
- Pictures: LibrarySyncStateEntry;
- Videos: LibrarySyncStateEntry;
-};
-
-interface LibrarySyncStateEntry {
- enabled: boolean;
- bisync: boolean;
- destination: string;
-};
-
-class AppState {
- private _subscribers: { id: number; callback: (e: LibrarySyncState) => void }[] = [];
-
- private _currentState: LibrarySyncState = {
- Documents: { enabled: false, bisync: false, destination: "deck-libraries/Documents" },
- Music: { enabled: false, bisync: false, destination: "deck-libraries/Music" },
- Pictures: { enabled: false, bisync: false, destination: "deck-libraries/Pictures" },
- Videos: { enabled: false, bisync: false, destination: "deck-libraries/Videos" },
- };
-
- private _serverApi: ServerAPI = null!;
- private _alreadyInit: boolean = true!;
-
- public get currentState() {
- return this._currentState;
- }
-
- public get serverApi() {
- return this._serverApi;
- }
-
- public get alreadyInit() {
- return this._alreadyInit;
- }
-
- public async initialize(serverApi: ServerAPI) {
- if (this._serverApi == null) {
- this._alreadyInit = false;
- }
-
- this._serverApi = serverApi;
-
- const data = await serverApi.callPluginMethod<{}, LibrarySyncState>("get_library_sync_config", {});
- if (data.success) {
- this.setState("Documents", data.result.Documents);
- this.setState("Music", data.result.Music);
- this.setState("Pictures", data.result.Pictures);
- this.setState("Videos", data.result.Videos);
- } else {
- Logger.error(data);
- }
- }
-
- public setState = (key: keyof LibrarySyncState, values: Partial<{ enabled: boolean; bisync: boolean; destination: string }>, persist = false) => {
- let entry = this._currentState[key];
- if (values.enabled !== undefined) {
- entry.enabled = values.enabled;
- }
- if (values.bisync !== undefined) {
- entry.bisync = values.bisync;
- }
- if (values.destination !== undefined) {
- entry.destination = values.destination;
- }
-
- if (persist) {
- this.serverApi
- .callPluginMethod<{ key: string; enabled: boolean; bisync: boolean, destination: string }, void>("set_library_sync_config", {
- key,
- enabled: entry.enabled,
- bisync: entry.bisync,
- destination: entry.destination,
- })
- .then(e => Logger.debug(e));
- }
-
- this._subscribers.forEach((e) => e.callback(this.currentState));
- }
-
- public subscribe = (callback: (e: LibrarySyncState) => void) => {
- const id = new Date().getTime();
- this._subscribers.push({ id, callback });
-
- return id;
- };
-
- public unsubscribe = (id: number) => {
- const index = this._subscribers.findIndex((f) => f.id === id);
- if (index > -1) {
- this._subscribers.splice(index, 1);
- }
- };
-}
-
-export class ApplicationLibrarySyncState {
-
- private constructor(){
- }
-
- private static appState = new AppState();
-
- public static async initialize(serverApi: ServerAPI) {
- await this.appState.initialize(serverApi);
- }
-
- public static useAppState = () => {
- const [state, setState] = useState(ApplicationLibrarySyncState.appState.currentState);
-
- useEffect(() => {
- const id = ApplicationLibrarySyncState.appState.subscribe((e) => {
- Logger.debug("Rendering: " + JSON.stringify(e));
- setState(e);
- });
- return () => {
- ApplicationLibrarySyncState.appState.unsubscribe(id);
- };
- }, []);
-
- return state;
- };
-
- public static getAppState(): AppState {
- return ApplicationLibrarySyncState.appState;
- }
- public static setAppState = ApplicationLibrarySyncState.appState.setState;
- public static getServerApi = () => ApplicationLibrarySyncState.appState.serverApi;
-}
diff --git a/src/helpers/state.ts b/src/helpers/state.ts
index 84bf33d..f7dce19 100644
--- a/src/helpers/state.ts
+++ b/src/helpers/state.ts
@@ -9,7 +9,23 @@ type State = {
experimental_menu: string;
toast_auto_sync: string;
destination_directory: string;
- playing: string
+ playing: string;
+ library_sync: LibrarySyncState;
+};
+
+type ValueOf = T[keyof T];
+
+export type LibrarySyncState = {
+ Documents: LibrarySyncStateEntry;
+ Music: LibrarySyncStateEntry;
+ Pictures: LibrarySyncStateEntry;
+ Videos: LibrarySyncStateEntry;
+};
+
+interface LibrarySyncStateEntry {
+ enabled: boolean;
+ bisync: boolean;
+ destination: string;
};
class AppState {
@@ -22,7 +38,13 @@ class AppState {
experimental_menu: "false",
toast_auto_sync: "true",
destination_directory: "decky-cloud-save",
- playing: "false"
+ playing: "false",
+ library_sync: {
+ Documents: { enabled: false, bisync: false, destination: "deck-libraries/Documents" },
+ Music: { enabled: false, bisync: false, destination: "deck-libraries/Music" },
+ Pictures: { enabled: false, bisync: false, destination: "deck-libraries/Pictures" },
+ Videos: { enabled: false, bisync: false, destination: "deck-libraries/Videos" },
+ },
};
private _serverApi: ServerAPI = null!;
@@ -47,21 +69,38 @@ class AppState {
this._serverApi = serverApi;
- const data = await serverApi.callPluginMethod<{}, string[][]>("get_config", {});
+ const data = await serverApi.callPluginMethod<{}, State>("get_config", {});
if (data.success) {
- data.result.forEach((e) => this.setState(e[0] as keyof State, e[1]));
+ for (const [key, value] of Object.entries(data.result)) {
+ this.setState(key as keyof State, value as ValueOf);
+ }
} else {
Logger.error(data);
}
}
- public setState = (key: keyof State, value: string, persist = false) => {
+ public setLibSyncState = (key: keyof LibrarySyncState, values: Partial<{ enabled: boolean; bisync: boolean; destination: string }>, persist = false) => {
+ let entry = this._currentState.library_sync[key];
+ if (values.enabled !== undefined) {
+ entry.enabled = values.enabled;
+ }
+ if (values.bisync !== undefined) {
+ entry.bisync = values.bisync;
+ }
+ if (values.destination !== undefined) {
+ entry.destination = values.destination;
+ }
+
+ this.setState("library_sync", this._currentState.library_sync, persist);
+ }
+
+ public setState = (key: keyof State, value: ValueOf, persist = false) => {
this._currentState = { ...this.currentState, [key]: value };
Logger.debug("Setting '" + key + "' to '" + value + "' with persistence: " + persist);
if (persist) {
- this.serverApi.callPluginMethod<{ key: string; value: string }, null>("set_config", { key, value }).then(e => Logger.debug(e));
+ this.serverApi.callPluginMethod<{ key: string; value: ValueOf }, null>("set_config", { key, value }).then(e => Logger.debug(e));
}
this._subscribers.forEach((e) => e.callback(this.currentState));
@@ -97,9 +136,9 @@ export class ApplicationState {
private constructor(){
}
-
+
private static appState = new AppState();
-
+
public static async initialize(serverApi: ServerAPI) {
await this.appState.initialize(serverApi);
}
@@ -125,6 +164,7 @@ export class ApplicationState {
return ApplicationState.appState;
}
public static setAppState = ApplicationState.appState.setState;
+ public static setLibSyncState = ApplicationState.appState.setLibSyncState;
public static setbisync_enabled = ApplicationState.appState.setbisync_enabled;
public static getServerApi = () => ApplicationState.appState.serverApi;
}
diff --git a/src/pages/ConfigurePathsPage.tsx b/src/pages/ConfigurePathsPage.tsx
index 42fe644..bb212fb 100644
--- a/src/pages/ConfigurePathsPage.tsx
+++ b/src/pages/ConfigurePathsPage.tsx
@@ -6,13 +6,11 @@ import { RenderExistingPathButton } from "../components/RenderExistingPathButton
import Container from "../components/Container";
import { HelpAssistant } from "../components/HelpAssistant";
import { ApiClient } from "../helpers/apiClient";
-import { ApplicationState } from "../helpers/state";
-import { ApplicationLibrarySyncState, LibrarySyncState } from "../helpers/libSyncState";
+import { ApplicationState, LibrarySyncState } from "../helpers/state";
import { Translator } from "../helpers/translator";
export default function ConfigurePathsPage({ serverApi }: PageProps<{}>) {
const appState = ApplicationState.useAppState();
- const librarySyncState = ApplicationLibrarySyncState.useAppState();
const [includePaths, setIncludePaths] = useState(undefined);
const [excludePaths, setExcludePaths] = useState(undefined);
@@ -86,8 +84,8 @@ export default function ConfigurePathsPage({ serverApi }: PageProps<{}>) {
-
+
@@ -107,19 +105,19 @@ export default function ConfigurePathsPage({ serverApi }: PageProps<{}>) {
ApplicationLibrarySyncState.setAppState(stateKey, {enabled: e}, true)}/>
+ checked={appState.library_sync[stateKey].enabled}
+ onChange={(e) => ApplicationState.setLibSyncState(stateKey, {enabled: e}, true)}/>
ApplicationLibrarySyncState.setAppState(stateKey, {bisync: e}, true)}/>
+ checked={appState.library_sync[stateKey].bisync}
+ onChange={(e) => ApplicationState.setLibSyncState(stateKey, {bisync: e}, true)}/>
ApplicationLibrarySyncState.setAppState(stateKey, {destination: e.target.value}, false)}
- onBlur={(e) => ApplicationLibrarySyncState.setAppState(stateKey, {destination: e.target.value}, true)}/>
+ defaultValue={appState.library_sync[stateKey].destination}
+ onChange={(e) => ApplicationState.setLibSyncState(stateKey, {destination: e.target.value}, false)}
+ onBlur={(e) => ApplicationState.setLibSyncState(stateKey, {destination: e.target.value}, true)}/>
From d5cc0f0f7f37f3b64b218c7f05fbe50df486b229 Mon Sep 17 00:00:00 2001
From: Akaza Renn <8340896+AkazaRenn@users.noreply.github.com>
Date: Thu, 20 Jun 2024 19:02:50 -0400
Subject: [PATCH 10/19] Move whole settings to the json
---
main.py | 10 ----------
py_modules/rclone_sync_manager.py | 4 ++--
src/helpers/apiClient.ts | 8 ++++----
src/helpers/state.ts | 26 +++++++++++++-------------
src/index.tsx | 19 ++++++++-----------
src/pages/ConfigurePathsPage.tsx | 4 ++--
src/pages/RenderDCSMenu.tsx | 26 +++++++++++++-------------
7 files changed, 42 insertions(+), 55 deletions(-)
diff --git a/main.py b/main.py
index 8ccb771..07bb0fd 100644
--- a/main.py
+++ b/main.py
@@ -93,16 +93,6 @@ async def set_config(self, key: str, value: str):
decky_plugin.logger.debug("Executing: set_config(%s, %s)", key, value)
plugin_config.set_config(key, value)
- async def get_library_sync_config(self, key: str = None):
- decky_plugin.logger.debug(
- f"Executing: get_library_sync_config({key})")
- return plugin_config.get_library_sync_config(key)
-
- async def set_library_sync_config(self, key: str, enabled, bisync, destination):
- decky_plugin.logger.debug(
- f"Executing: set_library_sync_config({key}:{{enabled:{enabled},bisync:{bisync},destination:{destination}}})")
- plugin_config.set_library_sync_config(key=key, enabled=enabled, bisync=bisync, destination=destination)
-
# Logger
async def log(self, level: str, msg: str) -> int:
diff --git a/py_modules/rclone_sync_manager.py b/py_modules/rclone_sync_manager.py
index ead2992..f68641d 100644
--- a/py_modules/rclone_sync_manager.py
+++ b/py_modules/rclone_sync_manager.py
@@ -25,7 +25,7 @@ async def sync_now(self, winner: str, resync: bool):
destination_path = plugin_config.get_config_item("destination_directory", "decky-cloud-save")
await self.sync_now_internal(
["/", f"backend:{destination_path}", "--filter-from", plugin_config.cfg_syncpath_filter_file],
- plugin_config.get_config_item("bisync_enabled", "false") == "true",
+ plugin_config.get_config_item("bisync_enabled", False),
winner,
resync
)
@@ -59,7 +59,7 @@ async def sync_now_internal(self, path_args: list, bisync: bool, winner: str, re
args.extend(path_args)
args.extend(["--copy-links"])
- if bisync_enabled:
+ if bisync:
if resync:
args.extend(["--resync-mode", winner, "--resync"])
else:
diff --git a/src/helpers/apiClient.ts b/src/helpers/apiClient.ts
index 74259eb..1e54566 100644
--- a/src/helpers/apiClient.ts
+++ b/src/helpers/apiClient.ts
@@ -128,15 +128,15 @@ export class ApiClient {
private static async syncNowInternal(showToast: boolean, winner: string, resync: boolean = false): Promise
{
Logger.info("Synchronizing");
const start = new Date();
- if (ApplicationState.getAppState().currentState.syncing === "true") {
+ if (ApplicationState.getAppState().currentState.syncing) {
Toast.toast(Translator.translate("waiting.previous"), 2000);
- while (ApplicationState.getAppState().currentState.syncing === "true") {
+ while (ApplicationState.getAppState().currentState.syncing) {
await sleep(300);
}
}
Storage.setSessionStorageItem("syncing", "true");
- ApplicationState.setAppState("syncing", "true");
+ ApplicationState.setAppState("syncing", true);
await ApplicationState.getServerApi().callPluginMethod("sync_now_internal", { winner, resync });
let exitCode = 0;
@@ -164,7 +164,7 @@ export class ApiClient {
pass = false;
break;
}
- ApplicationState.setAppState("syncing", "false");
+ ApplicationState.setAppState("syncing", false);
Storage.setSessionStorageItem("syncing", "false");
let body;
diff --git a/src/helpers/state.ts b/src/helpers/state.ts
index f7dce19..56e4f26 100644
--- a/src/helpers/state.ts
+++ b/src/helpers/state.ts
@@ -3,13 +3,13 @@ import { useEffect, useState } from "react";
import { Logger } from "./logger";
type State = {
- sync_on_game_exit: string;
- syncing: string;
- bisync_enabled: string;
- experimental_menu: string;
- toast_auto_sync: string;
+ sync_on_game_exit: boolean;
+ syncing: boolean;
+ bisync_enabled: boolean;
+ experimental_menu: boolean;
+ toast_auto_sync: boolean;
destination_directory: string;
- playing: string;
+ playing: boolean;
library_sync: LibrarySyncState;
};
@@ -32,13 +32,13 @@ class AppState {
private _subscribers: { id: number; callback: (e: State) => void }[] = [];
private _currentState: State = {
- syncing: "false",
- sync_on_game_exit: "true",
- bisync_enabled: "false",
- experimental_menu: "false",
- toast_auto_sync: "true",
+ syncing: false,
+ sync_on_game_exit: true,
+ bisync_enabled: false,
+ experimental_menu: false,
+ toast_auto_sync: true,
destination_directory: "decky-cloud-save",
- playing: "false",
+ playing: false,
library_sync: {
Documents: { enabled: false, bisync: false, destination: "deck-libraries/Documents" },
Music: { enabled: false, bisync: false, destination: "deck-libraries/Music" },
@@ -100,7 +100,7 @@ class AppState {
Logger.debug("Setting '" + key + "' to '" + value + "' with persistence: " + persist);
if (persist) {
- this.serverApi.callPluginMethod<{ key: string; value: ValueOf }, null>("set_config", { key, value }).then(e => Logger.debug(e));
+ this.serverApi.callPluginMethod<{ key: string; value: ValueOf }, null>("set_config", { key, value: this._currentState[key] }).then(e => Logger.debug(e));
}
this._subscribers.forEach((e) => e.callback(this.currentState));
diff --git a/src/index.tsx b/src/index.tsx
index 792110f..b55ccf7 100755
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -3,7 +3,6 @@ import { Toast } from "./helpers/toast";
import { Logger } from "./helpers/logger";
import { ApiClient } from "./helpers/apiClient";
import { ApplicationState } from "./helpers/state";
-import { ApplicationLibrarySyncState } from "./helpers/libSyncState";
import { Content } from "./pages/RenderDCSMenu";
import { Translator } from "./helpers/translator";
import { Storage } from './helpers/storage';
@@ -19,13 +18,11 @@ declare const appStore: any;
export default definePlugin((serverApi: ServerAPI) => {
Storage.clearAllSessionStorage()
- Promise.all([
- ApplicationState.initialize(serverApi),
- ApplicationLibrarySyncState.initialize(serverApi)]).then(
- async () => {
- Backend.initialize(serverApi);
- await Logger.initialize();
- await Translator.initialize();
+ ApplicationState.initialize(serverApi).then(
+ async () => {
+ Backend.initialize(serverApi);
+ await Logger.initialize();
+ await Translator.initialize();
});
serverApi.routerHook.addRoute("/dcs-configure-paths", () => , { exact: true });
@@ -35,11 +32,11 @@ export default definePlugin((serverApi: ServerAPI) => {
serverApi.routerHook.addRoute("/dcs-plugin-logs", () => , { exact: true });
const { unregister: removeGameExecutionListener } = SteamClient.GameSessions.RegisterForAppLifetimeNotifications((e: LifetimeNotification) => {
- if (ApplicationState.getAppState().currentState.sync_on_game_exit === "true") {
+ if (ApplicationState.getAppState().currentState.sync_on_game_exit) {
const gameInfo = appStore.GetAppOverviewByGameID(e.unAppID)
Logger.info((e.bRunning ? "Starting" : "Stopping") + " game '" + gameInfo.display_name + "' (" + e.unAppID + ")");
- ApplicationState.setAppState("playing", String(e.bRunning));
+ ApplicationState.setAppState("playing", e.bRunning);
let sync: boolean;
if (gameInfo?.app_type === 1) { // Steam Games == 1
@@ -56,7 +53,7 @@ export default definePlugin((serverApi: ServerAPI) => {
}
if (sync) {
- let toast = ApplicationState.getAppState().currentState.toast_auto_sync === "true";
+ let toast = ApplicationState.getAppState().currentState.toast_auto_sync;
if (e.bRunning) {
if (toast) {
Toast.toast(Translator.translate("synchronizing.savedata"), 2000);
diff --git a/src/pages/ConfigurePathsPage.tsx b/src/pages/ConfigurePathsPage.tsx
index bb212fb..5fc7d50 100644
--- a/src/pages/ConfigurePathsPage.tsx
+++ b/src/pages/ConfigurePathsPage.tsx
@@ -109,14 +109,14 @@ export default function ConfigurePathsPage({ serverApi }: PageProps<{}>) {
onChange={(e) => ApplicationState.setLibSyncState(stateKey, {enabled: e}, true)}/>
ApplicationState.setLibSyncState(stateKey, {bisync: e}, true)}/>