mirror of
https://github.com/msojocs/wechat-web-devtools-linux.git
synced 2025-07-07 00:02:14 +08:00
fix: theme - follow system
This commit is contained in:
parent
a7a2c98d25
commit
52b8d95a2f
16
test/fix-core.sh
Executable file
16
test/fix-core.sh
Executable file
@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
root_dir=$(cd `dirname $0`/.. && pwd -P)
|
||||||
|
|
||||||
|
package_dir="$root_dir/package.nw"
|
||||||
|
tmp_dir="$root_dir/package.nw"
|
||||||
|
mkdir -p $tmp_dir
|
||||||
|
unpack_script="$root_dir/tools/wxvpkg_unpack.js"
|
||||||
|
pack_script="$root_dir/tools/wxvpkg_pack.js"
|
||||||
|
|
||||||
|
find_result=$( grep -lr "OSThemeController=" "$tmp_dir/core.wxvpkg.ext" )
|
||||||
|
echo "theme: $find_result"
|
||||||
|
sed -i 's/"use strict";O/"use strict";const {execSync,spawn}=require("child_process");O/' $find_result
|
||||||
|
sed -i 's/this.registerListeners()/this.monitorTheme()/' $find_result
|
||||||
|
sed -i 's/}registerListeners/}monitorTheme(){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","gtk-theme",]);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.includes("dark");console.warn(data);console.warn("dark",t);(this._theme=t?i.Dark:i.Light),this._onDidThemeChange.fire(this._theme)},400))}registerListeners/' $find_result
|
||||||
|
sed -i 's/mediaQuery.matches/isDark/' $find_result
|
||||||
|
sed -i 's/}getDefaultTheme/}get isDark(){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 gtk-theme`);break;default:break}return theme.includes("dark")}getDefaultTheme/' $find_result
|
@ -35,7 +35,7 @@ class CheckDark {
|
|||||||
});
|
});
|
||||||
monitor &&
|
monitor &&
|
||||||
monitor.stdout.on("data", (chunk) => {
|
monitor.stdout.on("data", (chunk) => {
|
||||||
// TODO: 防抖动包装
|
// TODO: 防抖动包装
|
||||||
const data = chunk.toString();
|
const data = chunk.toString();
|
||||||
const t = data.includes("dark");
|
const t = data.includes("dark");
|
||||||
console.log(data);
|
console.log(data);
|
||||||
@ -68,12 +68,13 @@ class CheckDark {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const cd = new CheckDark();
|
const cd = new CheckDark();
|
||||||
console.log(cd.isDark);
|
|
||||||
cd.monitorTheme();
|
cd.monitorTheme();
|
||||||
|
console.log(cd.isDark);
|
||||||
|
|
||||||
function original() {
|
function original() {
|
||||||
!(function (require, directRequire) {
|
!(function (require, directRequire) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
const { execSync, spawn } = require("child_process");
|
||||||
Object.defineProperty(exports, "__esModule", { value: !0 }),
|
Object.defineProperty(exports, "__esModule", { value: !0 }),
|
||||||
(exports.OSThemeController = exports.OSTheme = void 0);
|
(exports.OSThemeController = exports.OSTheme = void 0);
|
||||||
const e = require("lodash"),
|
const e = require("lodash"),
|
||||||
@ -98,7 +99,7 @@ function original() {
|
|||||||
(this._theme = void 0),
|
(this._theme = void 0),
|
||||||
(this._isEnabled = void 0),
|
(this._isEnabled = void 0),
|
||||||
(this._mediaQuery2 = void 0),
|
(this._mediaQuery2 = void 0),
|
||||||
this.registerListeners();
|
this.monitorTheme();
|
||||||
}
|
}
|
||||||
static get shared() {
|
static get shared() {
|
||||||
return (
|
return (
|
||||||
@ -108,6 +109,47 @@ function original() {
|
|||||||
get onDidThemeChange() {
|
get onDidThemeChange() {
|
||||||
return this._onDidThemeChange.event;
|
return this._onDidThemeChange.event;
|
||||||
}
|
}
|
||||||
|
monitorTheme() {
|
||||||
|
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",
|
||||||
|
"gtk-theme",
|
||||||
|
]);
|
||||||
|
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) => {
|
||||||
|
// 防抖动包装 防抖动, 该函数会从上一次被调用后,延迟 400 毫秒后调用 本方法
|
||||||
|
const data = chunk.toString();
|
||||||
|
const t = data.includes("dark");
|
||||||
|
console.warn(data);
|
||||||
|
console.warn("dark", t);
|
||||||
|
(this._theme = t ? i.Dark : i.Light),
|
||||||
|
this._onDidThemeChange.fire(this._theme);
|
||||||
|
}, 400));
|
||||||
|
}
|
||||||
registerListeners() {
|
registerListeners() {
|
||||||
var e, t;
|
var e, t;
|
||||||
this.isEnabled() &&
|
this.isEnabled() &&
|
||||||
@ -143,8 +185,8 @@ function original() {
|
|||||||
}
|
}
|
||||||
tryGetCurrentTheme() {
|
tryGetCurrentTheme() {
|
||||||
if (this.isEnabled()) {
|
if (this.isEnabled()) {
|
||||||
// return this.isDark ? i.Dark : i.Light;
|
return this.isDark ? i.Dark : i.Light;
|
||||||
return this.mediaQuery.matches ? i.Dark : i.Light;
|
// return this.mediaQuery.matches ? i.Dark : i.Light;
|
||||||
}
|
}
|
||||||
return i.Unknown;
|
return i.Unknown;
|
||||||
}
|
}
|
||||||
@ -169,28 +211,28 @@ function original() {
|
|||||||
this._mediaQuery2
|
this._mediaQuery2
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
get isDark() {
|
get isDark() {
|
||||||
const { DESKTOP_SESSION } = process.env;
|
const { DESKTOP_SESSION } = process.env;
|
||||||
console.log(DESKTOP_SESSION);
|
console.log(DESKTOP_SESSION);
|
||||||
let theme = "";
|
let theme = "";
|
||||||
switch (DESKTOP_SESSION) {
|
switch (DESKTOP_SESSION) {
|
||||||
case "deepin":
|
case "deepin":
|
||||||
theme = execSync(
|
theme = execSync(
|
||||||
`gsettings get com.deepin.dde.appearance gtk-theme`
|
`gsettings get com.deepin.dde.appearance gtk-theme`
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case "gnome":
|
case "gnome":
|
||||||
case "gnome-classic":
|
case "gnome-classic":
|
||||||
theme = execSync(
|
theme = execSync(
|
||||||
`gsettings get org.gnome.desktop.interface gtk-theme`
|
`gsettings get org.gnome.desktop.interface gtk-theme`
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return theme.includes("dark");
|
return theme.includes("dark");
|
||||||
}
|
}
|
||||||
getDefaultTheme() {
|
getDefaultTheme() {
|
||||||
return i.Dark;
|
return i.Dark;
|
||||||
}
|
}
|
||||||
|
@ -69,6 +69,15 @@ if [[ $NO_WINE == 'true' ]];then
|
|||||||
echo $timeStamp > "${package_dir}/.build_time"
|
echo $timeStamp > "${package_dir}/.build_time"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# fix theme
|
||||||
|
find_result=$( grep -lr "OSThemeController=" "$tmp_dir/core.wxvpkg" )
|
||||||
|
echo "theme: $find_result"
|
||||||
|
sed -i 's/"use strict";O/"use strict";const {execSync,spawn}=require("child_process");O/' $find_result
|
||||||
|
sed -i 's/this.registerListeners()/this.monitorTheme()/' $find_result
|
||||||
|
sed -i 's/}registerListeners/}monitorTheme(){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","gtk-theme",]);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.includes("dark");console.warn(data);console.warn("dark",t);(this._theme=t?i.Dark:i.Light),this._onDidThemeChange.fire(this._theme)},400))}registerListeners/' $find_result
|
||||||
|
sed -i 's/mediaQuery.matches/isDark/' $find_result
|
||||||
|
sed -i 's/}getDefaultTheme/}get isDark(){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 gtk-theme`);break;default:break}return theme.includes("dark")}getDefaultTheme/' $find_result
|
||||||
|
|
||||||
# pack 路径 到 文件
|
# pack 路径 到 文件
|
||||||
echo "pack"
|
echo "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