| 21 | import { ColorConfig } from "@/common/rule"; |
| 22 | |
| 23 | export class RendererController extends RenController { |
| 24 | private static _instance: RendererController; |
| 25 | proxy = createProxy<MainController>(authorizeKey); |
| 26 | app: Vue | undefined; |
| 27 | keys: Identifier[] = []; |
| 28 | |
| 29 | set(identifier: Identifier, value: any): boolean { |
| 30 | //在渲染进程里不要直接设置,把信息传到主进程里,让主进程设置就好了 |
| 31 | this.proxy.set(identifier, value); |
| 32 | return true; |
| 33 | } |
| 34 | |
| 35 | public static getInstance(): RendererController { |
| 36 | if (this._instance == null) { |
| 37 | this._instance = new RendererController(); |
| 38 | } |
| 39 | return this._instance; |
| 40 | } |
| 41 | |
| 42 | private constructor() { |
| 43 | super(); |
| 44 | initLog(); |
| 45 | observers.push(this); |
| 46 | bus.once("initialized", () => { |
| 47 | restoreFromConfig(observers, store.state.config); |
| 48 | this.initApp(); |
| 49 | }); |
| 50 | } |
| 51 | |
| 52 | initApp() { |
| 53 | this.app = createApp(); |
| 54 | } |
| 55 | |
| 56 | notify(text: string) { |
| 57 | if (text.length > 0) { |
| 58 | new Notification(constants.appName + " " + version, { |
| 59 | body: text, |
| 60 | }); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | toast(text: string, force: boolean = false) { |
| 65 | if (force || config.get("toastTip")) { |
| 66 | Vue.toasted.show(text); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | handle(identifier: Identifier, param: any) { |
| 71 | switch (identifier) { |
| 72 | case "notify": |
| 73 | this.notify(param); |
| 74 | break; |
| 75 | case "toast": |
| 76 | this.toast(param); |
| 77 | break; |
| 78 | case "translateInput": |
| 79 | bus.at("translateInput"); |
| 80 | break; |
nothing calls this directly
no test coverage detected