Skip to content

Commit

Permalink
Create new user settings file if already exists. (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
robinjhuang authored Oct 16, 2024
1 parent e09478b commit 4491dc7
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ function createComfyDirectories(localComfyDirectory: string): void {
});

const userSettingsPath = path.join(localComfyDirectory, 'user', 'default');
createComfyConfigFile(userSettingsPath);
createComfyConfigFile(userSettingsPath, true);
}

/**
Expand All @@ -752,7 +752,7 @@ function createDirIfNotExists(dirPath: string): void {
}
}

function createComfyConfigFile(userSettingsPath: string): void {
function createComfyConfigFile(userSettingsPath: string, overwrite: boolean = false): void {
const configContent: any = {
'Comfy.ColorPalette': 'dark',
'Comfy.NodeLibrary.Bookmarks': [],
Expand All @@ -763,15 +763,22 @@ function createComfyConfigFile(userSettingsPath: string): void {

const configFilePath = path.join(userSettingsPath, 'comfy.settings.json');

if (fs.existsSync(configFilePath)) {
return;
if (fs.existsSync(configFilePath) && overwrite) {
const backupFilePath = path.join(userSettingsPath, 'old_comfy.settings.json');
try {
fs.renameSync(configFilePath, backupFilePath);
log.info(`Renaming existing user settings file to: ${backupFilePath}`);
} catch (error) {
log.error(`Failed to backup existing user settings file: ${error}`);
return;
}
}

try {
fs.writeFileSync(configFilePath, JSON.stringify(configContent, null, 2));
log.info(`Created ComfyUI config file at: ${configFilePath}`);
log.info(`Created new ComfyUI config file at: ${configFilePath}`);
} catch (error) {
log.error(`Failed to create ComfyUI config file: ${error}`);
log.error(`Failed to create new ComfyUI config file: ${error}`);
}
}

Expand Down

0 comments on commit 4491dc7

Please sign in to comment.