mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-04 22:06:06 +02:00
3324d0d279
* Update Vue devtools
* upgrade vue pinia element-plus vue-i18n, add vite
* fix: i18n
* global components
* change v-deep
* upgrade vue-lazyload
* data table
* update enlint and safe-dialog
* package.json and vite.config.js
* el-icon
* el-message
* vue 2 -> vue3 migration changes
* $pinia
* dialog
* el-popover slot
* lint
* chore
* slot
* scss
* remote state access
* misc
* jsconfig
* el-button size mini -> small
* :model-value
* ElMessageBox
* datatable
* remove v-lazyload
* template #dropdown
* mini -> small
* css
* byebye hideTooltips
* use sass-embedded
* Update SQLite, remove unneeded libraries
* Fix shift remove local avatar favorites
* Electron arm64
* arm64 support
* bye pug
* f-word vite hah
* misc
* remove safe dialog component
* Add self invite to launch dialog
* Fix errors
* Icons 1
* improve localfavorite loading performance
* improve favorites world item performance
* dialog visibility changes for Element Plus
* clear element plus error
* import performance
* revert App.vue hah
* hah
* Revert "Add self invite to launch dialog"
This reverts commit 4801cfad58.
* Toggle self invite/open in-game
* Self invite on launch dialog
* el-button icon
* el-icon
* fix user dialog tab switching logic
* fix PlayerList
* Formatting changes
* More icons
* Fix friend log table
* loading margin
* fix markdown
* fix world dialog tab switching issue
* Fixes and formatting
* fix: global i18n.t export
* fix favorites world tab not working
* Create instance, displayName
* Remove group members sort by userId
* Fix loading dialog tabs on swtich
* Star
* charts console.warn
* wip: fix charts
* wip: fix charts
* wip: charts composables
* fix favorite item tooltip warning
* Fixes and formatting
* Clean up image dialogs
* Remove unused method
* Fix platform/size border
* Fix platform/size border
* $vr
* fix friendExportDialogVisible binding
* ElMessageBox and Settings
* Login formatting
* Rename VR overlay query
* Fix image popover and userdialog badges
* Formatting
* Big buttons
* Fixes, update Cef
* Fix gameLog table nav buttons jumping around while using nav buttons
* Fix z-index
* vr overlay
* vite input add theme
* defineAsyncComponent
* ISO 639-1
* fix i18n
* clean t
* Formatting, fix calendar, rotate arrows
* Show user status when user is offline
* Fix VR overlay
* fix theme and clean up
* split InstanceActivity
* tweak
* Fix VR overlay formatting
* fix scss var
* AppDebug hahahaha
* Years
* remove reactive
* improve perf
* state hah…
* fix user rendering poblems when user object is not yet loaded
* improve perf
* Update avatar/world image uploader, licenses, remove previous images dialog (old images are now deleted)
* improve perf 1
* Suppress stray errors
* fix traveling location display issue
* Fix empty instance creator
* improve friend list refresh performance
* fix main charts
* fix chart
* Fix darkmode
* Fix avatar dialog tags
---------
Co-authored-by: pa <maplenagisa@gmail.com>
301 lines
9.8 KiB
JavaScript
301 lines
9.8 KiB
JavaScript
import { defineStore } from 'pinia';
|
|
import { computed, reactive } from 'vue';
|
|
import { ElMessage, ElMessageBox } from 'element-plus';
|
|
import * as workerTimers from 'worker-timers';
|
|
import configRepository from '../service/config.js';
|
|
import { database } from '../service/database';
|
|
import {
|
|
deleteVRChatCache as _deleteVRChatCache,
|
|
isRealInstance
|
|
} from '../shared/utils';
|
|
import { useAvatarStore } from './avatar';
|
|
import { useGameLogStore } from './gameLog';
|
|
import { useInstanceStore } from './instance';
|
|
import { useLaunchStore } from './launch';
|
|
import { useLocationStore } from './location';
|
|
import { useNotificationStore } from './notification';
|
|
import { useAdvancedSettingsStore } from './settings/advanced';
|
|
import { useUpdateLoopStore } from './updateLoop';
|
|
import { useUserStore } from './user';
|
|
import { useVrStore } from './vr';
|
|
import { useWorldStore } from './world';
|
|
|
|
export const useGameStore = defineStore('Game', () => {
|
|
const advancedSettingsStore = useAdvancedSettingsStore();
|
|
const locationStore = useLocationStore();
|
|
const notificationStore = useNotificationStore();
|
|
const avatarStore = useAvatarStore();
|
|
const launchStore = useLaunchStore();
|
|
const worldStore = useWorldStore();
|
|
const instanceStore = useInstanceStore();
|
|
const gameLogStore = useGameLogStore();
|
|
const vrStore = useVrStore();
|
|
const userStore = useUserStore();
|
|
const updateLoopStore = useUpdateLoopStore();
|
|
|
|
const state = reactive({
|
|
lastCrashedTime: null,
|
|
VRChatUsedCacheSize: '',
|
|
VRChatTotalCacheSize: 0,
|
|
VRChatCacheSizeLoading: false,
|
|
isGameRunning: false,
|
|
isGameNoVR: true,
|
|
isSteamVRRunning: false,
|
|
isHmdAfk: false
|
|
});
|
|
|
|
async function init() {
|
|
state.isGameNoVR = await configRepository.getBool('isGameNoVR');
|
|
}
|
|
|
|
init();
|
|
|
|
const VRChatUsedCacheSize = computed({
|
|
get: () => state.VRChatUsedCacheSize,
|
|
set: (value) => {
|
|
state.VRChatUsedCacheSize = value;
|
|
}
|
|
});
|
|
|
|
const VRChatTotalCacheSize = computed({
|
|
get: () => state.VRChatTotalCacheSize,
|
|
set: (value) => {
|
|
state.VRChatTotalCacheSize = value;
|
|
}
|
|
});
|
|
|
|
const VRChatCacheSizeLoading = computed({
|
|
get: () => state.VRChatCacheSizeLoading,
|
|
set: (value) => {
|
|
state.VRChatCacheSizeLoading = value;
|
|
}
|
|
});
|
|
|
|
const isGameRunning = computed({
|
|
get: () => state.isGameRunning,
|
|
set: (value) => {
|
|
state.isGameRunning = value;
|
|
}
|
|
});
|
|
|
|
const isGameNoVR = computed({
|
|
get: () => state.isGameNoVR,
|
|
set: (value) => {
|
|
state.isGameNoVR = value;
|
|
}
|
|
});
|
|
|
|
const isSteamVRRunning = computed({
|
|
get: () => state.isSteamVRRunning,
|
|
set: (value) => {
|
|
state.isSteamVRRunning = value;
|
|
}
|
|
});
|
|
|
|
const isHmdAfk = computed({
|
|
get: () => state.isHmdAfk,
|
|
set: (value) => {
|
|
state.isHmdAfk = value;
|
|
}
|
|
});
|
|
|
|
async function deleteVRChatCache(ref) {
|
|
await _deleteVRChatCache(ref);
|
|
getVRChatCacheSize();
|
|
worldStore.updateVRChatWorldCache();
|
|
avatarStore.updateVRChatAvatarCache();
|
|
}
|
|
|
|
function autoVRChatCacheManagement() {
|
|
if (advancedSettingsStore.autoSweepVRChatCache) {
|
|
sweepVRChatCache();
|
|
}
|
|
}
|
|
|
|
async function sweepVRChatCache() {
|
|
const output = await AssetBundleManager.SweepCache();
|
|
console.log('SweepCache', output);
|
|
if (advancedSettingsStore.isVRChatConfigDialogVisible) {
|
|
getVRChatCacheSize();
|
|
}
|
|
}
|
|
|
|
function checkIfGameCrashed() {
|
|
if (!advancedSettingsStore.relaunchVRChatAfterCrash) {
|
|
return;
|
|
}
|
|
const { location } = locationStore.lastLocation;
|
|
AppApi.VrcClosedGracefully().then((result) => {
|
|
if (result || !isRealInstance(location)) {
|
|
return;
|
|
}
|
|
// check if relaunched less than 2mins ago (prvent crash loop)
|
|
if (
|
|
state.lastCrashedTime &&
|
|
new Date().getTime() - state.lastCrashedTime.getTime() < 120_000
|
|
) {
|
|
console.log('VRChat was recently crashed, not relaunching');
|
|
return;
|
|
}
|
|
state.lastCrashedTime = new Date();
|
|
// wait a bit for SteamVR to potentially close before deciding to relaunch
|
|
let restartDelay = 8000;
|
|
if (state.isGameNoVR) {
|
|
// wait for game to close before relaunching
|
|
restartDelay = 2000;
|
|
}
|
|
workerTimers.setTimeout(
|
|
() => restartCrashedGame(location),
|
|
restartDelay
|
|
);
|
|
});
|
|
}
|
|
|
|
function restartCrashedGame(location) {
|
|
if (!state.isGameNoVR && !state.isSteamVRRunning) {
|
|
console.log("SteamVR isn't running, not relaunching VRChat");
|
|
return;
|
|
}
|
|
AppApi.FocusWindow();
|
|
const message = 'VRChat crashed, attempting to rejoin last instance';
|
|
ElMessage({
|
|
message,
|
|
type: 'info'
|
|
});
|
|
const entry = {
|
|
created_at: new Date().toJSON(),
|
|
type: 'Event',
|
|
data: message
|
|
};
|
|
database.addGamelogEventToDatabase(entry);
|
|
notificationStore.queueGameLogNoty(entry);
|
|
gameLogStore.addGameLog(entry);
|
|
launchStore.launchGame(location, '', state.isGameNoVR);
|
|
}
|
|
|
|
async function getVRChatCacheSize() {
|
|
state.VRChatCacheSizeLoading = true;
|
|
const totalCacheSize = 30;
|
|
state.VRChatTotalCacheSize = totalCacheSize;
|
|
const usedCacheSize = await AssetBundleManager.GetCacheSize();
|
|
state.VRChatUsedCacheSize = (usedCacheSize / 1073741824).toFixed(2);
|
|
state.VRChatCacheSizeLoading = false;
|
|
}
|
|
|
|
// use in C#
|
|
async function updateIsGameRunning(
|
|
isGameRunning,
|
|
isSteamVRRunning,
|
|
isHmdAfk
|
|
) {
|
|
const avatarStore = useAvatarStore();
|
|
if (advancedSettingsStore.gameLogDisabled) {
|
|
return;
|
|
}
|
|
if (isGameRunning !== state.isGameRunning) {
|
|
state.isGameRunning = isGameRunning;
|
|
if (isGameRunning) {
|
|
userStore.currentUser.$online_for = Date.now();
|
|
userStore.currentUser.$offline_for = '';
|
|
userStore.currentUser.$previousAvatarSwapTime = Date.now();
|
|
} else {
|
|
await configRepository.setBool('isGameNoVR', state.isGameNoVR);
|
|
userStore.currentUser.$online_for = 0;
|
|
userStore.currentUser.$offline_for = Date.now();
|
|
instanceStore.removeAllQueuedInstances();
|
|
autoVRChatCacheManagement();
|
|
checkIfGameCrashed();
|
|
updateLoopStore.ipcTimeout = 0;
|
|
avatarStore.addAvatarWearTime(
|
|
userStore.currentUser.currentAvatar
|
|
);
|
|
userStore.currentUser.$previousAvatarSwapTime = '';
|
|
}
|
|
locationStore.lastLocationReset();
|
|
gameLogStore.clearNowPlaying();
|
|
vrStore.updateVRLastLocation();
|
|
workerTimers.setTimeout(() => checkVRChatDebugLogging(), 60000);
|
|
updateLoopStore.nextDiscordUpdate = 0;
|
|
console.log(new Date(), 'isGameRunning', isGameRunning);
|
|
}
|
|
|
|
if (isSteamVRRunning !== state.isSteamVRRunning) {
|
|
state.isSteamVRRunning = isSteamVRRunning;
|
|
console.log('isSteamVRRunning:', isSteamVRRunning);
|
|
}
|
|
if (isHmdAfk !== state.isHmdAfk) {
|
|
state.isHmdAfk = isHmdAfk;
|
|
console.log('isHmdAfk:', isHmdAfk);
|
|
}
|
|
vrStore.updateOpenVR();
|
|
}
|
|
|
|
async function checkVRChatDebugLogging() {
|
|
if (advancedSettingsStore.gameLogDisabled) {
|
|
return;
|
|
}
|
|
try {
|
|
const loggingEnabled =
|
|
await getVRChatRegistryKey('LOGGING_ENABLED');
|
|
if (
|
|
loggingEnabled === null ||
|
|
typeof loggingEnabled === 'undefined'
|
|
) {
|
|
// key not found
|
|
return;
|
|
}
|
|
if (parseInt(loggingEnabled, 10) === 1) {
|
|
// already enabled
|
|
return;
|
|
}
|
|
const result = await AppApi.SetVRChatRegistryKey(
|
|
'LOGGING_ENABLED',
|
|
'1',
|
|
4
|
|
);
|
|
if (!result) {
|
|
// failed to set key
|
|
ElMessageBox.alert(
|
|
'VRCX has noticed VRChat debug logging is disabled. VRCX requires debug logging in order to function correctly. Please enable debug logging in VRChat quick menu settings > debug > enable debug logging, then rejoin the instance or restart VRChat.',
|
|
'Enable debug logging'
|
|
);
|
|
console.error('Failed to enable debug logging', result);
|
|
return;
|
|
}
|
|
ElMessageBox.alert(
|
|
'VRCX has noticed VRChat debug logging is disabled and automatically re-enabled it. VRCX requires debug logging in order to function correctly.',
|
|
'Enabled debug logging'
|
|
);
|
|
console.log('Enabled debug logging');
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
}
|
|
|
|
async function getVRChatRegistryKey(key) {
|
|
if (LINUX) {
|
|
return AppApi.GetVRChatRegistryKeyString(key);
|
|
}
|
|
return AppApi.GetVRChatRegistryKey(key);
|
|
}
|
|
|
|
return {
|
|
state,
|
|
|
|
VRChatUsedCacheSize,
|
|
VRChatTotalCacheSize,
|
|
VRChatCacheSizeLoading,
|
|
isGameRunning,
|
|
isGameNoVR,
|
|
isSteamVRRunning,
|
|
isHmdAfk,
|
|
|
|
deleteVRChatCache,
|
|
sweepVRChatCache,
|
|
getVRChatCacheSize,
|
|
updateIsGameRunning,
|
|
getVRChatRegistryKey,
|
|
checkVRChatDebugLogging
|
|
};
|
|
});
|