Skip to content

Commit

Permalink
Choose install location. (#81)
Browse files Browse the repository at this point in the history
* Set up.

* Add yaml.

* App local directory.

* v0.1.26

* Remove model config files.

* Notify when first time setup is complete.

* Format.
  • Loading branch information
robinjhuang authored Oct 14, 2024
1 parent 88b68ad commit 9461e51
Show file tree
Hide file tree
Showing 14 changed files with 431 additions and 183 deletions.
23 changes: 0 additions & 23 deletions config/model_paths_linux.yaml

This file was deleted.

23 changes: 0 additions & 23 deletions config/model_paths_mac.yaml

This file was deleted.

23 changes: 0 additions & 23 deletions config/model_paths_windows.yaml

This file was deleted.

20 changes: 0 additions & 20 deletions forge.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,12 @@ const config: ForgeConfig = {
rebuildConfig: {},
hooks: {
prePackage: async () => {
const configDir = path.join(__dirname, 'config');
const assetDir = path.join(__dirname, 'assets', 'ComfyUI');

// Ensure the asset directory exists
if (!fs.existsSync(assetDir)) {
fs.mkdirSync(assetDir, { recursive: true });
}

let sourceFile;
if (process.platform === 'darwin') {
sourceFile = path.join(configDir, 'model_paths_mac.yaml');
} else if (process.platform === 'win32') {
sourceFile = path.join(configDir, 'model_paths_windows.yaml');
} else {
sourceFile = path.join(configDir, 'model_paths_linux.yaml');
}

const destFile = path.join(assetDir, 'extra_model_paths.yaml');

try {
fs.copyFileSync(sourceFile, destFile);
console.log(`Copied ${sourceFile} to ${destFile}`);
} catch (err) {
console.error(`Failed to copy config file: ${err}`);
throw err; // This will stop the packaging process if the copy fails
}
},
postPackage: async (forgeConfig, packageResult) => {
console.log('Post-package hook started');
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/renderer.ts"></script>
<script type="module" src="/src/renderer.tsx"></script>
</body>
</html>
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"productName": "ComfyUI",
"repository": "github:comfy-org/electron",
"copyright": "Copyright © 2024 Comfy Org",
"version": "0.1.25",
"version": "0.1.26",
"description": "The best modular GUI to run AI diffusion models.",
"main": ".vite/build/main.js",
"packageManager": "[email protected]",
Expand Down Expand Up @@ -87,6 +87,7 @@
"react-dom": "^18.3.1",
"systeminformation": "^5.23.5",
"tar": "^7.4.3",
"update-electron-app": "^3.0.0"
"update-electron-app": "^3.0.0",
"yaml": "^2.6.0"
}
}
87 changes: 87 additions & 0 deletions src/config/extra_model_config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import * as fsPromises from 'node:fs/promises';
import path from 'path';
import log from 'electron-log/main';
import { stringify } from 'yaml';

interface ModelPaths {
comfyui: {
base_path: string;
is_default: boolean;
[key: string]: string | boolean;
};
}

const commonPaths = {
is_default: true,
checkpoints: 'models/checkpoints/',
classifiers: 'models/classifiers/',
clip: 'models/clip/',
clip_vision: 'models/clip_vision/',
configs: 'models/configs/',
controlnet: 'models/controlnet/',
diffusers: 'models/diffusers/',
diffusion_models: 'models/diffusion_models/',
embeddings: 'models/embeddings/',
gligen: 'models/gligen/',
hypernetworks: 'models/hypernetworks/',
loras: 'models/loras/',
photomaker: 'models/photomaker/',
style_models: 'models/style_models/',
unet: 'models/unet/',
upscale_models: 'models/upscale_models/',
vae: 'models/vae/',
vae_approx: 'models/vae_approx/',
custom_nodes: 'custom_nodes/',
};

const configTemplates: Record<string, ModelPaths> = {
win32: {
comfyui: {
base_path: '%USERPROFILE%/comfyui-electron',
...commonPaths,
},
},
darwin: {
comfyui: {
base_path: '~/Library/Application Support/ComfyUI',
...commonPaths,
},
},
linux: {
comfyui: {
base_path: '~/.config/ComfyUI',
...commonPaths,
},
},
};

export async function createModelConfigFiles(extraModelConfigPath: string, customBasePath?: string): Promise<boolean> {
log.info(`Creating model config files in ${extraModelConfigPath} with base path ${customBasePath}`);
try {
for (const [platform, config] of Object.entries(configTemplates)) {
if (platform !== process.platform) {
continue;
}

log.info(`Creating model config files for ${platform}`);

// If a custom base path is provided, use it
if (customBasePath) {
config.comfyui.base_path = customBasePath;
}

const yamlContent = stringify(config, { lineWidth: -1 });

// Add a comment at the top of the file
const fileContent = `# ComfyUI extra_model_paths.yaml for ${platform}\n${yamlContent}`;
await fsPromises.writeFile(extraModelConfigPath, fileContent, 'utf8');
log.info(`Created extra_model_paths.yaml at ${extraModelConfigPath}`);
return true;
}
log.info(`No model config files created for platform ${process.platform}`);
return false;
} catch (error) {
log.error('Error creating model config files:', error);
return false;
}
}
8 changes: 7 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ export const IPC_CHANNELS = {
RENDERER_READY: 'renderer-ready',
RESTART_APP: 'restart-app',
LOG_MESSAGE: 'log-message',
};
SHOW_SELECT_DIRECTORY: 'show-select-directory',
SELECTED_DIRECTORY: 'selected-directory',
OPEN_DIALOG: 'open-dialog',
FIRST_TIME_SETUP_COMPLETE: 'first-time-setup-complete',
} as const;

export type IPCChannel = (typeof IPC_CHANNELS)[keyof typeof IPC_CHANNELS];

export const ELECTRON_BRIDGE_API = 'electronAPI';

Expand Down
Loading

0 comments on commit 9461e51

Please sign in to comment.