From 6c91130b85eaf9c003b59fa69949c4c86815069e Mon Sep 17 00:00:00 2001 From: Lebster Date: Tue, 15 Dec 2020 10:16:42 -0800 Subject: [PATCH] Open base in craft of exile (#159) * Feature - Open base in craft of exile, default ALT + G * misc Co-authored-by: Alexander Drozdov --- src/ipc/ipc-event.ts | 2 +- src/ipc/main-process-bindings.ts | 4 ++++ src/ipc/types.ts | 2 ++ src/main/config.ts | 1 + src/main/shortcuts.ts | 16 ++++++++++++++++ src/web/other-services/craft-of-exile.ts | 12 ++++++++++++ src/web/other-services/index.ts | 5 +++++ src/web/settings/hotkeys.vue | 6 ++++++ 8 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/web/other-services/craft-of-exile.ts diff --git a/src/ipc/ipc-event.ts b/src/ipc/ipc-event.ts index fbdbadc5..a669f949 100644 --- a/src/ipc/ipc-event.ts +++ b/src/ipc/ipc-event.ts @@ -62,7 +62,7 @@ export interface IpcOpenSystemBrowser { } export const OPEN_WIKI = 'MAIN->OVERLAY::open-wiki' - +export const OPEN_COE = 'MAIN->OVERLAY::open-craft-of-exile' export const IMPORT_FILE = 'OVERLAY->MAIN::import-file' export const TOGGLE_DELVE_GRID = 'MAIN->OVERLAY::delve-grid' diff --git a/src/ipc/main-process-bindings.ts b/src/ipc/main-process-bindings.ts index 1cda0731..45c88c64 100644 --- a/src/ipc/main-process-bindings.ts +++ b/src/ipc/main-process-bindings.ts @@ -56,6 +56,10 @@ class MainProcessBinding extends EventTarget { this.dispatchEvent(new CustomEvent(ipcEvent.OPEN_WIKI, { detail })) }) + electron.ipcRenderer.on(ipcEvent.OPEN_COE, (e, detail) => { + this.dispatchEvent(new CustomEvent(ipcEvent.OPEN_COE, { detail })) + }) + electron.ipcRenderer.on(ipcEvent.TOGGLE_DELVE_GRID, (e) => { this.dispatchEvent(new CustomEvent(ipcEvent.TOGGLE_DELVE_GRID)) }) diff --git a/src/ipc/types.ts b/src/ipc/types.ts index 6c653d3c..b4d6777b 100644 --- a/src/ipc/types.ts +++ b/src/ipc/types.ts @@ -10,6 +10,7 @@ export interface Config { priceCheckKeyHold: string priceCheckLocked: string | null wikiKey: string | null + craftOfExileKey: string | null overlayKey: string overlayBackground: string overlayBackgroundExclusive: boolean @@ -63,6 +64,7 @@ export const defaultConfig: Config = { priceCheckKeyHold: 'Ctrl', priceCheckLocked: 'Ctrl + Alt + D', wikiKey: 'Alt + W', + craftOfExileKey: null, overlayKey: 'Shift + Space', overlayBackground: 'rgba(129, 139, 149, 0.15)', overlayBackgroundExclusive: true, diff --git a/src/main/config.ts b/src/main/config.ts index f5d75130..20ed5e02 100644 --- a/src/main/config.ts +++ b/src/main/config.ts @@ -32,6 +32,7 @@ export const config = (() => { if (forbidden.includes(config.priceCheckLocked as string)) { config.priceCheckLocked = null } if (forbidden.includes(config.wikiKey as string)) { config.wikiKey = null } + if (forbidden.includes(config.craftOfExileKey as string)) { config.craftOfExileKey = null } if (forbidden.includes(config.mapCheckKey as string)) { config.mapCheckKey = null } if (config.priceCheckKeyHold === 'Ctrl' && forbiddenCtrl.includes(config.priceCheckKey as string)) { config.priceCheckKey = null diff --git a/src/main/shortcuts.ts b/src/main/shortcuts.ts index 5c07919b..6f99974a 100644 --- a/src/main/shortcuts.ts +++ b/src/main/shortcuts.ts @@ -75,6 +75,13 @@ function registerGlobal () { robotjs.keyTap('C', ['Ctrl']) } ), + shortcutCallback( + config.get('craftOfExileKey'), + () => { + pollClipboard().then(openCraftOfExile).catch(() => {}) + robotjs.keyTap('C', ['Ctrl']) + } + ), shortcutCallback( config.get('mapCheckKey'), mapCheck @@ -154,6 +161,11 @@ export function setupShortcuts () { pollClipboard().then(openWiki).catch(() => {}) robotjs.keyTap('C', ['Ctrl']) }).cb() + } else if (pressed === config.get('craftOfExileKey')) { + shortcutCallback(pressed, () => { + pollClipboard().then(openCraftOfExile).catch(() => {}) + robotjs.keyTap('C', ['Ctrl']) + }).cb() } else if (pressed === config.get('mapCheckKey')) { shortcutCallback(pressed, mapCheck).cb() } else if (pressed === config.get('delveGridKey')) { @@ -209,6 +221,10 @@ function openWiki (clipboard: string) { overlayWindow!.webContents.send(ipc.OPEN_WIKI, clipboard) } +function openCraftOfExile (clipboard: string) { + overlayWindow!.webContents.send(ipc.OPEN_COE, clipboard) +} + function toggleDelveGrid () { overlayWindow!.webContents.send(ipc.TOGGLE_DELVE_GRID) } diff --git a/src/web/other-services/craft-of-exile.ts b/src/web/other-services/craft-of-exile.ts new file mode 100644 index 00000000..874ab9f0 --- /dev/null +++ b/src/web/other-services/craft-of-exile.ts @@ -0,0 +1,12 @@ +import { MainProcess } from '@/ipc/main-process-bindings' +import { parseClipboard } from '@/parser' + +const COE_URL = 'https://craftofexile.com/' + +export function openCOE (clipboard: string) { + const item = parseClipboard(clipboard) + if (!item) return + + const encodedClipboard = encodeURI(clipboard) + MainProcess.openSystemBrowser(`${COE_URL}?eimport=${encodedClipboard}`) +} diff --git a/src/web/other-services/index.ts b/src/web/other-services/index.ts index 720880b1..02290b8c 100644 --- a/src/web/other-services/index.ts +++ b/src/web/other-services/index.ts @@ -1,6 +1,7 @@ import { MainProcess } from '@/ipc/main-process-bindings' import * as ipc from '@/ipc/ipc-event' import { openWiki } from './wiki' +import { openCOE } from './craft-of-exile' import { handleLine } from '../client-log/client-log' export function registerOtherServices () { @@ -11,4 +12,8 @@ export function registerOtherServices () { MainProcess.addEventListener(ipc.CLIENT_LOG_UPDATE, (e) => { handleLine((e as CustomEvent).detail) }) + + MainProcess.addEventListener(ipc.OPEN_COE, (e) => { + openCOE((e as CustomEvent).detail) + }) } diff --git a/src/web/settings/hotkeys.vue b/src/web/settings/hotkeys.vue index a7e9e112..51d52c46 100644 --- a/src/web/settings/hotkeys.vue +++ b/src/web/settings/hotkeys.vue @@ -36,6 +36,12 @@ +
+
+
Open base item on Craft of Exile
+ +
+
{{ $t('Delve grid') }}