-
Notifications
You must be signed in to change notification settings - Fork 317
add installedVersion #4337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add installedVersion #4337
Conversation
Thanks for starting this implementation! I know I was the one who wrote the intial spec, but I have a suggestion to make this more robust and extensible so we can extend new user initialization in the future. Extract to a Service with Improved DetectionI recommend creating a dedicated service that:
// src/services/newUserService.ts
let isNewUserDetermined = false
let isNewUserCached: boolean | null = null
let pendingCallbacks: Array<() => Promise<void>> = []
function checkIsNewUser(settingStore: ReturnType<typeof useSettingStore>): boolean {
const hasNoSettings = Object.keys(settingStore.settingValues).length === 0
const hasNoWorkflow = !localStorage.getItem('workflow')
const hasNoPreviousWorkflow = !localStorage.getItem('Comfy.PreviousWorkflow')
return hasNoSettings && hasNoWorkflow && hasNoPreviousWorkflow
}
export const newUserService = {
async registerInitCallback(callback: () => Promise<void>) {
if (isNewUserDetermined) {
if (isNewUserCached) {
try {
await callback()
} catch (error) {
console.error('New user initialization callback failed:', error)
}
}
} else {
pendingCallbacks.push(callback)
}
},
async initializeIfNewUser(settingStore: ReturnType<typeof useSettingStore>) {
if (isNewUserDetermined) return
isNewUserCached = checkIsNewUser(settingStore)
isNewUserDetermined = true
if (\!isNewUserCached) {
pendingCallbacks = []
return
}
await settingStore.set('Comfy.InstalledVersion', __COMFYUI_FRONTEND_VERSION__)
// using a `while` loop here with `pop` is better though
for (const callback of pendingCallbacks) {
try {
await callback()
} catch (error) {
console.error('New user initialization callback failed:', error)
}
}
pendingCallbacks = []
},
isNewUser(): boolean | null {
return isNewUserDetermined ? isNewUserCached : null
}
} Then in GraphCanvas.vue: import { newUserService } from '@/services/newUserService'
// After settings load
await newUserService.initializeIfNewUser(settingStore) And update the setting to use This approach:
Using an empty string as the default value maintains consistency with other string settings in the codebase and avoids potential null handling issues. |
Actually, this line is not too robust: const hasNoSettings = Object.keys(settingStore.settingValues).length === 0 Because on Desktop, we pre-load some settings values before the python server starts. We can check for the const isNewUserSettings = Object.keys(settingStore.settingValues).length === 0 || settingsStore.get('Comfy.TutorialCompleted') !== true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For new user detection, we really should be setting a simple tri-state flag that explicitly says they're not a new user, immediately on first load.
Creating a new user (moving forward) should explicitly set this to false.
We can run the many-check workaround to cover the fact that we never set this for pre-existing users, but eventually it would be nice to remove it entirely.
Just pushed a small improvement to clarify the setting description. Changed from "Installed frontend version" to "The frontend version that was running when the user first installed ComfyUI" to better explain what this setting tracks. |
I also removed the console.log, but didn't realize one of the unit tests was using it to verify something. I can fix it. |
Update test to verify new user status without relying on console.log
first part for #4073, which is the foundation for next, when we should set Comfy.InstalledVersion, or in other words, how to determine whether a user is a new user or an existing user.
As research, the user settings will be stored in Comfy Core/BE folder - user/defalut/comfy.settings.json, and new instance of ComfyUI will have no settings. will return empty settings to frontend.
if this settings file is not empty, it means the user has already used ComfyUI before, and we should not set the Comfy.InstalledVersion, according to #4073
┆Issue is synchronized with this Notion page by Unito