From 0e92a66bf526010889387753135ee9433eb8d4e8 Mon Sep 17 00:00:00 2001 From: Max Tyler Date: Sat, 16 Jul 2016 01:19:05 +0200 Subject: [PATCH] fix: copy xcode-project && pokemonLocation.gpx to tmp dir --- main.js | 27 ++++++++++++++++++++++----- package.json | 3 +-- src/models/user-location.js | 3 ++- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/main.js b/main.js index 9a689c7..0e39784 100644 --- a/main.js +++ b/main.js @@ -1,4 +1,7 @@ const electron = require('electron') +const { resolve } = require('path') +const { execSync } = require('child_process') + const { app } = electron const { BrowserWindow } = electron @@ -13,10 +16,24 @@ const createWindow = () => { win.on('closed', () => { win = null }) } -app.on('ready', createWindow) +app.on('ready', () => { + const tmp = require('tmp') + tmp.dir((err, path) => { + if (err) throw err + + global.tmpProjectPath = path + createWindow() + + execSync(`cp -R ${resolve(__dirname, 'xcode-project')} ${resolve(path)}`) + execSync(`open -a xcode ${resolve(path, 'xcode-project/pokemon-webspoof.xcodeproj')}`) + + // quit xcode && remove tmp directory on exit + app.on('before-quit', () => { + execSync('killall Xcode') + execSync(`rm -rf ${path}`) + }) + }) +}) + app.on('window-all-closed', () => (process.platform !== 'darnwin') && app.quit()) app.on('activate', () => (win === null) && createWindow()) - -const { resolve } = require('path') -const { execSync } = require('child_process') -execSync(`open -a xcode ${resolve(__dirname, 'xcode-project/pokemon-webspoof.xcodeproj')}`) diff --git a/package.json b/package.json index fa1e160..be04498 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,7 @@ "clean": "rm -rf ./dist/* ./pokemongo-webspoof-darwin-x64", "build:code": "NODE_ENV=production webpack --config webpack.config.babel.js", "build:electron": "electron-packager . pokemongo-webspoof --platform=darwin --arch=x64", - "open:xcode": "open ./xcode-project/pokemon-webspoof.xcodeproj/", "open:app": "open ./pokemongo-webspoof-darwin-x64/pokemongo-webspoof.app", - "start": "npm run open:app && npm run open:xcode", "build": "npm run clean && npm run build:code && npm run build:electron" }, "bin": { @@ -19,6 +17,7 @@ "pgws": "./bin/pgws" }, "dependencies": { + "tmp": "0.0.28" }, "devDependencies": { "babel-eslint": "^6.1.2", diff --git a/src/models/user-location.js b/src/models/user-location.js index 5df73c0..1386673 100644 --- a/src/models/user-location.js +++ b/src/models/user-location.js @@ -9,6 +9,7 @@ import settings from './settings.js' const { writeFile } = window.require('fs') const { resolve } = window.require('path') const { exec } = window.require('child_process') +const { remote } = window.require('electron') const userLocation = observable([ 0, 0 ]) @@ -40,7 +41,7 @@ const updateXcodeLocation = throttle(([ lat, lng ]) => { if (settings.updateXcodeLocation.get()) { // write `pokemonLocation.gpx` file fro xcode spoof location - const filePath = resolve(window.__dirname, 'pokemonLocation.gpx') + const filePath = resolve(remote.getGlobal('tmpProjectPath'), 'pokemonLocation.gpx') writeFile(filePath, xcodeLocationData, async (error) => { if (error) { Alert.error(`