Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CHECK_SWIFTRAY handler #313

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading