Skip to content

Commit

Permalink
Added MacOS support
Browse files Browse the repository at this point in the history
  • Loading branch information
hsource committed Feb 15, 2022
1 parent 20528b2 commit c4c70bf
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion src/ipc/KeyToCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/PoeWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 10 additions & 4 deletions src/main/game-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
6 changes: 5 additions & 1 deletion src/main/game-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion src/main/shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 9 additions & 3 deletions src/main/tray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c4c70bf

Please sign in to comment.