You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mediarepo/mediarepo-ui/src/app/services/error-broker/error-broker.service.ts

45 lines
1.0 KiB
TypeScript

import {Injectable} from "@angular/core";
import {listen} from "@tauri-apps/api/event";
@Injectable({
providedIn: "root"
})
export class ErrorBrokerService {
errorCb: Function | undefined;
infoCb: Function | undefined;
constructor() {
this.registerListener().catch(err => console.error(err));
}
async registerListener() {
const _unlisten = await listen("error", event => {
const payload: any = event.payload;
if (payload.message) {
this.showError(payload);
} else {
this.showError(payload.toString());
}
});
}
showInfo(info: string) {
console.log(info);
if (this.infoCb) {
this.infoCb(info);
}
}
showError(error: { message: string } | any) {
console.error(error);
if (this.errorCb) {
if (!error.message) {
this.errorCb({ message: error });
} else {
this.errorCb({ ...error });
}
}
}
}