Plugin Context Calls

PluginContext provides plugins with the following capabilities:

Important

Some capabilities may require permissions, see the Plugin Permissions page

  • page: Current Flet Page instance,可用于构建 UI 控件或注册事件。
  • register_navigation(view): Register a main navigation view (see below).
  • register_route(view): Register an additional route, accessible through page.go().
  • register_startup_hook(hook): Register a callback to execute after application startup.
  • set_initial_route(route): Optionally change the initial route.
  • logger: loguru.Logger bound with plugin identifier, simply use logger.info("...").
  • metadata: Dictionary,可用于在插件及核心系统之间传递额外信息;也可通过 context.add_metadata(key, value) 辅助写入。
  • Global data interfaces:
    • register_data_namespace(identifier, *, description="", permission=None): Register namespace, declare data ownership and access permissions.
    • publish_data(namespace_id, entry_id, payload): Write/update data entries in the namespace.
    • latest_data(namespace_id) / get_data(namespace_id, entry_id) / list_data(namespace_id): Read shared data snapshots,需被授予命名空间所要求的权限。
  • Storage path factories: plugin_data_path, plugin_config_path, plugin_cache_path and corresponding *_dir methods for accessing/initializing plugin-specific data, config, cache directories.传入 create=True 时会确保目录存在。
  • add_bing_action(factory): Append custom buttons or other controls to the “Resources → Bing Daily” action row.
  • add_spotlight_action(factory): Append controls to the “Resources → Windows Spotlight” action row.
  • register_settings_page(label, builder, *, icon=None, button_label="Plugin Settings", description=None): Register plugin’s exclusive settings page.插件管理面板会在对应插件卡片中显示一个"插件设置"按钮,并在新页面中渲染 builder 返回的控件。
  • Favorites management interfaces (available after core plugin activation,需在 manifest 中声明并获批对应的 favorites_* 权限;使用前可通过 context.has_favorite_support() 判断):
    • context.favorites: Returns FavoriteService instance,包裹了全部收藏操作并在内部执行权限校验。历史属性 context.favorite_manager 仍可用,但会返回同一服务实例。
    • Read: favorites.list_folders() / favorites.get_folder(id) / favorites.list_items(folder_id="__all__") / favorites.get_item(item_id) / favorites.find_by_source(source) (requires favorites_read).
    • Write: favorites.create_folder(...), favorites.update_folder(...), favorites.delete_folder(...), favorites.add_or_update_item(...), favorites.update_item(...), favorites.remove_item(...), favorites.register_classifier(...), favorites.classify_item(...) (requires favorites_write).
    • Import/export: favorites.export_folders(target_path, folder_ids=None, include_assets=True), favorites.import_package(path), favorites.localize_items_from_files(mapping), favorites.localization_root() (requires favorites_export). Related data types (FavoriteSource, FavoriteItem, etc.) can be directly imported from app.plugins. Related data types (FavoriteSource, FavoriteItem, etc.) can be directly imported from app.plugins.
  • System operation interfaces (return PluginOperationResult,详见下文):
    • open_route(route: str): Request navigation to specified route.需声明并获得 app_route 权限。
    • switch_home(navigation_id: str): Switch homepage sidebar navigation item (e.g., home, resource). Requires app_home permission.
    • open_settings_tab(tab: int): Open settings page and locate to specified tab (按设置tabs顺序,从0开始). Requires app_settings permission.
    • set_wallpaper(path: str): Set local image as system wallpaper. Requires wallpaper_control permission.
    • ipc_broadcast(channel: str, payload: dict): Publish messages through cross-process broadcast. Requires ipc_broadcast permission.
    • ipc_subscribe(channel: str): Subscribe to cross-process broadcast channel,成功时结果的 dataIPCSubscription 对象,可调用 .get() 读取队列消息。
    • ipc_unsubscribe(subscription_id: str): Unsubscribe,传入 ipc_subscribe 返回的订阅 ID。