Skip to content

Commit

Permalink
Merge pull request #14 from chwebdude/updater
Browse files Browse the repository at this point in the history
Updater
  • Loading branch information
chwebdude authored Jan 12, 2018
2 parents 8b3bd25 + 26e7731 commit cde8c99
Show file tree
Hide file tree
Showing 7 changed files with 343 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,15 @@
</li>

<li>
<span *ngIf="backgroundTasks > 1" class="badge">{{backgroundTasks}} Background tasks</span>
<span *ngIf="backgroundTasks == 1" class="badge">{{backgroundTasks}} Background task</span>
<span *ngIf="backgroundTasks > 1" class="badge">{{backgroundTasks}} Background tasks running</span>
<span *ngIf="backgroundTasks == 1" class="badge">{{backgroundTasks}} Background task running</span>
</li>

<li *ngIf="updateRelease != null">
<button type="button" class="btn btn-danger" (click)="openGithubRelease()">
New Version available: <span class="badge badge-light">{{updateRelease.name}}</span>
</button>

</li>
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { HttpClient, HttpHeaders, HttpParams, HttpErrorResponse } from '@angular/common/http';
import { Observable } from "rxjs";
import { IntervalObservable } from "rxjs/observable/IntervalObservable";
import { CryptoApiClient } from '../../services/api-client';
import { environment } from '../../../environments/environment';


@Component({
selector: 'nav-menu',
templateUrl: './navmenu.component.html',
styleUrls: ['./navmenu.component.css']
selector: 'nav-menu',
templateUrl: './navmenu.component.html',
styleUrls: ['./navmenu.component.css']
})
export class NavMenuComponent {
httpParams: string;
backgroundTasks :number;
backgroundTasks: number;
updateRelease: LatestRelease;


constructor(private http: HttpClient, private client: CryptoApiClient) { }

Expand All @@ -32,6 +35,17 @@ export class NavMenuComponent {
this.backgroundTasks = data["processing:count"].value;
});
});

// Check every 10 Minutes
IntervalObservable.create(600000)
.subscribe(() => {
this.getLatestRelease();
});

var lastCheck = localStorage.getItem("lastUpdateCheck");
if (lastCheck == null || parseInt(lastCheck) < Date.now() - 600000) {
this.getLatestRelease();
}
}

getHangfireStats(): Observable<HangfireStats> {
Expand All @@ -46,6 +60,24 @@ export class NavMenuComponent {
recalculate(): void {
this.client.apiTransactionsRecalculatePost().subscribe();
}

getLatestRelease(): void {
this.http.get<LatestRelease>("https://api.github.com/repos/chwebdude/CryptoManager/releases/latest")
.subscribe((res) => {
var currentVersion = environment.version;
if (res.name != currentVersion) {
console.info("Update available. Current version " + currentVersion + ". Available: " + res.name);
this.updateRelease = res;
} else {
localStorage.setItem("lastUpdateCheck", Date.now().toString());
}
});
}

openGithubRelease() {
window.open(this.updateRelease.html_url, '_blank');

}
}


Expand All @@ -57,4 +89,14 @@ class HangfireStats {
'enqueued:count-or-null': HangfireMetric;
'processing:count': HangfireMetric;
'succeeded:count': HangfireMetric;
}

class LatestRelease {
html_url: string;
id: number;
name: string;
body: string;
draft: boolean;
prerelease: boolean;
published_at: Date;
}
11 changes: 11 additions & 0 deletions CryptoManager/ClientApp/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.

export const environment = {
production: true,
version: '#{GitVersion_SemVer}#'
};


11 changes: 11 additions & 0 deletions CryptoManager/ClientApp/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.

export const environment = {
production: false,
version: '#{GitVersion_SemVer}#'
};


8 changes: 6 additions & 2 deletions CryptoManager/CryptoManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
</ItemGroup>

<ItemGroup>
<None Remove="ClientApp\environments\environment.prod.ts" />
<None Remove="ClientApp\environments\environment.ts" />
<None Remove="ClientApp\polyfills.ts" />
</ItemGroup>

Expand All @@ -44,6 +46,8 @@
</ItemGroup>

<ItemGroup>
<TypeScriptCompile Include="ClientApp\environments\environment.prod.ts" />
<TypeScriptCompile Include="ClientApp\environments\environment.ts" />
<TypeScriptCompile Include="ClientApp\polyfills.ts" />
</ItemGroup>

Expand Down Expand Up @@ -76,8 +80,8 @@
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec Command="yarn install" />
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js" /><!-- Todo: Readd - -evn.prod for production build -->
<Exec Command="node node_modules/webpack/bin/webpack.js" /><!-- Todo: Readd - -evn.prod for production build -->
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js" /><!-- Todo: Re-add: - -env.prod -->
<Exec Command="node node_modules/webpack/bin/webpack.js" />

<!-- Include the newly-built files in the publish output -->
<ItemGroup>
Expand Down
Loading

0 comments on commit cde8c99

Please sign in to comment.