mirror of
https://github.com/Kvan7/Exiled-Exchange-2.git
synced 2026-09-24 21:55:41 +00:00
file protocol
This commit is contained in:
+5
-1
@@ -1,7 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
import { app, protocol, ipcMain, screen } from 'electron'
|
||||
import { installVueDevtools } from 'vue-cli-plugin-electron-builder/lib'
|
||||
import { installVueDevtools, createProtocol } from 'vue-cli-plugin-electron-builder/lib'
|
||||
import { setupShortcuts } from './main/shortcuts'
|
||||
import { createTray } from './main/tray'
|
||||
import { setupShowHide } from './main/price-check'
|
||||
@@ -15,6 +15,7 @@ import { setupCfProtection } from './main/cf-protection'
|
||||
import { createOverlayWindow } from './main/overlay-window'
|
||||
import { setupAltVisibility } from './main/alt-visibility'
|
||||
import { setupBuiltinBrowser } from './main/builtin-browser'
|
||||
import { createFileProtocol } from './main/app-file-protocol'
|
||||
const isDevelopment = process.env.NODE_ENV !== 'production'
|
||||
|
||||
if (!app.requestSingleInstanceLock()) {
|
||||
@@ -51,6 +52,9 @@ app.on('ready', async () => {
|
||||
}
|
||||
}
|
||||
|
||||
createProtocol('app')
|
||||
createFileProtocol()
|
||||
|
||||
setupConfigEvents()
|
||||
createTray()
|
||||
setupShowHide()
|
||||
|
||||
@@ -62,3 +62,5 @@ export interface IpcOpenSystemBrowser {
|
||||
}
|
||||
|
||||
export const OPEN_WIKI = 'MAIN->OVERLAY::open-wiki'
|
||||
|
||||
export const IMPORT_FILE = 'OVERLAY->MAIN::import-file'
|
||||
|
||||
@@ -140,6 +140,12 @@ class MainProcessBinding extends EventTarget {
|
||||
}
|
||||
}
|
||||
|
||||
importFile (filePath: string) {
|
||||
if (electron) {
|
||||
return electron.ipcRenderer.sendSync(ipcEvent.IMPORT_FILE, filePath)
|
||||
}
|
||||
}
|
||||
|
||||
get CORS () {
|
||||
return (!electron)
|
||||
? 'https://apt-cors.snos.workers.dev/?'
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { protocol, app, ipcMain } from 'electron'
|
||||
import { IMPORT_FILE } from '@/ipc/ipc-event'
|
||||
import path from 'path'
|
||||
import crypto from 'crypto'
|
||||
import fs from 'fs'
|
||||
|
||||
export function createFileProtocol () {
|
||||
protocol.registerFileProtocol('app-file', (req, resp) => {
|
||||
resp({ path: path.join(app.getPath('userData'), 'apt-data/files', req.url.substr('app-file://'.length)) })
|
||||
})
|
||||
|
||||
ipcMain.on(IMPORT_FILE, (e, filePath: string) => {
|
||||
const file = fs.readFileSync(filePath)
|
||||
const hash = crypto.createHash('md5').update(file).digest('hex')
|
||||
const filename = `${hash}${path.extname(filePath)}`
|
||||
|
||||
fs.mkdirSync(path.join(app.getPath('userData'), 'apt-data/files'), { recursive: true })
|
||||
fs.writeFileSync(path.join(app.getPath('userData'), 'apt-data/files', filename), file)
|
||||
|
||||
e.returnValue = `app-file://${filename}`
|
||||
})
|
||||
}
|
||||
@@ -3,7 +3,6 @@ import { BrowserWindow, ipcMain, dialog, Menu, systemPreferences } from 'electro
|
||||
import { PoeWindow } from './PoeWindow'
|
||||
import { logger } from './logger'
|
||||
import * as ipc from '@/ipc/ipc-event'
|
||||
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'
|
||||
import { overlayWindow as OW } from 'electron-overlay-window'
|
||||
import { config } from './config'
|
||||
|
||||
@@ -49,7 +48,6 @@ export async function createOverlayWindow () {
|
||||
overlayWindow.loadURL(process.env.WEBPACK_DEV_SERVER_URL + '#overlay')
|
||||
overlayWindow.webContents.openDevTools({ mode: 'detach', activate: false })
|
||||
} else {
|
||||
createProtocol('app')
|
||||
overlayWindow.loadURL('app://./index.html#overlay')
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user