-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Toggle auto-update and restart app for Electron settings. (#147)
* Restart app on change. * Remove auto update IPC call. * Add issue for hack. * Use https git url instead of SSH for CI.
- Loading branch information
1 parent
44263ae
commit f76ffb9
Showing
6 changed files
with
130 additions
and
99 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import log from 'electron-log/main'; | ||
|
||
interface ComfySettingsData { | ||
'Comfy-Desktop.AutoUpdate'?: boolean; | ||
'Comfy-Desktop.SendCrashStatistics'?: boolean; | ||
[key: string]: any; | ||
} | ||
|
||
/** | ||
* ComfySettings is a class that loads settings from the comfy.settings.json file. | ||
*/ | ||
export class ComfySettings { | ||
private filePath: string; | ||
private settings: ComfySettingsData; | ||
|
||
constructor(settingsPath: string) { | ||
this.filePath = path.join(settingsPath, 'user', 'default', 'comfy.settings.json'); | ||
this.settings = this.loadSettings(); | ||
} | ||
|
||
private loadSettings(): ComfySettingsData { | ||
if (!fs.existsSync(this.filePath)) { | ||
throw new Error(`Settings file ${this.filePath} does not exist`); | ||
} | ||
try { | ||
const fileContent = fs.readFileSync(this.filePath, 'utf-8'); | ||
return JSON.parse(fileContent); | ||
} catch (error) { | ||
log.error(`Failed to load settings from ${this.filePath}:`, error); | ||
return {}; | ||
} | ||
} | ||
|
||
get autoUpdate(): boolean { | ||
return this.settings['Comfy-Desktop.AutoUpdate'] ?? true; | ||
} | ||
|
||
get sendCrashStatistics(): boolean { | ||
return this.settings['Comfy-Desktop.SendCrashStatistics'] ?? true; | ||
} | ||
|
||
public reload(): void { | ||
this.settings = this.loadSettings(); | ||
} | ||
|
||
public getAllDesktopSettings(): Record<string, any> { | ||
return Object.entries(this.settings) | ||
.filter(([key]) => key.startsWith('Comfy-Desktop.')) | ||
.reduce( | ||
(acc, [key, value]) => { | ||
const settingName = key.replace('Comfy-Desktop.', ''); | ||
acc[settingName] = value; | ||
return acc; | ||
}, | ||
{} as Record<string, any> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters