|
@@ -1,3 +1,5 @@
|
|
|
+const fs = require('fs')
|
|
|
+const path = require('path')
|
|
|
const { ipcRenderer, contextBridge, shell } = require('electron')
|
|
|
|
|
|
contextBridge.exposeInMainWorld('apis', {
|
|
@@ -6,8 +8,8 @@ contextBridge.exposeInMainWorld('apis', {
|
|
|
},
|
|
|
|
|
|
on: (channel, callback) => {
|
|
|
- const newCallback = (_, data) => callback(data);
|
|
|
- ipcRenderer.on(channel, newCallback);
|
|
|
+ const newCallback = (_, data) => callback(data)
|
|
|
+ ipcRenderer.on(channel, newCallback)
|
|
|
},
|
|
|
|
|
|
checkForUpdates: async (...args) => {
|
|
@@ -28,5 +30,21 @@ contextBridge.exposeInMainWorld('apis', {
|
|
|
|
|
|
async openExternal (url, options) {
|
|
|
await shell.openExternal(url, options)
|
|
|
+ },
|
|
|
+
|
|
|
+ async copyFileToAssets (repoPathRoot, to, from) {
|
|
|
+ if (fs.statSync(from).isDirectory()) {
|
|
|
+ throw new Error('not support copy directory')
|
|
|
+ }
|
|
|
+
|
|
|
+ const dest = path.join(repoPathRoot, to)
|
|
|
+ const assetsRoot = path.dirname(dest)
|
|
|
+
|
|
|
+ if (!/assets$/.test(assetsRoot)) {
|
|
|
+ throw new Error('illegal assets dirname')
|
|
|
+ }
|
|
|
+
|
|
|
+ await fs.promises.mkdir(assetsRoot, { recursive: true })
|
|
|
+ await fs.promises.copyFile(from, dest)
|
|
|
}
|
|
|
})
|