update plugin packages

This commit is contained in:
nicwands
2026-02-25 22:22:17 -05:00
parent 949f14f0e1
commit fc4ba2c487
6 changed files with 79 additions and 75 deletions

View File

@@ -1,11 +1,14 @@
"use strict"; import { electronApp, optimizer, is } from "@electron-toolkit/utils";
const utils = require("@electron-toolkit/utils"); import { app, BrowserWindow, ipcMain, shell } from "electron";
const electron = require("electron"); import filesystemPlugin from "@takerofnotes/plugin-filesystem";
const filesystemPlugin = require("takerofnotes-plugin-filesystem"); import fs from "fs/promises";
const fs = require("fs/promises"); import path, { join } from "path";
const path = require("path"); import { Index } from "flexsearch";
const flexsearch = require("flexsearch"); import crypto from "crypto";
const crypto = require("crypto"); import __cjs_mod__ from "node:module";
const __filename = import.meta.filename;
const __dirname = import.meta.dirname;
const require2 = __cjs_mod__.createRequire(import.meta.url);
class PluginRegistry { class PluginRegistry {
constructor() { constructor() {
this.plugins = /* @__PURE__ */ new Map(); this.plugins = /* @__PURE__ */ new Map();
@@ -27,7 +30,7 @@ const USER_DATA_STRING = "__DEFAULT_USER_DATA__";
class PluginConfig { class PluginConfig {
constructor(defaultPlugin) { constructor(defaultPlugin) {
this.defaultPlugin = defaultPlugin; this.defaultPlugin = defaultPlugin;
this.configPath = path.join(electron.app.getPath("userData"), "config.json"); this.configPath = path.join(app.getPath("userData"), "config.json");
} }
// Helper to replace placeholders with dynamic values, recursively // Helper to replace placeholders with dynamic values, recursively
_resolveDefaults(config) { _resolveDefaults(config) {
@@ -40,7 +43,7 @@ class PluginConfig {
} }
return resolved; return resolved;
} else if (typeof config === "string" && config.includes(USER_DATA_STRING)) { } else if (typeof config === "string" && config.includes(USER_DATA_STRING)) {
return config.replace(USER_DATA_STRING, electron.app.getPath("userData")); return config.replace(USER_DATA_STRING, app.getPath("userData"));
} else { } else {
return config; return config;
} }
@@ -89,7 +92,7 @@ class NotesAPI {
} }
this.adapter = adapter; this.adapter = adapter;
this.notesCache = /* @__PURE__ */ new Map(); this.notesCache = /* @__PURE__ */ new Map();
this.index = new flexsearch.Index({ this.index = new Index({
tokenize: "tolerant", tokenize: "tolerant",
resolution: 9 resolution: 9
}); });
@@ -175,10 +178,10 @@ class NotesAPI {
return ids.map((id) => this.notesCache.get(id)); return ids.map((id) => this.notesCache.get(id));
} }
} }
const preloadPath = path.join(__dirname, "../preload/index.js"); const preloadPath = join(__dirname, "../preload/index.mjs");
const rendererPath = path.join(__dirname, "../renderer/index.html"); const rendererPath = join(__dirname, "../renderer/index.html");
function createWindow() { function createWindow() {
const mainWindow2 = new electron.BrowserWindow({ const mainWindow2 = new BrowserWindow({
width: 354, width: 354,
height: 549, height: 549,
show: false, show: false,
@@ -192,27 +195,28 @@ function createWindow() {
mainWindow2.show(); mainWindow2.show();
}); });
mainWindow2.webContents.setWindowOpenHandler((details) => { mainWindow2.webContents.setWindowOpenHandler((details) => {
electron.shell.openExternal(details.url); shell.openExternal(details.url);
return { action: "deny" }; return { action: "deny" };
}); });
if (utils.is.dev && process.env["ELECTRON_RENDERER_URL"]) { if (is.dev && process.env["ELECTRON_RENDERER_URL"]) {
mainWindow2.loadURL(process.env["ELECTRON_RENDERER_URL"]); mainWindow2.loadURL(process.env["ELECTRON_RENDERER_URL"]);
} else { } else {
mainWindow2.loadFile(rendererPath); mainWindow2.loadFile(rendererPath);
} }
} }
function createNoteWindow(noteId) { function createNoteWindow(noteId) {
const noteWindow = new electron.BrowserWindow({ const noteWindow = new BrowserWindow({
width: 354, width: 354,
height: 549, height: 549,
autoHideMenuBar: true, autoHideMenuBar: true,
webPreferences: { webPreferences: {
preload: preloadPath, preload: preloadPath,
contextIsolation: true, contextIsolation: true,
nodeIntegration: false nodeIntegration: false,
sandbox: false
} }
}); });
if (utils.is.dev && process.env["ELECTRON_RENDERER_URL"]) { if (is.dev && process.env["ELECTRON_RENDERER_URL"]) {
noteWindow.loadURL( noteWindow.loadURL(
`${process.env["ELECTRON_RENDERER_URL"]}/note/${noteId}` `${process.env["ELECTRON_RENDERER_URL"]}/note/${noteId}`
); );
@@ -222,34 +226,34 @@ function createNoteWindow(noteId) {
}); });
} }
} }
electron.app.whenReady().then(async () => { app.whenReady().then(async () => {
utils.electronApp.setAppUserModelId("com.electron"); electronApp.setAppUserModelId("com.electron");
electron.app.on("browser-window-created", (_, window) => { app.on("browser-window-created", (_, window) => {
utils.optimizer.watchWindowShortcuts(window); optimizer.watchWindowShortcuts(window);
}); });
createWindow(); createWindow();
electron.app.on("activate", function() { app.on("activate", function() {
if (electron.BrowserWindow.getAllWindows().length === 0) createWindow(); if (BrowserWindow.getAllWindows().length === 0) createWindow();
}); });
electron.ipcMain.on("open-note-window", (_, noteId) => { ipcMain.on("open-note-window", (_, noteId) => {
createNoteWindow(noteId); createNoteWindow(noteId);
}); });
const registry = new PluginRegistry(); const registry = new PluginRegistry();
registry.register(filesystemPlugin.default); registry.register(filesystemPlugin);
const config = await new PluginConfig(filesystemPlugin).load(); const config = await new PluginConfig(filesystemPlugin).load();
const plugin = registry.get(config.activeAdapter); const plugin = registry.get(config.activeAdapter);
const adapter = plugin.createAdapter(config.adapterConfig); const adapter = plugin.createAdapter(config.adapterConfig);
const notesAPI = new NotesAPI(adapter); const notesAPI = new NotesAPI(adapter);
await notesAPI.init(); await notesAPI.init();
electron.ipcMain.handle("notesAPI:call", (_, method, args) => { ipcMain.handle("notesAPI:call", (_, method, args) => {
if (!notesAPI[method]) { if (!notesAPI[method]) {
throw new Error("Invalid method"); throw new Error("Invalid method");
} }
return notesAPI[method](...args); return notesAPI[method](...args);
}); });
}); });
electron.app.on("window-all-closed", () => { app.on("window-all-closed", () => {
if (process.platform !== "darwin") { if (process.platform !== "darwin") {
electron.app.quit(); app.quit();
} }
}); });

View File

@@ -1,20 +0,0 @@
"use strict";
const electron = require("electron");
const api = {
openNoteWindow: (noteId) => {
electron.ipcRenderer.send("open-note-window", noteId);
}
};
const notesAPI = {
call: (method, ...args) => electron.ipcRenderer.invoke("notesAPI:call", method, args)
};
if (process.contextIsolated) {
try {
electron.contextBridge.exposeInMainWorld("api", api);
electron.contextBridge.exposeInMainWorld("notesAPI", notesAPI);
} catch (error) {
console.error(error);
}
} else {
window.api = api;
}

19
out/preload/index.mjs Normal file
View File

@@ -0,0 +1,19 @@
import { contextBridge, ipcRenderer } from "electron";
const api = {
openNoteWindow: (noteId) => {
ipcRenderer.send("open-note-window", noteId);
}
};
const notesAPI = {
call: (method, ...args) => ipcRenderer.invoke("notesAPI:call", method, args)
};
if (process.contextIsolated) {
try {
contextBridge.exposeInMainWorld("api", api);
contextBridge.exposeInMainWorld("notesAPI", notesAPI);
} catch (error) {
console.error(error);
}
} else {
window.api = api;
}

40
package-lock.json generated
View File

@@ -12,6 +12,7 @@
"@electron-toolkit/preload": "^3.0.2", "@electron-toolkit/preload": "^3.0.2",
"@electron-toolkit/utils": "^4.0.0", "@electron-toolkit/utils": "^4.0.0",
"@fuzzco/font-loader": "^1.0.2", "@fuzzco/font-loader": "^1.0.2",
"@takerofnotes/plugin-filesystem": "^0.1.1",
"@tiptap/extension-document": "^3.19.0", "@tiptap/extension-document": "^3.19.0",
"@tiptap/extension-image": "^3.19.0", "@tiptap/extension-image": "^3.19.0",
"@tiptap/extension-table": "^3.19.0", "@tiptap/extension-table": "^3.19.0",
@@ -27,7 +28,6 @@
"lodash": "^4.17.23", "lodash": "^4.17.23",
"sass": "^1.97.3", "sass": "^1.97.3",
"sass-embedded": "^1.97.3", "sass-embedded": "^1.97.3",
"takerofnotes-plugin-filesystem": "^1.6.0",
"tempus": "^1.0.0-dev.17", "tempus": "^1.0.0-dev.17",
"uuid": "^13.0.0", "uuid": "^13.0.0",
"vue-router": "^5.0.3" "vue-router": "^5.0.3"
@@ -2260,6 +2260,25 @@
"node": ">=10" "node": ">=10"
} }
}, },
"node_modules/@takerofnotes/plugin-filesystem": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/@takerofnotes/plugin-filesystem/-/plugin-filesystem-0.1.1.tgz",
"integrity": "sha512-u3L6HLxN/+t7PTtzzRA2uzgaVh/O1vasngU/tQeC6JsTnlIrypWFVbAlTS5zT9Km4y+8w6C16eEq7tcN8+5lPg==",
"license": "MIT",
"dependencies": {
"@takerofnotes/plugin-sdk": "^0.1.0",
"gray-matter": "^4.0.3"
}
},
"node_modules/@takerofnotes/plugin-sdk": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/@takerofnotes/plugin-sdk/-/plugin-sdk-0.1.0.tgz",
"integrity": "sha512-ofhwwiQ59kNMEg2vvYoNq5JdXHB9/6TkDsbyroM5nsP/VPUvJSQ5g0UWCYBhteSzJ36iFUB+LtUwVt6gOXDClw==",
"license": "MIT",
"dependencies": {
"zod": "^4.3.6"
}
},
"node_modules/@tiptap/core": { "node_modules/@tiptap/core": {
"version": "3.19.0", "version": "3.19.0",
"resolved": "https://registry.npmjs.org/@tiptap/core/-/core-3.19.0.tgz", "resolved": "https://registry.npmjs.org/@tiptap/core/-/core-3.19.0.tgz",
@@ -8314,25 +8333,6 @@
"node": ">=16.0.0" "node": ">=16.0.0"
} }
}, },
"node_modules/takerofnotes-plugin-filesystem": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/takerofnotes-plugin-filesystem/-/takerofnotes-plugin-filesystem-1.6.0.tgz",
"integrity": "sha512-wUcH8lV6ges9zkEU7b7h1SkDcvgoJ+TLfogqRirLg38fdJ/LGat6BBfItO3QlalkYobsb4wglEfd7wg4f4erJA==",
"license": "MIT",
"dependencies": {
"gray-matter": "^4.0.3",
"takerofnotes-plugin-sdk": "^0.4.0"
}
},
"node_modules/takerofnotes-plugin-sdk": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/takerofnotes-plugin-sdk/-/takerofnotes-plugin-sdk-0.4.0.tgz",
"integrity": "sha512-C1bXun19Zh603Aq/7sEI4c3dZ8QEUiz51ikDPJm5g+JWoQkH77OH6AY19SN+eOKnqEmY1yw3JYEVd//mJ06UAA==",
"license": "MIT",
"dependencies": {
"zod": "^4.3.6"
}
},
"node_modules/tar": { "node_modules/tar": {
"version": "7.5.9", "version": "7.5.9",
"resolved": "https://registry.npmjs.org/tar/-/tar-7.5.9.tgz", "resolved": "https://registry.npmjs.org/tar/-/tar-7.5.9.tgz",

View File

@@ -5,6 +5,7 @@
"main": "./out/main/index.js", "main": "./out/main/index.js",
"author": "example.com", "author": "example.com",
"homepage": "https://electron-vite.org", "homepage": "https://electron-vite.org",
"type": "module",
"prettier": { "prettier": {
"tabWidth": 4, "tabWidth": 4,
"semi": false, "semi": false,
@@ -27,6 +28,7 @@
"@electron-toolkit/preload": "^3.0.2", "@electron-toolkit/preload": "^3.0.2",
"@electron-toolkit/utils": "^4.0.0", "@electron-toolkit/utils": "^4.0.0",
"@fuzzco/font-loader": "^1.0.2", "@fuzzco/font-loader": "^1.0.2",
"@takerofnotes/plugin-filesystem": "^0.1.1",
"@tiptap/extension-document": "^3.19.0", "@tiptap/extension-document": "^3.19.0",
"@tiptap/extension-image": "^3.19.0", "@tiptap/extension-image": "^3.19.0",
"@tiptap/extension-table": "^3.19.0", "@tiptap/extension-table": "^3.19.0",
@@ -42,7 +44,6 @@
"lodash": "^4.17.23", "lodash": "^4.17.23",
"sass": "^1.97.3", "sass": "^1.97.3",
"sass-embedded": "^1.97.3", "sass-embedded": "^1.97.3",
"takerofnotes-plugin-filesystem": "^1.6.0",
"tempus": "^1.0.0-dev.17", "tempus": "^1.0.0-dev.17",
"uuid": "^13.0.0", "uuid": "^13.0.0",
"vue-router": "^5.0.3" "vue-router": "^5.0.3"

View File

@@ -1,12 +1,12 @@
import { electronApp, optimizer, is } from '@electron-toolkit/utils' import { electronApp, optimizer, is } from '@electron-toolkit/utils'
import { app, shell, BrowserWindow, ipcMain } from 'electron' import { app, shell, BrowserWindow, ipcMain } from 'electron'
import filesystemPlugin from 'takerofnotes-plugin-filesystem' import filesystemPlugin from '@takerofnotes/plugin-filesystem'
import PluginRegistry from './core/PluginRegistry.js' import PluginRegistry from './core/PluginRegistry.js'
import PluginConfig from './core/PluginConfig.js' import PluginConfig from './core/PluginConfig.js'
import NotesAPI from './core/NotesAPI.js' import NotesAPI from './core/NotesAPI.js'
import { join } from 'path' import { join } from 'path'
const preloadPath = join(__dirname, '../preload/index.js') const preloadPath = join(__dirname, '../preload/index.mjs')
const rendererPath = join(__dirname, '../renderer/index.html') const rendererPath = join(__dirname, '../renderer/index.html')
// Main window // Main window
@@ -48,6 +48,7 @@ function createNoteWindow(noteId) {
preload: preloadPath, preload: preloadPath,
contextIsolation: true, contextIsolation: true,
nodeIntegration: false, nodeIntegration: false,
sandbox: false,
}, },
}) })
@@ -84,8 +85,7 @@ app.whenReady().then(async () => {
const registry = new PluginRegistry() const registry = new PluginRegistry()
// Register built-in plugins // Register built-in plugins
// TODO figure out why export is under default registry.register(filesystemPlugin)
registry.register(filesystemPlugin.default)
// Pull plugin config // Pull plugin config
const config = await new PluginConfig(filesystemPlugin).load() const config = await new PluginConfig(filesystemPlugin).load()