From 88f7d2a7c1e4dde3279fedd42bc44a22b9f34048 Mon Sep 17 00:00:00 2001 From: Ken Date: Sat, 16 May 2026 20:56:32 +0800 Subject: [PATCH] fix: bundle sql.js wasm for Obsidian release --- .github/workflows/release.yml | 45 +++++++++++++++++++++++++++++++++++ README.md | 14 ++++++++--- README.zh-TW.md | 12 ++++++++-- THIRD_PARTY_NOTICES.md | 31 ++++++++++++++++++++++++ manifest.json | 2 +- package-lock.json | 4 ++-- package.json | 10 ++++---- src/main.ts | 23 +++++++++--------- src/types.d.ts | 4 ++++ 9 files changed, 121 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 THIRD_PARTY_NOTICES.md create mode 100644 src/types.d.ts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..8798fa3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,45 @@ +name: Release + +on: + push: + tags: + - "*" + +permissions: + contents: write + id-token: write + attestations: write + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: npm + + - name: Install dependencies + run: npm ci + + - name: Build plugin + run: npm run build + + - name: Attest build provenance + uses: actions/attest-build-provenance@v3 + with: + subject-path: | + dist/main.js + dist/manifest.json + + - name: Create release + uses: softprops/action-gh-release@v2 + with: + files: | + dist/main.js + dist/manifest.json diff --git a/README.md b/README.md index 100a572..127138a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Kobo Note Sync -[繁體中文](README.zh-TW.md) +[繁體中文](https://github.com/KennKyou/obsidian-kobo-note-sync/blob/main/README.zh-TW.md) An Obsidian plugin that imports highlights and annotations from your Kobo e-reader into Obsidian notes. @@ -25,7 +25,7 @@ The plugin reads the local `Kobo.sqlite` database created by the Kobo Desktop Ap ### Manual Installation -1. Download `main.js`, `manifest.json`, and `sql-wasm.wasm` from the [latest release](https://github.com/KennKyou/obsidian-kobo-note-sync/releases) +1. Download `main.js` and `manifest.json` from the [latest release](https://github.com/KennKyou/obsidian-kobo-note-sync/releases) 2. Create a folder `kobo-note-sync` in your vault's `.obsidian/plugins/` directory 3. Copy the downloaded files into that folder 4. Restart Obsidian and enable the plugin in Settings → Community Plugins @@ -42,6 +42,14 @@ The plugin reads the local `Kobo.sqlite` database created by the Kobo Desktop Ap Highlights will be created as Markdown files in the configured output folder (default: `Kobo Note Sync/`). +## Privacy + +This plugin reads the local Kobo SQLite database selected in settings and creates or updates notes in your Obsidian vault. It does not send your reading data to any external server. + +## Third Party Notices + +This plugin includes `sql.js`, which is licensed under the MIT License. See [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md). + ## Settings | Setting | Description | @@ -126,4 +134,4 @@ source: Kobo **Note:** <%= it.annotation %> <% } %> --- -``` \ No newline at end of file +``` diff --git a/README.zh-TW.md b/README.zh-TW.md index 7a0cc5c..3a5fe57 100644 --- a/README.zh-TW.md +++ b/README.zh-TW.md @@ -25,7 +25,7 @@ Kobo 閱讀器 / App → Kobo 雲端 → Kobo Desktop App → Kobo.sqlite → ### 手動安裝 -1. 從 [最新版本](https://github.com/KennKyou/obsidian-kobo-note-sync/releases) 下載 `main.js`、`manifest.json` 和 `sql-wasm.wasm` +1. 從 [最新版本](https://github.com/KennKyou/obsidian-kobo-note-sync/releases) 下載 `main.js` 和 `manifest.json` 2. 在 Vault 的 `.obsidian/plugins/` 目錄下建立 `kobo-note-sync` 資料夾 3. 將下載的檔案複製到該資料夾 4. 重新啟動 Obsidian,在 設定 → 社群插件 中啟用 @@ -42,6 +42,14 @@ Kobo 閱讀器 / App → Kobo 雲端 → Kobo Desktop App → Kobo.sqlite → 畫線會以 Markdown 檔案儲存在設定的輸出資料夾中(預設:`Kobo Note Sync/`)。 +## 隱私 + +本插件會讀取你在設定中指定的本機 Kobo SQLite 資料庫,並在你的 Obsidian Vault 中建立或更新筆記。插件不會將你的閱讀資料傳送到任何外部伺服器。 + +## 第三方授權聲明 + +本插件包含 `sql.js`,其授權條款為 MIT License。詳見 [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md)。 + ## 設定 | 設定項目 | 說明 | @@ -126,4 +134,4 @@ source: Kobo **Note:** <%= it.annotation %> <% } %> --- -``` \ No newline at end of file +``` diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md new file mode 100644 index 0000000..e033e3e --- /dev/null +++ b/THIRD_PARTY_NOTICES.md @@ -0,0 +1,31 @@ +# Third Party Notices + +This plugin includes sql.js. + +sql.js is licensed under the MIT License. + +Repository: https://github.com/sql-js/sql.js + +## sql.js MIT License + +MIT License + +Copyright (c) sql.js authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/manifest.json b/manifest.json index 2cacc84..1b38599 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "kobo-note-sync", "name": "Kobo Note Sync", - "version": "1.0.0", + "version": "1.0.1", "minAppVersion": "1.0.0", "description": "Import highlights and annotations from your Kobo e-reader into your notes.", "author": "KennKyou", diff --git a/package-lock.json b/package-lock.json index c42c8a8..b9997ab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "kobo-note-sync", - "version": "1.0.0", + "version": "1.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "kobo-note-sync", - "version": "1.0.0", + "version": "1.0.1", "dependencies": { "eta": "^4.5.1", "sql.js": "^1.14.1" diff --git a/package.json b/package.json index 31cfc42..af02ab2 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { "name": "kobo-note-sync", - "version": "1.0.0", + "version": "1.0.1", "description": "Import Kobo highlights and annotations into Obsidian notes", "main": "main.js", "scripts": { - "build": "esbuild src/main.ts --bundle --outfile=dist/main.js --external:obsidian --external:electron --format=cjs --platform=node --target=es2020 && npm run copy-assets", - "dev": "esbuild src/main.ts --bundle --outfile=dist/main.js --external:obsidian --external:electron --format=cjs --platform=node --target=es2020 --watch", - "copy-assets": "cp manifest.json node_modules/sql.js/dist/sql-wasm.wasm dist/", - "deploy": "npm run build && cp dist/main.js dist/manifest.json dist/sql-wasm.wasm \"$OBSIDIAN_PLUGINS/kobo-note-sync/\"" + "build": "esbuild src/main.ts --bundle --outfile=dist/main.js --external:obsidian --external:electron --format=cjs --platform=node --target=es2020 --loader:.wasm=binary && npm run copy-assets", + "dev": "esbuild src/main.ts --bundle --outfile=dist/main.js --external:obsidian --external:electron --format=cjs --platform=node --target=es2020 --loader:.wasm=binary --watch", + "copy-assets": "cp manifest.json dist/", + "deploy": "npm run build && cp dist/main.js dist/manifest.json \"$OBSIDIAN_PLUGINS/kobo-note-sync/\"" }, "devDependencies": { "@types/node": "^20.0.0", diff --git a/src/main.ts b/src/main.ts index f830d8d..4349fa4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,9 +1,10 @@ -import { App, Notice, Plugin, PluginSettingTab, Setting, normalizePath } from "obsidian"; +import { App, Notice, Plugin, PluginSettingTab, Setting, moment, normalizePath } from "obsidian"; import * as fs from "fs"; import * as path from "path"; import * as os from "os"; import { Eta } from "eta"; import initSqlJs from "sql.js"; +import sqlWasmBinary from "sql.js/dist/sql-wasm.wasm"; const eta = new Eta({ autoEscape: false, rmWhitespace: false, autoTrim: [false, false] }); @@ -153,9 +154,13 @@ const locales: Record = { }, }; +function getLocaleKey(): keyof typeof locales { + const lang = moment.locale().toLowerCase(); + return lang.startsWith("zh") ? "zh-TW" : "en"; +} + function getLocale(): LocaleStrings { - const lang = window.localStorage.getItem("language") || "en"; - return locales[lang] || locales["en"]; + return locales[getLocaleKey()]; } // --------------------------------------------------------------------------- @@ -237,7 +242,7 @@ function numVal(v: unknown, fallback = 0): number { return isNaN(n) ? fallback : n; } -async function readKoboDb(dbPath: string, pluginDir: string): Promise { +async function readKoboDb(dbPath: string): Promise { const resolvedPath = expandHome(dbPath); if (!fs.existsSync(resolvedPath)) { @@ -249,9 +254,7 @@ async function readKoboDb(dbPath: string, pluginDir: string): Promise