1
0
mirror of https://github.com/mgerb/ps-launcher synced 2026-01-09 01:52:57 +00:00

poll github for new releases - closes #6

This commit is contained in:
2017-10-29 14:01:24 -05:00
parent 9806b8ebe6
commit f39901ca70
7 changed files with 94 additions and 8 deletions

View File

@@ -47,6 +47,18 @@
font-size: 30px; font-size: 30px;
} }
.header__update {
color: darken($green, 5%);
&:hover {
color: $green;
}
.fa {
margin-right: 0;
}
}
.header__version { .header__version {
span { span {
font-size: 12px; font-size: 12px;

View File

@@ -33,19 +33,30 @@ export class Header extends React.Component<Props, any> {
remote.getCurrentWindow().minimize(); remote.getCurrentWindow().minimize();
} }
private openGithub(): void { private openReleases(): void {
shell.openExternal('https://github.com/mgerb/ps-launcher/releases'); shell.openExternal('https://github.com/mgerb/ps-launcher/releases');
} }
private openBugReport(): void {
shell.openExternal('https://github.com/mgerb/ps-launcher/issues');
}
public render(): any { public render(): any {
const { updateAvailable } = this.props.AppState;
const updateClass = updateAvailable ? 'header__update' : '';
return ( return (
<div className="header"> <div className="header">
<div className="header__version"> <div className="header__version">
<img src={headerIcon}/> <img src={headerIcon}/>
<span style={{ fontSize: '10px' }}>v{VERSION}</span> <span style={{ fontSize: '10px' }}>{VERSION}</span>
</div> </div>
<div className="header__draggable-region"></div> <div className="header__draggable-region"></div>
<i className="fa fa-lg fa-github header-icon" onClick={this.openGithub.bind(this)}/> <div className={'header-icon ' + updateClass} onClick={this.openReleases.bind(this)} title="Releases">
{updateAvailable && <span style={{ fontSize: '12px' }}>Update Available!</span>}
<i className="fa fa-lg fa-github"/>
</div>
<i className="fa fa-exclamation-triangle header-icon" onClick={this.openBugReport.bind(this)} title="Report a bug"/>
<div className="header-icon header-icon--minimize" onClick={this.minimize.bind(this)}/> <div className="header-icon header-icon--minimize" onClick={this.minimize.bind(this)}/>
<div className="header-icon header-icon--maximize" onClick={this.maximize.bind(this)}/> <div className="header-icon header-icon--maximize" onClick={this.maximize.bind(this)}/>
<div className="header-icon header-icon--close" onClick={() => this.exit()}>×</div> <div className="header-icon header-icon--close" onClick={() => this.exit()}>×</div>

View File

@@ -3,6 +3,8 @@ import * as _ from 'lodash';
import { action, computed, observable, runInAction } from 'mobx'; import { action, computed, observable, runInAction } from 'mobx';
import fs from 'fs'; import fs from 'fs';
import { persistentStateSeed } from './persistent-state-seed'; import { persistentStateSeed } from './persistent-state-seed';
import { versioning } from '../util';
import 'babel-polyfill';
export interface ExpansionType { export interface ExpansionType {
name: string; name: string;
@@ -27,6 +29,7 @@ export class AppState {
@observable public expansions: { [key: string]: ExpansionType }; @observable public expansions: { [key: string]: ExpansionType };
@observable public isBootstrapped: boolean = false; @observable public isBootstrapped: boolean = false;
@observable public selectedExpKey: string = 'vanilla'; @observable public selectedExpKey: string = 'vanilla';
@observable public updateAvailable: boolean = false;
constructor() { constructor() {
this.bootstrap(); this.bootstrap();
@@ -118,10 +121,17 @@ export class AppState {
this.persistState(); this.persistState();
} }
// bootstrap application // bootstrap process for application
// creates directory and persistent store in appData
@action @action
private bootstrap(): void { private bootstrap(): void {
// start interval to check for updates
// 5 minutes
this.startVersionCheck();
setInterval(() => {
this.startVersionCheck();
}, 5 * 60000);
if (!fs.statSync(this.appPath).isDirectory()) { if (!fs.statSync(this.appPath).isDirectory()) {
fs.mkdirSync(this.appPath); fs.mkdirSync(this.appPath);
} }
@@ -146,6 +156,16 @@ export class AppState {
}); });
} }
private async startVersionCheck(): Promise<void> {
const update = await versioning.checkForUpdates();
if (update) {
runInAction(() => {
this.updateAvailable = update;
});
}
}
// save state of app to file in app data // save state of app to file in app data
private persistState(): Promise<void> { private persistState(): Promise<void> {

View File

@@ -1 +1,2 @@
export * from './toast/toast'; export * from './toast/toast';
export * from './versioning/versioning';

View File

@@ -0,0 +1,28 @@
import axios from 'axios';
import * as _ from 'lodash';
class Versioning {
private readonly releaseEndPoint: string = 'https://api.github.com/repos/mgerb/ps-launcher/releases';
public async checkForUpdates(): Promise<boolean> {
const res = await axios.get(this.releaseEndPoint);
return !!_.find(res.data, (release: any) => {
return this.parseVersion(release.tag_name) > this.parseVersion(VERSION);
});
}
/**
* returns a number value for a version string matching '0.0.1'
* @param {string} version
* @returns {*}
* @memberof Versioning
*/
public parseVersion(version: string): number {
const parts = version.split('.');
return _.sumBy(parts, p => parseInt(p, 10));
}
}
export const versioning = new Versioning();

View File

@@ -35,7 +35,8 @@
"author": "Mitchell Gerber", "author": "Mitchell Gerber",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"babel-core": "^6.21.0", "axios": "^0.17.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2", "babel-loader": "^7.1.2",
"babel-plugin-add-module-exports": "^0.2.1", "babel-plugin-add-module-exports": "^0.2.1",
"babel-polyfill": "^6.26.0", "babel-polyfill": "^6.26.0",

View File

@@ -393,6 +393,13 @@ aws4@^1.2.1, aws4@^1.6.0:
version "1.6.0" version "1.6.0"
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e" resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e"
axios@^0.17.0:
version "0.17.0"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.17.0.tgz#7da747916db803f761651d6091d708789b953c6a"
dependencies:
follow-redirects "^1.2.3"
is-buffer "^1.1.5"
babel-code-frame@^6.11.0, babel-code-frame@^6.26.0: babel-code-frame@^6.11.0, babel-code-frame@^6.26.0:
version "6.26.0" version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b" resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b"
@@ -409,7 +416,7 @@ babel-code-frame@^6.22.0:
esutils "^2.0.2" esutils "^2.0.2"
js-tokens "^3.0.0" js-tokens "^3.0.0"
babel-core@^6.21.0, babel-core@^6.26.0: babel-core@^6.26.0:
version "6.26.0" version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-6.26.0.tgz#af32f78b31a6fcef119c87b0fd8d9753f03a0bb8" resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-6.26.0.tgz#af32f78b31a6fcef119c87b0fd8d9753f03a0bb8"
dependencies: dependencies:
@@ -1998,7 +2005,7 @@ debug@2.2.0:
dependencies: dependencies:
ms "0.7.1" ms "0.7.1"
debug@2.6.9, debug@^2.1.3, debug@^2.2.0, debug@^2.6.6, debug@^2.6.8: debug@2.6.9, debug@^2.1.3, debug@^2.2.0, debug@^2.6.6, debug@^2.6.8, debug@^2.6.9:
version "2.6.9" version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
dependencies: dependencies:
@@ -2771,6 +2778,12 @@ flatten@^1.0.2:
version "1.0.2" version "1.0.2"
resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782" resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782"
follow-redirects@^1.2.3:
version "1.2.5"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.2.5.tgz#ffd3e14cbdd5eaa72f61b6368c1f68516c2a26cc"
dependencies:
debug "^2.6.9"
font-awesome@^4.7.0: font-awesome@^4.7.0:
version "4.7.0" version "4.7.0"
resolved "https://registry.yarnpkg.com/font-awesome/-/font-awesome-4.7.0.tgz#8fa8cf0411a1a31afd07b06d2902bb9fc815a133" resolved "https://registry.yarnpkg.com/font-awesome/-/font-awesome-4.7.0.tgz#8fa8cf0411a1a31afd07b06d2902bb9fc815a133"