diff --git a/src/stores/auth.js b/src/stores/auth.js index e8099880..b8e04170 100644 --- a/src/stores/auth.js +++ b/src/stores/auth.js @@ -22,6 +22,7 @@ import { useGeneralSettingsStore } from './settings/general'; import { useModalStore } from './modal'; import { useUpdateLoopStore } from './updateLoop'; import { useUserStore } from './user'; +import { useVrcxStore } from './vrcx'; import { watchState } from '../services/watchState'; import configRepository from '../services/config'; @@ -36,6 +37,7 @@ export const useAuthStore = defineStore('Auth', () => { const userStore = useUserStore(); const updateLoopStore = useUpdateLoopStore(); const modalStore = useModalStore(); + const vrcxStore = useVrcxStore(); const { t } = useI18n(); const state = reactive({ @@ -177,6 +179,13 @@ export const useAuthStore = defineStore('Auth', () => { * @returns {Promise} */ async function autoLoginAfterMounted() { + const canAutoLogin = await vrcxStore.waitForDatabaseInit(); + if (!canAutoLogin) { + console.warn( + 'Skipping auto-login after mount because database initialization did not complete successfully.' + ); + return; + } if ( !advancedSettingsStore.enablePrimaryPassword && (await configRepository.getString('lastUserLoggedIn')) !== null @@ -800,6 +809,13 @@ export const useAuthStore = defineStore('Auth', () => { * */ async function handleAutoLogin() { + const canAutoLogin = await vrcxStore.waitForDatabaseInit(); + if (!canAutoLogin) { + console.warn( + 'Skipping auto-login because database initialization did not complete successfully.' + ); + return; + } await runHandleAutoLoginFlow(); } diff --git a/src/stores/vrcx.js b/src/stores/vrcx.js index 8da316fe..a8b89055 100644 --- a/src/stores/vrcx.js +++ b/src/stores/vrcx.js @@ -76,6 +76,11 @@ export const useVrcxStore = defineStore('Vrcx', () => { fromVersion: 0, toVersion: 0 }); + const databaseReadyForAutoLogin = ref(false); + let resolveDatabaseInit = () => {}; + const databaseInitComplete = new Promise((resolve) => { + resolveDatabaseInit = resolve; + }); const currentlyDroppingFile = ref(null); const isRegistryBackupDialogVisible = ref(false); @@ -90,93 +95,120 @@ export const useVrcxStore = defineStore('Vrcx', () => { * */ async function init() { - if (LINUX) { - window.electron.ipcRenderer.on('launch-command', (command) => { - if (command) { - eventLaunchCommand(command); + try { + if (LINUX) { + try { + window.electron.ipcRenderer.on('launch-command', (command) => { + if (command) { + eventLaunchCommand(command); + } + }); + + window.electron.onWindowPositionChanged((event, position) => { + state.locationX = position.x; + state.locationY = position.y; + debounce(saveVRCXWindowOption, 300)(); + }); + + window.electron.onWindowSizeChanged((event, size) => { + state.sizeWidth = size.width; + state.sizeHeight = size.height; + debounce(saveVRCXWindowOption, 300)(); + }); + + window.electron.onWindowStateChange((event, newState) => { + state.windowState = newState.toString(); + debounce(saveVRCXWindowOption, 300)(); + }); + + window.electron.onBrowserFocus(() => { + vrcStatusStore.onBrowserFocus(); + }); + } catch (err) { + console.error( + 'Failed to register Linux IPC handlers:', + err + ); } - }); + } - window.electron.onWindowPositionChanged((event, position) => { - state.locationX = position.x; - state.locationY = position.y; - debounce(saveVRCXWindowOption, 300)(); - }); - - window.electron.onWindowSizeChanged((event, size) => { - state.sizeWidth = size.width; - state.sizeHeight = size.height; - debounce(saveVRCXWindowOption, 300)(); - }); - - window.electron.onWindowStateChange((event, newState) => { - state.windowState = newState.toString(); - debounce(saveVRCXWindowOption, 300)(); - }); - - window.electron.onBrowserFocus(() => { - vrcStatusStore.onBrowserFocus(); - }); - } - - state.databaseVersion = await configRepository.getInt( - 'VRCX_databaseVersion', - 0 - ); - updateDatabaseVersion(); - - clearVRCXCacheFrequency.value = await configRepository.getInt( - 'VRCX_clearVRCXCacheFrequency', - 172800 - ); - - if (!(await VRCXStorage.Get('VRCX_DatabaseLocation'))) { - await VRCXStorage.Set('VRCX_DatabaseLocation', ''); - } - if (!(await VRCXStorage.Get('VRCX_ProxyServer'))) { - await VRCXStorage.Set('VRCX_ProxyServer', ''); - } - if ((await VRCXStorage.Get('VRCX_DisableGpuAcceleration')) === '') { - await VRCXStorage.Set('VRCX_DisableGpuAcceleration', 'false'); - } - if ( - (await VRCXStorage.Get('VRCX_DisableVrOverlayGpuAcceleration')) === - '' - ) { - await VRCXStorage.Set( - 'VRCX_DisableVrOverlayGpuAcceleration', - 'false' + state.databaseVersion = await configRepository.getInt( + 'VRCX_databaseVersion', + 0 ); - } - proxyServer.value = await VRCXStorage.Get('VRCX_ProxyServer'); - state.locationX = parseInt(await VRCXStorage.Get('VRCX_LocationX'), 10); - state.locationY = parseInt(await VRCXStorage.Get('VRCX_LocationY'), 10); - state.sizeWidth = parseInt(await VRCXStorage.Get('VRCX_SizeWidth'), 10); - state.sizeHeight = parseInt( - await VRCXStorage.Get('VRCX_SizeHeight'), - 10 - ); - state.windowState = await VRCXStorage.Get('VRCX_WindowState'); + const databaseUpgradeSucceeded = await updateDatabaseVersion(); + if (!databaseUpgradeSucceeded) { + return; + } - maxTableSize.value = await configRepository.getInt( - 'VRCX_maxTableSize_v2', - DEFAULT_MAX_TABLE_SIZE - ); - database.setMaxTableSize(maxTableSize.value); + clearVRCXCacheFrequency.value = await configRepository.getInt( + 'VRCX_clearVRCXCacheFrequency', + 172800 + ); - searchLimit.value = await configRepository.getInt( - 'VRCX_searchLimit', - DEFAULT_SEARCH_LIMIT - ); - if (searchLimit.value < SEARCH_LIMIT_MIN) { - searchLimit.value = SEARCH_LIMIT_MIN; - } - if (searchLimit.value > SEARCH_LIMIT_MAX) { - searchLimit.value = SEARCH_LIMIT_MAX; - } - database.setSearchTableSize(searchLimit.value); + if (!(await VRCXStorage.Get('VRCX_DatabaseLocation'))) { + await VRCXStorage.Set('VRCX_DatabaseLocation', ''); + } + if (!(await VRCXStorage.Get('VRCX_ProxyServer'))) { + await VRCXStorage.Set('VRCX_ProxyServer', ''); + } + if ((await VRCXStorage.Get('VRCX_DisableGpuAcceleration')) === '') { + await VRCXStorage.Set('VRCX_DisableGpuAcceleration', 'false'); + } + if ( + ( + await VRCXStorage.Get( + 'VRCX_DisableVrOverlayGpuAcceleration' + ) + ) === '' + ) { + await VRCXStorage.Set( + 'VRCX_DisableVrOverlayGpuAcceleration', + 'false' + ); + } + proxyServer.value = await VRCXStorage.Get('VRCX_ProxyServer'); + state.locationX = parseInt( + await VRCXStorage.Get('VRCX_LocationX'), + 10 + ); + state.locationY = parseInt( + await VRCXStorage.Get('VRCX_LocationY'), + 10 + ); + state.sizeWidth = parseInt( + await VRCXStorage.Get('VRCX_SizeWidth'), + 10 + ); + state.sizeHeight = parseInt( + await VRCXStorage.Get('VRCX_SizeHeight'), + 10 + ); + state.windowState = await VRCXStorage.Get('VRCX_WindowState'); - refreshCustomScript(); + maxTableSize.value = await configRepository.getInt( + 'VRCX_maxTableSize_v2', + DEFAULT_MAX_TABLE_SIZE + ); + database.setMaxTableSize(maxTableSize.value); + + searchLimit.value = await configRepository.getInt( + 'VRCX_searchLimit', + DEFAULT_SEARCH_LIMIT + ); + if (searchLimit.value < SEARCH_LIMIT_MIN) { + searchLimit.value = SEARCH_LIMIT_MIN; + } + if (searchLimit.value > SEARCH_LIMIT_MAX) { + searchLimit.value = SEARCH_LIMIT_MAX; + } + database.setSearchTableSize(searchLimit.value); + + refreshCustomScript(); + databaseReadyForAutoLogin.value = true; + } finally { + resolveDatabaseInit(); + } } resetSearchIndexOnLogin(); @@ -228,8 +260,15 @@ export const useVrcxStore = defineStore('Vrcx', () => { dismissible: false }); AppApi.ShowDevTools(); + return false; } } + return true; + } + + async function waitForDatabaseInit() { + await databaseInitComplete; + return databaseReadyForAutoLogin.value; } /** @@ -820,6 +859,7 @@ export const useVrcxStore = defineStore('Vrcx', () => { appStartAt, databaseUpgradeState, + databaseReadyForAutoLogin, proxyServer, setProxyServer, setIpcEnabled, @@ -842,6 +882,7 @@ export const useVrcxStore = defineStore('Vrcx', () => { ipcEvent, dragEnterCef, backupVrcRegistry, - updateDatabaseVersion + updateDatabaseVersion, + waitForDatabaseInit }; });