Skip to content

Commit 686db7e

Browse files
committed
Add macOS support and DMG packaging
Read native 64-bit interface counters and detect link state. Add app bundling and menu-bar access to statistics. Package Qt5/Qt6 builds using the NotQuiteRSS deployment workflow. Document macOS installation and behavior.
1 parent cfecebc commit 686db7e

9 files changed

Lines changed: 349 additions & 12 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 155 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Windows build and package
1+
name: Windows and macOS build and package
22

33
on:
44
push:
@@ -82,3 +82,157 @@ jobs:
8282
path: build/package/
8383
if-no-files-found: error
8484
retention-days: 14
85+
86+
macos:
87+
name: macOS ${{ matrix.arch }} (Qt ${{ matrix.qt }})
88+
runs-on: ${{ matrix.runner }}
89+
timeout-minutes: 45
90+
strategy:
91+
fail-fast: false
92+
matrix:
93+
qt: ['5', '6']
94+
arch: [arm64, x86_64]
95+
include:
96+
- arch: arm64
97+
runner: macos-15
98+
- arch: x86_64
99+
runner: macos-15-intel
100+
- qt: '5'
101+
formula: qt@5
102+
- qt: '6'
103+
formula: qt
104+
steps:
105+
- uses: actions/checkout@v4
106+
- name: Install macOS build dependencies
107+
run: brew install cmake ninja "${{ matrix.formula }}"
108+
109+
- name: Build QNetStats
110+
run: |
111+
set -euo pipefail
112+
qt_prefix="$(brew --prefix "${{ matrix.formula }}")"
113+
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release \
114+
-DUSE_QT=${{ matrix.qt }} -DCMAKE_PREFIX_PATH="$qt_prefix" \
115+
-DCMAKE_OSX_ARCHITECTURES=${{ matrix.arch }}
116+
cmake --build build --parallel 3
117+
118+
- name: Deploy, sign and package macOS app
119+
shell: bash
120+
run: |
121+
set -euo pipefail
122+
qt_prefix="$(brew --prefix "${{ matrix.formula }}")"
123+
qt_bin="$qt_prefix/bin"
124+
export PATH="$qt_bin:$PATH"
125+
cd build
126+
bundle=QNetStats.app
127+
test -d "$bundle"
128+
test "$(uname -m)" = "${{ matrix.arch }}"
129+
lipo "$bundle/Contents/MacOS/QNetStats" -verify_arch "${{ matrix.arch }}"
130+
cp ../COPYING "$bundle/Contents/Resources/LICENSE.txt"
131+
132+
# Stage the plugin types used by this Widgets application. Keep all
133+
# image formats, but exclude the unused QML virtual keyboard.
134+
qt_plugins="$("$qt_bin/qmake" -query QT_INSTALL_PLUGINS)"
135+
deploy_args=(-no-plugins -verbose=2 -no-codesign)
136+
shopt -s nullglob
137+
for plugin_type in platforms styles tls networkinformation imageformats iconengines; do
138+
for plugin in "$qt_plugins/$plugin_type/"*.dylib; do
139+
plugin_name="${plugin##*/}"
140+
case "$plugin_name" in
141+
*_debug.dylib|libqtvirtualkeyboard*.dylib) continue ;;
142+
esac
143+
if [ "$plugin_type" = platforms ] && [ "$plugin_name" != libqcocoa.dylib ]; then
144+
continue
145+
fi
146+
mkdir -p "$bundle/Contents/PlugIns/$plugin_type"
147+
destination="$bundle/Contents/PlugIns/$plugin_type/$plugin_name"
148+
cp "$plugin" "$destination"
149+
deploy_args+=("-executable=$destination")
150+
done
151+
done
152+
153+
# Homebrew installs Qt frameworks in separate formula directories.
154+
# Search them without copying modules that no retained binary uses.
155+
brew_prefix="$(brew --prefix)"
156+
deploy_args+=("-libpath=$brew_prefix/lib"
157+
"-libpath=$qt_prefix/lib")
158+
for qt_lib in "$brew_prefix"/opt/qt*/lib; do
159+
[ -d "$qt_lib" ] && deploy_args+=("-libpath=$qt_lib")
160+
done
161+
"$qt_bin/macdeployqt" "$bundle" "${deploy_args[@]}"
162+
test -f "$bundle/Contents/PlugIns/platforms/libqcocoa.dylib"
163+
164+
# Some transitive Homebrew references survive deployment even when
165+
# their libraries were copied. Repair only references with an existing
166+
# bundle counterpart; never leave a dependency on the build machine.
167+
while IFS= read -r -d '' binary; do
168+
file_type="$(file -b "$binary")"
169+
[[ "$file_type" == *Mach-O* ]] || continue
170+
dependencies="$(otool -L "$binary")"
171+
install_id="$(otool -D "$binary" | tail -n +2)"
172+
while IFS= read -r dependency; do
173+
case "$dependency" in
174+
"$brew_prefix"/*|@rpath/*)
175+
case "$dependency" in
176+
@rpath/*) relative="${dependency#@rpath/}" ;;
177+
*.framework/*) relative="${dependency#*/lib/}" ;;
178+
*) relative="${dependency##*/}" ;;
179+
esac
180+
target="$bundle/Contents/Frameworks/$relative"
181+
if [ ! -f "$target" ]; then
182+
echo "Missing bundled dependency for $binary: $dependency" >&2
183+
exit 1
184+
fi
185+
replacement="@executable_path/../Frameworks/$relative"
186+
if [ "$dependency" = "$install_id" ]; then
187+
install_name_tool -id "$replacement" "$binary"
188+
else
189+
install_name_tool -change "$dependency" "$replacement" "$binary"
190+
fi
191+
;;
192+
esac
193+
done <<< "$(printf '%s\n' "$dependencies" | sed -n '2,$s/^[[:space:]]*\(.*\) (compatibility version.*$/\1/p')"
194+
done < <(find "$bundle" -type f -print0)
195+
196+
# Signing does not check library availability. Reject missing
197+
# bundle-relative dependencies as well as build-host references.
198+
while IFS= read -r -d '' binary; do
199+
file_type="$(file -b "$binary")"
200+
[[ "$file_type" == *Mach-O* ]] || continue
201+
dependencies="$(otool -L "$binary")"
202+
while IFS= read -r dependency; do
203+
case "$dependency" in
204+
/System/Library/*|/usr/lib/*) continue ;;
205+
@executable_path/*)
206+
target="$bundle/Contents/MacOS/${dependency#@executable_path/}" ;;
207+
@loader_path/*)
208+
target="${binary%/*}/${dependency#@loader_path/}" ;;
209+
*)
210+
echo "Unbundled dependency in $binary: $dependency" >&2
211+
exit 1 ;;
212+
esac
213+
if [ ! -f "$target" ]; then
214+
echo "Missing bundled dependency for $binary: $dependency" >&2
215+
exit 1
216+
fi
217+
done <<< "$(printf '%s\n' "$dependencies" | sed -n '2,$s/^[[:space:]]*\(.*\) (compatibility version.*$/\1/p')"
218+
done < <(find "$bundle" -type f -print0)
219+
# All binary edits must precede signing. Deep signing is intentional
220+
# for this ad-hoc beta bundle, not a Developer ID/notarization workflow.
221+
codesign --force --deep --sign - "$bundle"
222+
codesign --verify --deep --strict --verbose=2 "$bundle"
223+
dmg_stage="$(mktemp -d "$RUNNER_TEMP/qnetstats-dmg.XXXXXX")"
224+
ditto "$bundle" "$dmg_stage/$bundle"
225+
ln -s /Applications "$dmg_stage/Applications"
226+
hdiutil create -volname "QNetStats" -srcfolder "$dmg_stage" \
227+
-format UDZO "QNetStats.dmg"
228+
hdiutil verify "QNetStats.dmg"
229+
mkdir -p package
230+
mv QNetStats.dmg "package/QNetStats-macOS-${{ matrix.arch }}-Qt${{ matrix.qt }}.dmg"
231+
232+
- name: Upload macOS package
233+
uses: actions/upload-artifact@v4
234+
with:
235+
name: QNetStats-macOS-${{ matrix.arch }}-Qt${{ matrix.qt }}-${{ github.sha }}
236+
path: build/package/*.dmg
237+
if-no-files-found: error
238+
retention-days: 14

‎CHANGELOG‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Version 2.2.0 (not yet released)
2+
- Added macOS support with native 64-bit counters, menu-bar controls, and Qt5/Qt6 DMG CI builds for Apple Silicon and Intel.
3+
4+
Version 2.1.0
5+
- Implement smooth traffic chart scrolling
6+
- Make traffic chart lines more rounded
7+
18
Version 2.1.0
29

310
- Renamed KNetStats to QNetStats and removed KDE dependencies.

‎CMakeLists.txt‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.16)
22
project(qnetstats)
33

4-
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT WIN32)
4+
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND NOT WIN32)
55
message(FATAL_ERROR "Building QNetStats is not supported on ${CMAKE_SYSTEM_NAME}")
66
endif()
77

@@ -67,7 +67,17 @@ if(WIN32)
6767
endif()
6868
endif()
6969

70-
install(TARGETS qnetstats RUNTIME)
70+
if(APPLE)
71+
set_target_properties(qnetstats PROPERTIES
72+
MACOSX_BUNDLE TRUE
73+
OUTPUT_NAME QNetStats
74+
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/dist/macos/Info.plist.in")
75+
target_sources(qnetstats PRIVATE dist/macos/QNetStats.icns)
76+
set_source_files_properties(dist/macos/QNetStats.icns PROPERTIES
77+
MACOSX_PACKAGE_LOCATION Resources)
78+
endif()
79+
80+
install(TARGETS qnetstats RUNTIME DESTINATION bin BUNDLE DESTINATION .)
7181
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
7282
install(FILES dist/com.birdie-github.QNetStats.desktop
7383
DESTINATION share/applications)

‎README.md‎

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
---
77

8-
<p>A simple network interface and statistics viewer for Linux and Windows 10/11 based on the <a href="https://knetstats.sourceforge.net/"> KDE 3 project KNetStats</a> by Hugo Parente Lima (hugo_pl).</p>
8+
<p>A simple network interface and statistics viewer for Linux, Windows 10/11, and macOS based on the <a href="https://knetstats.sourceforge.net/"> KDE 3 project KNetStats</a> by Hugo Parente Lima (hugo_pl).</p>
99
<p>QNetStats is a simple Qt network interface and statistics viewer with an associated tray icon to monitor activity.<br>It displays and graphs data transmission information for easy visualization. It also displays information such as associated IPs and MAC addresses.</p>
1010

1111
## Text statistics tray icons
@@ -30,7 +30,8 @@ interface digit wherever they overlap. A **Show interface digit** checkbox hides
3030
assignment. An independent **Text shadow** checkbox adds a thin contrasting
3131
shadow around the traffic text, including when the digit is hidden. The digit stays assigned
3232
when an interface disconnects, and unavailable rates appear as dashes. Hover for
33-
the interface name and full rates; click either icon to toggle its statistics.
33+
the interface name and full rates; click either icon to toggle its statistics
34+
(on macOS, choose **Statistics** from its menu).
3435

3536
**Display Tray Icon** controls the original activity icon independently.
3637
**Notify Interface Changes** controls connection notifications. With both kinds
@@ -89,7 +90,7 @@ Otherwise, building instructions are provided below:
8990

9091
An RPM SPEC file (untested) and an Arch PKGBUILD is provided within `dist/`. You can use those to install QNetStats on the appropriate distros.
9192

92-
QNetStats supports Qt 5.11 or newer and Qt 6 on Linux and Windows 10/11, using Qt Widgets and Qt Network. KDE Frameworks are not required.
93+
QNetStats supports Qt 5.11 or newer and Qt 6 on Linux, Windows 10/11, and macOS, using Qt Widgets and Qt Network. KDE Frameworks are not required.
9394
CMake prefers Qt6 when available and otherwise uses Qt5. The provided packaging definitions select Qt6 explicitly.
9495

9596
Manually building QNetStats requires Git and the following packages to be installed
@@ -126,6 +127,48 @@ cmake --build build-qt6
126127

127128
The default is `-DUSE_QT=AUTO`. An explicitly selected version must be installed; CMake will not fall back to another version.
128129

130+
### macOS
131+
132+
Install the Xcode Command Line Tools (`xcode-select --install`), Homebrew, and
133+
Qt. Both Apple Silicon and Intel Macs are supported; the minimum macOS version
134+
is determined by the installed Qt kit.
135+
136+
```bash
137+
brew install cmake ninja qt
138+
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DUSE_QT=6 \
139+
-DCMAKE_PREFIX_PATH="$(brew --prefix qt)"
140+
cmake --build build
141+
open build/QNetStats.app
142+
```
143+
144+
For Qt5, install `qt@5`, use `-DUSE_QT=5` and
145+
`-DCMAKE_PREFIX_PATH="$(brew --prefix qt@5)"` in a separate build directory.
146+
To make a self-contained Qt6 bundle before copying it to `/Applications`:
147+
148+
```bash
149+
cp COPYING build/QNetStats.app/Contents/Resources/LICENSE.txt
150+
"$(brew --prefix qt)/bin/macdeployqt" build/QNetStats.app
151+
codesign --force --deep --sign - build/QNetStats.app
152+
```
153+
154+
`cmake --install build --prefix /Applications` installs the app bundle.
155+
Deploy Qt before installing if the app must run without the build machine's Qt.
156+
CI builds and packages Qt5 and Qt6 bundles in DMG images separately for arm64
157+
and x86_64. It checks bundled dependencies and signatures before packaging.
158+
These packages are ad-hoc signed, without Developer ID signing or notarization;
159+
Gatekeeper may require approval when opening a downloaded app.
160+
161+
QNetStats runs in the menu bar without a Dock icon. Click an interface icon and
162+
choose **Statistics** to open its window; **Configure Interfaces** and **Quit
163+
QNetStats** are available from every icon. Traffic counters use the native
164+
`NET_RT_IFLIST2` sysctl API with 64-bit byte and packet counters, without root
165+
privileges. Interface availability uses its native index; connection state uses
166+
Qt's up/running flags and native media status where supported, with a flag-based
167+
fallback for virtual interfaces. IP addresses, netmasks, MTU,
168+
and MAC addresses use Qt Network as on the other platforms. Settings use Qt's
169+
native preferences storage. Notification delivery depends on macOS permissions
170+
and Qt support.
171+
129172
### Windows 10 and 11
130173

131174
Install CMake, a matching Qt 5.11+ or Qt 6 desktop kit, and its compiler. For example, use

‎dist/macos/Info.plist.in‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleExecutable</key>
6+
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
7+
<key>CFBundleIdentifier</key>
8+
<string>com.birdie-github.QNetStats</string>
9+
<key>CFBundleName</key>
10+
<string>QNetStats</string>
11+
<key>CFBundleDisplayName</key>
12+
<string>QNetStats</string>
13+
<key>CFBundleIconFile</key>
14+
<string>QNetStats.icns</string>
15+
<key>CFBundlePackageType</key>
16+
<string>APPL</string>
17+
<key>NSHighResolutionCapable</key>
18+
<true/>
19+
<key>LSUIElement</key>
20+
<true/>
21+
</dict>
22+
</plist>

‎dist/macos/QNetStats.icns‎

98.8 KB
Binary file not shown.

‎src/qnetstats.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extern const char *programName;
3535
namespace {
3636
ViewOptions defaultInterfaceOptions(const QString &name) {
3737
int theme = name.startsWith("wlan") ? 3 : 0;
38-
#ifdef Q_OS_WIN
38+
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
3939
if (QNetworkInterface::interfaceFromName(name).type() == QNetworkInterface::Wifi)
4040
theme = 3;
4141
#endif
@@ -179,6 +179,7 @@ void QNetStats::setupBackupTrayIcon() {
179179
mContextMenu->addAction("Quit QNetStats", this, []() { QApplication::quit(); });
180180
mBackupTrayIcon->setContextMenu(mContextMenu);
181181

182+
#ifndef Q_OS_MACOS
182183
connect(mBackupTrayIcon, &QSystemTrayIcon::activated, this, [this](QSystemTrayIcon::ActivationReason reason) {
183184
if (reason != QSystemTrayIcon::Trigger)
184185
return;
@@ -188,6 +189,7 @@ void QNetStats::setupBackupTrayIcon() {
188189
}
189190
mConfigure->show();
190191
});
192+
#endif
191193
}
192194

193195
void QNetStats::setupFallbackWindow() {

0 commit comments

Comments
 (0)