mirror of
https://github.com/Kvan7/Exiled-Exchange-2.git
synced 2026-09-28 15:45:58 +00:00
refactor
This commit is contained in:
@@ -13,4 +13,10 @@ export const CLOSE_SETTINGS_WINDOW = 'close-settings-window'
|
||||
|
||||
export const UPDATE_AVAILABLE = 'update-available'
|
||||
|
||||
export const OVERLAY_ACTIVE_CHANGE = 'overlay-active-change'
|
||||
export const FOCUS_CHANGE = 'OVERLAY::focus-change'
|
||||
|
||||
export const PRICE_CHECK = 'OVERLAY::price-check'
|
||||
export const PRICE_CHECK_STATE = 'OVERLAY::price-check-state'
|
||||
export const PRICE_CHECK_CANCELED = 'OVERLAY::price-check-canceled'
|
||||
|
||||
export const OVERLAY_READY = 'OVERLAY::ready'
|
||||
|
||||
@@ -12,7 +12,7 @@ class MainProcessBinding extends EventTarget {
|
||||
super()
|
||||
|
||||
if (electron) {
|
||||
electron.ipcRenderer.on('price-check', (e, data) => {
|
||||
electron.ipcRenderer.on(ipcEvent.PRICE_CHECK, (e, data) => {
|
||||
this.selfEmitPriceCheck(data)
|
||||
})
|
||||
|
||||
@@ -28,8 +28,12 @@ class MainProcessBinding extends EventTarget {
|
||||
}))
|
||||
})
|
||||
|
||||
electron.ipcRenderer.on(ipcEvent.OVERLAY_ACTIVE_CHANGE, (e, updateInfo) => {
|
||||
this.dispatchEvent(new CustomEvent(ipcEvent.OVERLAY_ACTIVE_CHANGE))
|
||||
electron.ipcRenderer.on(ipcEvent.FOCUS_CHANGE, (e, data) => {
|
||||
this.dispatchEvent(new CustomEvent(ipcEvent.FOCUS_CHANGE, { detail: data }))
|
||||
})
|
||||
|
||||
electron.ipcRenderer.on(ipcEvent.PRICE_CHECK_CANCELED, () => {
|
||||
this.dispatchEvent(new CustomEvent(ipcEvent.PRICE_CHECK_CANCELED))
|
||||
})
|
||||
|
||||
electron.ipcRenderer.on(ipcEvent.UPDATE_AVAILABLE, (e, updateInfo) => {
|
||||
@@ -46,6 +50,12 @@ class MainProcessBinding extends EventTarget {
|
||||
}))
|
||||
}
|
||||
|
||||
readyReceiveEvents () {
|
||||
if (electron) {
|
||||
electron.ipcRenderer.send(ipcEvent.OVERLAY_READY)
|
||||
}
|
||||
}
|
||||
|
||||
priceCheckHide () {
|
||||
if (electron) {
|
||||
electron.ipcRenderer.send(ipcEvent.PRICE_CHECK_HIDE)
|
||||
|
||||
+9
-4
@@ -1,13 +1,18 @@
|
||||
import Store from 'electron-store'
|
||||
import { ipcMain } from 'electron'
|
||||
import { Config, defaultConfig } from '@/ipc/types'
|
||||
import { GET_CONFIG, PUSH_CONFIG } from '@/ipc/ipc-event'
|
||||
import { win } from './window'
|
||||
import { GET_CONFIG, PUSH_CONFIG, CLOSE_SETTINGS_WINDOW } from '@/ipc/ipc-event'
|
||||
import { overlayWindow } from './overlay-window'
|
||||
|
||||
export function setupConfig () {
|
||||
export function setupConfigEvents () {
|
||||
ipcMain.on(GET_CONFIG, (e) => {
|
||||
e.returnValue = config.store
|
||||
})
|
||||
ipcMain.on(CLOSE_SETTINGS_WINDOW, (e, cfg) => {
|
||||
if (cfg != null) {
|
||||
batchUpdateConfig(cfg)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export const config = new Store<Config>({
|
||||
@@ -21,5 +26,5 @@ export function batchUpdateConfig (upd: Config) {
|
||||
// config.set(key as keyof Config, upd[key as keyof Config])
|
||||
// }
|
||||
config.store = upd
|
||||
win.webContents.send(PUSH_CONFIG, upd)
|
||||
overlayWindow!.webContents.send(PUSH_CONFIG, upd)
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@ import { screen, Point, clipboard, globalShortcut, Notification } from 'electron
|
||||
import robotjs from 'robotjs'
|
||||
import { uIOhook, UiohookKey } from 'uiohook-napi'
|
||||
import { pollClipboard } from './PollClipboard'
|
||||
import { win } from './window'
|
||||
import { showWindow, lockWindow, poeUserInterfaceWidth, getPoeUiPosition, mousePosFromEvent } from './positioning'
|
||||
import { showWindow, lockWindow, getPoeUiPosition, mousePosFromEvent } from './positioning'
|
||||
import { KeyToElectron } from '@/ipc/KeyToCode'
|
||||
import { PRICE_CHECK } from '@/ipc/ipc-event'
|
||||
import { config } from './config'
|
||||
import { PoeWindow } from './PoeWindow'
|
||||
import { openWiki } from './wiki'
|
||||
import { logger } from './logger'
|
||||
import { toggleOverlayState } from './overlay-window'
|
||||
import { toggleOverlayState, overlayWindow } from './overlay-window'
|
||||
|
||||
export let isPollingClipboard = false
|
||||
export let checkPressPosition: Point | undefined
|
||||
@@ -23,8 +23,8 @@ function priceCheck (lockedMode: boolean) {
|
||||
isPollingClipboard = true
|
||||
pollClipboard(32, 500)
|
||||
.then(async (clipboard) => {
|
||||
win.webContents.send('price-check', { clipboard, position: getPoeUiPosition(checkPressPosition!) })
|
||||
await showWindow(lockedMode)
|
||||
overlayWindow!.webContents.send(PRICE_CHECK, { clipboard, position: getPoeUiPosition(checkPressPosition!) })
|
||||
showWindow()
|
||||
if (lockedMode) {
|
||||
lockWindow(true)
|
||||
}
|
||||
@@ -148,7 +148,7 @@ export function setupShortcuts () {
|
||||
uIOhook.on('wheel', async (e) => {
|
||||
if (!e.ctrlKey || !PoeWindow.bounds || !PoeWindow.isActive || !config.get('stashScroll')) return
|
||||
|
||||
const stashCheckX = PoeWindow.bounds.x + poeUserInterfaceWidth(PoeWindow.bounds.height)
|
||||
const stashCheckX = PoeWindow.bounds.x + PoeWindow.uiSidebarWidth
|
||||
const mouseX = mousePosFromEvent(e).x
|
||||
if (mouseX > stashCheckX) {
|
||||
if (e.rotation > 0) {
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@ import path from 'path'
|
||||
import { app, Tray, Menu, ipcMain, MenuItem, MenuItemConstructorOptions, shell, nativeImage } from 'electron'
|
||||
import { checkForUpdates, UpdateState } from './updates'
|
||||
import { config } from './config'
|
||||
import { win } from './window'
|
||||
import { overlayWindow } from './overlay-window'
|
||||
import { League } from '@/ipc/types'
|
||||
import { LEAGUES_READY, LEAGUE_SELECTED } from '@/ipc/ipc-event'
|
||||
import { createWindow as settingsWindow } from './SettingsWindow'
|
||||
@@ -21,7 +21,7 @@ function selectLeague (league: League) {
|
||||
league.selected = true
|
||||
rebuildContextMenu()
|
||||
|
||||
win.webContents.send(LEAGUE_SELECTED, league.id)
|
||||
overlayWindow!.webContents.send(LEAGUE_SELECTED, league.id)
|
||||
}
|
||||
|
||||
function leaguesMenuItem () {
|
||||
|
||||
+7
-5
@@ -1,21 +1,22 @@
|
||||
import { autoUpdater } from 'electron-updater'
|
||||
import { logger } from './logger'
|
||||
import { rebuildContextMenu } from './tray'
|
||||
import { win } from './window'
|
||||
import { UPDATE_AVAILABLE } from '@/ipc/ipc-event'
|
||||
import { overlayWindow, overlayReady } from './overlay-window'
|
||||
|
||||
export const UpdateState = {
|
||||
canCheck: true,
|
||||
status: ''
|
||||
}
|
||||
|
||||
autoUpdater.on('update-available', (info: { version: string }) => {
|
||||
autoUpdater.on('update-available', async (info: { version: string }) => {
|
||||
UpdateState.canCheck = false
|
||||
if (autoUpdater.autoDownload) {
|
||||
UpdateState.status = `Downloading v${info.version} ...`
|
||||
} else {
|
||||
UpdateState.status = `Update v${info.version} available on GitHub`
|
||||
win.webContents.send(UPDATE_AVAILABLE, { auto: false, version: info.version })
|
||||
await overlayReady
|
||||
overlayWindow!.webContents.send(UPDATE_AVAILABLE, { auto: false, version: info.version })
|
||||
}
|
||||
rebuildContextMenu()
|
||||
})
|
||||
@@ -32,11 +33,12 @@ autoUpdater.on('error', () => {
|
||||
rebuildContextMenu()
|
||||
})
|
||||
|
||||
autoUpdater.on('update-downloaded', (info: { version: string }) => {
|
||||
autoUpdater.on('update-downloaded', async (info: { version: string }) => {
|
||||
UpdateState.canCheck = false
|
||||
UpdateState.status = `v${info.version} will be installed on exit`
|
||||
rebuildContextMenu()
|
||||
win.webContents.send(UPDATE_AVAILABLE, { auto: true, version: info.version })
|
||||
await overlayReady
|
||||
overlayWindow!.webContents.send(UPDATE_AVAILABLE, { auto: true, version: info.version })
|
||||
})
|
||||
|
||||
// on('download-progress') https://github.com/electron-userland/electron-builder/issues/2521
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
import path from 'path'
|
||||
import { BrowserWindow } from 'electron'
|
||||
import { checkForUpdates } from './updates'
|
||||
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'
|
||||
import { hideWindow } from './positioning'
|
||||
import { isQuiting } from './tray'
|
||||
import { PoeWindow } from './PoeWindow'
|
||||
|
||||
export let win: BrowserWindow
|
||||
|
||||
export const WIDTH = 460
|
||||
export const TITLE_HEIGHT = 24
|
||||
|
||||
export function createWindow () {
|
||||
win = new BrowserWindow({
|
||||
width: WIDTH,
|
||||
height: 200,
|
||||
icon: path.join(__static, 'icon.png'),
|
||||
fullscreenable: false,
|
||||
alwaysOnTop: true,
|
||||
skipTaskbar: true,
|
||||
frame: false,
|
||||
show: false,
|
||||
transparent: true,
|
||||
fullscreen: true, // linux does not support changing at runtime, add config?
|
||||
resizable: false,
|
||||
// backgroundColor: '#2d3748', // gray-800
|
||||
webPreferences: {
|
||||
nodeIntegration: process.env.ELECTRON_NODE_INTEGRATION as any,
|
||||
webSecurity: false
|
||||
}
|
||||
})
|
||||
|
||||
if (process.env.WEBPACK_DEV_SERVER_URL) {
|
||||
// Load the url of the dev server if in development mode
|
||||
win.loadURL(process.env.WEBPACK_DEV_SERVER_URL as string)
|
||||
if (!process.env.IS_TEST) win.webContents.openDevTools({ mode: 'detach' })
|
||||
} else {
|
||||
createProtocol('app')
|
||||
// Load the index.html when not in development
|
||||
win.loadURL('app://./index.html')
|
||||
checkForUpdates()
|
||||
}
|
||||
|
||||
win.setIgnoreMouseEvents(true)
|
||||
win.once('ready-to-show', () => {
|
||||
// place here because of linux
|
||||
win.setAlwaysOnTop(true, 'screen-saver')
|
||||
})
|
||||
win.on('close', (e) => {
|
||||
if (!isQuiting) {
|
||||
e.preventDefault()
|
||||
hideWindow()
|
||||
}
|
||||
})
|
||||
|
||||
PoeWindow.once('active-change', () => {
|
||||
win.setBounds(PoeWindow.bounds!)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user