Skip to content

Commit

Permalink
working (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
UnchartedBull committed Oct 4, 2019
1 parent b83de16 commit 371c8c4
Show file tree
Hide file tree
Showing 18 changed files with 178 additions and 118 deletions.
8 changes: 7 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,18 @@ function createWindow() {
if (config && config.octodash && config.octodash.temperatureSensor !== null) {
queryTemperatureSensor();
}

setTimeout(sendVersionInfo, 42 * 1000);
window.on('closed', () => {
window = null;
});
}

function sendVersionInfo() {
window.webContents.send("versionInformation", {
version: process.env.npm_package_version
})
}

function queryTemperatureSensor() {
if (process.platform !== "linux") {
sensor.initialize({
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<app-error></app-error>
<app-notification></app-notification>
<div class="container">
<router-outlet></router-outlet>
</div>
8 changes: 4 additions & 4 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AppRoutingModule } from './app.routing.module';
import { AppComponent } from './app.component';
import { BottomBarComponent } from './bottom-bar/bottom-bar.component';
import { ControlComponent } from './control/control.component';
import { ErrorComponent } from './error/error.component';
import { NotificationComponent } from './notification/notification.component';
import { FilamentComponent } from './filament/filament.component';
import { FilesComponent } from './files/files.component';
import { InvalidConfigComponent } from './config/invalid-config/invalid-config.component';
Expand All @@ -24,7 +24,7 @@ import { PrinterStatusComponent } from './printer-status/printer-status.componen

import { AppService } from './app.service';
import { ConfigService } from './config/config.service';
import { ErrorService } from './error/error.service';
import { NotificationService } from './notification/notification.service';
import { JobService } from './job.service';
import { PrinterService } from './printer.service';

Expand Down Expand Up @@ -55,7 +55,7 @@ export class MyHammerConfig extends HammerGestureConfig {
InvalidConfigComponent,
NoConfigComponent,
PrintControlComponent,
ErrorComponent,
NotificationComponent,
MainMenuComponent,
ControlComponent,
MainScreenComponent,
Expand All @@ -77,7 +77,7 @@ export class MyHammerConfig extends HammerGestureConfig {
providers: [
AppService,
ConfigService,
ErrorService,
NotificationService,
PrinterService,
JobService,
{
Expand Down
40 changes: 39 additions & 1 deletion src/app/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Injectable } from '@angular/core';
import { ConfigService } from './config/config.service';
import { NotificationService } from './notification/notification.service';
import { HttpClient } from '@angular/common/http';

@Injectable({
providedIn: 'root'
Expand All @@ -8,14 +10,41 @@ export class AppService {

private updateError: string[];
private loadedFile = false;
private ipc: any;
private version: string;

constructor(private configService: ConfigService, private notificationService: NotificationService, private http: HttpClient) {
if (window.require && configService.config.octodash.temperatureSensor !== null) {
try {
this.ipc = window.require('electron').ipcRenderer;
this.ipc.on('versionInformation', ({ }, versionInformation: VersionInformation) => {
this.version = versionInformation.version;
this.checkUpdate();
});
} catch (e) {
this.notificationService.setError('Can\'t retrieve version information', 'Please open an issue for GitHub as this shouldn\'t happen.');
}
}

constructor(private configService: ConfigService) {
this.updateError = [
'.printer should have required property \'xySpeed\'',
'.printer should have required property \'zSpeed\'',
'.octodash should have required property \'customActions\''];
}

private checkUpdate(): void {
this.http.get('https://api.github.com/repos/UnchartedBull/OctoDash/releases/latest').subscribe(
(data: GitHubRealeaseInformation) => {
if (this.version !== data.name.replace('v', '')) {
this.notificationService.setUpdate('It\'s time for an update',
`Version ${data.name} is available now, while you're on v${this.version}. Consider updating :)`);
}
},
() => null
);
setTimeout(this.checkUpdate.bind(this), 21.6 * 1000000);
}

public getUpdateError(): string[] {
return this.updateError;
}
Expand Down Expand Up @@ -96,3 +125,12 @@ export class AppService {
}

}

interface VersionInformation {
version: string;
}

interface GitHubRealeaseInformation {
name: string;
[key: string]: any;
}
5 changes: 0 additions & 5 deletions src/app/error/error.component.html

This file was deleted.

37 changes: 0 additions & 37 deletions src/app/error/error.component.ts

This file was deleted.

31 changes: 0 additions & 31 deletions src/app/error/error.service.ts

This file was deleted.

18 changes: 9 additions & 9 deletions src/app/files.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@angular/core';
import { ConfigService } from './config/config.service';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { ErrorService } from './error/error.service';
import { NotificationService } from './notification/notification.service';
import { Subscription } from 'rxjs';
import { OctoprintFolderAPI, OctoprintFilesAPI, OctoprintFolderContentAPI } from './octoprint-api/filesAPI';
import { AppService } from './app.service';
Expand All @@ -18,7 +18,7 @@ export class FilesService {
constructor(
private configService: ConfigService,
private http: HttpClient,
private errorService: ErrorService,
private notificationService: NotificationService,
private service: AppService) { }

public getFolder(folderPath: string = '/'): Promise<Array<File | Folder>> {
Expand Down Expand Up @@ -62,14 +62,14 @@ export class FilesService {
},
(error: HttpErrorResponse) => {
if (error.status === 404) {
this.errorService.setError('Can\'t find specified folder!', error.message);
this.notificationService.setError('Can\'t find specified folder!', error.message);
if (folderPath !== '/') {
this.getFolder(folderPath.substring(0, folderPath.lastIndexOf('/')));
} else {
reject();
}
} else {
this.errorService.setError('Can\'t retrieve folder!', error.message);
this.notificationService.setError('Can\'t retrieve folder!', error.message);
reject();
}
}
Expand Down Expand Up @@ -99,10 +99,10 @@ export class FilesService {
},
(error: HttpErrorResponse) => {
if (error.status === 404) {
this.errorService.setError('Can\'t find specified file!', error.message);
this.notificationService.setError('Can\'t find specified file!', error.message);
reject();
} else {
this.errorService.setError('Can\'t retrieve folder!', error.message);
this.notificationService.setError('Can\'t retrieve folder!', error.message);
reject();
}
}
Expand All @@ -122,7 +122,7 @@ export class FilesService {
loadFileBody, this.configService.getHTTPHeaders()).subscribe(
() => null,
(error: HttpErrorResponse) => {
this.errorService.setError('Can\'t load the file!', error.message);
this.notificationService.setError('Can\'t load the file!', error.message);
}
);
}
Expand All @@ -139,7 +139,7 @@ export class FilesService {
printFileBody, this.configService.getHTTPHeaders()).subscribe(
() => null,
(error: HttpErrorResponse) => {
this.errorService.setError('Can\'t start print!', error.message);
this.notificationService.setError('Can\'t start print!', error.message);
}
);
}
Expand All @@ -152,7 +152,7 @@ export class FilesService {
this.configService.getHTTPHeaders()).subscribe(
() => null,
(error: HttpErrorResponse) => {
this.errorService.setError('Can\'t delete file!', error.message);
this.notificationService.setError('Can\'t delete file!', error.message);
}
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/job-status/job-status.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, OnInit, OnDestroy } from '@angular/core';
import { JobService, Job } from '../job.service';
import { Subscription } from 'rxjs';
import { AppService } from '../app.service';
import { ErrorService } from '../error/error.service';
import { NotificationService } from '../notification/notification.service';

@Component({
selector: 'app-job-status',
Expand All @@ -14,7 +14,7 @@ export class JobStatusComponent implements OnInit, OnDestroy {
private subscriptions: Subscription = new Subscription();
public job: Job;

constructor(private jobService: JobService, private service: AppService, private errorService: ErrorService) { }
constructor(private jobService: JobService, private service: AppService, private notificationService: NotificationService) { }

ngOnInit() {
this.subscriptions.add(this.jobService.getObservable().subscribe((job: Job) => this.job = job));
Expand All @@ -29,7 +29,7 @@ export class JobStatusComponent implements OnInit, OnDestroy {
}

public preheat(): void {
this.errorService.setError('Operation not yet supported', 'sorry about that one ... will come in the future!');
this.notificationService.setError('Operation not yet supported', 'sorry about that one ... will come in the future!');
}

public cancelLoadedFile(): void {
Expand Down
22 changes: 11 additions & 11 deletions src/app/job.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ConfigService } from './config/config.service';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { shareReplay } from 'rxjs/operators';
import { OctoprintJobAPI, JobCommand } from './octoprint-api/jobAPI';
import { ErrorService } from './error/error.service';
import { NotificationService } from './notification/notification.service';
import { AppService } from './app.service';

@Injectable({
Expand All @@ -20,7 +20,7 @@ export class JobService {
constructor(
private configService: ConfigService,
private http: HttpClient,
private errorService: ErrorService,
private notificationService: NotificationService,
private service: AppService) {
this.observable = new Observable((observer: Observer<any>) => {
this.observer = observer;
Expand Down Expand Up @@ -49,7 +49,7 @@ export class JobService {
}
observer.next(job);
}, (error: HttpErrorResponse) => {
this.errorService.setError('Can\'t retrieve jobs!', error.message);
this.notificationService.setError('Can\'t retrieve jobs!', error.message);
});

});
Expand All @@ -74,9 +74,9 @@ export class JobService {
this.httpPOSTRequest = this.http.post(this.configService.getURL('job'), cancelPayload, this.configService.getHTTPHeaders()).subscribe(
() => null, (error: HttpErrorResponse) => {
if (error.status === 409) {
this.errorService.setError('Can\'t cancel Job!', 'There is no running job, that could be cancelled (409)');
this.notificationService.setError('Can\'t cancel Job!', 'There is no running job, that could be cancelled (409)');
} else {
this.errorService.setError('Can\'t cancel Job!', error.message);
this.notificationService.setError('Can\'t cancel Job!', error.message);
}
}
);
Expand All @@ -93,9 +93,9 @@ export class JobService {
this.httpPOSTRequest = this.http.post(this.configService.getURL('job'), pausePayload, this.configService.getHTTPHeaders()).subscribe(
() => null, (error: HttpErrorResponse) => {
if (error.status === 409) {
this.errorService.setError('Can\'t pause Job!', 'There is no running job, that could be paused (409)');
this.notificationService.setError('Can\'t pause Job!', 'There is no running job, that could be paused (409)');
} else {
this.errorService.setError('Can\'t pause Job!', error.message);
this.notificationService.setError('Can\'t pause Job!', error.message);
}
}
);
Expand All @@ -112,9 +112,9 @@ export class JobService {
this.httpPOSTRequest = this.http.post(this.configService.getURL('job'), pausePayload, this.configService.getHTTPHeaders()).subscribe(
() => null, (error: HttpErrorResponse) => {
if (error.status === 409) {
this.errorService.setError('Can\'t resume Job!', 'There is no paused job, that could be resumed (409)');
this.notificationService.setError('Can\'t resume Job!', 'There is no paused job, that could be resumed (409)');
} else {
this.errorService.setError('Can\'t resume Job!', error.message);
this.notificationService.setError('Can\'t resume Job!', error.message);
}
}
);
Expand All @@ -130,9 +130,9 @@ export class JobService {
this.httpPOSTRequest = this.http.post(this.configService.getURL('job'), pausePayload, this.configService.getHTTPHeaders()).subscribe(
() => null, (error: HttpErrorResponse) => {
if (error.status === 409) {
this.errorService.setError('Can\'t start Job!', 'There is already a job running (409)');
this.notificationService.setError('Can\'t start Job!', 'There is already a job running (409)');
} else {
this.errorService.setError('Can\'t start Job!', error.message);
this.notificationService.setError('Can\'t start Job!', error.message);
}
}
);
Expand Down
Loading

0 comments on commit 371c8c4

Please sign in to comment.