update plugin packages
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
"use strict";
|
||||
const utils = require("@electron-toolkit/utils");
|
||||
const electron = require("electron");
|
||||
const filesystemPlugin = require("takerofnotes-plugin-filesystem");
|
||||
const fs = require("fs/promises");
|
||||
const path = require("path");
|
||||
const flexsearch = require("flexsearch");
|
||||
const crypto = require("crypto");
|
||||
import { electronApp, optimizer, is } from "@electron-toolkit/utils";
|
||||
import { app, BrowserWindow, ipcMain, shell } from "electron";
|
||||
import filesystemPlugin from "@takerofnotes/plugin-filesystem";
|
||||
import fs from "fs/promises";
|
||||
import path, { join } from "path";
|
||||
import { Index } from "flexsearch";
|
||||
import crypto from "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 {
|
||||
constructor() {
|
||||
this.plugins = /* @__PURE__ */ new Map();
|
||||
@@ -27,7 +30,7 @@ const USER_DATA_STRING = "__DEFAULT_USER_DATA__";
|
||||
class PluginConfig {
|
||||
constructor(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
|
||||
_resolveDefaults(config) {
|
||||
@@ -40,7 +43,7 @@ class PluginConfig {
|
||||
}
|
||||
return resolved;
|
||||
} 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 {
|
||||
return config;
|
||||
}
|
||||
@@ -89,7 +92,7 @@ class NotesAPI {
|
||||
}
|
||||
this.adapter = adapter;
|
||||
this.notesCache = /* @__PURE__ */ new Map();
|
||||
this.index = new flexsearch.Index({
|
||||
this.index = new Index({
|
||||
tokenize: "tolerant",
|
||||
resolution: 9
|
||||
});
|
||||
@@ -175,10 +178,10 @@ class NotesAPI {
|
||||
return ids.map((id) => this.notesCache.get(id));
|
||||
}
|
||||
}
|
||||
const preloadPath = path.join(__dirname, "../preload/index.js");
|
||||
const rendererPath = path.join(__dirname, "../renderer/index.html");
|
||||
const preloadPath = join(__dirname, "../preload/index.mjs");
|
||||
const rendererPath = join(__dirname, "../renderer/index.html");
|
||||
function createWindow() {
|
||||
const mainWindow2 = new electron.BrowserWindow({
|
||||
const mainWindow2 = new BrowserWindow({
|
||||
width: 354,
|
||||
height: 549,
|
||||
show: false,
|
||||
@@ -192,27 +195,28 @@ function createWindow() {
|
||||
mainWindow2.show();
|
||||
});
|
||||
mainWindow2.webContents.setWindowOpenHandler((details) => {
|
||||
electron.shell.openExternal(details.url);
|
||||
shell.openExternal(details.url);
|
||||
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"]);
|
||||
} else {
|
||||
mainWindow2.loadFile(rendererPath);
|
||||
}
|
||||
}
|
||||
function createNoteWindow(noteId) {
|
||||
const noteWindow = new electron.BrowserWindow({
|
||||
const noteWindow = new BrowserWindow({
|
||||
width: 354,
|
||||
height: 549,
|
||||
autoHideMenuBar: true,
|
||||
webPreferences: {
|
||||
preload: preloadPath,
|
||||
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(
|
||||
`${process.env["ELECTRON_RENDERER_URL"]}/note/${noteId}`
|
||||
);
|
||||
@@ -222,34 +226,34 @@ function createNoteWindow(noteId) {
|
||||
});
|
||||
}
|
||||
}
|
||||
electron.app.whenReady().then(async () => {
|
||||
utils.electronApp.setAppUserModelId("com.electron");
|
||||
electron.app.on("browser-window-created", (_, window) => {
|
||||
utils.optimizer.watchWindowShortcuts(window);
|
||||
app.whenReady().then(async () => {
|
||||
electronApp.setAppUserModelId("com.electron");
|
||||
app.on("browser-window-created", (_, window) => {
|
||||
optimizer.watchWindowShortcuts(window);
|
||||
});
|
||||
createWindow();
|
||||
electron.app.on("activate", function() {
|
||||
if (electron.BrowserWindow.getAllWindows().length === 0) createWindow();
|
||||
app.on("activate", function() {
|
||||
if (BrowserWindow.getAllWindows().length === 0) createWindow();
|
||||
});
|
||||
electron.ipcMain.on("open-note-window", (_, noteId) => {
|
||||
ipcMain.on("open-note-window", (_, noteId) => {
|
||||
createNoteWindow(noteId);
|
||||
});
|
||||
const registry = new PluginRegistry();
|
||||
registry.register(filesystemPlugin.default);
|
||||
registry.register(filesystemPlugin);
|
||||
const config = await new PluginConfig(filesystemPlugin).load();
|
||||
const plugin = registry.get(config.activeAdapter);
|
||||
const adapter = plugin.createAdapter(config.adapterConfig);
|
||||
const notesAPI = new NotesAPI(adapter);
|
||||
await notesAPI.init();
|
||||
electron.ipcMain.handle("notesAPI:call", (_, method, args) => {
|
||||
ipcMain.handle("notesAPI:call", (_, method, args) => {
|
||||
if (!notesAPI[method]) {
|
||||
throw new Error("Invalid method");
|
||||
}
|
||||
return notesAPI[method](...args);
|
||||
});
|
||||
});
|
||||
electron.app.on("window-all-closed", () => {
|
||||
app.on("window-all-closed", () => {
|
||||
if (process.platform !== "darwin") {
|
||||
electron.app.quit();
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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
19
out/preload/index.mjs
Normal 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
40
package-lock.json
generated
@@ -12,6 +12,7 @@
|
||||
"@electron-toolkit/preload": "^3.0.2",
|
||||
"@electron-toolkit/utils": "^4.0.0",
|
||||
"@fuzzco/font-loader": "^1.0.2",
|
||||
"@takerofnotes/plugin-filesystem": "^0.1.1",
|
||||
"@tiptap/extension-document": "^3.19.0",
|
||||
"@tiptap/extension-image": "^3.19.0",
|
||||
"@tiptap/extension-table": "^3.19.0",
|
||||
@@ -27,7 +28,6 @@
|
||||
"lodash": "^4.17.23",
|
||||
"sass": "^1.97.3",
|
||||
"sass-embedded": "^1.97.3",
|
||||
"takerofnotes-plugin-filesystem": "^1.6.0",
|
||||
"tempus": "^1.0.0-dev.17",
|
||||
"uuid": "^13.0.0",
|
||||
"vue-router": "^5.0.3"
|
||||
@@ -2260,6 +2260,25 @@
|
||||
"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": {
|
||||
"version": "3.19.0",
|
||||
"resolved": "https://registry.npmjs.org/@tiptap/core/-/core-3.19.0.tgz",
|
||||
@@ -8314,25 +8333,6 @@
|
||||
"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": {
|
||||
"version": "7.5.9",
|
||||
"resolved": "https://registry.npmjs.org/tar/-/tar-7.5.9.tgz",
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"main": "./out/main/index.js",
|
||||
"author": "example.com",
|
||||
"homepage": "https://electron-vite.org",
|
||||
"type": "module",
|
||||
"prettier": {
|
||||
"tabWidth": 4,
|
||||
"semi": false,
|
||||
@@ -27,6 +28,7 @@
|
||||
"@electron-toolkit/preload": "^3.0.2",
|
||||
"@electron-toolkit/utils": "^4.0.0",
|
||||
"@fuzzco/font-loader": "^1.0.2",
|
||||
"@takerofnotes/plugin-filesystem": "^0.1.1",
|
||||
"@tiptap/extension-document": "^3.19.0",
|
||||
"@tiptap/extension-image": "^3.19.0",
|
||||
"@tiptap/extension-table": "^3.19.0",
|
||||
@@ -42,7 +44,6 @@
|
||||
"lodash": "^4.17.23",
|
||||
"sass": "^1.97.3",
|
||||
"sass-embedded": "^1.97.3",
|
||||
"takerofnotes-plugin-filesystem": "^1.6.0",
|
||||
"tempus": "^1.0.0-dev.17",
|
||||
"uuid": "^13.0.0",
|
||||
"vue-router": "^5.0.3"
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
||||
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 PluginConfig from './core/PluginConfig.js'
|
||||
import NotesAPI from './core/NotesAPI.js'
|
||||
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')
|
||||
|
||||
// Main window
|
||||
@@ -48,6 +48,7 @@ function createNoteWindow(noteId) {
|
||||
preload: preloadPath,
|
||||
contextIsolation: true,
|
||||
nodeIntegration: false,
|
||||
sandbox: false,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -84,8 +85,7 @@ app.whenReady().then(async () => {
|
||||
const registry = new PluginRegistry()
|
||||
|
||||
// Register built-in plugins
|
||||
// TODO figure out why export is under default
|
||||
registry.register(filesystemPlugin.default)
|
||||
registry.register(filesystemPlugin)
|
||||
|
||||
// Pull plugin config
|
||||
const config = await new PluginConfig(filesystemPlugin).load()
|
||||
|
||||
Reference in New Issue
Block a user