| 54 | } |
| 55 | |
| 56 | bind() { |
| 57 | bus.gon("callback", (args: Args) => { |
| 58 | const { identifier, param, type: actionType, isMain: fromMain } = args; |
| 59 | console.debug( |
| 60 | "action triggered", |
| 61 | identifier, |
| 62 | param, |
| 63 | actionType, |
| 64 | fromMain, |
| 65 | currentProcessIsMain |
| 66 | ); |
| 67 | switch (actionType) { |
| 68 | case "normal": |
| 69 | case "param_normal": |
| 70 | if ( |
| 71 | !( |
| 72 | this.handleWithLinks(identifier, param) || |
| 73 | this.handle(identifier, param) |
| 74 | ) && |
| 75 | fromMain == currentProcessIsMain |
| 76 | ) { |
| 77 | //跨进程动作,防止出现回声 |
| 78 | bus.iat("callback", args); |
| 79 | } |
| 80 | break; |
| 81 | case "submenu": |
| 82 | case "constant": |
| 83 | case "config": |
| 84 | case "color_picker": |
| 85 | this.set(identifier, param); |
| 86 | break; |
| 87 | case "multi_select": |
| 88 | if (param instanceof Array) { |
| 89 | this.set(identifier, param); |
| 90 | } else { |
| 91 | let currentItems = [...this.get<string[]>(identifier)]; |
| 92 | const idx = currentItems.indexOf(param); |
| 93 | if (idx == -1) { |
| 94 | currentItems.push(param); |
| 95 | } else { |
| 96 | currentItems.splice(idx, 1); |
| 97 | } |
| 98 | this.set(identifier, currentItems); |
| 99 | } |
| 100 | break; |
| 101 | case "checkbox": |
| 102 | if (param == undefined) { |
| 103 | this.set(identifier, !this.get(identifier)); |
| 104 | } else { |
| 105 | if (typeof param == "boolean") { |
| 106 | this.set(identifier, param); |
| 107 | } else { |
| 108 | throw `invalid type of param for ${identifier}, the value is ${param}, the type if ${typeof param}`; |
| 109 | } |
| 110 | } |
| 111 | break; |
| 112 | default: |
| 113 | throw `Unhandled Action Type <${actionType}>`; |