mirror of
https://github.com/open-webui/desktop.git
synced 2026-07-15 04:35:40 -04:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 238cce6dc8 | |||
| b255f22fe7 | |||
| d205c176ef | |||
| 2a223e62b6 | |||
| eb2ebd2c1d | |||
| a6a944c847 | |||
| 03fea4a7cc |
+31
-2
@@ -125,6 +125,13 @@ function createWindow(show = true): void {
|
||||
uninstallHandler();
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
label: "Reset",
|
||||
click: async () => {
|
||||
await resetAppHandler();
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
const updatedMenu = Menu.buildFromTemplate(menuTemplate);
|
||||
@@ -351,6 +358,29 @@ const stopServerHandler = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const resetAppHandler = async () => {
|
||||
try {
|
||||
await stopServerHandler(); // Stop the server if running
|
||||
SERVER_STATUS = null;
|
||||
await resetApp(); // Reset the application state
|
||||
|
||||
// Show success notification
|
||||
const notification = new Notification({
|
||||
title: "Open WebUI",
|
||||
body: "Application has been reset successfully.",
|
||||
});
|
||||
notification.show();
|
||||
} catch (error) {
|
||||
log.error("Failed to reset application:", error);
|
||||
// Show error notification
|
||||
const notification = new Notification({
|
||||
title: "Open WebUI",
|
||||
body: `Failed to reset application: ${error.message}`,
|
||||
});
|
||||
notification.show();
|
||||
}
|
||||
};
|
||||
|
||||
const gotTheLock = app.requestSingleInstanceLock();
|
||||
if (!gotTheLock) {
|
||||
app.quit(); // Quit if another instance is already running
|
||||
@@ -488,8 +518,7 @@ if (!gotTheLock) {
|
||||
});
|
||||
|
||||
ipcMain.handle("app:reset", async (event) => {
|
||||
await stopServerHandler();
|
||||
return await resetApp();
|
||||
return await resetAppHandler();
|
||||
});
|
||||
|
||||
ipcMain.handle("get:config", async (event) => {
|
||||
|
||||
+30
-33
@@ -249,7 +249,7 @@ export const getPythonDownloadPath = (): string => {
|
||||
return downloadPath;
|
||||
};
|
||||
|
||||
export const getPythonInstallationPath = (): string => {
|
||||
export const getPythonInstallationDir = (): string => {
|
||||
const installDir = path.join(app.getPath("userData"), "python");
|
||||
|
||||
if (!fs.existsSync(installDir)) {
|
||||
@@ -311,7 +311,7 @@ const checkInternet = async () => {
|
||||
};
|
||||
|
||||
export const installPython = async (
|
||||
installationPath?: string
|
||||
installationDir?: string
|
||||
): Promise<boolean> => {
|
||||
let pythonDownloadPath = getPythonDownloadPath();
|
||||
if (!isPythonDownloaded()) {
|
||||
@@ -326,9 +326,6 @@ export const installPython = async (
|
||||
log.info(
|
||||
`Downloading Python: ${progress.toFixed(2)}% (${downloaded} of ${total} bytes)`
|
||||
);
|
||||
log.info(
|
||||
`Downloading Python: ${progress.toFixed(2)}% (${downloaded} of ${total} bytes)`
|
||||
);
|
||||
});
|
||||
}
|
||||
if (!fs.existsSync(pythonDownloadPath)) {
|
||||
@@ -336,8 +333,8 @@ export const installPython = async (
|
||||
return false;
|
||||
}
|
||||
|
||||
installationPath = installationPath || getPythonInstallationPath();
|
||||
log.info(installationPath, pythonDownloadPath);
|
||||
installationDir = installationDir || getPythonInstallationDir();
|
||||
log.info(installationDir, pythonDownloadPath);
|
||||
|
||||
try {
|
||||
const userDataPath = getUserDataPath();
|
||||
@@ -351,8 +348,8 @@ export const installPython = async (
|
||||
}
|
||||
|
||||
// Get the path to the installed Python binary
|
||||
if (isPythonInstalled(installationPath)) {
|
||||
const pythonPath = getPythonPath(installationPath);
|
||||
if (isPythonInstalled(installationDir)) {
|
||||
const pythonPath = getPythonPath(installationDir);
|
||||
|
||||
execFileSync(pythonPath, ["-m", "pip", "install", "uv"], {
|
||||
encoding: "utf-8",
|
||||
@@ -382,14 +379,14 @@ export const getPythonExecutablePath = (envPath: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const getPythonPath = (installationPath?: string) => {
|
||||
export const getPythonPath = (installationDir?: string) => {
|
||||
return path.normalize(
|
||||
getPythonExecutablePath(installationPath || getPythonInstallationPath())
|
||||
getPythonExecutablePath(installationDir || getPythonInstallationDir())
|
||||
);
|
||||
};
|
||||
|
||||
export const isPythonInstalled = (installationPath?: string) => {
|
||||
const pythonPath = getPythonPath(installationPath);
|
||||
export const isPythonInstalled = (installationDir?: string) => {
|
||||
const pythonPath = getPythonPath(installationDir);
|
||||
|
||||
if (!fs.existsSync(pythonPath)) {
|
||||
log.error("Python binary not found in install path");
|
||||
@@ -416,8 +413,8 @@ export const isPythonInstalled = (installationPath?: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const isUvInstalled = (installationPath?: string) => {
|
||||
const pythonPath = getPythonPath(installationPath);
|
||||
export const isUvInstalled = (installationDir?: string) => {
|
||||
const pythonPath = getPythonPath(installationDir);
|
||||
try {
|
||||
// Check if uv is installed by running the command
|
||||
const result = execFileSync(pythonPath, ["-m", "uv", "--version"], {
|
||||
@@ -441,16 +438,17 @@ export const isUvInstalled = (installationPath?: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const uninstallPython = (installationPath?: string): boolean => {
|
||||
installationPath = installationPath || getPythonInstallationPath();
|
||||
export const uninstallPython = (installationDir?: string): boolean => {
|
||||
installationDir = installationDir || getPythonInstallationDir();
|
||||
|
||||
if (!fs.existsSync(installationPath)) {
|
||||
if (!fs.existsSync(installationDir)) {
|
||||
log.error("Python installation not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
fs.rmSync(installationPath, { recursive: true });
|
||||
fs.rmSync(installationDir, { recursive: true, force: true });
|
||||
log.info("Python installation removed successfully:", installationDir);
|
||||
} catch (error) {
|
||||
log.error("Failed to remove Python installation", error);
|
||||
return false;
|
||||
@@ -471,17 +469,6 @@ export const resetApp = async (): Promise<void> => {
|
||||
await uninstallPython();
|
||||
log.info("Uninstalled Python environment");
|
||||
|
||||
// remove /data folder
|
||||
const dataPath = getOpenWebUIDataPath();
|
||||
if (fs.existsSync(dataPath)) {
|
||||
try {
|
||||
fs.rmSync(dataPath, { recursive: true });
|
||||
log.info("Removed data directory:", dataPath);
|
||||
} catch (error) {
|
||||
log.error("Failed to remove data directory:", error);
|
||||
}
|
||||
}
|
||||
|
||||
// remove config file
|
||||
const configPath = path.join(getUserDataPath(), "config.json");
|
||||
if (fs.existsSync(configPath)) {
|
||||
@@ -503,6 +490,17 @@ export const resetApp = async (): Promise<void> => {
|
||||
log.error("Failed to remove secret key file:", error);
|
||||
}
|
||||
}
|
||||
|
||||
// remove /data folder
|
||||
const dataPath = getOpenWebUIDataPath();
|
||||
if (fs.existsSync(dataPath)) {
|
||||
try {
|
||||
fs.rmSync(dataPath, { recursive: true, force: true });
|
||||
log.info("Removed data directory:", dataPath);
|
||||
} catch (error) {
|
||||
log.error("Failed to remove data directory:", error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////
|
||||
@@ -670,16 +668,15 @@ export const startServer = async (
|
||||
const pythonPath = getPythonPath();
|
||||
log.info(`Using Python at: ${pythonPath}`);
|
||||
|
||||
const openWebUIPath = path.join(path.dirname(pythonPath), "open-webui");
|
||||
|
||||
let commandArgs: string[];
|
||||
commandArgs = ["-m", "uv", "run", "open-webui", "serve", "--host", host];
|
||||
|
||||
const dataDir = path.join(app.getPath("userData"), "data");
|
||||
const dataDir = getOpenWebUIDataPath();
|
||||
const secretKey = getSecretKey();
|
||||
if (!fs.existsSync(dataDir)) {
|
||||
fs.mkdirSync(dataDir, { recursive: true });
|
||||
}
|
||||
|
||||
process.env.DATA_DIR = dataDir;
|
||||
process.env.WEBUI_SECRET_KEY = secretKey;
|
||||
|
||||
|
||||
@@ -59,8 +59,9 @@
|
||||
await window.electronAPI.resetApp();
|
||||
toast.success("App has been reset successfully.");
|
||||
|
||||
// refresh the page to apply changes
|
||||
window.location.reload();
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 1000);
|
||||
} catch (error) {
|
||||
toast.error("Failed to reset the app");
|
||||
}
|
||||
|
||||
@@ -49,10 +49,12 @@
|
||||
(await window.electronAPI.getPythonStatus()) &&
|
||||
(await window.electronAPI.getPackageStatus())
|
||||
) {
|
||||
// Notify the user that the installation is complete
|
||||
// Start the server if it's not already running
|
||||
if (!(await window.electronAPI.getServerStatus())) {
|
||||
await window.electronAPI.startServer();
|
||||
}
|
||||
|
||||
// Notify the user that the installation is complete
|
||||
await window.electronAPI.notification(
|
||||
"Installation Complete",
|
||||
"Open WebUI is now ready to use."
|
||||
|
||||
Reference in New Issue
Block a user