Plugin API
繁體中文
繁體中文
  • 入門
    • 簡介
    • 你的第一個插件
    • 檔案結構概述
    • 插件類型
      • 視窗
      • 背景服務
      • 格式擴充
      • 檢查器
    • 除錯插件
  • 部署
    • 準備插件
    • 打包插件
    • 發佈插件
    • 更新插件
    • 開發者政策
    • 插件圖示樣板
  • 開發指南
    • manifest.json 完整設定
    • 取得數據
    • 修改數據
    • 存取本機檔案
    • 發出網路請求
    • 使用 Node.js 原生 API
    • 使用第三方模快
    • 多國語言(i18n)
    • 無邊框視窗
  • API 參考
    • event(事件)
    • item(項目)
    • folder(資料夾)
    • tag(標籤)
    • tagGroup(標籤群組)
    • library(資源庫)
    • window(視窗)
    • app(應用)
    • os(作業系統)
    • screen(螢幕)
    • notification(通知)
    • contextMenu(右鍵選單)
    • dialog(對話框)
    • clipboard(剪貼板)
    • drag(拖曳檔案)
    • shell(殼)
    • log(日誌)
  • 额外组件
    • FFmpeg
Powered by GitBook
On this page
  1. 入門
  2. 插件類型

背景服務

這篇文章將闡述背景服務插件的基本概念。

Previous視窗Next格式擴充

Last updated 1 year ago

背景服務插件與開發方式類似,主要區別在於程式碼的執行時機。背景服務插件會在軟體啓動時自動啓動,而視窗插件只會在使用者點擊時執行。要新增一個背景服務插件,只需要在 manifest.json 中的 main 欄位新增 "serviceMode": true,如下所示:

{
    "main":
    {
        "serviceMode": true,    // 主要差異
        "url": "index.html",
        "width": 640,
        "height": 480
    }
}

背景服務插件也能彈出視窗,你可以在這個視窗顯示當前背景任務的進度、狀態,以便使用者可以清楚地瞭解插件的當前狀態。

最終程式碼如下:

{
    "id": "LBCZEHP8BBO94",
    "version": "1.0.0",
    "name": "Service Plugin",
    "logo": "/logo.png",
    "keywords": [],
    "main":
    {
        "serviceMode": true,
        "url": "index.html",
        "width": 640,
        "height": 480
    }
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <script type="text/javascript" src="js/plugin.js"></script>
</head>

<body>
    <div>Background services can be without UI, but you can still display the status of background services here.</div>
</body>
</html>
console.log(`Plugins will be created automatically, no need for users to execute them.`);

eagle.onPluginCreate((plugin) => {
    console.log('eagle.onPluginCreate');
    console.log(plugin);
});

eagle.onPluginShow(() => {
    console.log('eagle.onPluginShow');
});

eagle.onPluginHide(() => {
    console.log('eagle.onPluginHide');
});

完整範例程式碼:

注:你可以查看這篇文章,。

注意: 如果插件執行過程必須依賴相對的資源庫路徑,你可能需要透過,在資源庫切換時,做出對應的調整,避免程式執行過程發生錯誤。

視窗插件
https://github.com/eagle-app/eagle-plugin-examples/tree/main/Service
瞭解 manifest.json的所有設定方式
onLibraryChanged(callback)