mirror of
https://github.com/mgerb/ps-launcher
synced 2026-01-10 18:42:48 +00:00
poll github for new releases - closes #6
This commit is contained in:
@@ -47,6 +47,18 @@
|
||||
font-size: 30px;
|
||||
}
|
||||
|
||||
.header__update {
|
||||
color: darken($green, 5%);
|
||||
|
||||
&:hover {
|
||||
color: $green;
|
||||
}
|
||||
|
||||
.fa {
|
||||
margin-right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.header__version {
|
||||
span {
|
||||
font-size: 12px;
|
||||
|
||||
@@ -33,19 +33,30 @@ export class Header extends React.Component<Props, any> {
|
||||
remote.getCurrentWindow().minimize();
|
||||
}
|
||||
|
||||
private openGithub(): void {
|
||||
private openReleases(): void {
|
||||
shell.openExternal('https://github.com/mgerb/ps-launcher/releases');
|
||||
}
|
||||
|
||||
private openBugReport(): void {
|
||||
shell.openExternal('https://github.com/mgerb/ps-launcher/issues');
|
||||
}
|
||||
|
||||
public render(): any {
|
||||
const { updateAvailable } = this.props.AppState;
|
||||
const updateClass = updateAvailable ? 'header__update' : '';
|
||||
|
||||
return (
|
||||
<div className="header">
|
||||
<div className="header__version">
|
||||
<img src={headerIcon}/>
|
||||
<span style={{ fontSize: '10px' }}>v{VERSION}</span>
|
||||
<span style={{ fontSize: '10px' }}>{VERSION}</span>
|
||||
</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--maximize" onClick={this.maximize.bind(this)}/>
|
||||
<div className="header-icon header-icon--close" onClick={() => this.exit()}>×</div>
|
||||
|
||||
@@ -3,6 +3,8 @@ import * as _ from 'lodash';
|
||||
import { action, computed, observable, runInAction } from 'mobx';
|
||||
import fs from 'fs';
|
||||
import { persistentStateSeed } from './persistent-state-seed';
|
||||
import { versioning } from '../util';
|
||||
import 'babel-polyfill';
|
||||
|
||||
export interface ExpansionType {
|
||||
name: string;
|
||||
@@ -27,6 +29,7 @@ export class AppState {
|
||||
@observable public expansions: { [key: string]: ExpansionType };
|
||||
@observable public isBootstrapped: boolean = false;
|
||||
@observable public selectedExpKey: string = 'vanilla';
|
||||
@observable public updateAvailable: boolean = false;
|
||||
|
||||
constructor() {
|
||||
this.bootstrap();
|
||||
@@ -118,10 +121,17 @@ export class AppState {
|
||||
this.persistState();
|
||||
}
|
||||
|
||||
// bootstrap application
|
||||
// creates directory and persistent store in appData
|
||||
// bootstrap process for application
|
||||
@action
|
||||
private bootstrap(): void {
|
||||
|
||||
// start interval to check for updates
|
||||
// 5 minutes
|
||||
this.startVersionCheck();
|
||||
setInterval(() => {
|
||||
this.startVersionCheck();
|
||||
}, 5 * 60000);
|
||||
|
||||
if (!fs.statSync(this.appPath).isDirectory()) {
|
||||
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
|
||||
private persistState(): Promise<void> {
|
||||
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
export * from './toast/toast';
|
||||
export * from './versioning/versioning';
|
||||
|
||||
28
app/util/versioning/versioning.ts
Normal file
28
app/util/versioning/versioning.ts
Normal 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();
|
||||
Reference in New Issue
Block a user