Skip to content

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

Merged
merged 6 commits into from
Jul 4, 2025
Merged

add installedVersion #4337

merged 6 commits into from
Jul 4, 2025

Conversation

jtydhr88
Copy link
Collaborator

@jtydhr88 jtydhr88 commented Jul 3, 2025

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

@jtydhr88 jtydhr88 requested a review from a team as a code owner July 3, 2025 03:01
@christian-byrne
Copy link
Contributor

christian-byrne commented Jul 3, 2025

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 Detection

I recommend creating a dedicated service that:

  1. Uses multiple indicators for more reliable new user detection
  2. Allows extensions to register callbacks for new user initialization
// 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 defaultValue: '' instead of defaultValue: null in coreSettings.ts.

This approach:

  • Uses multiple indicators (settings, workflow, previousWorkflow) for more reliable detection
  • Provides a clean API for extensions to hook into new user initialization
  • Handles timing issues by queuing callbacks if needed
  • Has minimal memory overhead

Using an empty string as the default value maintains consistency with other string settings in the codebase and avoids potential null handling issues.

@christian-byrne
Copy link
Contributor

christian-byrne commented Jul 3, 2025

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 Comfy.TutorialCompleted for that case like

const isNewUserSettings = Object.keys(settingStore.settingValues).length === 0 || settingsStore.get('Comfy.TutorialCompleted') !== true

Copy link
Contributor

@webfiltered webfiltered left a 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.

@jtydhr88 jtydhr88 requested a review from a team as a code owner July 4, 2025 01:31
@christian-byrne
Copy link
Contributor

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.

@christian-byrne
Copy link
Contributor

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
@christian-byrne christian-byrne merged commit c1db367 into main Jul 4, 2025
10 checks passed
@christian-byrne christian-byrne deleted the installedVersion branch July 4, 2025 23:52
This was referenced Jul 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants