diff --git a/backend/src/config_util.rs b/backend/src/config_util.rs index 9ca8c88..f3b3d9e 100644 --- a/backend/src/config_util.rs +++ b/backend/src/config_util.rs @@ -127,6 +127,7 @@ pub struct ProxyAuth { // Enums /// Specifies which fields in the configuration are being updated. pub enum ConfigUpdate { + Default, Config(Box), Region(String), Auth(String), @@ -178,6 +179,7 @@ pub async fn update_config(update: ConfigUpdate) { let mut new_config = get_config().as_ref().clone(); match update { + ConfigUpdate::Default => new_config = UFCRConfig::default(), ConfigUpdate::Config(data) => new_config = *data, ConfigUpdate::Region(data) => new_config.region = data, ConfigUpdate::Auth(data) => new_config.auth_token = data, diff --git a/backend/src/ws_util.rs b/backend/src/ws_util.rs index 09974c3..6f3bc34 100644 --- a/backend/src/ws_util.rs +++ b/backend/src/ws_util.rs @@ -18,11 +18,11 @@ use ufcr_libs::{log_err, log_info}; use crate::{ app_util::{check_app_update, get_app_metadata}, bin_util::{cancel_download, get_vod_formats, start_download, validate_bins}, - config_util::{ConfigUpdate, get_config, is_debug, UFCRConfig, update_config}, + config_util::{get_config, is_debug, update_config, ConfigUpdate, UFCRConfig}, fs_util::open_downloads_dir, net_util::{ - download_media_tools, get_vod_meta, get_vod_stream_url, JSON, JsonTryGet, - login_to_fight_pass, search_vods, update_proxied_client, + download_media_tools, get_vod_meta, get_vod_stream_url, login_to_fight_pass, search_vods, + update_proxied_client, JsonTryGet, JSON, }, rt_util::QuitUnwrap, state_util::{clear_inactive_dlq_vods, get_dlq, Vod}, @@ -60,6 +60,8 @@ fn handle_ws_client(socket: &SocketRef) { socket.on("save-config", handle_save_config_event); + socket.on("reset-config", handle_reset_config_event); + socket.on("get-dlq", |ack: AckSender| { ack.send(get_dlq().clone()).ok(); }); @@ -192,6 +194,16 @@ async fn handle_save_config_event(ack: AckSender, Data(data): Data) { } } +/// Handles the `reset-config` WS event. +async fn handle_reset_config_event(ack: AckSender) { + update_config(ConfigUpdate::Default).await; + ack.send(get_config().as_ref()).ok(); + + if let Err(error) = update_proxied_client() { + emit_error(error); + } +} + /// Handles the `get-media-tools` WS event. async fn handle_get_media_tools_event(socket: SocketRef, ack: AckSender, Data(data): Data) { if let Ok(missing_tools) = serde_json::from_value::>(data) { @@ -285,7 +297,7 @@ async fn handle_get_playable_event(ack: AckSender, Data(data): Data) { Ok(hls) => { vod.hls = hls; vod.q_id = create_uuid(); - + ack.send(vod).ok(); } Err(error) => send_error(ack, error), diff --git a/frontend/src/components/ModConfig.vue b/frontend/src/components/ModConfig.vue index 33e7e05..458504c 100644 --- a/frontend/src/components/ModConfig.vue +++ b/frontend/src/components/ModConfig.vue @@ -104,12 +104,21 @@ +
@@ -469,6 +478,17 @@ Save + + + This process will reset all of the configurations to default and log you out of the currently logged in Fight Pass + account. Are you sure you want to continue? + @@ -481,6 +501,7 @@ import {useAppStore} from '@/store'; import {useWSUtil} from '@/modules/ws-util'; // Components import VAnchor from '@/components/VAnchor.vue'; +import ModMsgBox from '@/components/ModMsgBox.vue'; // Store const store = useAppStore(); @@ -495,7 +516,7 @@ const fail = (error) => { }; // Websocket -const {login, saveConfig} = useWSUtil(); +const {login, resetConfig, saveConfig} = useWSUtil(); // Account const txtEmail = ref(''); @@ -542,6 +563,16 @@ function onConfigFileExport() { window.location.href = '/export_config'; } +// Config reset +function onConfigReset() { + resetConfig() + .then(() => { + store.popSuccess('Configuration was successfully reset to default'); + window.ui('#modConfig'); + }) + .catch(fail); +} + // Misc functions function save(config) { saveConfig(config || modConfig.data) diff --git a/frontend/src/modules/ws-util.js b/frontend/src/modules/ws-util.js index 14c2391..3022eda 100644 --- a/frontend/src/modules/ws-util.js +++ b/frontend/src/modules/ws-util.js @@ -98,6 +98,10 @@ export function useWSUtil() { store.config = await emitPromise('save-config', newConfig); } + async function resetConfig() { + store.config = await emitPromise('reset-config'); + } + async function login(region, email, pass) { store.config = await emitPromise('login', region, email, pass); } @@ -170,6 +174,7 @@ export function useWSUtil() { initSocket, getConfig, saveConfig, + resetConfig, login, verifyURL, getPlayableVOD, diff --git a/frontend/src/store/index.js b/frontend/src/store/index.js index fe2fafb..a0977f4 100644 --- a/frontend/src/store/index.js +++ b/frontend/src/store/index.js @@ -95,6 +95,9 @@ export const useAppStore = defineStore('app', { showModUpdatePrompt() { window.ui('#modUpdatePrompt'); }, + showModConfigResetPrompt() { + window.ui('#modConfigResetPrompt'); + }, showModConfig() { this.modals.modConfig.data = JSON.parse(JSON.stringify(this.config)); window.ui('#modConfig');