ya-webadb/apps/demo/state/global.ts
2021-12-09 16:01:08 +08:00

39 lines
868 B
TypeScript

import { Adb } from "@yume-chan/adb";
import { action, makeAutoObservable } from 'mobx';
export class GlobalState {
device: Adb | undefined;
errorDialogVisible = false;
errorDialogMessage = '';
logVisible = false;
constructor() {
makeAutoObservable(this, {
hideErrorDialog: action.bound,
toggleLog: action.bound,
});
}
setDevice(device: Adb | undefined) {
this.device = device;
device?.onDisconnected(() => {
this.setDevice(undefined);
});
}
showErrorDialog(message: string) {
this.errorDialogVisible = true;
this.errorDialogMessage = message;
}
hideErrorDialog() {
this.errorDialogVisible = false;
}
toggleLog() {
this.logVisible = !this.logVisible;
}
}
export const global = new GlobalState();