|
1 | 1 | /* patch wechat devtools begin */ |
2 | 2 | (() => { |
3 | 3 | try { |
4 | | - const originalSpawn = require("child_process").spawn; |
5 | | - require("child_process").spawn = function (command, args, options) { |
6 | | - if (command.includes("wcc.exe")) { |
7 | | - command = command.replace("code/package.nw", "package.nw"); |
8 | | - command = command.replace("wcc.exe", "wcc"); |
9 | | - } else if (command.includes("wcsc.exe")) { |
10 | | - command = command.replace("code/package.nw", "package.nw"); |
11 | | - command = command.replace("wcsc.exe", "wcsc"); |
12 | | - } |
13 | | - return originalSpawn.apply(this, [command, args, options]); |
14 | | - }; |
15 | | - const originalResolve = require("path").resolve; |
16 | | - require("path").resolve = function (...paths) { |
17 | | - if (paths.length === 2 && paths[1].includes("code/package.nw")) { |
18 | | - paths[1] = paths[1].replace("code/package.nw", "package.nw"); |
19 | | - } |
20 | | - return originalResolve.apply(this, paths); |
21 | | - }; |
| 4 | + { |
| 5 | + // 修正编译器路径 |
| 6 | + const originalSpawn = require("child_process").spawn; |
| 7 | + require("child_process").spawn = function (command, args, options) { |
| 8 | + if (command.includes("wcc.exe")) { |
| 9 | + command = command.replace("code/package.nw", "package.nw"); |
| 10 | + command = command.replace("wcc.exe", "wcc"); |
| 11 | + } else if (command.includes("wcsc.exe")) { |
| 12 | + command = command.replace("code/package.nw", "package.nw"); |
| 13 | + command = command.replace("wcsc.exe", "wcsc"); |
| 14 | + } |
| 15 | + return originalSpawn.apply(this, [command, args, options]); |
| 16 | + }; |
| 17 | + } |
| 18 | + { |
| 19 | + // 修正路径错误 |
| 20 | + const originalResolve = require("path").resolve; |
| 21 | + require("path").resolve = function (...paths) { |
| 22 | + if (paths.length === 2 && paths[1].includes("code/package.nw")) { |
| 23 | + paths[1] = paths[1].replace("code/package.nw", "package.nw"); |
| 24 | + } |
| 25 | + return originalResolve.apply(this, paths); |
| 26 | + }; |
| 27 | + } |
22 | 28 | if (typeof nw === "undefined") { |
23 | 29 | return; |
24 | 30 | } |
|
111 | 117 | item.parentMenu = this; |
112 | 118 | return originInsert.call(this, item, index); |
113 | 119 | }; |
114 | | - const originalOpen = nw.Window.open |
115 | | - nw.Window.open = function (url, options, callback) { |
116 | | - console.warn('[wechat-devtools] nw.Window.open is called, url:', url, 'options:', options); |
117 | | - let cb = callback |
118 | | - if (options.title === '版本更新提示') { |
119 | | - options.inject_js_start = 'js/unpack/hackrequire/index.js'; |
120 | | - cb = (...args) => { |
121 | | - const keys = [ |
122 | | - "shareData", |
123 | | - "windowMap", |
124 | | - "isSimple", |
125 | | - "masterProxyPort", |
126 | | - "proxyPort", |
127 | | - "masterH2ProxyPort", |
128 | | - "h2ProxyPort" |
129 | | - ]; |
130 | | - for(let k of keys) |
131 | | - args[0].window.global[k] = global[k]; |
132 | | - callback(...args) |
| 120 | + { |
| 121 | + // 修正新窗口数据丢失的问题 |
| 122 | + const originalOpen = nw.Window.open |
| 123 | + nw.Window.open = function (url, options, callback) { |
| 124 | + console.warn('[wechat-devtools] nw.Window.open is called, url:', url, 'options:', options); |
| 125 | + let cb = callback |
| 126 | + if (options.title === '版本更新提示') { |
| 127 | + options.inject_js_start = 'js/unpack/hackrequire/index.js'; |
| 128 | + cb = (...args) => { |
| 129 | + const keys = [ |
| 130 | + "shareData", |
| 131 | + "windowMap", |
| 132 | + "isSimple", |
| 133 | + "masterProxyPort", |
| 134 | + "proxyPort", |
| 135 | + "masterH2ProxyPort", |
| 136 | + "h2ProxyPort" |
| 137 | + ]; |
| 138 | + for(let k of keys) |
| 139 | + args[0].window.global[k] = global[k]; |
| 140 | + callback(...args) |
| 141 | + } |
133 | 142 | } |
134 | | - } |
135 | | - else if (options.title === '云开发控制台') { |
136 | | - cb = (...args) => { |
137 | | - const keys = [ |
138 | | - "shareData", |
139 | | - "windowMap", |
140 | | - "isSimple", |
141 | | - "masterProxyPort", |
142 | | - "proxyPort", |
143 | | - "masterH2ProxyPort", |
144 | | - "h2ProxyPort", |
145 | | - 'tokenData', |
146 | | - ]; |
147 | | - for(let k of keys) |
148 | | - args[0].window.global[k] = global[k]; |
149 | | - callback(...args) |
| 143 | + else if (options.title === '云开发控制台') { |
| 144 | + cb = (...args) => { |
| 145 | + const keys = [ |
| 146 | + "shareData", |
| 147 | + "windowMap", |
| 148 | + "isSimple", |
| 149 | + "masterProxyPort", |
| 150 | + "proxyPort", |
| 151 | + "masterH2ProxyPort", |
| 152 | + "h2ProxyPort", |
| 153 | + 'tokenData', |
| 154 | + ]; |
| 155 | + for(let k of keys) |
| 156 | + args[0].window.global[k] = global[k]; |
| 157 | + callback(...args) |
| 158 | + } |
150 | 159 | } |
151 | | - } |
152 | | - else if (options.title.includes('微信开发者工具')) { |
153 | | - cb = (...args) => { |
154 | | - const keys = [ |
155 | | - "shareData", |
156 | | - "windowMap", |
157 | | - "isSimple", |
158 | | - "masterProxyPort", |
159 | | - "proxyPort", |
160 | | - "masterH2ProxyPort", |
161 | | - "h2ProxyPort", |
162 | | - 'tokenData', |
163 | | - ]; |
164 | | - for(let k of keys) |
165 | | - args[0].window.global[k] = global[k]; |
166 | | - callback(...args) |
| 160 | + else if (options.title.includes('微信开发者工具')) { |
| 161 | + cb = (...args) => { |
| 162 | + const keys = [ |
| 163 | + "shareData", |
| 164 | + "windowMap", |
| 165 | + "isSimple", |
| 166 | + "masterProxyPort", |
| 167 | + "proxyPort", |
| 168 | + "masterH2ProxyPort", |
| 169 | + "h2ProxyPort", |
| 170 | + 'tokenData', |
| 171 | + ]; |
| 172 | + for(let k of keys) |
| 173 | + args[0].window.global[k] = global[k]; |
| 174 | + callback(...args) |
| 175 | + } |
167 | 176 | } |
| 177 | + return originalOpen.apply(this, [url, options, cb]) |
168 | 178 | } |
169 | | - return originalOpen.apply(this, [url, options, cb]) |
170 | 179 | } |
171 | | - const originalExec = require('child_process').exec; |
172 | | - require('child_process').exec = function (command, options, callback) { |
173 | | - if (command.includes('open -a Terminal')) { |
174 | | - command = 'gnome-terminal' |
| 180 | + { |
| 181 | + // 修正打开外部Terminal的功能 |
| 182 | + const originalExec = require('child_process').exec; |
| 183 | + require('child_process').exec = function (command, options, callback) { |
| 184 | + if (command.includes('open -a Terminal')) { |
| 185 | + command = 'gnome-terminal' |
| 186 | + } |
| 187 | + return originalExec.apply(this, [command, options, callback]) |
175 | 188 | } |
176 | | - return originalExec.apply(this, [command, options, callback]) |
177 | 189 | } |
178 | 190 | { |
| 191 | + // 修正 暗色/亮色 自动跟随系统 |
179 | 192 | const {spawn, execSync} = require('child_process') |
180 | 193 | let isDark = (function () { |
181 | 194 | try { |
|
310 | 323 | return original.apply(this, args) |
311 | 324 | } |
312 | 325 | } |
| 326 | + { |
| 327 | + // 修复云开发控制台 |
| 328 | + const originalBind = Function.prototype.bind |
| 329 | + Function.prototype.bind = function(...args) { |
| 330 | + if (args[0]?._tokenMap) { |
| 331 | + console.warn('---------set tokenData') |
| 332 | + if (window.tokenData) { |
| 333 | + args[0]._sessionToken = window.tokenData._sessionToken |
| 334 | + args[0]._tokenMap = window.tokenData._tokenMap |
| 335 | + } |
| 336 | + else |
| 337 | + window.tokenData = args[0] |
| 338 | + } |
| 339 | + return originalBind.apply(this, args) |
| 340 | + } |
| 341 | + } |
313 | 342 | } catch (error) { |
314 | 343 | process.stderr.write(error.message); |
315 | 344 | process.stderr.write(error.stack); |
|
0 commit comments