Permalink
Browse files

use new update server (closes #271), add export to MTGG

  • Loading branch information...
shawkinsl committed Sep 16, 2018
1 parent 33fe6a4 commit b2a867a5541eac20659d4f22f72235eb3300a6a4
Showing with 332 additions and 50 deletions.
  1. +1 −0 app/parsers.py
  2. +25 −6 build.sh
  3. +23 −6 electron/main.js
  4. +16 −1 electron/mainRenderer.js
  5. +164 −9 electron/package-lock.json
  6. +9 −3 electron/package.json
  7. +30 −1 electron/settings.html
  8. +58 −1 electron/settingsRenderer.js
  9. +6 −23 electron/updates.js
@@ -28,6 +28,7 @@ def parse_get_decklists(blob):
@util.debug_log_trace
def parse_get_player_cards_v3(blob):
import app.mtga_app as mtga_app
pass_through("collection", None, blob)
mtga_app.mtga_watch_app.collection = blob
mtga_app.mtga_watch_app.save_settings()

@@ -1,13 +1,16 @@
#!/usr/bin/env bash

start=$(date +%s)
start_raw=$(date)

if (( "$#" != 1 ))
then
echo "Must provide version string to use (e.g. 0.1.0-alpha)"
exit 1
fi

echo "Build start: $start_raw"

version=$1
cleanVer=$(echo $version | cut -f1 -d "-")

@@ -47,27 +50,43 @@ mv MTGATracker-win32-x64 MTGATracker-win32-x64_$version

cd electron
cat > testbuild.js <<- EOM
const request = require("request")
console.log("enter winstaller")
var electronInstaller = require('electron-winstaller');
resultPromise = electronInstaller.createWindowsInstaller({
let releasesUrl = "https://api.github.com/repos/mtgatracker/mtgatracker-updates/releases"
let requestOptions = {
url: releasesUrl,
headers: {
'User-Agent': 'mtgatracker-build-script'
}
}
request(requestOptions, (err, res, body) => {
let { tag_name } = JSON.parse(body)[0]
let remoteReleasesURL = \`https://github.com/mtgatracker/mtgatracker-updates/releases/download/\${tag_name}\`
let resultPromise = electronInstaller.createWindowsInstaller({
appDirectory: '../MTGATracker-win32-x64_$version',
outputDirectory: '../MTGATracker-win32-x64_$version-SQUIRREL',
authors: 'MTGATracker',
exe: 'MTGATracker.exe',
loadingGif: '../updating.gif',
remoteReleases: 'https://s3-us-west-1.amazonaws.com/mtgatracker/autoupdates/win',
remoteReleases: remoteReleasesURL,
});
resultPromise.then(() => console.log("It worked!"), (e) => console.log(e));
console.log("waiting on winstaller to finish...")
resultPromise.then(() => console.log("It worked!"), (e) => console.log(e));
console.log("waiting on winstaller to finish...")
})
EOM

sleep 1

node testbuild.js
DEBUG=electron-windows-installer:main node testbuild.js

md5sum ../MTGATracker-win32-x64_$version.zip
end=$(date +%s)
secs=$((end-start))
printf 'build took %dh:%dm:%ds\n' $(($secs/3600)) $(($secs%3600/60)) $(($secs%60))
printf 'build took %dh:%dm:%ds\n' $(($secs/3600)) $(($secs%3600/60)) $(($secs%60))
@@ -1,13 +1,14 @@
const console = require('console');

global.updateReady = false
const { handleStartupEvent } = require("./updates")
global.updateDownloading = false
const { handleStartupEvent, updater } = require("./updates")

if (handleStartupEvent()) {
return;
}

const { app, ipcMain, BrowserWindow, autoUpdater } = require('electron')
const { app, ipcMain, BrowserWindow } = require('electron')
const fs = require('fs');
const path = require('path')
const keytar = require('keytar')
@@ -16,15 +17,26 @@ const request = require('request')
const API_URL = "https://gxt.mtgatracker.com/str-85b6a06b2d213fac515a8ba7b582387a-pt/mtgatracker-prod-EhDvLyq7PNb";

const firstRun = process.argv[1] == '--squirrel-firstrun';
global.firstRun = firstRun
const runFromSource = !process.execPath.endsWith("MTGATracker.exe")

if (!firstRun && fs.existsSync(path.resolve(path.dirname(process.execPath), '..', 'update.exe'))) {
autoUpdater.checkForUpdates()
setInterval(() => {
if (!global.updateDownloading) {
updater.check((err, status) => {
if (!err && status) {
// Download the update
updater.download()
global.updateDownloading = true;
}
})
}
}, 1000)
}

const findProcess = require('find-process');
const settings = require('electron-settings');
autoUpdater.on('update-downloaded', (e) => {
updater.autoUpdater.on('update-downloaded', (e) => {
global.updateReady = true
mainWindow.webContents.send('updateReadyToInstall', {
text: "A new version has been downloaded. Restart to update!"
@@ -104,6 +116,7 @@ let invertHideMode = settings.get('invertHideMode', false);
let winLossCounter = settings.get('winLossCounter', {win: 0, loss: 0});
let showWinLossCounter = settings.get('showWinLossCounter', true);
let showVaultProgress = settings.get('showVaultProgress', true);
let lastCollection = settings.get('lastCollection', {});
let lastVaultProgress = settings.get('lastVaultProgress', 0);
let minVaultProgress = settings.get('minVaultProgress', 0);
let sortMethod = settings.get('sortMethod', 'draw');
@@ -121,7 +134,10 @@ userMap.forEach(user => {
json: true,
headers: {'User-Agent': 'MTGATracker-App', 'token': token}
}, (err, res, data) => {
if(res.statusCode == 200) {
if (err) {
console.log(err)
}
if(res && res.statusCode == 200) {
user.auth = true;
}
})
@@ -383,6 +399,7 @@ global.winLossCounter = winLossCounter;
global.showWinLossCounter = showWinLossCounter;
global.showVaultProgress = showVaultProgress;
global.lastVaultProgress = lastVaultProgress;
global.lastCollection = lastCollection;
global.minVaultProgress = minVaultProgress;
global.version = app.getVersion()
global.messagesAcknowledged = settings.get("messagesAcknowledged", [])
@@ -481,7 +498,7 @@ const killServer = () => {
}
if (global.updateReady) {
console.log("doing quitAndInstall")
autoUpdater.quitAndInstall()
updater.install()
} else {
console.log("app.quit()")
app.quit()
@@ -40,6 +40,7 @@ var appVersionStr = remote.getGlobal('version');
var runFromSource = remote.getGlobal('runFromSource');
var showWinLossCounter = remote.getGlobal('showWinLossCounter');
var showVaultProgress = remote.getGlobal('showVaultProgress');
var lastCollection = remote.getGlobal('lastCollection');
var lastVaultProgress = remote.getGlobal('lastVaultProgress');
var minVaultProgress = remote.getGlobal('minVaultProgress');
var sortMethod = remote.getGlobal('sortMethod');
@@ -106,6 +107,7 @@ var appData = {
show_iids: showIIDs,
last_connect: 0,
last_connect_as_seconds: 0,
lastCollection: lastCollection,
lastVaultProgress: lastVaultProgress,
minVaultProgress: minVaultProgress,
game_in_progress: false,
@@ -821,7 +823,20 @@ let onMessage = (data) => {
console.log("error uploading inventory data: ")
console.log(e)
})
} else if (data.draftPick) {
} else if (data.collection) {
if (data.collection) {
appData.lastCollection = data.collection
ipcRenderer.send('settingsChanged', {
key: "lastCollection",
value: appData.lastCollection
})

passThrough("tracker-api/collection", data.collection, data.player_key).catch(e => {
console.log("error uploading collections data: ")
console.log(e)
})
}
} else if (data.draftPick) {
passThrough("tracker-api/draft-pick", data.draftPick, data.player_key).catch(e => {
console.log("error uploading draftPick data: ")
console.log(e)
Oops, something went wrong.

0 comments on commit b2a867a

Please sign in to comment.