summarylogtreecommitdiffstats
path: root/wechat.sh
blob: 528ac7dd8b16605b07033d1f5673d11177e53058 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
# https://cdn4.cnxclm.com/uploads/2024/03/08/85uZHDjz_store.spark-app.wechat-linux-spark_2.2-real1.0.0.0_amd64.deb?attname=store.spark-app.wechat-linux-spark_2.2-real1.0.0.0_amd64.deb

BWRAP_ENV_APPEND="--setenv QT_QPA_PLATFORM xcb "
if [ -z ${QT_IM_MODULE} ]; then
	BWRAP_ENV_APPEND="${BWRAP_ENV_APPEND} --setenv QT_IM_MODULE fcitx"
fi

case "$XDG_CURRENT_DESKTOP" in 
	KDE)
	SCALE_FACTOR=$(kreadconfig6 --group KScreen --key ScaleFactor --default 1.0)
	BWRAP_ENV_APPEND="${BWRAP_ENV_APPEND} --setenv QT_SCALE_FACTOR ${SCALE_FACTOR}"
	;;
	*)
	BWRAP_ENV_APPEND="${BWRAP_ENV_APPEND} --setenv QT_AUTO_SCREEN_SCALE_FACTOR ${QT_AUTO_SCREEN_SCALE_FACTOR:-1}"
	;;
esac

if [ -z ${GTK_USE_PORTAL} ]; then
	BWRAP_ENV_APPEND="${BWRAP_ENV_APPEND} --setenv GTK_USE_PORTAL 1"
fi

function moeDect() {
	if [[ -f /usr/share/moeOS-Docs/os-release ]]; then
		osRel="/usr/share/moeOS-Docs/os-release"
	else
		osRel="/usr/lib/os-release"
	fi

}

function sourceXDG() {
	if [[ -d "${HOME}"/.config ]]; then
		source "${HOME}"/.config/user-dirs.dirs
	else
		source "${XDG_CONFIG_HOME}"/user-dirs.dirs
	fi
}

function manageDirs() {
	sourceXDG
	createWrapIfNotExist "${XDG_DOCUMENTS_DIR}"/WeChat_Downloads
	createWrapIfNotExist "${XDG_DOCUMENTS_DIR}"/WeChat_Data
	if [ -d "${HOME}/Documents/TrashBox" ]; then
		mv "${HOME}/Documents/TrashBox"/* \
			"${XDG_DOCUMENTS_DIR}"/WeChat_Data
	fi
}

function detectXauth() {
	if [ ! ${XAUTHORITY} ]; then
		XAUTHORITY=/dev/null
	fi
}

function createWrapIfNotExist() {
	if [ -d "$@" ]; then
		return 0
	else
		mkdir -p "$@"
	fi
}

function inputMethod() {
	if [[ ${XMODIFIERS} =~ fcitx ]]; then
		export QT_IM_MODULE=fcitx
	elif [[ ${XMODIFIERS} =~ ibus ]]; then
		export QT_IM_MODULE=ibus
		export IBUS_USE_PORTAL=1
	fi
}

function lnDir() {
	if [ ! -e "${HOME}"/xwechat_files ]; then
		ln -s "${XDG_DOCUMENTS_DIR}"/WeChat_Data/xwechat_files "${HOME}"/xwechat_files
	fi
}

function execApp() {
	LSB_RELEASE_FILE=$(realpath /etc/lsb-release)
	bwrap \
		--tmpfs /tmp \
		--symlink usr/lib /lib \
		--symlink usr/lib64 /lib64 \
		--symlink usr/bin /bin \
		--symlink usr/bin /sbin \
		--ro-bind /opt /opt \
		--ro-bind "$XDG_RUNTIME_DIR/bus" "$XDG_RUNTIME_DIR/bus" \
		--ro-bind "$XDG_RUNTIME_DIR/pulse" "$XDG_RUNTIME_DIR/pulse" \
		--dev /dev \
		--dev-bind /dev/dri /dev/dri \
		--dev-bind /dev/shm /dev/shm \
		--ro-bind /sys/dev/char /sys/dev/char \
		--ro-bind /sys/devices /sys/devices \
		--proc /proc \
		--ro-bind /usr /usr \
		--bind "${XDG_DOCUMENTS_DIR}"/WeChat_Data "${HOME}" \
		--ro-bind-try "$HOME/.config/fontconfig" "${HOME}/.config/fontconfig" \
		--bind "${XDG_DOCUMENTS_DIR}"/WeChat_Downloads "${XDG_DOWNLOAD_DIR}" \
		--ro-bind-try "${XAUTHORITY}" "${XAUTHORITY}" \
		--ro-bind /etc /etc \
		--unshare-all \
		--share-net \
		--bind /usr/bin/true /usr/bin/lsblk \
		--ro-bind /opt/apps/store.spark-app.wechat-linux-spark/files/license/usr/lib/license/libuosdevicea.so /usr/lib/license/libuosdevicea.so \
		--ro-bind /opt/apps/store.spark-app.wechat-linux-spark/files/license/var/lib/uos-license /var/lib/uos-license \
		--ro-bind /opt/apps/store.spark-app.wechat-linux-spark/files/license/var/uos /var/uos \
		--ro-bind /opt/apps/store.spark-app.wechat-linux-spark/files/uos-lsb "${LSB_RELEASE_FILE}" \
		--ro-bind /opt/apps/store.spark-app.wechat-linux-spark/files/uos-release /usr/lib/os-release \
		--ro-bind /usr/lib/snapd-xdg-open/xdg-open /usr/bin/xdg-open \
		${BWRAP_ENV_APPEND} \
		/opt/apps/store.spark-app.wechat-linux-spark/files/files/wechat
}

function launch() {
	detectXauth
	inputMethod
	moeDect
	lnDir
	echo "Launching WeChat Beta..."
	execApp
}

manageDirs
launch $@