feat: flatpak

This commit is contained in:
msojocs 2022-03-22 22:58:52 +08:00
parent 83677cba04
commit e463415599
4 changed files with 89 additions and 38 deletions

10
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,10 @@
{
"files.watcherExclude": {
"**/.git/objects/**": true,
"**/.git/subtree-cache/**": true,
"**/node_modules/*/**": true,
"**/.hg/store/**": true,
".flatpak/**": true,
"_build/**": true
}
}

View File

@ -1,13 +0,0 @@
app-id: github.msojocs.wechat-devtools
runtime: org.freedesktop.Platform
runtime-version: '21.08'
sdk: org.freedesktop.Sdk
command: hello.sh
modules:
- name: hello
buildsystem: simple
build-commands:
- install -D hello.sh /app/bin/hello.sh
sources:
- type: file
path: hello.sh

View File

@ -0,0 +1,57 @@
app-id: io.github.msojocs.wechat-devtools
runtime: org.freedesktop.Platform
runtime-version: '21.08'
sdk: org.freedesktop.Sdk
command: startup
finish-args:
# X11 + XShm access
- --share=ipc
- --socket=x11
# Wayland access
- --socket=wayland
# Needs to talk to the network:
- --share=network
# Needs to save files locally
- --filesystem=host
- --metadata=X-DConf=migrate-path=/org/gnome/dictionary/
modules:
- name: nwjs
buildsystem: simple
sources:
- type: dir
# url: https://npm.taobao.org/mirrors/nwjs/v0.53.1/nwjs-sdk-v0.53.1-linux-x64.tar.gz
# md5: b6f49803c51d0abacca2d1e566c7fe19
path: nwjs
build-commands:
- ls -l
- rm package.nw
- mkdir -p /app/opt/nwjs
- cp -r . /app/opt/nwjs
- name: package.nw
buildsystem: simple
sources:
- type: dir
# url: https://npm.taobao.org/mirrors/nwjs/v0.53.1/nwjs-sdk-v0.53.1-linux-x64.tar.gz
# md5: b6f49803c51d0abacca2d1e566c7fe19
path: package.nw
build-commands:
- ls -l
- mkdir -p /app/opt/package.nw
- cp -r . /app/opt/package.nw
- name: wechat-devtools
buildsystem: simple
build-commands:
- install -Dm755 wechat-devtools /app/opt/bin/wechat-devtools
- install -Dm755 startup.sh /app/bin/startup
- install -Dm644 io.github.msojocs.wechat_devtools.desktop /app/share/applications/io.github.msojocs.wechat-devtools.desktop
- install -Dm644 io.github.msojocs.wechat_devtools.svg /app/share/icons/hicolor/scalable/apps/io.github.msojocs.wechat-devtools.svg
sources:
- type: file
path: bin/wechat-devtools
- type: file
path: startup.sh
- type: file
path: io.github.msojocs.wechat_devtools.desktop
- type: file
path: io.github.msojocs.wechat_devtools.svg

View File

@ -19,20 +19,6 @@ if [ -n "$2" ];then
export ARCH=$2
fi
if [[ $VERSION == '' ]];then
fail "请指定版本"
exit 1
elif [[ $ARCH == '' ]];then
fail "请指定架构"
exit 1
fi
if [[ $NO_WINE == 'true' ]];then
TYPE='no_wine'
else
TYPE='wine'
fi
root_dir=$(cd `dirname $0`/.. && pwd -P)
tmp_dir="$root_dir/tmp"
app_dir="$tmp_dir/Flatpak"
@ -43,24 +29,23 @@ notice "检查版本号"
DEVTOOLS_VERSION=$( cat "$root_dir/package.nw/package.json" | grep -m 1 -Eo "\"[0-9]{1}\.[0-9]{2}\.[0-9]+" )
DEVTOOLS_VERSION="${DEVTOOLS_VERSION//\"/}"
INPUT_VERSION=$( echo $VERSION | sed 's/v//' | sed 's/-.*//' )
if [[ "$INPUT_VERSION" != "$DEVTOOLS_VERSION" ]];then
fail "传入版本号与实际版本号不一致!"
exit 1
fi
# if [[ "$INPUT_VERSION" != "$DEVTOOLS_VERSION" ]];then
# fail "传入版本号与实际版本号不一致!"
# exit 1
# fi
# Remove any previous build
rm -rf $app_dir
# Make usr and icons dirs
mkdir -p $app_dir/bin
mkdir -p $app_dir/usr/{src,bin}
mkdir -p $app_dir/usr/share/{metainfo,icons,applications}
notice "COPY FILES"
cp "$root_dir/bin/wechat-devtools" "$app_dir/bin/wechat-devtools"
cp "$root_dir/res/icons/wechat-devtools.png" "$app_dir/wechat-devtools.png"
cp "$root_dir/res/icons/wechat-devtools.svg" "$app_dir/io.github.msojocs.wechat_devtools.svg"
\cp -rf "$root_dir/res/flatpak"/* "$app_dir"
cp $root_dir/res/template.desktop "$app_dir/github.msojocs.wechat_devtools.desktop"
cp $root_dir/res/template.desktop "$app_dir/io.github.msojocs.wechat_devtools.desktop"
sed -i 's/Icon=dir\/res\/icons\/wechat-devtools.svg/Icon=io.github.msojocs.wechat_devtools/' "$app_dir/io.github.msojocs.wechat_devtools.desktop"
sed -i 's/Exec=dir\/bin\/wechat-devtools/Exec=startup/' "$app_dir/io.github.msojocs.wechat_devtools.desktop"
cp -r "$root_dir/package.nw" "$app_dir/package.nw"
cp -r "$root_dir/nwjs" "$app_dir/nwjs"
if [ -f $root_dir/node/bin/node ];then
@ -68,8 +53,20 @@ if [ -f $root_dir/node/bin/node ];then
cp "$root_dir/node/bin/node" "$app_dir/nwjs/node"
cd "$app_dir/nwjs/" && ln -s "node" "node.exe"
fi
cd "$app_dir"
# appimagetool $app_dir
notice "MAKE FLATPAK"
cd $app_dir
# 此处关键参照 https://unix.stackexchange.com/questions/412869/how-to-allow-gui-application-in-flatpak-to-run-cli-tool
cat > startup.sh <<- 'EOF'
#!/bin/sh
export PATH="/var/run/host/usr/bin:$PATH"
exec /app/opt/bin/wechat-devtools
EOF
# flatpak-builder build-dir io.github.msojocs.wechat-devtools.yml --force-clean
flatpak-builder build-dir io.github.msojocs.wechat-devtools.yml --install --force-clean --user
flatpak run io.github.msojocs.wechat-devtools