Skip to content

Commit 2f58d9f

Browse files
GCQ1217barry-ran
authored andcommitted
feat: package appimage for linux
1 parent 7954406 commit 2f58d9f

File tree

5 files changed

+524
-42
lines changed

5 files changed

+524
-42
lines changed

.github/workflows/ubuntu.yml

100644100755
Lines changed: 91 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,71 +11,126 @@ on:
1111
- 'QtScrcpy/**'
1212
- '!QtScrcpy/res/**'
1313
- '.github/workflows/ubuntu.yml'
14+
- 'ci/linux/**'
1415
jobs:
1516
build:
1617
name: Build
17-
runs-on: ${{ matrix.os }}
18+
runs-on: ubuntu-22.04
19+
container:
20+
image: ubuntu:20.04
21+
options: --privileged
1822
strategy:
1923
matrix:
20-
os: [ubuntu-22.04]
2124
qt-ver: [5.15.2]
2225
qt-arch-install: [gcc_64]
2326
gcc-arch: [x64]
2427
env:
2528
target-name: QtScrcpy
26-
qt-install-path: ${{ github.workspace }}/${{ matrix.qt-ver }}
29+
qt-install-path: ${{ github.workspace }}/Qt/${{ matrix.qt-ver }}
2730
plantform-des: ubuntu
31+
DEBIAN_FRONTEND: noninteractive
2832
steps:
29-
- name: Install Qt
30-
uses: jurplel/[email protected]
31-
with:
32-
version: ${{ matrix.qt-ver }}
33-
cached: ${{ steps.cache-qt.outputs.cache-hit }}
34-
- name: Cache Qt
35-
id: cache-qt
36-
uses: actions/cache@v4
37-
with:
38-
path: ${{ env.qt-install-path }}/${{ matrix.qt-arch-install }}
39-
key: ${{ runner.os }}/${{ matrix.qt-ver }}/${{ matrix.qt-arch-install }}
40-
- name: Install GL library
41-
run: sudo apt-get install -y libglew-dev libglfw3-dev
33+
- name: Install Git and basic dependencies
34+
run: |
35+
apt-get update
36+
apt-get install -y git ca-certificates sudo
4237
- uses: actions/checkout@v2
4338
with:
4439
fetch-depth: 0
4540
submodules: 'true'
4641
ssh-key: ${{ secrets.BOT_SSH_KEY }}
47-
- name: Build RelWithDebInfo
48-
env:
49-
ENV_QT_PATH: ${{ env.qt-install-path }}
42+
- name: Install system dependencies
5043
run: |
51-
ci/linux/build_for_linux.sh "RelWithDebInfo"
52-
- name: Upload RelWithDebInfo
53-
uses: actions/upload-artifact@v4
44+
apt-get update
45+
apt-get install -y \
46+
build-essential \
47+
cmake \
48+
libglew-dev \
49+
libglfw3-dev \
50+
imagemagick \
51+
wget \
52+
patchelf \
53+
zip \
54+
libxcb1-dev \
55+
libxkbcommon-dev \
56+
libxkbcommon-x11-dev \
57+
libx11-dev \
58+
libx11-xcb-dev \
59+
libfontconfig1-dev \
60+
libfreetype6-dev \
61+
libxrender-dev \
62+
libxext-dev \
63+
gnupg \
64+
lsb-release \
65+
python3 \
66+
python3-pip \
67+
fuse \
68+
libasound2-dev
69+
- name: Setup FUSE
70+
run: |
71+
apt-get install -y fuse
72+
if [ ! -e /dev/fuse ]; then
73+
mknod /dev/fuse c 10 229 || true
74+
chmod 666 /dev/fuse || true
75+
fi
76+
export APPIMAGE_EXTRACT_AND_RUN=1
77+
- name: Install CMake 3.19+
78+
run: |
79+
apt-get install -y software-properties-common
80+
apt-get update
81+
apt-get install -y cmake=3.19.* || {
82+
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | apt-key add -
83+
apt-add-repository 'deb https://apt.kitware.com/ubuntu/ focal main'
84+
apt-get update
85+
apt-get install -y cmake
86+
}
87+
- name: Cache Qt
88+
id: cache-qt
89+
uses: actions/cache@v4
5490
with:
55-
name: QtScrcpy-${{ matrix.os }}-${{ matrix.qt-arch-install }}-RelWithDebInfo
56-
path: output/x64/RelWithDebInfo/*
91+
path: ${{ env.qt-install-path }}/${{ matrix.qt-arch-install }}
92+
key: ubuntu-20.04/${{ matrix.qt-ver }}/${{ matrix.qt-arch-install }}
93+
- name: Install Qt
94+
uses: jurplel/[email protected]
95+
with:
96+
version: ${{ matrix.qt-ver }}
97+
cache: ${{ steps.cache-qt.outputs.cache-hit }}
98+
setup-python: false
5799
- name: Build Release
100+
shell: bash
58101
env:
59-
ENV_QT_PATH: ${{ env.qt-install-path }}
102+
ENV_QT_PATH: ${{ github.workspace }}/Qt/${{ matrix.qt-ver }}
60103
run: |
61104
ci/linux/build_for_linux.sh "Release"
62-
- name: Upload Release
105+
- name: Package AppImage
106+
shell: bash
107+
env:
108+
ENV_QT_PATH: ${{ github.workspace }}/Qt/${{ matrix.qt-ver }}
109+
run: |
110+
chmod +x ci/linux/package_appimage.sh
111+
ci/linux/package_appimage.sh "Release"
112+
- name: Upload AppImage Artifact
63113
uses: actions/upload-artifact@v4
64114
with:
65-
name: QtScrcpy-${{ matrix.os }}-${{ matrix.qt-arch-install }}-Release
66-
path: output/x64/Release/*
67-
- name: Install the zip utility
68-
run: |
69-
sudo apt install zip -y
70-
- name: Zip the Artifacts
115+
name: QtScrcpy-ubuntu-20.04-${{ matrix.qt-arch-install }}-AppImage
116+
path: output/appimage/*.AppImage
117+
if-no-files-found: error
118+
- name: Prepare AppImage for Release
119+
if: startsWith(github.ref, 'refs/tags/')
71120
run: |
72-
zip -r QtScrcpy-${{ matrix.os }}-${{ matrix.qt-arch-install }}.zip output/x64/Release
73-
- name: Upload to Releases
121+
APPIMAGE_FILE=$(find output/appimage -name "QtScrcpy-*.AppImage" -type f | head -n 1)
122+
if [ -z "$APPIMAGE_FILE" ] || [ ! -f "$APPIMAGE_FILE" ]; then
123+
echo "Error: AppImage file not found"
124+
exit 1
125+
fi
126+
FINAL_NAME="QtScrcpy-ubuntu-20.04-${{ matrix.qt-arch-install }}.AppImage"
127+
cp "$APPIMAGE_FILE" "$FINAL_NAME"
128+
- name: Upload AppImage to Releases
74129
if: startsWith(github.ref, 'refs/tags/')
75130
uses: svenstaro/[email protected]
76131
with:
77-
file: QtScrcpy-${{ matrix.os }}-${{ matrix.qt-arch-install }}.zip
78-
asset_name: QtScrcpy-${{ matrix.os }}-${{ matrix.qt-arch-install }}.zip
132+
file: QtScrcpy-ubuntu-20.04-${{ matrix.qt-arch-install }}.AppImage
133+
asset_name: QtScrcpy-ubuntu-20.04-${{ matrix.qt-arch-install }}.AppImage
79134
repo_token: ${{ secrets.GITHUB_TOKEN }}
80135
tag: ${{ github.ref }}
81136
overwrite: true

QtScrcpy/main.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#include <QApplication>
22
#include <QDebug>
33
#include <QFile>
4+
#ifdef Q_OS_LINUX
5+
#include <QFileInfo>
6+
#include <QIcon>
7+
#endif
48
#include <QSurfaceFormat>
59
#include <QTcpServer>
610
#include <QTcpSocket>
@@ -37,10 +41,19 @@ int main(int argc, char *argv[])
3741
#endif
3842

3943
#ifdef Q_OS_LINUX
40-
qputenv("QTSCRCPY_ADB_PATH", "../../../QtScrcpy/QtScrcpyCore/src/third_party/adb/linux/adb");
41-
qputenv("QTSCRCPY_SERVER_PATH", "../../../QtScrcpy/QtScrcpyCore/src/third_party/scrcpy-server");
42-
qputenv("QTSCRCPY_KEYMAP_PATH", "../../../keymap");
43-
qputenv("QTSCRCPY_CONFIG_PATH", "../../../config");
44+
// Only set environment variables if they are not already set (e.g., by AppImage AppRun)
45+
if (qgetenv("QTSCRCPY_ADB_PATH").isEmpty()) {
46+
qputenv("QTSCRCPY_ADB_PATH", "../../../QtScrcpy/QtScrcpyCore/src/third_party/adb/linux/adb");
47+
}
48+
if (qgetenv("QTSCRCPY_SERVER_PATH").isEmpty()) {
49+
qputenv("QTSCRCPY_SERVER_PATH", "../../../QtScrcpy/QtScrcpyCore/src/third_party/scrcpy-server");
50+
}
51+
if (qgetenv("QTSCRCPY_KEYMAP_PATH").isEmpty()) {
52+
qputenv("QTSCRCPY_KEYMAP_PATH", "../../../keymap");
53+
}
54+
if (qgetenv("QTSCRCPY_CONFIG_PATH").isEmpty()) {
55+
qputenv("QTSCRCPY_CONFIG_PATH", "../../../config");
56+
}
4457
#endif
4558

4659
g_msgType = covertLogLevel(Config::getInstance().getLogLevel());
@@ -80,6 +93,15 @@ int main(int argc, char *argv[])
8093
g_oldMessageHandler = qInstallMessageHandler(myMessageOutput);
8194
QApplication a(argc, argv);
8295

96+
// Set application icon for Linux (taskbar icon)
97+
#ifdef Q_OS_LINUX
98+
// Load icon from Qt resource (logo.png is included in res.qrc)
99+
QIcon appIcon(":/image/tray/logo.png");
100+
if (!appIcon.isNull()) {
101+
a.setWindowIcon(appIcon);
102+
}
103+
#endif
104+
83105
// windows下通过qmake VERSION变量或者rc设置版本号和应用名称后,这里可以直接拿到
84106
// mac下拿到的是CFBundleVersion的值
85107
qDebug() << a.applicationVersion();

QtScrcpy/ui/dialog.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ void Dialog::initUI()
141141
//setWindowFlags(windowFlags() | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint | Qt::CustomizeWindowHint);
142142

143143
setWindowTitle(Config::getInstance().getTitle());
144+
#ifdef Q_OS_LINUX
145+
// Set window icon (inherits from application icon set in main.cpp)
146+
// If application icon was set, this will use it automatically
147+
if (!qApp->windowIcon().isNull()) {
148+
setWindowIcon(qApp->windowIcon());
149+
}
150+
#endif
144151

145152
#ifdef Q_OS_WIN32
146153
WinUtils::setDarkBorderToWindow((HWND)this->winId(), true);

ci/linux/build_for_linux.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ echo Current ENV_QT_PATH: $ENV_QT_PATH
88
echo Current directory: $(pwd)
99
# Set variables
1010
qt_cmake_path=$ENV_QT_PATH/gcc_64/lib/cmake/Qt5
11+
qt_gcc_path=$ENV_QT_PATH/gcc_64
1112
export PATH=$qt_gcc_path/bin:$PATH
1213

1314
# Remember working directory
1415
old_cd=$(pwd)
1516

16-
# Set working dir to the script's path
17-
cd $(dirname "$0")/.../
17+
# Set working dir to the script's path (go up two levels from ci/linux/ to project root)
18+
cd $(dirname "$0")/../../
1819

1920
echo
2021
echo

0 commit comments

Comments
 (0)