Skip to content

Commit

Permalink
Fix autoclick freezing issue in Mojave
Browse files Browse the repository at this point in the history
Update `autoclick.applescript` to avoid freezing issue in Mojave.

See: iam4x#450
  • Loading branch information
asd123cqp committed Nov 9, 2018
1 parent a7925a4 commit 50dda53
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
7 changes: 5 additions & 2 deletions autoclick.applescript
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
tell application "System Events" to tell process "Xcode"
repeat
tell application "System Events" to tell process "Xcode"
click menu item "pokemonLocation" of menu 1 of menu item "Simulate Location" of menu 1 of menu bar item "Debug" of menu bar 1
end tell
end tell
delay 0.5
end repeat
40 changes: 22 additions & 18 deletions src/models/user-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import stats from './stats.js'
// electron specific import
const { writeFile } = window.require('fs')
const { resolve } = window.require('path')
const { exec } = window.require('child_process')
const { spawn } = window.require('child_process')
const { remote } = window.require('electron')

const userLocation = observable([ 0, 0 ])
const userLocation = observable([0, 0])
const isValidLocation = /^([-+]?\d{1,2}([.]\d+)?),\s*([-+]?\d{1,3}([.]\d+)?)$/
const validateCoordinates = ((change) => {
// check that we have valid coordinates before update
if (change.type === 'splice') {
const { added: [ lat, lng ] } = change
const { added: [lat, lng] } = change
const isValid = isValidLocation.test(`${lat}, ${lng}`)
if (isValid) {
return change
Expand All @@ -31,7 +31,7 @@ const validateCoordinates = ((change) => {
return change
})

const updateXcodeLocation = throttle(([ lat, lng ]) => {
const updateXcodeLocation = throttle(([lat, lng]) => {
// track location changes for total distance & average speed
stats.pushMove(lat, lng)

Expand All @@ -50,20 +50,6 @@ const updateXcodeLocation = throttle(([ lat, lng ]) => {
`)
return console.warn(error)
}

if (settings.updateXcodeLocation.get()) {
// reload location into xcode
const scriptPath = resolve(window.__dirname, 'autoclick.applescript')
exec(`osascript ${scriptPath}`, (autoclickErr, stdout, stderr) => {
if (stderr) {
Alert.error(`
<strong>Error autoclick Xcode - Code 2</strong>
<div class='stack'>${stderr}</div>
`)
return console.warn(stderr)
}
})
}
})
}, 1000)

Expand Down Expand Up @@ -102,4 +88,22 @@ settings.stationaryUpdates.observe(() => scheduleUpdate())
// initial trigger
scheduleUpdate()

// Update xcode location
var autoclick_proc = null
var scriptPath = resolve(window.__dirname, 'autoclick.applescript')
function toggleXcodeLocation() {
if (autoclick_proc) {
console.log(`Killing: ${autoclick_proc}`)
autoclick_proc.kill('SIGINT')
autoclick_proc = null
}
if (settings.updateXcodeLocation.get()) {
// reload location into xcode
autoclick_proc = spawn('osascript', [scriptPath])
console.log(`Spawned: ${autoclick_proc}`)
}
}

settings.updateXcodeLocation.observe(() => toggleXcodeLocation())

export default userLocation

0 comments on commit 50dda53

Please sign in to comment.