This commit is contained in:
Timothy Jaeryang Baek 2025-01-14 00:50:00 -08:00
parent 347ff2aa18
commit 77b6706add
2 changed files with 39 additions and 38 deletions

View File

@ -99,34 +99,34 @@ if (!gotTheLock) {
...(SERVER_STATUS === 'started'
? [
{
label: 'Stop Server',
click: async () => {
await stopAllServers();
SERVER_STATUS = 'stopped';
mainWindow.webContents.send('main:data', {
type: 'server:status',
data: SERVER_STATUS
});
updateTrayMenu('Open WebUI: Stopped', null); // Update tray menu with stopped status
}
}
]
: SERVER_STATUS === 'starting'
? [
{
label: 'Starting Server...',
enabled: false
}
]
: [
{
label: 'Start Server',
label: 'Stop Server',
click: async () => {
await startServerHandler();
await stopAllServers();
SERVER_STATUS = 'stopped';
mainWindow.webContents.send('main:data', {
type: 'server:status',
data: SERVER_STATUS
});
updateTrayMenu('Open WebUI: Stopped', null); // Update tray menu with stopped status
}
}
]),
]
: SERVER_STATUS === 'starting'
? [
{
label: 'Starting Server...',
enabled: false
}
]
: [
{
label: 'Start Server',
click: async () => {
await startServerHandler();
}
}
]),
{
type: 'separator'
@ -197,8 +197,6 @@ if (!gotTheLock) {
}
};
const onReady = async () => {
console.log(process.resourcesPath);
console.log(app.getName());
@ -305,7 +303,8 @@ if (!gotTheLock) {
{
label: 'Quit Open WebUI',
accelerator: 'CommandOrControl+Q',
click: () => {
click: async () => {
await stopAllServers();
app.isQuiting = true; // Mark as quitting
app.quit(); // Quit the application
}
@ -408,14 +407,14 @@ if (!gotTheLock) {
});
app.on('before-quit', async () => {
app.isQuiting = true; // Ensure quit flag is set
await stopAllServers();
app.isQuiting = true; // Ensure quit flag is set
});
// Quit when all windows are closed, except on macOS
app.on('window-all-closed', async () => {
if (process.platform !== 'darwin') {
await stopAllServers()
await stopAllServers();
app.isQuitting = true;
app.quit();
}

View File

@ -39,7 +39,7 @@ export function getAppPath(): string {
}
export function getUserHomePath(): string {
return path.normalize(app.getPath('home'))
return path.normalize(app.getPath('home'));
}
export function getUserDataPath(): string {
@ -142,9 +142,11 @@ export function isCondaEnv(envPath: string): boolean {
export function getPythonPath(envPath: string, isConda?: boolean) {
if (process.platform === 'win32') {
return path.normalize((isConda ?? isCondaEnv(envPath))
? path.join(envPath, 'python.exe')
: path.join(envPath, 'Scripts', 'python.exe'));
return path.normalize(
(isConda ?? isCondaEnv(envPath))
? path.join(envPath, 'python.exe')
: path.join(envPath, 'Scripts', 'python.exe')
);
} else {
return path.normalize(path.join(envPath, 'bin', 'python'));
}
@ -401,15 +403,15 @@ export async function startServer(installationPath?: string, port?: number): Pro
return;
}
let startCommand = process.platform === 'win32'
? `"${installationPath}\\Scripts\\activate.bat" && open-webui serve`
: `source "${installationPath}/bin/activate" && open-webui serve`;
let startCommand =
process.platform === 'win32'
? `"${installationPath}\\Scripts\\activate.bat" && open-webui serve`
: `source "${installationPath}/bin/activate" && open-webui serve`;
// Set environment variables in a platform-agnostic way
process.env.DATA_DIR = path.join(app.getPath('userData'), 'data');
process.env.WEBUI_SECRET_KEY = getSecretKey();
port = port || 8080;
while (await portInUse(port)) {
port++;
@ -422,7 +424,7 @@ export async function startServer(installationPath?: string, port?: number): Pro
const childProcess = spawn(startCommand, {
shell: true,
detached: false,
detached: process.platform !== 'win32', // Detach the child process on Unix-like platforms
stdio: ['ignore', 'pipe', 'pipe'], // Let us capture logs via stdout/stderr
windowsHide: true
});