Desktop state persistence

This commit is contained in:
Igor Katson 2023-12-07 00:13:11 +00:00
parent d258a9afe2
commit 53868ad45e
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
7 changed files with 171 additions and 79 deletions

View file

@ -43,3 +43,8 @@ export interface RqbitDesktopConfig {
peer_opts: RqbitDesktopConfigPeerOpts;
http_api: RqbitDesktopConfigHttpApi;
}
export interface CurrentDesktopState {
config: RqbitDesktopConfig | null,
configured: boolean,
}

View file

@ -164,6 +164,7 @@ export const ConfigModal: React.FC<{
name="dht.disable_persistence"
checked={!config.dht.disable_persistence}
onChange={handleToggleChange}
disabled={config.dht.disable}
help="Enable to store DHT state in a file periodically. If disabled, DHT will bootstrap from scratch on restart."
/>
@ -172,6 +173,7 @@ export const ConfigModal: React.FC<{
name="dht.persistence_filename"
value={config.dht.persistence_filename}
inputType="text"
disabled={config.dht.disable}
onChange={handleInputChange}
help="The filename to store DHT state into"
/>

View file

@ -3,7 +3,7 @@ import ReactDOM from 'react-dom/client';
import { APIContext, RqbitWebUI } from "./rqbit-webui-src/rqbit-web";
import { API } from "./api";
import { invoke } from "@tauri-apps/api";
import { RqbitDesktopConfig } from "./configuration";
import { CurrentDesktopState, RqbitDesktopConfig } from "./configuration";
import { RqbitDesktop } from "./rqbit-desktop";
async function get_version(): Promise<string> {
@ -14,11 +14,15 @@ async function get_default_config(): Promise<RqbitDesktopConfig> {
return invoke<RqbitDesktopConfig>("config_default");
}
Promise.all([get_version(), get_default_config()]).then(([version, config]) => {
async function get_current_config(): Promise<CurrentDesktopState> {
return invoke<CurrentDesktopState>("config_current");
}
Promise.all([get_version(), get_default_config(), get_current_config()]).then(([version, defaultConfig, currentState]) => {
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<StrictMode>
<APIContext.Provider value={API}>
<RqbitDesktop version={version} defaultConfig={config} />
<RqbitDesktop version={version} defaultConfig={defaultConfig} currentState={currentState} />
</APIContext.Provider>
</StrictMode>
);

View file

@ -1,15 +1,16 @@
import { useState } from "react";
import { RqbitWebUI } from "./rqbit-webui-src/rqbit-web";
import { RqbitDesktopConfig } from "./configuration";
import { CurrentDesktopState, RqbitDesktopConfig } from "./configuration";
import { ConfigModal } from "./configure";
export const RqbitDesktop: React.FC<{
version: string,
defaultConfig: RqbitDesktopConfig,
}> = ({ version, defaultConfig }) => {
let [configured, setConfigured] = useState<boolean>(false);
let [config, setConfig] = useState<RqbitDesktopConfig>(defaultConfig);
currentState: CurrentDesktopState,
}> = ({ version, defaultConfig, currentState }) => {
let [configured, setConfigured] = useState<boolean>(currentState.configured);
let [config, setConfig] = useState<RqbitDesktopConfig>(currentState.config ?? defaultConfig);
let [configurationOpened, setConfigurationOpened] = useState<boolean>(false);
return <>