mirror of
https://github.com/open-webui/desktop
synced 2025-06-26 18:15:59 +00:00
refac
This commit is contained in:
parent
f5c69a0d72
commit
25b98ea31b
40
src/main.ts
40
src/main.ts
@ -167,6 +167,8 @@ if (!gotTheLock) {
|
||||
|
||||
try {
|
||||
SERVER_URL = await startServer();
|
||||
// SERVER_URL = 'http://localhost:5050';
|
||||
|
||||
SERVER_STATUS = 'started';
|
||||
mainWindow.webContents.send('main:data', {
|
||||
type: 'server:status',
|
||||
@ -198,8 +200,10 @@ if (!gotTheLock) {
|
||||
console.log(app.getPath('appData'));
|
||||
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 800,
|
||||
width: 1000,
|
||||
height: 600,
|
||||
minWidth: 425,
|
||||
minHeight: 600,
|
||||
icon: path.join(__dirname, 'assets/icon.png'),
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, 'preload.js')
|
||||
@ -370,6 +374,24 @@ if (!gotTheLock) {
|
||||
return SERVER_URL;
|
||||
});
|
||||
|
||||
ipcMain.handle('renderer:data', async (event, { type, data }) => {
|
||||
console.log('Received data from renderer:', type, data);
|
||||
|
||||
if (type === 'version') {
|
||||
return {
|
||||
version: app.getVersion()
|
||||
};
|
||||
}
|
||||
|
||||
if (type === 'window:isFocused') {
|
||||
return {
|
||||
isFocused: mainWindow?.isFocused()
|
||||
};
|
||||
}
|
||||
|
||||
return { type, data };
|
||||
});
|
||||
|
||||
ipcMain.handle('notification', async (event, { title, body }) => {
|
||||
console.log('Received notification:', title, body);
|
||||
const notification = new Notification({
|
||||
@ -379,22 +401,6 @@ if (!gotTheLock) {
|
||||
notification.show();
|
||||
});
|
||||
|
||||
ipcMain.handle('load-webui', async (event, arg) => {
|
||||
console.log(arg); // prints "ping"
|
||||
mainWindow.loadURL('http://localhost:8080');
|
||||
|
||||
mainWindow.webContents.once('did-finish-load', () => {
|
||||
mainWindow.webContents.send('main:data', {
|
||||
type: 'ping' // This is the same type you're listening for in the renderer
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on('send-ping', (event) => {
|
||||
console.log('Received PING from renderer process');
|
||||
mainWindow.webContents.send('ping-reply', 'PONG from Main Process!');
|
||||
});
|
||||
});
|
||||
|
||||
app.on('before-quit', () => {
|
||||
app.isQuiting = true; // Ensure quit flag is set
|
||||
stopAllServers();
|
||||
|
||||
@ -36,6 +36,10 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
||||
ipcRenderer.on('main:log', (_, message: string) => callback(message));
|
||||
},
|
||||
|
||||
send: async ({ type, data }: { type: string; data?: any }) => {
|
||||
return await ipcRenderer.invoke('renderer:data', { type, data });
|
||||
},
|
||||
|
||||
installPackage: async () => {
|
||||
if (!isLocalSource()) {
|
||||
throw new Error('Access restricted: This operation is only allowed in a local environment.');
|
||||
|
||||
@ -12,6 +12,15 @@
|
||||
font-display: swap;
|
||||
}
|
||||
|
||||
.drag-region {
|
||||
-webkit-app-region: drag;
|
||||
}
|
||||
|
||||
.drag-region a,
|
||||
.drag-region button {
|
||||
-webkit-app-region: no-drag;
|
||||
}
|
||||
|
||||
.font-secondary {
|
||||
font-family: 'InstrumentSerif', sans-serif;
|
||||
}
|
||||
|
||||
@ -41,9 +41,7 @@
|
||||
</script>
|
||||
|
||||
{#if $installStatus === null}
|
||||
<div class="flex flex-row w-full h-full relative dark:text-gray-100">
|
||||
<div class="absolute top-0 left-0 w-full h-7 bg-transparent draggable"></div>
|
||||
|
||||
<div class="flex flex-row w-full h-full relative dark:text-gray-100 drag-region">
|
||||
<div class="flex-1 w-full flex justify-center relative">
|
||||
<div class="m-auto">
|
||||
<img
|
||||
@ -55,9 +53,7 @@
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex flex-row w-full h-full relative dark:text-gray-100 p-1">
|
||||
<div class="absolute top-0 left-0 w-full h-7 bg-transparent draggable"></div>
|
||||
|
||||
<div class="flex flex-row w-full h-full relative dark:text-gray-100 p-1 drag-region">
|
||||
<div class="fixed right-0 m-10 z-50">
|
||||
<div class="flex space-x-2">
|
||||
<button class=" self-center cursor-pointer" onclick={() => (showLogs = !showLogs)}>
|
||||
@ -196,9 +192,3 @@
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.draggable {
|
||||
-webkit-app-region: drag;
|
||||
}
|
||||
</style>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user