auto-login when db upgraded

This commit is contained in:
pa
2026-03-22 20:58:22 +09:00
parent 4a8418a0b3
commit 297e81f32c
2 changed files with 139 additions and 82 deletions

View File

@@ -22,6 +22,7 @@ import { useGeneralSettingsStore } from './settings/general';
import { useModalStore } from './modal'; import { useModalStore } from './modal';
import { useUpdateLoopStore } from './updateLoop'; import { useUpdateLoopStore } from './updateLoop';
import { useUserStore } from './user'; import { useUserStore } from './user';
import { useVrcxStore } from './vrcx';
import { watchState } from '../services/watchState'; import { watchState } from '../services/watchState';
import configRepository from '../services/config'; import configRepository from '../services/config';
@@ -36,6 +37,7 @@ export const useAuthStore = defineStore('Auth', () => {
const userStore = useUserStore(); const userStore = useUserStore();
const updateLoopStore = useUpdateLoopStore(); const updateLoopStore = useUpdateLoopStore();
const modalStore = useModalStore(); const modalStore = useModalStore();
const vrcxStore = useVrcxStore();
const { t } = useI18n(); const { t } = useI18n();
const state = reactive({ const state = reactive({
@@ -177,6 +179,13 @@ export const useAuthStore = defineStore('Auth', () => {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async function autoLoginAfterMounted() { 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 ( if (
!advancedSettingsStore.enablePrimaryPassword && !advancedSettingsStore.enablePrimaryPassword &&
(await configRepository.getString('lastUserLoggedIn')) !== null (await configRepository.getString('lastUserLoggedIn')) !== null
@@ -800,6 +809,13 @@ export const useAuthStore = defineStore('Auth', () => {
* *
*/ */
async function handleAutoLogin() { 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(); await runHandleAutoLoginFlow();
} }

View File

@@ -76,6 +76,11 @@ export const useVrcxStore = defineStore('Vrcx', () => {
fromVersion: 0, fromVersion: 0,
toVersion: 0 toVersion: 0
}); });
const databaseReadyForAutoLogin = ref(false);
let resolveDatabaseInit = () => {};
const databaseInitComplete = new Promise((resolve) => {
resolveDatabaseInit = resolve;
});
const currentlyDroppingFile = ref(null); const currentlyDroppingFile = ref(null);
const isRegistryBackupDialogVisible = ref(false); const isRegistryBackupDialogVisible = ref(false);
@@ -90,93 +95,120 @@ export const useVrcxStore = defineStore('Vrcx', () => {
* *
*/ */
async function init() { async function init() {
if (LINUX) { try {
window.electron.ipcRenderer.on('launch-command', (command) => { if (LINUX) {
if (command) { try {
eventLaunchCommand(command); 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.databaseVersion = await configRepository.getInt(
state.locationX = position.x; 'VRCX_databaseVersion',
state.locationY = position.y; 0
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'
); );
} const databaseUpgradeSucceeded = await updateDatabaseVersion();
proxyServer.value = await VRCXStorage.Get('VRCX_ProxyServer'); if (!databaseUpgradeSucceeded) {
state.locationX = parseInt(await VRCXStorage.Get('VRCX_LocationX'), 10); return;
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');
maxTableSize.value = await configRepository.getInt( clearVRCXCacheFrequency.value = await configRepository.getInt(
'VRCX_maxTableSize_v2', 'VRCX_clearVRCXCacheFrequency',
DEFAULT_MAX_TABLE_SIZE 172800
); );
database.setMaxTableSize(maxTableSize.value);
searchLimit.value = await configRepository.getInt( if (!(await VRCXStorage.Get('VRCX_DatabaseLocation'))) {
'VRCX_searchLimit', await VRCXStorage.Set('VRCX_DatabaseLocation', '');
DEFAULT_SEARCH_LIMIT }
); if (!(await VRCXStorage.Get('VRCX_ProxyServer'))) {
if (searchLimit.value < SEARCH_LIMIT_MIN) { await VRCXStorage.Set('VRCX_ProxyServer', '');
searchLimit.value = SEARCH_LIMIT_MIN; }
} if ((await VRCXStorage.Get('VRCX_DisableGpuAcceleration')) === '') {
if (searchLimit.value > SEARCH_LIMIT_MAX) { await VRCXStorage.Set('VRCX_DisableGpuAcceleration', 'false');
searchLimit.value = SEARCH_LIMIT_MAX; }
} if (
database.setSearchTableSize(searchLimit.value); (
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(); resetSearchIndexOnLogin();
@@ -228,8 +260,15 @@ export const useVrcxStore = defineStore('Vrcx', () => {
dismissible: false dismissible: false
}); });
AppApi.ShowDevTools(); AppApi.ShowDevTools();
return false;
} }
} }
return true;
}
async function waitForDatabaseInit() {
await databaseInitComplete;
return databaseReadyForAutoLogin.value;
} }
/** /**
@@ -820,6 +859,7 @@ export const useVrcxStore = defineStore('Vrcx', () => {
appStartAt, appStartAt,
databaseUpgradeState, databaseUpgradeState,
databaseReadyForAutoLogin,
proxyServer, proxyServer,
setProxyServer, setProxyServer,
setIpcEnabled, setIpcEnabled,
@@ -842,6 +882,7 @@ export const useVrcxStore = defineStore('Vrcx', () => {
ipcEvent, ipcEvent,
dragEnterCef, dragEnterCef,
backupVrcRegistry, backupVrcRegistry,
updateDatabaseVersion updateDatabaseVersion,
waitForDatabaseInit
}; };
}); });