Skip to content

Commit

Permalink
Add CHECK_SWIFTRAY handler (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkdkwizard authored Nov 4, 2024
1 parent fb54067 commit 55a7df2
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/node/backend-manager.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import EventEmitter from 'events';
import fs from 'fs'
import os from 'os';
import path from 'path';
import WebSocket from 'ws';
import { ChildProcess, spawn } from 'child_process';

import WebSocket from 'ws';
// eslint-disable-next-line import/no-extraneous-dependencies
import { app } from 'electron';
import { app, ipcMain } from 'electron';

import EventEmitter from 'events';



function uglyJsonParser(data: string): any {
try {
Expand Down Expand Up @@ -91,6 +95,10 @@ class BackendManager extends EventEmitter {
this.proc = undefined;
this.ws = undefined;
this.wsConn = undefined;
ipcMain.on('CHECK_SWIFTRAY', (event) => {
// eslint-disable-next-line no-param-reassign
event.returnValue = this.checkSwiftrayExists();
});
}

setRecover(): void {
Expand Down Expand Up @@ -168,6 +176,23 @@ class BackendManager extends EventEmitter {
});
}

checkSwiftrayExists = (): boolean => {
if (!process.env.BACKEND_ROOT) return false;
let swiftrayDir: string;
let swiftrayExec: string;
if (os.platform() === 'win32') {
swiftrayDir = path.join(process.env.BACKEND_ROOT, 'swiftray');
swiftrayExec = 'swiftray.exe';
} else if (os.platform() === 'darwin') {
swiftrayDir = path.join(process.env.BACKEND_ROOT, 'Swiftray.app', 'Contents', 'MacOS');
swiftrayExec = 'Swiftray';
} else {
console.error('checkSwiftrayExists: Unsupported platform');
return false;
}
return fs.existsSync(path.join(swiftrayDir, swiftrayExec));
}

spawnSwiftray(): void {
if (!process.env.BACKEND_ROOT) {
console.error('spawnSwiftray: BACKEND_ROOT not set');
Expand Down

0 comments on commit 55a7df2

Please sign in to comment.