Albert Launcher Documentation
repository·main·Indexed 27 days ago
https://github.com/albertlauncher/albertA plugin-based, desktop-agnostic keyboard launcher implemented in C++ using the Qt framework. Documentation covers the albert::App singleton for application lifecycle and extension management, the PluginRegistry for handling plugin dependencies and states, and the QueryEngine for managing search queries, usage scoring, and trigger, global, and fallback handlers.
What's inside Albert
- Albert is a plugin-based, desktop-agnostic keyboard launcher built with C++ and Qt. It is designed to provide quick access to applications, files, and other resources via keyboard shortcuts.
Manage Trigger Handlers
mainTrigger handlers allow specific extensions to respond to certain input prefixes (triggers).
triggerHandlers(): Returns a map of all registeredalbert::QueryHandler*objects indexed by their trigger string.activeTriggerHandlers(): Returns the map of currently active handlers.trigger(const QString&) const: Returns the trigger string associated with the provided input.setTrigger(const QString&, const QString&): Sets the trigger string for a handler.fuzzy(const QString&) const: Checks if fuzzy matching is enabled for a specific trigger.setFuzzy(const QString&, bool): Enables or disables fuzzy matching for a specific trigger.
Manage Global Handlers
mainGlobal handlers are available across different contexts.
globalHandlers(): Returns a map ofalbert::GlobalQueryHandler*objects indexed by their identifier.isEnabled(const QString&) const: Checks if a specific global handler is currently enabled.setEnabled(const QString&, bool = true): Enables or disables a specific global handler.
Access the global Albert application instance
mainTo interact with the core Albert application (e.g., managing extensions, accessing settings, or controlling application lifecycle), use the globalalbert::app()function. This returns a reference to the singletonalbert::Appinstance.Execute a search query with QueryEngine::query
mainUseQueryEngine::query(QString query)to initiate a search. It returns astd::unique_ptr<albert::detail::Query>which can be used to interact with the resulting search process.Observe QueryEngine changes via signals
mainThe
QueryEngineemits signals when its internal handler registries change. You can connect to these to react to new extensions or handlers being registered/unregistered:queryHandlerAdded(albert::QueryHandler*)/queryHandlerRemoved(albert::QueryHandler*)globalQueryHandlerAdded(albert::GlobalQueryHandler*)/globalQueryHandlerRemoved(albert::GlobalQueryHandler*)fallbackHandlerAdded(albert::FallbackHandler*)/fallbackHandlerRemoved(albert::FallbackHandler*)activeTriggersChanged()
Manage plugins with PluginRegistry
mainThe
PluginRegistryclass is used to manage the lifecycle, loading state, and enabled status of plugins within Albert. It handles transitive dependencies and dependees when changing states.Key Operations
- Enable/Disable a plugin: Use
setEnabled(id, enable)to toggle a plugin. This will automatically handle its transitive dependencies and dependees. - Load/Unload a plugin: Use
setLoaded(id, load)to change the loading state of a plugin. - User Confirmation:
setEnabledWithUserConfirmation(id, enable)allows enabling/disabling a plugin while prompting the user (useful for handling dependency conflicts). - Accessing Plugins: Use
plugins()to retrieve astd::map<QString, Plugin>containing all registered plugins, keyed by their ID.
Dependency Management
dependencies(plugin): Returns the set of plugins that the specified plugin depends on.dependees(plugin): Returns the set of plugins that depend on the specified plugin.dependencyClosure(set): Returns the full set of dependencies for a given set of plugins.dependeeClosure(set): Returns the full set of dependees for a given set of plugins.
Signals
pluginsChanged(): Emitted when the set of registered plugins changes.pluginEnabledChanged(id): Emitted when a specific plugin's enabled status changes.pluginStateChanged(id): Emitted when a specific plugin's loading state changes.
- Enable/Disable a plugin: Use
Control the Albert application lifecycle
mainUse the following static methods to control the application state. These methods are thread-safe.
albert::App::restart(): Restarts the application.albert::App::quit(): Quits the application.
Manage extensions via the App class
mainThe
albert::Appclass provides methods to discover and retrieve extensions. Extensions are identified by aQStringID.extensions(): Returns a map of all registered extensions (std::map<QString, Extension*>).extensions<T>(): Returns a map of all extensions that can be cast to typeT.extension<T>(id): Retrieves a specific extension by its ID, automatically performing adynamic_castto typeT. Returnsnullptrif the ID is not found or the type is incorrect.
Configure usage scoring and item activation
mainThe
QueryEnginemanages usage scoring to prioritize frequently used items.usageScoring(): Returns the currentalbert::UsageScoringinstance.setMemoryDecay(double): Sets the decay rate for usage scoring.setPrioritizePerfectMatch(bool): Determines if perfect matches should be prioritized.storeItemActivation(const QString &query, const QString &extension, const QString &item, const QString &action): Records that a specific item/action was activated for a given query, which influences future scoring.
Access application persistence and file locations
mainThe
albert::Appclass provides access to configuration, state, and filesystem paths. These methods are thread-safe.settings(): Returns astd::unique_ptr<QSettings>initialized with the application configuration file path.state(): Returns astd::unique_ptr<QSettings>initialized with the application state file path.cacheLocation(): Returns the path to the application cache directory.configLocation(): Returns the path to the application config directory.dataLocation(): Returns the path to the application data directory.
Manage Fallback Handlers
mainFallback handlers provide alternative results when primary handlers do not produce matches.
fallbackHandlers(): Returns a map ofalbert::FallbackHandler*objects indexed by their identifier.fallbackOrder(): Returns the current order of fallbacks as a map where the key is astd::pair<QString, QString>(likely representing handler/context identifiers) and the value is anintpriority.setFallbackOrder(std::map<std::pair<QString, QString>, int>): Sets the priority order for fallback handlers.