This commit is contained in:
Timothy Jaeryang Baek 2025-01-17 17:06:11 -08:00
parent 7300ef8a4b
commit 9c20ed3de9
2 changed files with 46 additions and 35 deletions

View File

@ -71,7 +71,9 @@ if (!gotTheLock) {
if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {
mainWindow.loadURL(MAIN_WINDOW_VITE_DEV_SERVER_URL);
} else {
mainWindow.loadFile(path.join(__dirname, `../renderer/${MAIN_WINDOW_VITE_NAME}/index.html`));
mainWindow.loadFile(
path.join(__dirname, `../renderer/${MAIN_WINDOW_VITE_NAME}/index.html`)
);
}
};
@ -99,34 +101,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'
@ -180,7 +182,7 @@ if (!gotTheLock) {
}
mainWindow.loadURL(SERVER_URL);
mainWindow
mainWindow;
const urlObj = new URL(SERVER_URL);
const port = urlObj.port || '8080'; // Fallback to port 8080 if not provided
@ -213,9 +215,11 @@ if (!gotTheLock) {
webPreferences: {
preload: path.join(__dirname, 'preload.js')
},
...(process.platform === 'win32' ? {
frame: false
} : {}),
...(process.platform === 'win32'
? {
frame: false
}
: {}),
titleBarStyle: process.platform === 'win32' ? 'default' : 'hidden',
trafficLightPosition: { x: 10, y: 10 },
// expose window controlls in Windows/Linux
@ -386,8 +390,9 @@ if (!gotTheLock) {
ipcMain.handle('renderer:data', async (event, { type, data }) => {
console.log('Received data from renderer:', type, data);
if (type === 'version') {
if (type === 'info') {
return {
platform: process.platform,
version: app.getVersion()
};
}

View File

@ -394,7 +394,11 @@ const serverPIDs: Set<number> = new Set();
/**
* Spawn the Open-WebUI server process.
*/
export async function startServer(installationPath?: string, port?: number): Promise<string> {
export async function startServer(
installationPath?: string,
expose = false,
port = 8080
): Promise<string> {
installationPath = path.normalize(installationPath || getBundledPythonInstallationPath());
if (!(await validateInstallation(installationPath))) {
@ -416,14 +420,14 @@ export async function startServer(installationPath?: string, port?: number): Pro
log.error('Failed to execute Python binary', error);
}
const host = expose ? '0.0.0.0' : '127.0.0.1';
// Windows HATES Typer-CLI used to create the CLI for Open-WebUI
// So we have to manually create the command to start the server
let startCommand =
process.platform === 'win32'
? `"${installationPath}\\Scripts\\activate.bat" && uvicorn open_webui.main:app --host "0.0.0.0" --forwarded-allow-ips '*'`
: `source "${installationPath}/bin/activate" && open-webui serve`;
? `"${installationPath}\\Scripts\\activate.bat" && uvicorn open_webui.main:app --host "${host}" --forwarded-allow-ips '*'`
: `source "${installationPath}/bin/activate" && open-webui serve --host "${host}"`;
if (process.platform === 'win32') {
process.env.FROM_INIT_PY = 'true';
@ -479,7 +483,9 @@ export async function startServer(installationPath?: string, port?: number): Pro
serverCrashed = true;
if (!detectedURL) {
reject(
new Error(`Process exited unexpectedly with code ${code}. No server URL detected.`)
new Error(
`Process exited unexpectedly with code ${code}. No server URL detected.`
)
);
}
});