From 8d4648b8f561fb77e6840cccee9a1954a62794d7 Mon Sep 17 00:00:00 2001 From: KenCorma <37089104+KenCorma@users.noreply.github.com> Date: Wed, 11 Sep 2024 02:46:57 +0000 Subject: [PATCH] Clean up Pathing and code base (#15) * Move Entitlements out of assets folder entitlements should not be packaged into built app * SubWorkflows need 'workflow_call' Removed Push as it is redundant as debug all will build all 3 on push. * fix pathing for .env in assets * fix typo --------- Co-authored-by: telamonian --- .../actions/build/macos/signwheel/action.yml | 2 +- .github/workflows/debug_linux.yml | 5 ++--- .github/workflows/debug_macos.yml | 1 - .github/workflows/debug_windows.yml | 7 +++---- forge.config.ts | 6 +++--- package.json | 4 ++-- {assets => scripts}/entitlements.mac.plist | 0 scripts/env.mjs | 2 +- src/main.ts | 20 +++++++++---------- 9 files changed, 22 insertions(+), 25 deletions(-) rename {assets => scripts}/entitlements.mac.plist (100%) diff --git a/.github/actions/build/macos/signwheel/action.yml b/.github/actions/build/macos/signwheel/action.yml index ccd5e668..2625e44b 100644 --- a/.github/actions/build/macos/signwheel/action.yml +++ b/.github/actions/build/macos/signwheel/action.yml @@ -13,7 +13,7 @@ runs: shell: sh run: | cd ./assets/python/wheels - find . -name "*so" -o -name "*.dylib" -print0 | while read -d $'\0' file; do codesign --sign 6698D856280DC1662A8E01E5B63428CB6D6651BB --force --timestamp --options runtime --entitlements ../../entitlements.mac.plist "$file"; done + find . -name "*so" -o -name "*.dylib" -print0 | while read -d $'\0' file; do codesign --sign 6698D856280DC1662A8E01E5B63428CB6D6651BB --force --timestamp --options runtime --entitlements ../../../scripts/entitlements.mac.plist "$file"; done - name: Repack shell: sh run: | diff --git a/.github/workflows/debug_linux.yml b/.github/workflows/debug_linux.yml index fe023596..2fae7de0 100644 --- a/.github/workflows/debug_linux.yml +++ b/.github/workflows/debug_linux.yml @@ -1,9 +1,8 @@ name: Build App Linux Debug on: - push: - branches: - - main + workflow_dispatch: + workflow_call: pull_request: branches: - main diff --git a/.github/workflows/debug_macos.yml b/.github/workflows/debug_macos.yml index 4cc56512..f115c054 100644 --- a/.github/workflows/debug_macos.yml +++ b/.github/workflows/debug_macos.yml @@ -1,4 +1,3 @@ -# .github/workflows/debug_macos.yml name: Build App Macos Debug on: diff --git a/.github/workflows/debug_windows.yml b/.github/workflows/debug_windows.yml index 9e3353fd..0dcf00da 100644 --- a/.github/workflows/debug_windows.yml +++ b/.github/workflows/debug_windows.yml @@ -1,9 +1,8 @@ -name: Build Windows Debug +name: Build App Windows Debug on: - push: - branches: - - main + workflow_dispatch: + workflow_call: pull_request: branches: - main diff --git a/forge.config.ts b/forge.config.ts index cb13626a..f80f2742 100644 --- a/forge.config.ts +++ b/forge.config.ts @@ -12,7 +12,7 @@ import { FuseV1Options, FuseVersion } from '@electron/fuses'; const config: ForgeConfig = { packagerConfig: { asar: true, - ...process.env.PUBLISH == 'true' && { + ...process.env.PUBLISH == 'true' && { windowsSign: { debug:true, hookFunction: (filePath) => { @@ -23,7 +23,7 @@ const config: ForgeConfig = { osxSign: { identity: process.env.SIGN_ID, optionsForFile: (filepath) => { - return { entitlements: './assets/entitlements.mac.plist' }; + return { entitlements: './scripts/entitlements.mac.plist' }; } }, osxNotarize: { @@ -32,7 +32,7 @@ const config: ForgeConfig = { teamId: process.env.APPLE_TEAM_ID }, }, - extraResource: ['./assets/UI', './assets/ComfyUI', './assets/python.tgz'], + extraResource: ['./assets/ComfyUI', './assets/python.tgz', './assets/UI'], icon: process.platform === 'linux' ? 'assets/UI/Comfy_Logo_x128.png' : 'assets/UI/Comfy_Logo', }, diff --git a/package.json b/package.json index d94d6707..a36938a6 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,8 @@ "packageManager": "yarn@4.4.1", "scripts": { "clean": "rimraf .vite dist out", - "clean:assets": "rimraf assets/.env assets/ComfyUI assets/python.tgz && yarn run clean:assets:dev", - "clean:assets:dev": "rimraf assets/python assets/override.txt | rimraf assets/cpython*.tar.gz | rimraf assets/requirements.*", + "clean:assets": "rimraf assets/.env assets/ComfyUI assets/python.tgz & yarn run clean:assets:dev", + "clean:assets:dev": "rimraf assets/python assets/override.txt & rimraf assets/cpython*.tar.gz & rimraf assets/requirements.*", "clean:slate": "yarn run clean && yarn run clean:assets && rimraf node_modules", "lint": "eslint --ext .ts,.tsx .", "lint:fix": "eslint --fix --ext .ts,.tsx .", diff --git a/assets/entitlements.mac.plist b/scripts/entitlements.mac.plist similarity index 100% rename from assets/entitlements.mac.plist rename to scripts/entitlements.mac.plist diff --git a/scripts/env.mjs b/scripts/env.mjs index 22f67377..1c01d6f1 100644 --- a/scripts/env.mjs +++ b/scripts/env.mjs @@ -4,4 +4,4 @@ const envContent = `# env vars picked up by the ComfyUI executable on startup COMFYUI_CPU_ONLY=true ` -fs.writeFile(".env", envContent); +fs.writeFile("ComfyUI/.env", envContent); diff --git a/src/main.ts b/src/main.ts index 50ea1c32..982fee23 100644 --- a/src/main.ts +++ b/src/main.ts @@ -41,10 +41,10 @@ const createWindow = () => { mainWindow.loadFile(path.join(__dirname, `../renderer/${MAIN_WINDOW_VITE_NAME}/index.html`)); // Set up the System Tray Icon for all platforms - // Returns a tray so you can set a global var to access. + // Returns a tray so you can set a global var to access. SetupTray(mainWindow); - // Overrides the behavior of closing the window to allow for + // Overrides the behavior of closing the window to allow for // the python server to continue to run in the background mainWindow.on('close' , (e:Electron.Event) => { e.preventDefault(); @@ -105,7 +105,7 @@ const launchPythonServer = async (args: {userResourcesPath: string, appResources console.log('Python server is already running'); // Server has been started outside the app, so attach to it. setTimeout(() => { - // Not sure if needed but wait a few moments before sending the connect message up. + // Not sure if needed but wait a few moments before sending the connect message up. webContents.getAllWebContents()[0].send("python-server-status", "active"); }, 5000); clearInterval(serverHeartBeatReference); @@ -175,14 +175,14 @@ const launchPythonServer = async (args: {userResourcesPath: string, appResources const checkServerReady = async () => { currentWaitTime += 1000; if (currentWaitTime > maxFailWait) { - //Something has gone wrong and we need to backout. + //Something has gone wrong and we need to backout. clearTimeout(spawnServerTimeout); reject("Python Server Failed To Start"); } const isReady = await isPortInUse(host, port); if (isReady) { console.log('Python server is ready'); - // Start the Heartbeat listener, send connected message to Renderer and resolve promise. + // Start the Heartbeat listener, send connected message to Renderer and resolve promise. serverHeartBeatReference = setInterval(serverHeartBeat, serverHeartBeatInterval); webContents.getAllWebContents()[0].send("python-server-status", "active"); //For now just replace the source of the main window to the python server @@ -217,7 +217,7 @@ app.on('ready', async () => { console.log(`appResourcesPath: ${appResourcesPath}`); try { - dotenv.config({path: path.join(appResourcesPath, ".env")}); + dotenv.config({path: path.join(appResourcesPath, "ComfyUI", ".env")}); } catch { // if no .env file, skip it } @@ -227,7 +227,7 @@ app.on('ready', async () => { } catch { // if user-specific resources dir already exists, that is fine } - try { + try { createWindow(); await launchPythonServer({userResourcesPath, appResourcesPath}); } catch (error) { @@ -239,7 +239,7 @@ const killPythonServer = () => { console.log('Python server:', pythonProcess); return new Promise(async(resolve, reject) => { if (pythonProcess) { - try { + try { pythonProcess.kill(); setTimeout(() => { resolve(); // Force the issue after 5seconds @@ -247,13 +247,13 @@ const killPythonServer = () => { // Make sure exit code was set so we can close gracefully while (pythonProcess.exitCode == null) {} - resolve(); + resolve(); } catch(error) { console.error(error); reject(error); - } + } } else {