summarylogtreecommitdiffstats
path: root/electronic-wechat-uos-bin
blob: 76063b2e6fee42af70d08ad46f12c863faa095f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash

function main(){
	if [[ $@ =~ '-xwayland' ]]; then
		x11Launch
	fi
	if [[ ${_enable_Wayland} ]]; then
		waylandLaunch "$@"
	fi
	if [[ ${XDG_SESSION_DESKTOP} = KDE ]] && [[ ${XDG_SESSION_TYPE} = wayland ]]; then
		probeKwinVersion "$@"
	else
		x11Launch "$@"
	fi
}

function launch(){
	bwrap --die-with-parent \
	--symlink usr/lib /lib \
	--symlink usr/lib64 /lib64 \
	--symlink usr/bin /bin \
	--symlink usr/bin /sbin \
	--ro-bind /opt /opt \
	--ro-bind /usr/lib/electronic-wechat-uos-bin/os-release /etc/os-release \
	--ro-bind /usr/lib/electronic-wechat-uos-bin/lsb-release /etc/lsb-release \
	--ro-bind /etc /etc \
	--ro-bind /usr /usr \
	--bind /run /run \
	--bind /var /var \
	--dev /dev \
	--dev-bind /dev/dri /dev/dri \
	--dev-bind /dev/shm /dev/shm \
	--bind /proc /proc \
	--ro-bind /sys/dev/char /sys/dev/char \
	--ro-bind /sys/devices /sys/devices \
	--bind "$XDG_RUNTIME_DIR" "$XDG_RUNTIME_DIR" \
	--bind "$HOME" "$HOME" \
	--bind "$XDG_RUNTIME_DIR" "$XDG_RUNTIME_DIR" \
	env GTK_USE_PORTAL=1 electron$(cat /usr/lib/electronic-wechat-uos-bin/electronVer) \
	/usr/lib/electronic-wechat-uos-bin/app.asar "$@"
	exit $?
}

function x11Launch(){
    note '使用 XWayland / X11...'
    launch --ignore-gpu-blocklist \
    --enable-gpu-rasterization \
    --enable-zero-copy \
    --enable-features=VaapiVideoDecoder,VaapiIgnoreDriverChecks \
    "$@"
}

function probeKwinVersion(){
    _kwinVersion=`kwin_wayland --version | cut -c 6- | cut -c -4`
    if [[ `echo "${_kwinVersion} > 5.27" | bc` = 1 ]]; then
        waylandLaunch "$@"
    elif [[ ${_kwinVersion} = '5.27' ]]; then
        waylandLaunch "$@"
    else
        x11Launch "$@"
    fi
}

function waylandLaunch(){
    note '使用 Wayland...'
    note '在 KDE 系统设置中将虚拟键盘设置为 Fcitx5'
    _electronVer=`electron --version | cut -c 2-`

    if [[ `echo "${_electronVer} > 20" | bc` = 1 ]]; then
        waylandFlag="--ozone-platform-hint=auto"
    else
        waylandFlag="--ozone-platform=wayland"
    fi
    launch \
    ${waylandFlag} \
    --ignore-gpu-blocklist \
    --enable-features=WaylandWindowDecorations \
    --enable-gpu-rasterization \
    --enable-zero-copy \
    --enable-wayland-ime \
    --disable-gpu-driver-bug-workarounds \
    --enable-features=VaapiVideoDecoder,VaapiIgnoreDriverChecks \
    --disable-features=UseChromeOSDirectVideoDecoder \
    "$@" "${flagsIn}"
}

function note() {
	if [ -f /usr/bin/pamac ]; then
		echo "  ==> [Info]: $@"
	else
        all_off="$(tput sgr0)"
        bold="${all_off}$(tput bold)"
        blue="${bold}$(tput setaf 4)"
        yellow="${bold}$(tput setaf 3)"
        printf "${blue}==>${yellow} [Info]:${bold} $1${all_off}\n"
    fi
}

main "$@"