mirror of
https://github.com/Nystik-gh/ignis.git
synced 2026-06-17 04:35:53 +00:00
add shim, basic stubs
This commit is contained in:
33
shims/electron/index.js
Normal file
33
shims/electron/index.js
Normal file
@@ -0,0 +1,33 @@
|
||||
// Electron module shim
|
||||
// Returned when Obsidian calls: window.require('electron')
|
||||
|
||||
import { ipcRenderer } from "./ipc-renderer.js";
|
||||
import { webFrame } from "./web-frame.js";
|
||||
import { remoteShim } from "./remote/index.js";
|
||||
|
||||
export const electronShim = {
|
||||
ipcRenderer,
|
||||
webFrame,
|
||||
remote: remoteShim,
|
||||
|
||||
// electron.deprecate - used by Obsidian to mark deprecated APIs
|
||||
deprecate: {
|
||||
function(fn, name) {
|
||||
return fn;
|
||||
},
|
||||
event(emitter, name) {},
|
||||
removeFunction(fn, name) {
|
||||
return fn;
|
||||
},
|
||||
log(message) {
|
||||
console.log("[electron:deprecate]", message);
|
||||
},
|
||||
warn(oldName, newName) {},
|
||||
promisify(fn) {
|
||||
return fn;
|
||||
},
|
||||
renameFunction(fn, newName) {
|
||||
return fn;
|
||||
},
|
||||
},
|
||||
};
|
||||
107
shims/electron/ipc-renderer.js
Normal file
107
shims/electron/ipc-renderer.js
Normal file
@@ -0,0 +1,107 @@
|
||||
// Shim for electron.ipcRenderer
|
||||
// Obsidian uses: .send(), .sendSync(), .on(), .once()
|
||||
//
|
||||
// sendSync channels discovered in app.js:
|
||||
// vault → {id, path} - critical for startup
|
||||
// version → string - app version
|
||||
// is-dev → boolean - dev mode flag
|
||||
// file-url → string - base URL prefix for vault assets
|
||||
// disable-update → boolean - whether updates are disabled
|
||||
// update → string - update status
|
||||
// disable-gpu → boolean - GPU acceleration toggle
|
||||
// frame → void - window frame style
|
||||
// set-icon → void - custom vault icon
|
||||
// get-icon → null|object - get custom vault icon
|
||||
// relaunch → void - restart app
|
||||
// starter → void - open vault chooser
|
||||
// help → void - open help
|
||||
// sandbox → void - open sandbox vault
|
||||
// copy-asar → boolean - install update
|
||||
|
||||
const listeners = new Map();
|
||||
|
||||
// Sync channel handlers - must return values synchronously
|
||||
const syncHandlers = {
|
||||
vault: () => window.__vaultConfig || { id: "default-vault", path: "/" },
|
||||
version: () => "1.8.9",
|
||||
"is-dev": () => false,
|
||||
"file-url": () => "",
|
||||
"disable-update": () => true,
|
||||
update: () => "",
|
||||
"disable-gpu": () => false,
|
||||
frame: () => null,
|
||||
"set-icon": () => null,
|
||||
"get-icon": () => null,
|
||||
relaunch: () => {
|
||||
window.location.reload();
|
||||
return null;
|
||||
},
|
||||
starter: () => null,
|
||||
help: () => {
|
||||
window.open("https://help.obsidian.md/", "_blank");
|
||||
return null;
|
||||
},
|
||||
sandbox: () => null,
|
||||
"copy-asar": () => false,
|
||||
"check-update": () => null,
|
||||
};
|
||||
|
||||
export const ipcRenderer = {
|
||||
send(channel, ...args) {
|
||||
console.log("[shim:ipcRenderer] send:", channel, args);
|
||||
// TODO: route to server via chosen sync mechanism if needed
|
||||
},
|
||||
|
||||
sendSync(channel, ...args) {
|
||||
console.log("[shim:ipcRenderer] sendSync:", channel, args);
|
||||
if (syncHandlers[channel]) {
|
||||
return syncHandlers[channel](...args);
|
||||
}
|
||||
console.warn("[shim:ipcRenderer] Unhandled sendSync channel:", channel);
|
||||
return null;
|
||||
},
|
||||
|
||||
on(channel, listener) {
|
||||
if (!listeners.has(channel)) {
|
||||
listeners.set(channel, []);
|
||||
}
|
||||
listeners.get(channel).push(listener);
|
||||
return ipcRenderer;
|
||||
},
|
||||
|
||||
once(channel, listener) {
|
||||
const wrapped = (...args) => {
|
||||
ipcRenderer.removeListener(channel, wrapped);
|
||||
listener(...args);
|
||||
};
|
||||
return ipcRenderer.on(channel, wrapped);
|
||||
},
|
||||
|
||||
removeListener(channel, listener) {
|
||||
const arr = listeners.get(channel);
|
||||
if (arr) {
|
||||
const idx = arr.indexOf(listener);
|
||||
if (idx >= 0) arr.splice(idx, 1);
|
||||
}
|
||||
return ipcRenderer;
|
||||
},
|
||||
|
||||
removeAllListeners(channel) {
|
||||
if (channel) {
|
||||
listeners.delete(channel);
|
||||
} else {
|
||||
listeners.clear();
|
||||
}
|
||||
return ipcRenderer;
|
||||
},
|
||||
|
||||
// Internal: emit an event to registered listeners (used by ws bridge)
|
||||
_emit(channel, ...args) {
|
||||
const arr = listeners.get(channel);
|
||||
if (arr) {
|
||||
for (const fn of arr) {
|
||||
fn({}, ...args);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
27
shims/electron/web-frame.js
Normal file
27
shims/electron/web-frame.js
Normal file
@@ -0,0 +1,27 @@
|
||||
// Shim for electron.webFrame
|
||||
// Obsidian uses: getZoomLevel(), setZoomLevel()
|
||||
|
||||
let currentZoom = 0;
|
||||
|
||||
export const webFrame = {
|
||||
getZoomLevel() {
|
||||
return currentZoom;
|
||||
},
|
||||
|
||||
setZoomLevel(level) {
|
||||
currentZoom = level;
|
||||
// Approximate Electron's zoom behavior via CSS zoom
|
||||
// Electron zoom level 0 = 100%, each step is ~20%
|
||||
const scale = Math.pow(1.2, level);
|
||||
document.body.style.zoom = scale;
|
||||
},
|
||||
|
||||
getZoomFactor() {
|
||||
return Math.pow(1.2, currentZoom);
|
||||
},
|
||||
|
||||
setZoomFactor(factor) {
|
||||
currentZoom = Math.log(factor) / Math.log(1.2);
|
||||
document.body.style.zoom = factor;
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user