-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpreload.ts
More file actions
63 lines (54 loc) · 2.26 KB
/
preload.ts
File metadata and controls
63 lines (54 loc) · 2.26 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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Tune Player - A cute music player ❤ *
* Copyright © 2026 Moebytes <moebytes.com> *
* Licensed under CC BY-NC 4.0. See license.txt for details. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
import {contextBridge, ipcRenderer, webUtils, IpcRendererEvent} from "electron"
declare global {
interface Window {
platform: "mac" | "windows",
ipcRenderer: {
invoke: (channel: string, ...args: any[]) => Promise<any>
send: (channel: string, ...args: any[]) => void
on: (channel: string, listener: (...args: any[]) => void) => any
removeListener: (channel: string, listener: (...args: any[]) => void) => void
},
shell: {
showItemInFolder: (path: string) => Promise<void>
},
webUtils: {
getPathForFile: (file: File) => string
},
path: {
basename: (filepath: string, suffix?: string) => Promise<string>
extname: (filepath: string) => Promise<string>
}
}
}
contextBridge.exposeInMainWorld("ipcRenderer", {
invoke: async (channel: string, ...args: any[]) => {
return ipcRenderer.invoke(channel, ...args)
},
send: (channel: string, ...args: any[]) => {
ipcRenderer.send(channel, ...args)
},
on: (channel: string, listener: (...args: any[]) => void) => {
const subscription = (event: IpcRendererEvent, ...args: any[]) => listener(event, ...args)
ipcRenderer.on(channel, subscription)
return subscription
},
removeListener: (channel: string, listener: (...args: any[]) => void) => {
ipcRenderer.removeListener(channel, listener)
}
})
contextBridge.exposeInMainWorld("shell", {
showItemInFolder: async (location: string) => ipcRenderer.invoke("shell:showItemInFolder", location)
})
contextBridge.exposeInMainWorld("webUtils", {
getPathForFile: (file: File) => webUtils.getPathForFile(file)
})
contextBridge.exposeInMainWorld("path", {
basename: (filepath: string, suffix?: string) => ipcRenderer.invoke("path:basename", filepath, suffix),
extname: (filepath: string) => ipcRenderer.invoke("path:extname", filepath)
})
contextBridge.exposeInMainWorld("platform", process.platform === "darwin" ? "mac" : "windows")