Skip to content

Commit

Permalink
Remove electron logviewer (#146)
Browse files Browse the repository at this point in the history
* Remove electron logviewer

* Remove react-logviewer

* nit
  • Loading branch information
huchenlei authored Oct 30, 2024
1 parent 03be5b1 commit 44263ae
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 231 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
},
"license": "GPL-3.0-only",
"dependencies": {
"@melloware/react-logviewer": "^5.2.3",
"@sentry/electron": "^5.4.0",
"@sentry/vite-plugin": "^2.22.4",
"@todesktop/runtime": "^1.6.4",
Expand Down
2 changes: 0 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ export const IPC_CHANNELS = {
OPEN_DIALOG: 'open-dialog',
FIRST_TIME_SETUP_COMPLETE: 'first-time-setup-complete',
DEFAULT_INSTALL_LOCATION: 'default-install-location',
GET_LOGS: 'get-logs',
GET_COMFYUI_URL: 'get-comfyui-url',
TOGGLE_LOGS: 'toggle-logs',
COMFYUI_READY: 'comfyui-ready',
GET_PRELOAD_SCRIPT: 'get-preload-script',
OPEN_DEVTOOLS: 'open-devtools',
Expand Down
29 changes: 0 additions & 29 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,6 @@ if (!gotTheLock) {
fs.rmSync(modelConfigPath);
restartApp();
},
() => {
if (mainWindow) {
mainWindow.webContents.send(IPC_CHANNELS.TOGGLE_LOGS);
}
},
pythonEnvironment
);
sendProgressUpdate('Starting Comfy Server...');
Expand All @@ -237,24 +232,9 @@ if (!gotTheLock) {
ipcMain.handle(IPC_CHANNELS.GET_COMFYUI_URL, () => {
return `http://${host}:${port}`;
});

ipcMain.handle(IPC_CHANNELS.GET_LOGS, async (): Promise<string[]> => {
return await readComfyUILogs();
});
});
}

async function readComfyUILogs(): Promise<string[]> {
try {
const logContent = await fsPromises.readFile(path.join(app.getPath('logs'), 'comfyui.log'), 'utf-8');
const logs = logContent.split('\n');
return logs;
} catch (error) {
console.error('Error reading log file:', error);
return [];
}
}

function loadComfyIntoMainWindow() {
if (!mainWindow) {
log.error('Trying to load ComfyUI into main window but it is not ready yet.');
Expand Down Expand Up @@ -372,22 +352,13 @@ export const createWindow = async (userResourcesPath?: string): Promise<BrowserW
mainWindow.on('resize', updateBounds);
mainWindow.on('move', updateBounds);

const shortcut = globalShortcut.register('CommandOrControl+Shift+L', () => {
if (mainWindow) mainWindow.webContents.send(IPC_CHANNELS.TOGGLE_LOGS);
});

if (!shortcut) {
log.error('Failed to register global shortcut');
}

mainWindow.on('close', (e: Electron.Event) => {
// Mac Only Behavior
if (process.platform === 'darwin') {
e.preventDefault();
if (mainWindow) mainWindow.hide();
app.dock.hide();
}
globalShortcut.unregister('CommandOrControl+Shift+L');
mainWindow = null;
});

Expand Down
8 changes: 0 additions & 8 deletions src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ export interface ElectronAPI {
onComfyUIReady: (callback: (port: number) => void) => void;
sendReady: () => void;
restartApp: () => void;
onToggleLogsView: (callback: () => void) => void;
onOpenDevTools: (callback: () => void) => void;
isPackaged: () => Promise<boolean>;
openDialog: (options: Electron.OpenDialogOptions) => Promise<string[] | undefined>;
getComfyUIUrl: () => Promise<string>;
getPreloadScript: () => Promise<string>;
getLogs: () => Promise<string[]>;
/**
* Open the logs folder in the system's default file explorer.
*/
Expand Down Expand Up @@ -79,9 +77,6 @@ const electronAPI: ElectronAPI = {
console.log('Sending restarting app message to main process');
ipcRenderer.send(IPC_CHANNELS.RESTART_APP);
},
onToggleLogsView: (callback: () => void) => {
ipcRenderer.on(IPC_CHANNELS.TOGGLE_LOGS, () => callback());
},
onOpenDevTools: (callback: () => void) => {
ipcRenderer.on(IPC_CHANNELS.OPEN_DEVTOOLS, () => callback());
},
Expand All @@ -91,9 +86,6 @@ const electronAPI: ElectronAPI = {
selectSetupDirectory: (directory: string) => {
ipcRenderer.send(IPC_CHANNELS.SELECTED_DIRECTORY, directory);
},
getLogs: (): Promise<string[]> => {
return ipcRenderer.invoke(IPC_CHANNELS.GET_LOGS);
},
getComfyUIUrl: (): Promise<string> => {
return ipcRenderer.invoke(IPC_CHANNELS.GET_COMFYUI_URL);
},
Expand Down
12 changes: 1 addition & 11 deletions src/renderer/components/ComfyUIContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useEffect, useRef, useState } from 'react';
import LogViewer from './LogViewer';
import React, { useEffect, useRef } from 'react';
import { ElectronAPI } from 'src/preload';
import { ELECTRON_BRIDGE_API } from 'src/constants';
import { WebviewTag } from 'electron';
Expand Down Expand Up @@ -29,15 +28,11 @@ const logContainerStyle: React.CSSProperties = {
};

const ComfyUIContainer: React.FC<ComfyUIContainerProps> = ({ comfyPort, preloadScript }) => {
const [showStreamingLogs, setShowStreamingLogs] = useState(false);
const webviewRef = useRef<WebviewTag>(null);

useEffect(() => {
const electronAPI: ElectronAPI = (window as any)[ELECTRON_BRIDGE_API];

electronAPI.onToggleLogsView(() => {
setShowStreamingLogs((prevState) => !prevState);
});
electronAPI.onOpenDevTools(() => {
webviewRef.current?.openDevTools();
});
Expand All @@ -52,11 +47,6 @@ const ComfyUIContainer: React.FC<ComfyUIContainerProps> = ({ comfyPort, preloadS
preload={`file://${preloadScript}`}
ref={webviewRef}
/>
{showStreamingLogs && (
<div style={logContainerStyle}>
<LogViewer onClose={() => setShowStreamingLogs(false)} />
</div>
)}
</div>
);
};
Expand Down
106 changes: 0 additions & 106 deletions src/renderer/components/LogViewer.tsx

This file was deleted.

5 changes: 0 additions & 5 deletions src/tray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export function SetupTray(
basePath: string,
modelConfigPath: string,
reinstall: () => void,
toggleLogs: () => void,
pythonEnvironment: PythonEnvironment
): Tray {
// Set icon for the tray
Expand Down Expand Up @@ -96,10 +95,6 @@ export function SetupTray(
label: 'Open devtools (ComfyUI)',
click: () => mainView.webContents.send(IPC_CHANNELS.OPEN_DEVTOOLS),
},
{
label: 'Toggle Log Viewer',
click: () => toggleLogs(),
},
{
label: 'Install Python Packages (Open Terminal)',
click: () => {
Expand Down
70 changes: 1 addition & 69 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ __metadata:
languageName: node
linkType: hard

"@babel/runtime@npm:^7.0.0, @babel/runtime@npm:^7.10.0, @babel/runtime@npm:^7.15.4, @babel/runtime@npm:^7.21.0":
"@babel/runtime@npm:^7.10.0, @babel/runtime@npm:^7.15.4, @babel/runtime@npm:^7.21.0":
version: 7.25.9
resolution: "@babel/runtime@npm:7.25.9"
dependencies:
Expand Down Expand Up @@ -1540,22 +1540,6 @@ __metadata:
languageName: node
linkType: hard

"@melloware/react-logviewer@npm:^5.2.3":
version: 5.2.3
resolution: "@melloware/react-logviewer@npm:5.2.3"
dependencies:
hotkeys-js: "npm:^3.13.7"
mitt: "npm:^3.0.1"
react-string-replace: "npm:^1.1.1"
react-virtualized-auto-sizer: "npm:^1.0.24"
react-window: "npm:^1.8.10"
peerDependencies:
react: ^17.1.1 || ^18.0.0 || ^19.0.0
react-dom: ^17.1.1 || ^18.0.0 || ^19.0.0
checksum: 10c0/2c966c75acd7a7b26f5234a5035dad54468d1477432ff050ae95e5e0c98e352e00805196bf915b0e61df7c94f0070962f82d9b09fbfa5238bf16f9a04af69189
languageName: node
linkType: hard

"@nodelib/fs.scandir@npm:2.1.5":
version: 2.1.5
resolution: "@nodelib/fs.scandir@npm:2.1.5"
Expand Down Expand Up @@ -4867,7 +4851,6 @@ __metadata:
"@electron/fuses": "npm:^1.8.0"
"@electron/notarize": "npm:^2.4.0"
"@electron/windows-sign": "npm:^1.1.3"
"@melloware/react-logviewer": "npm:^5.2.3"
"@playwright/test": "npm:^1.47.2"
"@sentry/electron": "npm:^5.4.0"
"@sentry/vite-plugin": "npm:^2.22.4"
Expand Down Expand Up @@ -7104,13 +7087,6 @@ __metadata:
languageName: node
linkType: hard

"hotkeys-js@npm:^3.13.7":
version: 3.13.7
resolution: "hotkeys-js@npm:3.13.7"
checksum: 10c0/5e3ed01d1993202a0c77298caf1b9ec13d70b7fe1a85fcc45f5886f1805318af32e01039c952d45ad0f768984887eca85942a3b5326f39cd2bc3dede1c3ba949
languageName: node
linkType: hard

"html-escaper@npm:^2.0.0":
version: 2.0.2
resolution: "html-escaper@npm:2.0.2"
Expand Down Expand Up @@ -9065,13 +9041,6 @@ __metadata:
languageName: node
linkType: hard

"memoize-one@npm:>=3.1.1 <6":
version: 5.2.1
resolution: "memoize-one@npm:5.2.1"
checksum: 10c0/fd22dbe9a978a2b4f30d6a491fc02fb90792432ad0dab840dc96c1734d2bd7c9cdeb6a26130ec60507eb43230559523615873168bcbe8fafab221c30b11d54c1
languageName: node
linkType: hard

"merge-stream@npm:^2.0.0":
version: 2.0.0
resolution: "merge-stream@npm:2.0.0"
Expand Down Expand Up @@ -9354,13 +9323,6 @@ __metadata:
languageName: node
linkType: hard

"mitt@npm:^3.0.1":
version: 3.0.1
resolution: "mitt@npm:3.0.1"
checksum: 10c0/3ab4fdecf3be8c5255536faa07064d05caa3dd332bd318ff02e04621f7b3069ca1de9106cfe8e7ced675abfc2bec2ce4c4ef321c4a1bb1fb29df8ae090741913
languageName: node
linkType: hard

"mkdirp@npm:^0.5.5, mkdirp@npm:~0.5.1":
version: 0.5.6
resolution: "mkdirp@npm:0.5.6"
Expand Down Expand Up @@ -10552,36 +10514,6 @@ __metadata:
languageName: node
linkType: hard

"react-string-replace@npm:^1.1.1":
version: 1.1.1
resolution: "react-string-replace@npm:1.1.1"
checksum: 10c0/5a4a4fd9c3758b4680da113adf411342116238b4dc68fa4c4e9b04c046cb757d4f00d6ba441301fa3afb44c847dacc17a2707865698ff1fc78a369182458e894
languageName: node
linkType: hard

"react-virtualized-auto-sizer@npm:^1.0.24":
version: 1.0.24
resolution: "react-virtualized-auto-sizer@npm:1.0.24"
peerDependencies:
react: ^15.3.0 || ^16.0.0-alpha || ^17.0.0 || ^18.0.0
react-dom: ^15.3.0 || ^16.0.0-alpha || ^17.0.0 || ^18.0.0
checksum: 10c0/d400489e5005a2ad0635228958379aa26b66fdae62a5b9fbf4dcb5fecd4e99454990b1cd59fe55ff277419b37bdf098c26e7185e0ef1b6ca775a477f913bb763
languageName: node
linkType: hard

"react-window@npm:^1.8.10":
version: 1.8.10
resolution: "react-window@npm:1.8.10"
dependencies:
"@babel/runtime": "npm:^7.0.0"
memoize-one: "npm:>=3.1.1 <6"
peerDependencies:
react: ^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0
react-dom: ^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0
checksum: 10c0/eda9afb667d9784513dcc2755b65edf3a1412e7877975322993c1382908aaef0c0b948b7e3b2d705e353306556274d90f7ab19ac40aef2184fa39d4c1e2232ea
languageName: node
linkType: hard

"react@npm:^17.0.2":
version: 17.0.2
resolution: "react@npm:17.0.2"
Expand Down

0 comments on commit 44263ae

Please sign in to comment.