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;
|
||||
}
|
||||
Reference in New Issue
Block a user