mirror of
https://github.com/open-webui/desktop
synced 2025-06-26 18:15:59 +00:00
refac
This commit is contained in:
parent
7300ef8a4b
commit
9c20ed3de9
65
src/main.ts
65
src/main.ts
@ -71,7 +71,9 @@ if (!gotTheLock) {
|
|||||||
if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {
|
if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {
|
||||||
mainWindow.loadURL(MAIN_WINDOW_VITE_DEV_SERVER_URL);
|
mainWindow.loadURL(MAIN_WINDOW_VITE_DEV_SERVER_URL);
|
||||||
} else {
|
} 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'
|
...(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...',
|
label: 'Stop Server',
|
||||||
enabled: false
|
|
||||||
}
|
|
||||||
]
|
|
||||||
: [
|
|
||||||
{
|
|
||||||
label: 'Start Server',
|
|
||||||
click: async () => {
|
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'
|
type: 'separator'
|
||||||
@ -180,7 +182,7 @@ if (!gotTheLock) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mainWindow.loadURL(SERVER_URL);
|
mainWindow.loadURL(SERVER_URL);
|
||||||
mainWindow
|
mainWindow;
|
||||||
|
|
||||||
const urlObj = new URL(SERVER_URL);
|
const urlObj = new URL(SERVER_URL);
|
||||||
const port = urlObj.port || '8080'; // Fallback to port 8080 if not provided
|
const port = urlObj.port || '8080'; // Fallback to port 8080 if not provided
|
||||||
@ -213,9 +215,11 @@ if (!gotTheLock) {
|
|||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload: path.join(__dirname, 'preload.js')
|
preload: path.join(__dirname, 'preload.js')
|
||||||
},
|
},
|
||||||
...(process.platform === 'win32' ? {
|
...(process.platform === 'win32'
|
||||||
frame: false
|
? {
|
||||||
} : {}),
|
frame: false
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
titleBarStyle: process.platform === 'win32' ? 'default' : 'hidden',
|
titleBarStyle: process.platform === 'win32' ? 'default' : 'hidden',
|
||||||
trafficLightPosition: { x: 10, y: 10 },
|
trafficLightPosition: { x: 10, y: 10 },
|
||||||
// expose window controlls in Windows/Linux
|
// expose window controlls in Windows/Linux
|
||||||
@ -386,8 +390,9 @@ if (!gotTheLock) {
|
|||||||
ipcMain.handle('renderer:data', async (event, { type, data }) => {
|
ipcMain.handle('renderer:data', async (event, { type, data }) => {
|
||||||
console.log('Received data from renderer:', type, data);
|
console.log('Received data from renderer:', type, data);
|
||||||
|
|
||||||
if (type === 'version') {
|
if (type === 'info') {
|
||||||
return {
|
return {
|
||||||
|
platform: process.platform,
|
||||||
version: app.getVersion()
|
version: app.getVersion()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -394,7 +394,11 @@ const serverPIDs: Set<number> = new Set();
|
|||||||
/**
|
/**
|
||||||
* Spawn the Open-WebUI server process.
|
* 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());
|
installationPath = path.normalize(installationPath || getBundledPythonInstallationPath());
|
||||||
|
|
||||||
if (!(await validateInstallation(installationPath))) {
|
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);
|
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
|
// Windows HATES Typer-CLI used to create the CLI for Open-WebUI
|
||||||
// So we have to manually create the command to start the server
|
// So we have to manually create the command to start the server
|
||||||
let startCommand =
|
let startCommand =
|
||||||
process.platform === 'win32'
|
process.platform === 'win32'
|
||||||
? `"${installationPath}\\Scripts\\activate.bat" && uvicorn open_webui.main:app --host "0.0.0.0" --forwarded-allow-ips '*'`
|
? `"${installationPath}\\Scripts\\activate.bat" && uvicorn open_webui.main:app --host "${host}" --forwarded-allow-ips '*'`
|
||||||
: `source "${installationPath}/bin/activate" && open-webui serve`;
|
: `source "${installationPath}/bin/activate" && open-webui serve --host "${host}"`;
|
||||||
|
|
||||||
|
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
process.env.FROM_INIT_PY = 'true';
|
process.env.FROM_INIT_PY = 'true';
|
||||||
@ -479,7 +483,9 @@ export async function startServer(installationPath?: string, port?: number): Pro
|
|||||||
serverCrashed = true;
|
serverCrashed = true;
|
||||||
if (!detectedURL) {
|
if (!detectedURL) {
|
||||||
reject(
|
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.`
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user