Albert Launcher Documentation

repository·main·Indexed 27 days ago

https://github.com/albertlauncher/albert

A 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.

Tokens
1.8K
Snippets
0
Records
15
Agent score
93%

What's inside Albert

  1. Manage Trigger Handlers

    main

    Trigger handlers allow specific extensions to respond to certain input prefixes (triggers).

    • triggerHandlers(): Returns a map of all registered albert::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.
  2. Manage Global Handlers

    main

    Global handlers are available across different contexts.

    • globalHandlers(): Returns a map of albert::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.
  3. Observe QueryEngine changes via signals

    main

    The QueryEngine emits 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()
  4. Manage plugins with PluginRegistry

    main

    The PluginRegistry class 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 a std::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.
  5. Manage extensions via the App class

    main

    The albert::App class provides methods to discover and retrieve extensions. Extensions are identified by a QString ID.

    • 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 type T.
    • extension<T>(id): Retrieves a specific extension by its ID, automatically performing a dynamic_cast to type T. Returns nullptr if the ID is not found or the type is incorrect.
  6. Configure usage scoring and item activation

    main

    The QueryEngine manages usage scoring to prioritize frequently used items.

    • usageScoring(): Returns the current albert::UsageScoring instance.
    • 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.
  7. Access application persistence and file locations

    main

    The albert::App class provides access to configuration, state, and filesystem paths. These methods are thread-safe.

    • settings(): Returns a std::unique_ptr<QSettings> initialized with the application configuration file path.
    • state(): Returns a std::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.
  8. Manage Fallback Handlers

    main

    Fallback handlers provide alternative results when primary handlers do not produce matches.

    • fallbackHandlers(): Returns a map of albert::FallbackHandler* objects indexed by their identifier.
    • fallbackOrder(): Returns the current order of fallbacks as a map where the key is a std::pair<QString, QString> (likely representing handler/context identifiers) and the value is an int priority.
    • setFallbackOrder(std::map<std::pair<QString, QString>, int>): Sets the priority order for fallback handlers.