From c4c70bf53bb52124a72219da253bc20a4907e68c Mon Sep 17 00:00:00 2001 From: Harry Yu Date: Fri, 4 Feb 2022 00:03:13 -0800 Subject: [PATCH] Added MacOS support --- package.json | 2 +- src/ipc/KeyToCode.ts | 4 +++- src/main/PoeWindow.ts | 2 +- src/main/game-chat.ts | 14 ++++++++++---- src/main/game-config.ts | 6 +++++- src/main/shortcuts.ts | 8 +++++++- src/main/tray.ts | 12 +++++++++--- vue.config.js | 7 +++++++ yarn.lock | 7 +++---- 9 files changed, 46 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 8ccd0033..d6b66970 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "animate.css": "^4.1.1", "apexcharts": "^3.23.1", "dot-prop": "6.x.x", - "electron-overlay-window": "3.0.0-beta.1", + "electron-overlay-window": "hsource/electron-overlay-window#3.0.0-macos.2", "electron-store": "8.0.x", "electron-updater": "^4.2.0", "fast-deep-equal": "3.1.x", diff --git a/src/ipc/KeyToCode.ts b/src/ipc/KeyToCode.ts index 35d78abb..29a8cea4 100644 --- a/src/ipc/KeyToCode.ts +++ b/src/ipc/KeyToCode.ts @@ -217,7 +217,9 @@ export const KeyToElectron = { Backslash: '\\', BracketRight: ']', Quote: "'", - Ctrl: 'CmdOrCtrl', + // Do not change Ctrl to CmdOrCtrl. It causes registered shortcuts to + // often not work on Mac for unknown reasons. + Ctrl: 'Ctrl', Alt: 'Alt', Shift: 'Shift' } diff --git a/src/main/PoeWindow.ts b/src/main/PoeWindow.ts index bd123ca3..913fa4f6 100644 --- a/src/main/PoeWindow.ts +++ b/src/main/PoeWindow.ts @@ -36,7 +36,7 @@ class PoeWindowClass extends EventEmitter { OW.events.on('focus', () => { this.isActive = true }) OW.events.on('blur', () => { this.isActive = false }) - OW.attachTo(window, config.get('windowTitle')) + OW.attachTo(window, config.get('windowTitle'), { hasTitleBarOnMac: true }) } onAttach (cb: (hasAccess: boolean | undefined) => void) { diff --git a/src/main/game-chat.ts b/src/main/game-chat.ts index eb2b631f..a4ded217 100644 --- a/src/main/game-chat.ts +++ b/src/main/game-chat.ts @@ -13,25 +13,31 @@ const AUTO_CLEAR = [ export function typeInChat (text: string, send: boolean) { restoreClipboard((clipboard) => { + // Modifier keys have to be one of this set: + // http://robotjs.io/docs/syntax#keytapkey-modifier + // Modifier keys are translated by code here: + // https://github.com/octalmage/robotjs/blob/v0.6.0/src/robotjs.cc#L425 + const modifiers = process.platform === 'darwin' ? ['Cmd'] : ['Ctrl'] + if (text.startsWith(PLACEHOLDER_LAST)) { text = text.substr(`${PLACEHOLDER_LAST} `.length) clipboard.writeText(text) - robotjs.keyTap('Enter', ['Ctrl']) + robotjs.keyTap('Enter', modifiers) } else if (text.endsWith(PLACEHOLDER_LAST)) { text = text.slice(0, -PLACEHOLDER_LAST.length) clipboard.writeText(text) - robotjs.keyTap('Enter', ['Ctrl']) + robotjs.keyTap('Enter', modifiers) robotjs.keyTap('Home') robotjs.keyTap('Delete') } else { clipboard.writeText(text) robotjs.keyTap('Enter') if (!AUTO_CLEAR.includes(text[0])) { - robotjs.keyTap('A', ['Ctrl']) + robotjs.keyTap('A', modifiers) } } - robotjs.keyTap('V', ['Ctrl']) + robotjs.keyTap('V', modifiers) if (send) { robotjs.keyTap('Enter') diff --git a/src/main/game-config.ts b/src/main/game-config.ts index 7d774844..8ae34700 100644 --- a/src/main/game-config.ts +++ b/src/main/game-config.ts @@ -24,7 +24,11 @@ export function readConfig (): GameConfig { let filePath = appConfig.get('gameConfig') if (!filePath) { - filePath = path.join(app.getPath('documents'), 'My Games', 'Path of Exile', 'production_Config.ini') + if (process.platform === 'darwin') { + filePath = path.join(app.getPath('appData'), 'Path of Exile', 'Preferences', 'production_Config.ini') + } else { + filePath = path.join(app.getPath('documents'), 'My Games', 'Path of Exile', 'production_Config.ini') + } try { fs.accessSync(filePath) appConfig.set('gameConfig', filePath) diff --git a/src/main/shortcuts.ts b/src/main/shortcuts.ts index 5ff8f5f8..d4e96a65 100644 --- a/src/main/shortcuts.ts +++ b/src/main/shortcuts.ts @@ -203,8 +203,14 @@ function pressKeysToCopyItemText (pressedModKeys: string[] = []) { robotjs.keyToggle(key, 'down') } + const modifierKeys = keys.filter(key => ['Ctrl', 'Alt', 'Shift'].includes(key)) // finally press `C` to copy text - robotjs.keyTap('C') + robotjs.keyTap( + 'C', + // On Mac, robotjs requires the modifiers to be specified in this way to + // register. See https://github.com/octalmage/robotjs/issues/208#issuecomment-223828356 + process.platform === 'darwin' ? modifierKeys : undefined + ) keys.reverse() for (const key of keys) { diff --git a/src/main/tray.ts b/src/main/tray.ts index 978da49f..116fae47 100644 --- a/src/main/tray.ts +++ b/src/main/tray.ts @@ -6,9 +6,15 @@ import { config } from './config' let tray: Tray export function createTray () { - tray = new Tray( - nativeImage.createFromPath(path.join(__static, process.platform === 'win32' ? 'icon.ico' : 'icon.png')) - ) + let trayImage = nativeImage.createFromPath(path.join(__static, process.platform === 'win32' ? 'icon.ico' : 'icon.png')) + if (process.platform === 'darwin') { + // Mac image size needs to be smaller, or else it looks huge. Size + // guideline is from https://iconhandbook.co.uk/reference/chart/osx/ + trayImage = trayImage.resize({ width: 22, height: 22 }) + // Hide the app in the dock as soon as the tray icon is active + app.dock.hide() + } + tray = new Tray(trayImage) tray.setToolTip('Awakened PoE Trade') rebuildTrayMenu() diff --git a/vue.config.js b/vue.config.js index a65a8d65..34f3d548 100644 --- a/vue.config.js +++ b/vue.config.js @@ -16,6 +16,13 @@ module.exports = { }, linux: { target: ['AppImage'] + }, + mac: { + // Disable code signing. While we could release with an official + // developer identity, we haven't set it up yet. Disabled based on + // instructions here: + // https://www.electron.build/code-signing#how-to-disable-code-signing-during-the-build-process-on-macos + identity: null } } } diff --git a/yarn.lock b/yarn.lock index 0c012d03..1af14f9f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3709,10 +3709,9 @@ electron-osx-sign@^0.5.0: minimist "^1.2.0" plist "^3.0.1" -electron-overlay-window@3.0.0-beta.1: - version "3.0.0-beta.1" - resolved "https://registry.yarnpkg.com/electron-overlay-window/-/electron-overlay-window-3.0.0-beta.1.tgz#94072bb8527c45d7c15db555279044077d04ee0f" - integrity sha512-59+Zw3e8ou/9fuX22gEHCbItbp2HQBEjHi7vNO5fbYe/r7niU3wEAhqMvYrWPcw/T1bhqTWsmnBjMy7yjLlRmw== +electron-overlay-window@hsource/electron-overlay-window#3.0.0-macos.2: + version "3.0.0-macos.2" + resolved "https://codeload.github.com/hsource/electron-overlay-window/tar.gz/17700b26ef2d298ac0238e1fc27f74b74aaf8cef" dependencies: node-gyp-build "4.x.x" throttle-debounce "3.x.x"