mirror of
https://github.com/msojocs/wechat-web-devtools-linux.git
synced 2025-07-22 00:00:04 +08:00
Compare commits
3 Commits
v1.06.2504
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
5b68973fc4 | ||
|
080ee2b6df | ||
|
465af9b79a |
@ -1,3 +1,6 @@
|
|||||||
|
# 1.06.2504010-3 / 2025-07-
|
||||||
|
- refactor: 重构主题监听处理方案
|
||||||
|
|
||||||
# 1.06.2504010-2 / 2025-07-15
|
# 1.06.2504010-2 / 2025-07-15
|
||||||
- fix: cli使用异常。#147
|
- fix: cli使用异常。#147
|
||||||
|
|
||||||
|
@ -1,24 +1,30 @@
|
|||||||
/* patch wechat devtools begin */
|
/* patch wechat devtools begin */
|
||||||
(() => {
|
(() => {
|
||||||
try {
|
try {
|
||||||
const originalSpawn = require("child_process").spawn;
|
{
|
||||||
require("child_process").spawn = function (command, args, options) {
|
// 修正编译器路径
|
||||||
if (command.includes("wcc.exe")) {
|
const originalSpawn = require("child_process").spawn;
|
||||||
command = command.replace("code/package.nw", "package.nw");
|
require("child_process").spawn = function (command, args, options) {
|
||||||
command = command.replace("wcc.exe", "wcc");
|
if (command.includes("wcc.exe")) {
|
||||||
} else if (command.includes("wcsc.exe")) {
|
command = command.replace("code/package.nw", "package.nw");
|
||||||
command = command.replace("code/package.nw", "package.nw");
|
command = command.replace("wcc.exe", "wcc");
|
||||||
command = command.replace("wcsc.exe", "wcsc");
|
} else if (command.includes("wcsc.exe")) {
|
||||||
}
|
command = command.replace("code/package.nw", "package.nw");
|
||||||
return originalSpawn.apply(this, [command, args, options]);
|
command = command.replace("wcsc.exe", "wcsc");
|
||||||
};
|
}
|
||||||
const originalResolve = require("path").resolve;
|
return originalSpawn.apply(this, [command, args, options]);
|
||||||
require("path").resolve = function (...paths) {
|
};
|
||||||
if (paths.length === 2 && paths[1].includes("code/package.nw")) {
|
}
|
||||||
paths[1] = paths[1].replace("code/package.nw", "package.nw");
|
{
|
||||||
}
|
// 修正路径错误
|
||||||
return originalResolve.apply(this, paths);
|
const originalResolve = require("path").resolve;
|
||||||
};
|
require("path").resolve = function (...paths) {
|
||||||
|
if (paths.length === 2 && paths[1].includes("code/package.nw")) {
|
||||||
|
paths[1] = paths[1].replace("code/package.nw", "package.nw");
|
||||||
|
}
|
||||||
|
return originalResolve.apply(this, paths);
|
||||||
|
};
|
||||||
|
}
|
||||||
if (typeof nw === "undefined") {
|
if (typeof nw === "undefined") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -111,69 +117,227 @@
|
|||||||
item.parentMenu = this;
|
item.parentMenu = this;
|
||||||
return originInsert.call(this, item, index);
|
return originInsert.call(this, item, index);
|
||||||
};
|
};
|
||||||
const originalOpen = nw.Window.open
|
{
|
||||||
nw.Window.open = function (url, options, callback) {
|
// 修正新窗口数据丢失的问题
|
||||||
console.warn('[wechat-devtools] nw.Window.open is called, url:', url, 'options:', options);
|
const originalOpen = nw.Window.open
|
||||||
let cb = callback
|
nw.Window.open = function (url, options, callback) {
|
||||||
if (options.title === '版本更新提示') {
|
console.warn('[wechat-devtools] nw.Window.open is called, url:', url, 'options:', options);
|
||||||
options.inject_js_start = 'js/unpack/hackrequire/index.js';
|
let cb = callback
|
||||||
cb = (...args) => {
|
if (options.title === '版本更新提示') {
|
||||||
const keys = [
|
options.inject_js_start = 'js/unpack/hackrequire/index.js';
|
||||||
"shareData",
|
cb = (...args) => {
|
||||||
"windowMap",
|
const keys = [
|
||||||
"isSimple",
|
"shareData",
|
||||||
"masterProxyPort",
|
"windowMap",
|
||||||
"proxyPort",
|
"isSimple",
|
||||||
"masterH2ProxyPort",
|
"masterProxyPort",
|
||||||
"h2ProxyPort"
|
"proxyPort",
|
||||||
];
|
"masterH2ProxyPort",
|
||||||
for(let k of keys)
|
"h2ProxyPort"
|
||||||
args[0].window.global[k] = global[k];
|
];
|
||||||
callback(...args)
|
for(let k of keys)
|
||||||
|
args[0].window.global[k] = global[k];
|
||||||
|
callback(...args)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else if (options.title === '云开发控制台') {
|
||||||
else if (options.title === '云开发控制台') {
|
cb = (...args) => {
|
||||||
cb = (...args) => {
|
const keys = [
|
||||||
const keys = [
|
"shareData",
|
||||||
"shareData",
|
"windowMap",
|
||||||
"windowMap",
|
"isSimple",
|
||||||
"isSimple",
|
"masterProxyPort",
|
||||||
"masterProxyPort",
|
"proxyPort",
|
||||||
"proxyPort",
|
"masterH2ProxyPort",
|
||||||
"masterH2ProxyPort",
|
"h2ProxyPort",
|
||||||
"h2ProxyPort",
|
'tokenData',
|
||||||
'tokenData',
|
];
|
||||||
];
|
for(let k of keys)
|
||||||
for(let k of keys)
|
args[0].window.global[k] = global[k];
|
||||||
args[0].window.global[k] = global[k];
|
callback(...args)
|
||||||
callback(...args)
|
}
|
||||||
}
|
}
|
||||||
}
|
else if (options.title.includes('微信开发者工具')) {
|
||||||
else if (options.title.includes('微信开发者工具')) {
|
cb = (...args) => {
|
||||||
cb = (...args) => {
|
const keys = [
|
||||||
const keys = [
|
"shareData",
|
||||||
"shareData",
|
"windowMap",
|
||||||
"windowMap",
|
"isSimple",
|
||||||
"isSimple",
|
"masterProxyPort",
|
||||||
"masterProxyPort",
|
"proxyPort",
|
||||||
"proxyPort",
|
"masterH2ProxyPort",
|
||||||
"masterH2ProxyPort",
|
"h2ProxyPort",
|
||||||
"h2ProxyPort",
|
'tokenData',
|
||||||
'tokenData',
|
];
|
||||||
];
|
for(let k of keys)
|
||||||
for(let k of keys)
|
args[0].window.global[k] = global[k];
|
||||||
args[0].window.global[k] = global[k];
|
callback(...args)
|
||||||
callback(...args)
|
}
|
||||||
}
|
}
|
||||||
|
return originalOpen.apply(this, [url, options, cb])
|
||||||
}
|
}
|
||||||
return originalOpen.apply(this, [url, options, cb])
|
|
||||||
}
|
}
|
||||||
const originalExec = require('child_process').exec;
|
{
|
||||||
require('child_process').exec = function (command, options, callback) {
|
// 修正打开外部Terminal的功能
|
||||||
if (command.includes('open -a Terminal')) {
|
const originalExec = require('child_process').exec;
|
||||||
command = 'gnome-terminal'
|
require('child_process').exec = function (command, options, callback) {
|
||||||
|
if (command.includes('open -a Terminal')) {
|
||||||
|
command = 'gnome-terminal'
|
||||||
|
}
|
||||||
|
return originalExec.apply(this, [command, options, callback])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// 修正 暗色/亮色 自动跟随系统
|
||||||
|
const {spawn, execSync} = require('child_process')
|
||||||
|
let isDark = (function () {
|
||||||
|
try {
|
||||||
|
const { DESKTOP_SESSION } = process.env;
|
||||||
|
console.log(DESKTOP_SESSION);
|
||||||
|
let theme = "";
|
||||||
|
switch (DESKTOP_SESSION) {
|
||||||
|
case "deepin":
|
||||||
|
theme = execSync(
|
||||||
|
`gsettings get com.deepin.dde.appearance gtk-theme`
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case "gnome":
|
||||||
|
case "gnome-classic":
|
||||||
|
theme = execSync(
|
||||||
|
`gsettings get org.gnome.desktop.interface ${this.gnomeScheme}`
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "plasma":
|
||||||
|
theme = execSync(
|
||||||
|
`gsettings get org.gnome.desktop.interface color-scheme`,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.warn(
|
||||||
|
`NOT SUPPORTED !!! DESKTOP_SESSION: ${DESKTOP_SESSION}`
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
console.log(theme.toString());
|
||||||
|
return theme.toString().toLowerCase().includes("dark");
|
||||||
|
} catch (error) {
|
||||||
|
console.error("尝试获取主题信息失败,使用默认暗色");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
const originalMatchMedia = window.matchMedia
|
||||||
|
window.matchMedia = function (...args) {
|
||||||
|
console.warn('----------------> matchMedia:', ...args)
|
||||||
|
const mm = originalMatchMedia.apply(this, args)
|
||||||
|
Object.defineProperty(mm, 'matches', {
|
||||||
|
get(){
|
||||||
|
return isDark
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return mm
|
||||||
|
}
|
||||||
|
class CheckDark {
|
||||||
|
// 监听gsettings monitor org.gnome.desktop.interface gtk-theme
|
||||||
|
monitorTheme(callback) {
|
||||||
|
try {
|
||||||
|
if (this.callback) {
|
||||||
|
this.callback = callback
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.callback = callback
|
||||||
|
let monitor = null;
|
||||||
|
const { DESKTOP_SESSION } = process.env;
|
||||||
|
switch (DESKTOP_SESSION) {
|
||||||
|
case "deepin":
|
||||||
|
monitor = spawn("gsettings", [
|
||||||
|
"monitor",
|
||||||
|
"com.deepin.dde.appearance",
|
||||||
|
"gtk-theme",
|
||||||
|
]);
|
||||||
|
break;
|
||||||
|
case "gnome":
|
||||||
|
case "gnome-classic":
|
||||||
|
monitor = spawn("gsettings", [
|
||||||
|
"monitor",
|
||||||
|
"org.gnome.desktop.interface",
|
||||||
|
this.gnomeScheme,
|
||||||
|
]);
|
||||||
|
break;
|
||||||
|
case "plasma":
|
||||||
|
monitor = spawn("gsettings", [
|
||||||
|
"monitor",
|
||||||
|
"org.gnome.desktop.interface",
|
||||||
|
'color-scheme',
|
||||||
|
]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.warn(
|
||||||
|
`NOT SUPPORTED !!! DESKTOP_SESSION: ${DESKTOP_SESSION}`
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
monitor &&
|
||||||
|
monitor.on("error", (err) => {
|
||||||
|
console.error("monitorTheme", err);
|
||||||
|
});
|
||||||
|
monitor &&
|
||||||
|
monitor.stdout.on("data", (chunk) => {
|
||||||
|
const data = chunk.toString();
|
||||||
|
console.warn('Theme changed:', data)
|
||||||
|
isDark = data.toLowerCase().includes("dark");
|
||||||
|
this.callback(isDark)
|
||||||
|
});
|
||||||
|
process.on("SIGTERM", (signal) => {
|
||||||
|
monitor.kill(signal);
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.error("尝试监听主题失败!", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
get gnomeScheme() {
|
||||||
|
try {
|
||||||
|
// 判断 Gnome-Shell 版本 from @icepie
|
||||||
|
const gnomeVersion = execSync(`gnome-shell --version`)
|
||||||
|
.toString()
|
||||||
|
.replace(/[\r\n]/g, "")
|
||||||
|
.split(" ");
|
||||||
|
const gnomeVersionNum =
|
||||||
|
gnomeVersion.length == 3 ? Number(gnomeVersion[2]) : 0;
|
||||||
|
return gnomeVersionNum >= 42 ? "color-scheme" : "gtk-theme";
|
||||||
|
} catch (err) {
|
||||||
|
console.error("检查gnome版本失败, 使用gtk-theme", err);
|
||||||
|
return "gtk-theme";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const checkDark = new CheckDark()
|
||||||
|
const original = MediaQueryList.prototype.addEventListener
|
||||||
|
MediaQueryList.prototype.addEventListener = function (...args) {
|
||||||
|
console.warn('----------> MediaQueryList.addEventListener:', ...args)
|
||||||
|
checkDark.monitorTheme((isDark) => {
|
||||||
|
args[1]({
|
||||||
|
matches: isDark
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return original.apply(this, args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// 修复云开发控制台
|
||||||
|
const originalBind = Function.prototype.bind
|
||||||
|
Function.prototype.bind = function(...args) {
|
||||||
|
if (args[0]?._tokenMap) {
|
||||||
|
console.warn('---------set tokenData')
|
||||||
|
if (window.tokenData) {
|
||||||
|
args[0]._sessionToken = window.tokenData._sessionToken
|
||||||
|
args[0]._tokenMap = window.tokenData._tokenMap
|
||||||
|
}
|
||||||
|
else
|
||||||
|
window.tokenData = args[0]
|
||||||
|
}
|
||||||
|
return originalBind.apply(this, args)
|
||||||
}
|
}
|
||||||
return originalExec.apply(this, [command, options, callback])
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
process.stderr.write(error.message);
|
process.stderr.write(error.message);
|
||||||
|
@ -3,7 +3,7 @@ const { execSync, spawn } = require("child_process");
|
|||||||
|
|
||||||
class CheckDark {
|
class CheckDark {
|
||||||
// 监听gsettings monitor org.gnome.desktop.interface gtk-theme
|
// 监听gsettings monitor org.gnome.desktop.interface gtk-theme
|
||||||
monitorTheme() {
|
monitorTheme(callback) {
|
||||||
try {
|
try {
|
||||||
let monitor = null;
|
let monitor = null;
|
||||||
const { DESKTOP_SESSION } = process.env;
|
const { DESKTOP_SESSION } = process.env;
|
||||||
@ -37,11 +37,8 @@ class CheckDark {
|
|||||||
monitor.stdout.on("data", (chunk) => {
|
monitor.stdout.on("data", (chunk) => {
|
||||||
// TODO: 防抖动包装
|
// TODO: 防抖动包装
|
||||||
const data = chunk.toString();
|
const data = chunk.toString();
|
||||||
const t = data.toLowerCase().includes("dark");
|
const isDark = data.toLowerCase().includes("dark");
|
||||||
console.log(data);
|
callback(isDark)
|
||||||
console.log("dark", t);
|
|
||||||
// (this._theme = t ? i.Dark : i.Light),
|
|
||||||
// this._onDidThemeChange.fire(this._theme);
|
|
||||||
});
|
});
|
||||||
process.on("SIGTERM", (signal) => {
|
process.on("SIGTERM", (signal) => {
|
||||||
monitor.kill(signal);
|
monitor.kill(signal);
|
||||||
@ -83,7 +80,7 @@ class CheckDark {
|
|||||||
}
|
}
|
||||||
get gnomeScheme() {
|
get gnomeScheme() {
|
||||||
try {
|
try {
|
||||||
// 判断 Gnome-Shell 版本
|
// 判断 Gnome-Shell 版本 from @icepie
|
||||||
const gnomeVersion = execSync(`gnome-shell --version`)
|
const gnomeVersion = execSync(`gnome-shell --version`)
|
||||||
.toString()
|
.toString()
|
||||||
.replace(/[\r\n]/g, "")
|
.replace(/[\r\n]/g, "")
|
||||||
@ -98,7 +95,9 @@ class CheckDark {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const cd = new CheckDark();
|
const cd = new CheckDark();
|
||||||
cd.monitorTheme();
|
cd.monitorTheme((isDark) => {
|
||||||
|
console.info('is dark:', isDark)
|
||||||
|
});
|
||||||
console.log(cd.isDark);
|
console.log(cd.isDark);
|
||||||
|
|
||||||
function original() {
|
function original() {
|
||||||
|
@ -37,14 +37,14 @@ node "$unpack_script" "$package_dir/core.wxvpkg" "$tmp_dir/core.wxvpkg"
|
|||||||
# |_| \_\_____|_| |_____/_/ \_\____|_____| \____\___/|_| \_\_____|
|
# |_| \_\_____|_| |_____/_/ \_\____|_____| \____\___/|_| \_\_____|
|
||||||
#
|
#
|
||||||
|
|
||||||
token_find_result=$( grep -lr "constructor(){this._sessionToken=\"\",this._tokenMap={}}" "$tmp_dir/core.wxvpkg" )
|
# token_find_result=$( grep -lr "constructor(){this._sessionToken=\"\",this._tokenMap={}}" "$tmp_dir/core.wxvpkg" )
|
||||||
echo "WebSocket token存储对象位置: $token_find_result"
|
# echo "WebSocket token存储对象位置: $token_find_result"
|
||||||
if [[ ! -z $token_find_result ]];then
|
# if [[ ! -z $token_find_result ]];then
|
||||||
new_constructor="constructor(){if(window.tokenData){/*有就直接用*/this._sessionToken=window.tokenData._sessionToken;this._tokenMap=window.tokenData._tokenMap;}else{/*没有就新建*/this._sessionToken=\"\",this._tokenMap={};window.tokenData=this;/*新建完要给中间人*/}}"
|
# new_constructor="constructor(){if(window.tokenData){/*有就直接用*/this._sessionToken=window.tokenData._sessionToken;this._tokenMap=window.tokenData._tokenMap;}else{/*没有就新建*/this._sessionToken=\"\",this._tokenMap={};window.tokenData=this;/*新建完要给中间人*/}}"
|
||||||
sed -i "s#constructor(){this._sessionToken=\"\",this._tokenMap={}}#$new_constructor#g" "$token_find_result"
|
# sed -i "s#constructor(){this._sessionToken=\"\",this._tokenMap={}}#$new_constructor#g" "$token_find_result"
|
||||||
else
|
# else
|
||||||
warn "WebSocket token存储对象位置未找到"
|
# warn "WebSocket token存储对象位置未找到"
|
||||||
fi
|
# fi
|
||||||
|
|
||||||
# wcc、wcsc处理,设置WINE=fasle环境变量生效
|
# wcc、wcsc处理,设置WINE=fasle环境变量生效
|
||||||
if [[ "$WINE" != 'true' ]];then
|
if [[ "$WINE" != 'true' ]];then
|
||||||
@ -64,23 +64,6 @@ if [[ "$WINE" != 'true' ]];then
|
|||||||
echo $timeStamp > "${package_dir}/.build_time"
|
echo $timeStamp > "${package_dir}/.build_time"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# fix theme
|
|
||||||
notice "fix theme"
|
|
||||||
find_result=$( grep -lr "OSThemeController=" "$tmp_dir/core.wxvpkg" )
|
|
||||||
echo "theme: $find_result"
|
|
||||||
if [[ -n $find_result ]];then
|
|
||||||
# require of child_process
|
|
||||||
sed -i 's/"use strict";O/"use strict";const {execSync,spawn}=require("child_process");O/' $find_result
|
|
||||||
# replace listener to monitor
|
|
||||||
sed -i 's/this.registerListeners()/this.monitorTheme()/' $find_result
|
|
||||||
# replace check func
|
|
||||||
sed -i 's/mediaQuery.matches/isDark/' $find_result
|
|
||||||
# add functions
|
|
||||||
sed -i 's#}getDefaultTheme#}get isDark(){try{const{DESKTOP_SESSION}=process.env;console.log(DESKTOP_SESSION);let theme="";switch(DESKTOP_SESSION){case"deepin":theme=execSync(`gsettings get com.deepin.dde.appearance gtk-theme`);break;case"gnome":case"gnome-classic":theme=execSync(`gsettings get org.gnome.desktop.interface ${this.gnomeScheme}`);break;default:break}return theme.includes("dark");}catch(err){console.error("尝试获取主题信息失败,使用默认暗色",err);return true;}}get gnomeScheme(){try{const gnomeVersion=execSync(`gnome-shell --version`).toString().replace(/[\\r\\n]/g,"").split(" ");const gnomeVersionNum=gnomeVersion.length==3?Number(gnomeVersion[2]):0;return gnomeVersionNum>=42?"color-scheme":"gtk-theme";}catch(err){console.error("检查gnome版本失败, 使用gtk-theme", err);return "gtk-theme";}}monitorTheme(){try{let monitor=null;const{DESKTOP_SESSION}=process.env;switch(DESKTOP_SESSION){case"deepin":monitor=spawn("gsettings",["monitor","com.deepin.dde.appearance","gtk-theme",]);break;case"gnome":case"gnome-classic":monitor=spawn("gsettings",["monitor","org.gnome.desktop.interface",this.gnomeScheme,]);break;default:console.warn(`NOT SUPPORTED!!!DESKTOP_SESSION:${DESKTOP_SESSION}`);break}monitor\&\&monitor.on("error",(err)=>{console.error("monitorTheme",err)});monitor\&\&monitor.stdout.on("data",e.debounce((chunk)=>{const data=chunk.toString();const t=data.toLowerCase().includes("dark");(this._theme=t?i.Dark:i.Light),this._onDidThemeChange.fire(this._theme)},400));process.on("SIGTERM",(signal)=>{monitor.kill(signal);});}catch(err){console.error("尝试监听主题失败!", err);}}getDefaultTheme#' $find_result
|
|
||||||
else
|
|
||||||
warn "theme位置未找到"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# pack 路径 到 文件
|
# pack 路径 到 文件
|
||||||
notice "pack"
|
notice "pack"
|
||||||
node "$pack_script" "$tmp_dir/core.wxvpkg" "$package_dir/core.wxvpkg"
|
node "$pack_script" "$tmp_dir/core.wxvpkg" "$package_dir/core.wxvpkg"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user