-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpreload.js
More file actions
140 lines (126 loc) · 6.03 KB
/
preload.js
File metadata and controls
140 lines (126 loc) · 6.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
const { contextBridge, ipcRenderer } = require('electron');
function invokeBoard(op, ...args) {
return ipcRenderer.invoke('board-call', { op, args });
}
function getNormalizedBaseName(filePath) {
const normalized = String(filePath || '').replace(/\\/g, '/').replace(/\/+$/, '');
if (!normalized) {
return '';
}
const parts = normalized.split('/').filter(Boolean);
return parts[parts.length - 1] || '';
}
contextBridge.exposeInMainWorld('board', {
authorizeBoardSelection: async (selectionToken) => invokeBoard('authorizeBoardSelection', selectionToken),
adoptLegacyBoardRoots: async (boardRoots) => invokeBoard('adoptLegacyBoardRoots', boardRoots),
setActiveBoardRoot: async (boardRoot) => invokeBoard('setActiveBoardRoot', boardRoot),
clearActiveBoardRoot: async () => invokeBoard('clearActiveBoardRoot'),
listLists: async (root) => invokeBoard('listLists', root),
listCards: async (listPath) => invokeBoard('listCards', listPath),
countCards: async (listPath) => invokeBoard('countCards', listPath),
getBoardName: (filePath) => getNormalizedBaseName(filePath),
getCardID: (filePath) => {
const cardFileName = getNormalizedBaseName(filePath);
return cardFileName.slice(cardFileName.length - 8, cardFileName.length - 3);
},
getCardTitle: async (filePath) => invokeBoard('getCardTitle', filePath),
formatDueDate: async (dateString) => invokeBoard('formatDueDate', dateString),
getCardFileName: (filePath) => getNormalizedBaseName(filePath),
getListDirectoryName: (filePath) => getNormalizedBaseName(filePath),
listDirectories: async (root) => invokeBoard('listDirectories', root),
startBoardWatch: async (boardRoot) => invokeBoard('startBoardWatch', boardRoot),
stopBoardWatch: async () => invokeBoard('stopBoardWatch'),
getBoardWatchToken: async () => invokeBoard('getBoardWatchToken'),
openCard: async (filePath) => invokeBoard('openCard', filePath),
shareCard: async (filePath) => ipcRenderer.invoke('share-file', filePath),
readCard: async (filePath) => invokeBoard('readCard', filePath),
listArchiveEntries: async () => invokeBoard('listArchiveEntries'),
readArchiveEntry: async (entryPath) => invokeBoard('readArchiveEntry', entryPath),
writeCard: async (filePath, card) => invokeBoard('writeCard', filePath, card),
updateFrontmatter: async (filePath, partialFrontmatter) =>
invokeBoard('updateFrontmatter', filePath, partialFrontmatter),
normalizeFrontmatter: async (frontmatter) => invokeBoard('normalizeFrontmatter', frontmatter),
readBoardSettings: async (boardRoot) => invokeBoard('readBoardSettings', boardRoot),
updateBoardLabels: async (boardRoot, labels) => invokeBoard('updateBoardLabels', boardRoot, labels),
updateBoardThemeOverrides: async (boardRoot, themeOverrides) =>
invokeBoard('updateBoardThemeOverrides', boardRoot, themeOverrides),
updateBoardSettings: async (boardRoot, partialSettings) =>
invokeBoard('updateBoardSettings', boardRoot, partialSettings),
createCard: async (filePath, content) => invokeBoard('createCard', filePath, content),
archiveCard: async (filePath) => invokeBoard('archiveCard', filePath),
archiveList: async (listPath) => invokeBoard('archiveList', listPath),
restoreArchivedCard: async (archivedCardPath, targetListPath) =>
invokeBoard('restoreArchivedCard', archivedCardPath, targetListPath),
restoreArchivedList: async (archivedListPath, restoredDirectoryName) =>
invokeBoard('restoreArchivedList', archivedListPath, restoredDirectoryName),
recordCardListMove: async (cardPath, fromListPath, toListPath) =>
invokeBoard('recordCardListMove', cardPath, fromListPath, toListPath),
moveCard: async (src, dst) => invokeBoard('moveCard', src, dst),
moveList: async (src, dst) => invokeBoard('moveList', src, dst),
createList: async (listPath) => invokeBoard('createList', listPath),
deleteList: async (listPath) => invokeBoard('deleteList', listPath),
importTrello: async (boardRoot, selectionToken) => invokeBoard('importTrello', boardRoot, selectionToken),
importObsidian: async (boardRoot, selectionTokens) => invokeBoard('importObsidian', boardRoot, selectionTokens),
importTasksMd: async (boardRoot, selectionTokens) => invokeBoard('importTasksMd', boardRoot, selectionTokens),
copyExternal: async () => {
throw new Error('UNSUPPORTED_OPERATION');
},
});
contextBridge.exposeInMainWorld('chooser', {
pickDirectory: (opts = {}) => ipcRenderer.invoke('choose-directory', opts),
pickImportSources: (opts = {}) => ipcRenderer.invoke('pick-import-sources', opts),
});
contextBridge.exposeInMainWorld('electronAPI', {
getAppInfo: () => ipcRenderer.invoke('get-app-info'),
openExternal: (url) => ipcRenderer.invoke('open-external-url', url),
checkForUpdates: () => ipcRenderer.invoke('check-for-updates'),
notifyDueCards: (payload) => ipcRenderer.invoke('notify-due-cards', payload),
onOpenAboutSignboard: (callback) => {
if (typeof callback !== 'function') {
return () => {};
}
const listener = () => {
callback();
};
ipcRenderer.on('open-about-signboard', listener);
return () => {
ipcRenderer.removeListener('open-about-signboard', listener);
};
},
onOpenKeyboardShortcuts: (callback) => {
if (typeof callback !== 'function') {
return () => {};
}
const listener = () => {
callback();
};
ipcRenderer.on('open-keyboard-shortcuts', listener);
return () => {
ipcRenderer.removeListener('open-keyboard-shortcuts', listener);
};
},
onOpenBoardSettings: (callback) => {
if (typeof callback !== 'function') {
return () => {};
}
const listener = () => {
callback();
};
ipcRenderer.on('open-board-settings', listener);
return () => {
ipcRenderer.removeListener('open-board-settings', listener);
};
},
onToggleThemeMode: (callback) => {
if (typeof callback !== 'function') {
return () => {};
}
const listener = () => {
callback();
};
ipcRenderer.on('toggle-theme-mode', listener);
return () => {
ipcRenderer.removeListener('toggle-theme-mode', listener);
};
},
});