diff options
author | Rémy Raes <contact@remyraes.com> | 2023-04-16 19:41:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-16 19:41:26 +0200 |
commit | 05f39a0cf0c2f5b00dcbc44e7b3fb9e228343c90 (patch) | |
tree | 0b9d5c98939ae73ed38b34a7531c018bec533c02 /src-vue/src/plugins | |
parent | e38ac9a343dca4a5cdc15b255b287473c26c6c8e (diff) | |
download | FlightCore-05f39a0cf0c2f5b00dcbc44e7b3fb9e228343c90.tar.gz FlightCore-05f39a0cf0c2f5b00dcbc44e7b3fb9e228343c90.zip |
feat: Persist dev mode (#265)
* feat: store dev mode state in persistent store
* feat: display dev view on app launch if it was previously activated
* refactor: separate debug and developper modes activation
* docs: update debug/dev modes comment
Diffstat (limited to 'src-vue/src/plugins')
-rw-r--r-- | src-vue/src/plugins/store.ts | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src-vue/src/plugins/store.ts b/src-vue/src/plugins/store.ts index 6f878277..00b8f35a 100644 --- a/src-vue/src/plugins/store.ts +++ b/src-vue/src/plugins/store.ts @@ -89,7 +89,13 @@ export const store = createStore<FlightCoreStore>({ checkNorthstarUpdates(state) { _get_northstar_version_number(state); }, - toggleDeveloperMode(state, affectMenuStyle = false) { + async toggleDebugMode(_state) { + let menu_bar_handle = document.querySelector('#fc_menu-bar'); + if (menu_bar_handle !== null) { + menu_bar_handle.classList.toggle('developer_build'); + } + }, + async toggleDeveloperMode(state) { state.developer_mode = !state.developer_mode; // Reset tab when closing dev mode. @@ -97,10 +103,9 @@ export const store = createStore<FlightCoreStore>({ store.commit('updateCurrentTab', Tabs.PLAY); } - let menu_bar_handle = document.querySelector('#fc_menu-bar'); - if (affectMenuStyle && menu_bar_handle !== null) { - menu_bar_handle.classList.toggle('developer_build'); - } + // Save dev mode state in persistent store + await persistentStore.set('dev_mode', state.developer_mode); + await persistentStore.save(); }, initialize(state) { _initializeApp(state); @@ -337,11 +342,18 @@ export const store = createStore<FlightCoreStore>({ * It invokes all Rust methods that are needed to initialize UI. */ async function _initializeApp(state: any) { - // Enable dev mode directly if application is in debug mode - if (await invoke("is_debug_mode")) { - store.commit('toggleDeveloperMode', true); - } else { - // Disable context menu in release build. + // Display dev view if dev mode was previously enabled. + const devModeEnabled: boolean = await persistentStore.get('dev_mode') ?? false; + const debugModeEnabled: boolean = await invoke("is_debug_mode"); + if (devModeEnabled) { + store.commit('toggleDeveloperMode'); + } + if (debugModeEnabled) { + store.commit('toggleDebugMode'); + } + + // Disable context menu in release build. + if (!debugModeEnabled) { document.addEventListener('contextmenu', event => event.preventDefault()); } |