mirror of
https://github.com/msojocs/wechat-web-devtools-linux.git
synced 2025-07-22 00:00:04 +08:00
Compare commits
No commits in common. "master" and "v1.06.2504010-2" have entirely different histories.
master
...
v1.06.2504
@ -1,6 +1,3 @@
|
|||||||
# 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,30 +1,24 @@
|
|||||||
/* patch wechat devtools begin */
|
/* patch wechat devtools begin */
|
||||||
(() => {
|
(() => {
|
||||||
try {
|
try {
|
||||||
{
|
const originalSpawn = require("child_process").spawn;
|
||||||
// 修正编译器路径
|
require("child_process").spawn = function (command, args, options) {
|
||||||
const originalSpawn = require("child_process").spawn;
|
if (command.includes("wcc.exe")) {
|
||||||
require("child_process").spawn = function (command, args, options) {
|
command = command.replace("code/package.nw", "package.nw");
|
||||||
if (command.includes("wcc.exe")) {
|
command = command.replace("wcc.exe", "wcc");
|
||||||
command = command.replace("code/package.nw", "package.nw");
|
} else if (command.includes("wcsc.exe")) {
|
||||||
command = command.replace("wcc.exe", "wcc");
|
command = command.replace("code/package.nw", "package.nw");
|
||||||
} else if (command.includes("wcsc.exe")) {
|
command = command.replace("wcsc.exe", "wcsc");
|
||||||
command = command.replace("code/package.nw", "package.nw");
|
}
|
||||||
command = command.replace("wcsc.exe", "wcsc");
|
return originalSpawn.apply(this, [command, args, options]);
|
||||||
}
|
};
|
||||||
return originalSpawn.apply(this, [command, args, options]);
|
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");
|
||||||
// 修正路径错误
|
}
|
||||||
const originalResolve = require("path").resolve;
|
return originalResolve.apply(this, paths);
|
||||||
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;
|
||||||
}
|
}
|
||||||
@ -117,227 +111,69 @@
|
|||||||
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) {
|
||||||
const originalOpen = nw.Window.open
|
console.warn('[wechat-devtools] nw.Window.open is called, url:', url, 'options:', options);
|
||||||
nw.Window.open = function (url, options, callback) {
|
let cb = callback
|
||||||
console.warn('[wechat-devtools] nw.Window.open is called, url:', url, 'options:', options);
|
if (options.title === '版本更新提示') {
|
||||||
let cb = callback
|
options.inject_js_start = 'js/unpack/hackrequire/index.js';
|
||||||
if (options.title === '版本更新提示') {
|
cb = (...args) => {
|
||||||
options.inject_js_start = 'js/unpack/hackrequire/index.js';
|
const keys = [
|
||||||
cb = (...args) => {
|
"shareData",
|
||||||
const keys = [
|
"windowMap",
|
||||||
"shareData",
|
"isSimple",
|
||||||
"windowMap",
|
"masterProxyPort",
|
||||||
"isSimple",
|
"proxyPort",
|
||||||
"masterProxyPort",
|
"masterH2ProxyPort",
|
||||||
"proxyPort",
|
"h2ProxyPort"
|
||||||
"masterH2ProxyPort",
|
];
|
||||||
"h2ProxyPort"
|
for(let k of keys)
|
||||||
];
|
args[0].window.global[k] = global[k];
|
||||||
for(let k of keys)
|
callback(...args)
|
||||||
args[0].window.global[k] = global[k];
|
|
||||||
callback(...args)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (options.title === '云开发控制台') {
|
|
||||||
cb = (...args) => {
|
|
||||||
const keys = [
|
|
||||||
"shareData",
|
|
||||||
"windowMap",
|
|
||||||
"isSimple",
|
|
||||||
"masterProxyPort",
|
|
||||||
"proxyPort",
|
|
||||||
"masterH2ProxyPort",
|
|
||||||
"h2ProxyPort",
|
|
||||||
'tokenData',
|
|
||||||
];
|
|
||||||
for(let k of keys)
|
|
||||||
args[0].window.global[k] = global[k];
|
|
||||||
callback(...args)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (options.title.includes('微信开发者工具')) {
|
|
||||||
cb = (...args) => {
|
|
||||||
const keys = [
|
|
||||||
"shareData",
|
|
||||||
"windowMap",
|
|
||||||
"isSimple",
|
|
||||||
"masterProxyPort",
|
|
||||||
"proxyPort",
|
|
||||||
"masterH2ProxyPort",
|
|
||||||
"h2ProxyPort",
|
|
||||||
'tokenData',
|
|
||||||
];
|
|
||||||
for(let k of keys)
|
|
||||||
args[0].window.global[k] = global[k];
|
|
||||||
callback(...args)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return originalOpen.apply(this, [url, options, cb])
|
|
||||||
}
|
}
|
||||||
|
else if (options.title === '云开发控制台') {
|
||||||
|
cb = (...args) => {
|
||||||
|
const keys = [
|
||||||
|
"shareData",
|
||||||
|
"windowMap",
|
||||||
|
"isSimple",
|
||||||
|
"masterProxyPort",
|
||||||
|
"proxyPort",
|
||||||
|
"masterH2ProxyPort",
|
||||||
|
"h2ProxyPort",
|
||||||
|
'tokenData',
|
||||||
|
];
|
||||||
|
for(let k of keys)
|
||||||
|
args[0].window.global[k] = global[k];
|
||||||
|
callback(...args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (options.title.includes('微信开发者工具')) {
|
||||||
|
cb = (...args) => {
|
||||||
|
const keys = [
|
||||||
|
"shareData",
|
||||||
|
"windowMap",
|
||||||
|
"isSimple",
|
||||||
|
"masterProxyPort",
|
||||||
|
"proxyPort",
|
||||||
|
"masterH2ProxyPort",
|
||||||
|
"h2ProxyPort",
|
||||||
|
'tokenData',
|
||||||
|
];
|
||||||
|
for(let k of keys)
|
||||||
|
args[0].window.global[k] = global[k];
|
||||||
|
callback(...args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return originalOpen.apply(this, [url, options, cb])
|
||||||
}
|
}
|
||||||
{
|
const originalExec = require('child_process').exec;
|
||||||
// 修正打开外部Terminal的功能
|
require('child_process').exec = function (command, options, callback) {
|
||||||
const originalExec = require('child_process').exec;
|
if (command.includes('open -a Terminal')) {
|
||||||
require('child_process').exec = function (command, options, callback) {
|
command = 'gnome-terminal'
|
||||||
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(callback) {
|
monitorTheme() {
|
||||||
try {
|
try {
|
||||||
let monitor = null;
|
let monitor = null;
|
||||||
const { DESKTOP_SESSION } = process.env;
|
const { DESKTOP_SESSION } = process.env;
|
||||||
@ -37,8 +37,11 @@ class CheckDark {
|
|||||||
monitor.stdout.on("data", (chunk) => {
|
monitor.stdout.on("data", (chunk) => {
|
||||||
// TODO: 防抖动包装
|
// TODO: 防抖动包装
|
||||||
const data = chunk.toString();
|
const data = chunk.toString();
|
||||||
const isDark = data.toLowerCase().includes("dark");
|
const t = data.toLowerCase().includes("dark");
|
||||||
callback(isDark)
|
console.log(data);
|
||||||
|
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);
|
||||||
@ -80,7 +83,7 @@ class CheckDark {
|
|||||||
}
|
}
|
||||||
get gnomeScheme() {
|
get gnomeScheme() {
|
||||||
try {
|
try {
|
||||||
// 判断 Gnome-Shell 版本 from @icepie
|
// 判断 Gnome-Shell 版本
|
||||||
const gnomeVersion = execSync(`gnome-shell --version`)
|
const gnomeVersion = execSync(`gnome-shell --version`)
|
||||||
.toString()
|
.toString()
|
||||||
.replace(/[\r\n]/g, "")
|
.replace(/[\r\n]/g, "")
|
||||||
@ -95,9 +98,7 @@ class CheckDark {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const cd = new CheckDark();
|
const cd = new CheckDark();
|
||||||
cd.monitorTheme((isDark) => {
|
cd.monitorTheme();
|
||||||
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,6 +64,23 @@ 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