Skip to content

Add configurable device aliases to Qt dropdowns - #1768

Merged
Mysticial merged 2 commits into
PokemonAutomation:mainfrom
pifopi:rename-devices
Nov 2, 2026
Merged

Mysticial merged 2 commits into
PokemonAutomation:mainfrom
pifopi:rename-devices

Conversation

@pifopi

@pifopi pifopi commented Oct 30, 2026

Copy link
Copy Markdown
Member

I made this for my fork and thought about sharing this

@pifopi

pifopi commented Oct 31, 2026

Copy link
Copy Markdown
Member Author

Added documentation in PR PokemonAutomation/pokemonautomation.github.io#114

@pifopi
pifopi marked this pull request as ready for review October 31, 2026 11:34

@pa-devbot pa-devbot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review: ## Summary

Nice feature — configurable aliases for the camera/audio dropdowns. I verified the following on this branch (aarch64 Linux, same toolchain as CI):

  • Full build of SerialPrograms succeeds.
  • --command-line-test-mode: 20,325 passed, 0 failed, 3 skipped.

Things I checked that look good:

  • Aliases are presentation-only: both AudioSourceDescriptor_Device and VideoSourceDescriptor_Camera serialize device_name() (the device ID), not the display name, so changing an alias can't break settings round-trips, and dropdown selection matching uses operator== on the ID.
  • The AudioDeviceInfo::display_name() signature change (const std::string& → std::string) is safe; I checked all callers (AudioSource_Device.cpp, AudioSession.cpp, AudioSelectorWidget.cpp) — none store the reference.
  • No recursive-initialization hazard: GlobalSettings's constructor doesn't enumerate cameras/audio, so display_name() → GlobalSettings::instance() can't re-enter mid-construction. GlobalSettings::instance() is a function-local static, so calling it from worker-thread logging paths is safe.
  • DeviceAliasOptions overriding to_json()/load_json() to serialize the raw table array is fine: GlobalSettings (a BatchOption) saves/loads it by the DEVICE_ALIASES key, and enable_saveload=false only hides the table's Load/Save/Restore-Defaults buttons.
  • The EnumDropdownCell + StringCell row pattern matches existing tables (e.g. PokemonLA_CustomPathTable), and the branch is 1 commit behind main (an unrelated module), so it should merge cleanly.

Minor points below; none are blockers.

if (!alias.empty()){
result = std::move(alias);
}
return true;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review: Minor: the lookup stops at the first row matching (category, device ID), even when that row's alias is empty. If the settings JSON ever ends up with two rows for the same device (only possible by hand-editing the JSON, since add_device() deduplicates), an empty-alias row earlier in the table would shadow a later row with a real alias. Consider only returning true (stopping) when a non-empty alias was found, i.e. keep scanning while result is still empty.

GlobalSettingsPanel::GlobalSettingsPanel()
: settings(GlobalSettings::instance())
{
settings.DEVICE_ALIASES->add_connected_devices();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review: Note: this runs synchronously on the GUI thread every time Global Settings is opened. AudioDeviceInfo::all_input_devices() probes every input device's supported formats (and get_all_cameras() enumerates the video backend), so on a machine with many virtual audio devices or a stuck USB camera this can stall the UI for several seconds while the panel is being constructed. Consider deferring it (e.g. a one-shot QTimer::singleShot after the panel is shown) or enumerating on a worker thread.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is fine I think. We already have this delay when loading any program. If it becomes a problem in the future, we can add an async refresher like what the video sources already do.

}
}

void DeviceDropdownAliases::add_connected_devices(){

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review: Design question: auto-added rows are persisted into the settings JSON (via GlobalSettings::to_json()) and never pruned, so over time the table accumulates rows for devices that are no longer connected (the table is collapsed by default past 10 rows, so this is mostly invisible). A stale alias could also apply to a different device that later gets the same ID (device IDs from Qt/ALSA are not guaranteed stable across reboots or when other devices are plugged in). It may be worth pruning rows for devices that aren't currently connected when refreshing here (keeping user-edited rows with aliases?), or at least mentioning the persistence in the table label.

@Mysticial
Mysticial merged commit 0fc0e44 into PokemonAutomation:main Nov 2, 2026
7 checks passed
@pifopi
pifopi deleted the rename-devices branch November 2, 2026 09:37
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