This commit is contained in:
Natsumi
2025-08-27 12:15:24 +12:00
parent 21dcc51e83
commit 23053c1339
3 changed files with 59 additions and 34 deletions
+24 -21
View File
@@ -14,19 +14,8 @@ const { spawn, spawnSync } = require('child_process');
const fs = require('fs'); const fs = require('fs');
const https = require('https'); const https = require('https');
const VRCX_URI_PREFIX = "vrcx"
//app.disableHardwareAcceleration(); //app.disableHardwareAcceleration();
if (process.defaultApp) {
if (process.argv.length >= 2) {
app.setAsDefaultProtocolClient(VRCX_URI_PREFIX, process.execPath, [path.resolve(process.argv[1])])
} else {
app.setAsDefaultProtocolClient(VRCX_URI_PREFIX)
}
}
if (process.platform === 'linux') { if (process.platform === 'linux') {
// Include bundled .NET runtime // Include bundled .NET runtime
const bundledDotNetPath = path.join( const bundledDotNetPath = path.join(
@@ -59,6 +48,7 @@ if (!isDotNetInstalled()) {
}); });
} }
const VRCX_URI_PREFIX = 'vrcx';
let isOverlayActive = false; let isOverlayActive = false;
let appIsQuitting = false; let appIsQuitting = false;
@@ -69,6 +59,15 @@ const noInstall = args.includes('--no-install');
const x11 = args.includes('--x11'); const x11 = args.includes('--x11');
const noDesktop = args.includes('--no-desktop'); const noDesktop = args.includes('--no-desktop');
const startup = args.includes('--startup'); const startup = args.includes('--startup');
if (process.defaultApp) {
if (process.argv.length >= 2) {
app.setAsDefaultProtocolClient(VRCX_URI_PREFIX, process.execPath, [
path.resolve(process.argv[1])
]);
} else {
app.setAsDefaultProtocolClient(VRCX_URI_PREFIX);
}
}
const homePath = getHomePath(); const homePath = getHomePath();
tryRelaunchWithArgs(args); tryRelaunchWithArgs(args);
@@ -108,7 +107,6 @@ interopApi.getDotNetObject('Discord').Init();
interopApi.getDotNetObject('WebApi').Init(); interopApi.getDotNetObject('WebApi').Init();
interopApi.getDotNetObject('LogWatcher').Init(); interopApi.getDotNetObject('LogWatcher').Init();
interopApi.getDotNetObject('IPCServer').Init();
interopApi.getDotNetObject('SystemMonitorElectron').Init(); interopApi.getDotNetObject('SystemMonitorElectron').Init();
interopApi.getDotNetObject('AppApiVrElectron').Init(); interopApi.getDotNetObject('AppApiVrElectron').Init();
@@ -124,26 +122,31 @@ const hasAskedToMoveAppImage =
VRCXStorage.Get('VRCX_HasAskedToMoveAppImage') === 'true'; VRCXStorage.Get('VRCX_HasAskedToMoveAppImage') === 'true';
let isCloseToTray = VRCXStorage.Get('VRCX_CloseToTray') === 'true'; let isCloseToTray = VRCXStorage.Get('VRCX_CloseToTray') === 'true';
const gotTheLock = app.requestSingleInstanceLock() const gotTheLock = app.requestSingleInstanceLock();
const strip_vrcx_prefix_regex = new RegExp("^" + VRCX_URI_PREFIX + ":\/\/") const strip_vrcx_prefix_regex = new RegExp('^' + VRCX_URI_PREFIX + '://');
if (!gotTheLock) { if (!gotTheLock) {
app.quit() app.quit();
} else { } else {
app.on('second-instance', (event, commandLine, workingDirectory) => { app.on('second-instance', (event, commandLine, workingDirectory) => {
if (mainWindow && commandLine.length >= 2) { if (mainWindow && commandLine.length >= 2) {
mainWindow.webContents.send('launch-command', commandLine.pop().trim().replace(strip_vrcx_prefix_regex, "")) mainWindow.webContents.send(
'launch-command',
commandLine.pop().trim().replace(strip_vrcx_prefix_regex, '')
);
} }
}) });
app.on('open-url', (event, url) => { app.on('open-url', (event, url) => {
if (mainWindow && url) { if (mainWindow && url) {
mainWindow.webContents.send('launch-command', url.replace(strip_vrcx_prefix_regex, "")) mainWindow.webContents.send(
'launch-command',
url.replace(strip_vrcx_prefix_regex, '')
);
} }
}) });
} }
ipcMain.handle('applyWindowSettings', (event, position, size, state) => { ipcMain.handle('applyWindowSettings', (event, position, size, state) => {
if (position) { if (position) {
mainWindow.setPosition(parseInt(position.x), parseInt(position.y)); mainWindow.setPosition(parseInt(position.x), parseInt(position.y));
@@ -302,7 +305,7 @@ function createWindow() {
icon: path.join(rootDir, 'VRCX.png'), icon: path.join(rootDir, 'VRCX.png'),
autoHideMenuBar: true, autoHideMenuBar: true,
webPreferences: { webPreferences: {
preload: path.join(__dirname, 'preload.js'), preload: path.join(__dirname, 'preload.js')
} }
}); });
applyWindowState(); applyWindowState();
+14 -9
View File
@@ -19,9 +19,7 @@ contextBridge.exposeInMainWorld('interopApi', {
} }
}); });
const validChannels = ['launch-command'];
const validChannels = ['launch-command']
contextBridge.exposeInMainWorld('electron', { contextBridge.exposeInMainWorld('electron', {
openFileDialog: () => ipcRenderer.invoke('dialog:openFile'), openFileDialog: () => ipcRenderer.invoke('dialog:openFile'),
@@ -35,17 +33,24 @@ contextBridge.exposeInMainWorld('electron', {
desktopNotification: (title, body, icon) => desktopNotification: (title, body, icon) =>
ipcRenderer.invoke('notification:showNotification', title, body, icon), ipcRenderer.invoke('notification:showNotification', title, body, icon),
restartApp: () => ipcRenderer.invoke('app:restart'), restartApp: () => ipcRenderer.invoke('app:restart'),
getWristOverlayWindow: () => ipcRenderer.invoke('app:getWristOverlayWindow'), getWristOverlayWindow: () =>
ipcRenderer.invoke('app:getWristOverlayWindow'),
getHmdOverlayWindow: () => ipcRenderer.invoke('app:getHmdOverlayWindow'), getHmdOverlayWindow: () => ipcRenderer.invoke('app:getHmdOverlayWindow'),
updateVr: (active, hmdOverlay, wristOverlay, menuButton, overlayHand) => updateVr: (active, hmdOverlay, wristOverlay, menuButton, overlayHand) =>
ipcRenderer.invoke('app:updateVr', active, hmdOverlay, wristOverlay, menuButton, overlayHand), ipcRenderer.invoke(
'app:updateVr',
active,
hmdOverlay,
wristOverlay,
menuButton,
overlayHand
),
ipcRenderer: { ipcRenderer: {
on(channel, func) { on(channel, func) {
if (validChannels.includes(channel)) { if (validChannels.includes(channel)) {
console.log("contextBridge", channel, func) console.log('contextBridge', channel, func);
ipcRenderer.on(channel, (event, ...args) => func(...args)); ipcRenderer.on(channel, (event, ...args) => func(...args));
} }
}, }
} }
}); });
+21 -4
View File
@@ -65,6 +65,12 @@ export const useVrcxStore = defineStore('Vrcx', () => {
async function init() { async function init() {
if (LINUX) { if (LINUX) {
window.electron.ipcRenderer.on('launch-command', (command) => {
if (command) {
eventLaunchCommand(command);
}
});
window.electron.onWindowPositionChanged((event, position) => { window.electron.onWindowPositionChanged((event, position) => {
state.locationX = position.x; state.locationX = position.x;
state.locationY = position.y; state.locationY = position.y;
@@ -516,6 +522,12 @@ export const useVrcxStore = defineStore('Vrcx', () => {
case 'MsgPing': case 'MsgPing':
state.externalNotifierVersion = data.version; state.externalNotifierVersion = data.version;
break; break;
case 'LaunchCommand':
eventLaunchCommand(data.command);
break;
case 'VRCXLaunch':
console.log('VRCXLaunch:', data);
break;
default: default:
console.log('IPC:', data); console.log('IPC:', data);
} }
@@ -532,17 +544,22 @@ export const useVrcxStore = defineStore('Vrcx', () => {
watch( watch(
() => watchState.isLoggedIn, () => watchState.isLoggedIn,
(_isLoggedIn) => { (isLoggedIn) => {
state.isRegistryBackupDialogVisible = false; state.isRegistryBackupDialogVisible = false;
if (isLoggedIn) {
startupLaunchCommand();
}
}, },
{ flush: 'sync' } { flush: 'sync' }
); );
window.electron.ipcRenderer.on('launch-command', (command) => { async function startupLaunchCommand() {
const command = await AppApi.GetLaunchCommand();
if (command) { if (command) {
eventLaunchCommand(command) eventLaunchCommand(command);
} }
}) }
function eventLaunchCommand(input) { function eventLaunchCommand(input) {
if (!watchState.isLoggedIn) { if (!watchState.isLoggedIn) {
return; return;