Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix annoying notifications #2722

Merged
merged 1 commit into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/bottom-bar/bottom-bar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{{ enclosureTemperature.temperature }}{{ enclosureTemperature.unit }}
</td>
<td class="bottom-bar__current-status">
{{ getStringStatus(printerStatus) }}
{{ statusText }}
</td>
</tr>
</table>
53 changes: 29 additions & 24 deletions src/app/bottom-bar/bottom-bar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import { SocketService } from '../services/socket/socket.service';
})
export class BottomBarComponent implements OnDestroy {
private subscriptions: Subscription = new Subscription();
private printerReady = false;
private lastStatusText: string;

public printerStatus: PrinterState;
public statusText: string;
public enclosureTemperature: TemperatureReading;

public constructor(
Expand All @@ -28,44 +28,49 @@ export class BottomBarComponent implements OnDestroy {
) {
if (this.configService.getAmbientTemperatureSensorName() !== null) {
this.subscriptions.add(
timer(2500, 15000).subscribe(() => {
if (this.printerReady) {
// TODO
this.enclosureService.getEnclosureTemperature().subscribe({
next: (temperatureReading: TemperatureReading) => (this.enclosureTemperature = temperatureReading),
error: (error: HttpErrorResponse) => {
this.notificationService.setNotification({
heading: $localize`:@@error-enclosure-temp:Can't retrieve enclosure temperature!`,
text: error.message,
type: NotificationType.ERROR,
time: new Date(),
});
},
});
}
timer(10000, 15000).subscribe(() => {
this.enclosureService.getEnclosureTemperature().subscribe({
next: (temperatureReading: TemperatureReading) => (this.enclosureTemperature = temperatureReading),
error: (error: HttpErrorResponse) => {
this.notificationService.setNotification({
heading: $localize`:@@error-enclosure-temp:Can't retrieve enclosure temperature!`,
text: error.message,
type: NotificationType.ERROR,
time: new Date(),
});
},
});
}),
);
}

this.subscriptions.add(
this.socketService.getPrinterStatusSubscribable().subscribe((printerStatus: PrinterStatus): void => {
this.printerStatus = printerStatus?.status;
if (!this.printerReady) {
this.printerReady = [PrinterState.operational, PrinterState.printing, PrinterState.paused].includes(
this.printerStatus,
);
}
this.setStatusText(this.getStringStatus(printerStatus?.status));
}),
);

this.subscriptions.add(
this.socketService.getPrinterStatusText().subscribe((statusText: string): void => {
this.setStatusText(statusText);
}),
);
}

public getStringStatus(printerState: PrinterState): string {
private getStringStatus(printerState: PrinterState): string {
if (printerState === PrinterState.socketDead) {
return 'socket is dead';
}
return PrinterState[printerState];
}

private setStatusText(statusText: string) {
if (statusText !== this.lastStatusText) {
this.lastStatusText = this.statusText;
this.statusText = statusText;
}
}

public getPrinterName(): string {
return this.configService.getPrinterName();
}
Expand Down
4 changes: 4 additions & 0 deletions src/app/notification/notification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export class NotificationService {
if (this.observer) {
this.observer.next(notification);
this.notificationStack.push(notification);

if (this.notificationStack.length > 25) {
this.notificationStack.shift();
}
} else {
setTimeout(this.setNotification.bind(this), 1000, notification);
}
Expand Down
16 changes: 9 additions & 7 deletions src/app/services/socket/socket.octoprint.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class OctoPrintSocketService implements SocketService {
private printerStatusSubject: Subject<PrinterStatus>;
private jobStatusSubject: Subject<JobStatus>;
private eventSubject: Subject<PrinterEvent>;
private statusTextSubject: Subject<string>;

private printerStatus: PrinterStatus;
private jobStatus: JobStatus;
Expand All @@ -51,7 +52,8 @@ export class OctoPrintSocketService implements SocketService {
) {
this.printerStatusSubject = new ReplaySubject<PrinterStatus>(1);
this.jobStatusSubject = new Subject<JobStatus>();
this.eventSubject = new ReplaySubject<PrinterEvent>();
this.eventSubject = new ReplaySubject<PrinterEvent>(5);
this.statusTextSubject = new ReplaySubject<string>(1);
}

//==== SETUP & AUTH ====//
Expand Down Expand Up @@ -383,12 +385,8 @@ export class OctoPrintSocketService implements SocketService {
sticky: true,
} as Notification);
} else if (notification.text || notification.message) {
this.notificationService.setNotification({
heading: $localize`:@@printer-information:Printer information`,
text: notification.text ?? notification.message,
type: NotificationType.INFO,
time: new Date(),
} as Notification);
console.log(notification.text ?? notification.message);
this.statusTextSubject.next(notification.text ?? notification.message);
}
}
}
Expand Down Expand Up @@ -427,4 +425,8 @@ export class OctoPrintSocketService implements SocketService {
public getEventSubscribable(): Observable<PrinterEvent> {
return this.eventSubject;
}

public getPrinterStatusText(): Observable<string> {
return this.statusTextSubject;
}
}
2 changes: 2 additions & 0 deletions src/app/services/socket/socket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export abstract class SocketService {

abstract getPrinterStatusSubscribable(): Observable<PrinterStatus>;

abstract getPrinterStatusText(): Observable<string>;

abstract getJobStatusSubscribable(): Observable<JobStatus>;

abstract getEventSubscribable(): Observable<PrinterEvent | PrinterNotification>;
Expand Down