fix image urls, fix context menu

This commit is contained in:
Nystik
2026-03-10 20:49:10 +01:00
parent b48ef720b8
commit d8d12054b7
9 changed files with 157 additions and 39 deletions

View File

@@ -10,6 +10,13 @@ export const electronShim = {
webFrame,
remote: remoteShim,
// electron.webUtils - used for drag/drop file path extraction (desktop only)
webUtils: {
getPathForFile(file) {
return "";
},
},
// electron.deprecate - used by Obsidian to mark deprecated APIs
deprecate: {
function(fn, name) {

View File

@@ -25,7 +25,7 @@ const syncHandlers = {
vault: () => window.__vaultConfig || { id: "default-vault", path: "/" },
version: () => "1.8.9",
"is-dev": () => false,
"file-url": () => "",
"file-url": () => "/vault-files/",
"disable-update": () => true,
update: () => "",
"disable-gpu": () => false,
@@ -49,7 +49,20 @@ const syncHandlers = {
export const ipcRenderer = {
send(channel, ...args) {
console.log("[shim:ipcRenderer] send:", channel, args);
// TODO: route to server via chosen sync mechanism if needed
// context-menu: Obsidian sends this and waits (up to 1s) for a response.
// In Electron, the main process returns spell-check info + edit flags.
// We reply immediately with a response object so Obsidian proceeds to
// build and show its HTML context menu without delay.
if (channel === "context-menu") {
queueMicrotask(() =>
ipcRenderer._emit("context-menu", {
webContentsId: 1,
editFlags: { canCut: true, canCopy: true, canPaste: true },
}),
);
return;
}
},
sendSync(channel, ...args) {

View File

@@ -1,18 +1,18 @@
// @electron/remote shim
// Returned when Obsidian calls: window.require('@electron/remote')
import { clipboardShim } from './clipboard.js';
import { shellShim } from './shell.js';
import { dialogShim } from './dialog.js';
import { menuShim, menuItemShim } from './menu.js';
import { appShim } from './app.js';
import { windowShim, webContentsShim } from './window.js';
import { themeShim } from './theme.js';
import { sessionShim } from './session.js';
import { systemPreferencesShim } from './system-preferences.js';
import { screenShim } from './screen.js';
import { nativeImageShim } from './native-image.js';
import { notificationShim } from './notification.js';
import { clipboardShim } from "./clipboard.js";
import { shellShim } from "./shell.js";
import { dialogShim } from "./dialog.js";
import { menuShim, menuItemShim } from "./menu.js";
import { appShim } from "./app.js";
import { windowShim, webContentsShim } from "./window.js";
import { themeShim } from "./theme.js";
import { sessionShim } from "./session.js";
import { systemPreferencesShim } from "./system-preferences.js";
import { screenShim } from "./screen.js";
import { nativeImageShim } from "./native-image.js";
import { notificationShim } from "./notification.js";
export const remoteShim = {
clipboard: clipboardShim,
@@ -33,6 +33,8 @@ export const remoteShim = {
return windowShim._current();
},
webContents: webContentsShim,
getCurrentWebContents() {
return webContentsShim._current();
},

View File

@@ -135,6 +135,7 @@ const currentWindow = {
};
const currentWebContents = {
id: 1,
_zoomLevel: 0,
get zoomLevel() {
@@ -182,7 +183,25 @@ const currentWebContents = {
undo() {},
redo() {},
pasteAndMatchStyle() {},
cut() {
document.execCommand("cut");
},
copy() {
document.execCommand("copy");
},
paste() {
document.execCommand("paste");
},
pasteAndMatchStyle() {
document.execCommand("paste");
},
replaceMisspelling(word) {},
session: {
availableSpellCheckerLanguages: [],
setSpellCheckerLanguages(langs) {},
addWordToSpellCheckerDictionary(word) {},
},
setSpellCheckerLanguages(langs) {},
@@ -212,4 +231,7 @@ export const windowShim = {
export const webContentsShim = {
_current: () => currentWebContents,
fromId(id) {
return id === currentWebContents.id ? currentWebContents : null;
},
};