Skip to content

Commit 061b5b8

Browse files
authored
Merge pull request #2 from derryl/fix/qml-errors-and-ci
Fix QML runtime type errors and add CI
2 parents d19724e + f400399 commit 061b5b8

7 files changed

Lines changed: 172 additions & 7 deletions

File tree

.github/workflows/ci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
lint-qml:
9+
name: QML lint & type check
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Install Qt 6 and xvfb
16+
run: |
17+
sudo apt-get update
18+
sudo apt-get install -y --no-install-recommends \
19+
qt6-declarative-dev-tools \
20+
qml-qt6 \
21+
qml6-module-qtquick \
22+
qml6-module-qtquick-controls \
23+
qml6-module-qtquick-layouts \
24+
qml6-module-qtquick-window \
25+
qml6-module-qtquick-templates \
26+
xvfb
27+
28+
- name: Run QML checks
29+
run: ./scripts/lint-qml.sh

assets/background.jpg

2.44 MB
Loading

components/LoginForm.qml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Item {
4747
color: root.textColor
4848
font.pointSize: root.fontSize + 8
4949
font.weight: Font.Light
50-
font.family: root.fontFamily || undefined
50+
font.family: root.fontFamily
5151
renderType: Text.NativeRendering
5252
}
5353

@@ -59,7 +59,7 @@ Item {
5959
placeholderText: "Username"
6060
text: root.defaultUsername
6161
font.pointSize: root.fontSize
62-
font.family: root.fontFamily || undefined
62+
font.family: root.fontFamily
6363

6464
color: root.textColor
6565
placeholderTextColor: Qt.rgba(1, 1, 1, 0.5)
@@ -86,7 +86,7 @@ Item {
8686
placeholderText: "Password"
8787
echoMode: TextInput.Password
8888
font.pointSize: root.fontSize
89-
font.family: root.fontFamily || undefined
89+
font.family: root.fontFamily
9090

9191
color: root.textColor
9292
placeholderTextColor: Qt.rgba(1, 1, 1, 0.5)
@@ -122,7 +122,7 @@ Item {
122122
height: 44
123123
text: "Log In"
124124
font.pointSize: root.fontSize
125-
font.family: root.fontFamily || undefined
125+
font.family: root.fontFamily
126126

127127
contentItem: Text {
128128
text: loginButton.text

components/SessionSelector.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Item {
2828
textRole: "name"
2929

3030
font.pointSize: root.fontSize
31-
font.family: root.fontFamily || undefined
31+
font.family: root.fontFamily
3232

3333
contentItem: Text {
3434
leftPadding: 10

preview/Preview.qml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Window {
3232

3333
QtObject {
3434
id: mockConfig
35+
// Set to "" to use the solid fallback color, or provide a path
36+
// to an image (e.g. drop your own into assets/background.jpg).
3537
property string background: Qt.resolvedUrl("../assets/background.jpg")
3638
property string type: "image"
3739
property string color: "#1a1a2e"
@@ -121,9 +123,14 @@ Window {
121123
Image {
122124
id: backgroundImage
123125
anchors.fill: parent
124-
source: mockConfig.background
126+
source: mockConfig.background || ""
125127
fillMode: Image.PreserveAspectCrop
126128
asynchronous: true
129+
onStatusChanged: {
130+
if (status === Image.Error && source != "")
131+
console.log("Background image not found — using fallback color. " +
132+
"Drop an image into assets/background.jpg or update theme.conf.")
133+
}
127134
}
128135

129136
Rectangle {

scripts/lint-qml.sh

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/usr/bin/env bash
2+
#
3+
# lint-qml.sh - Static analysis and runtime type-error check for QML files.
4+
#
5+
# Runs qmllint (static) on all QML source files, then launches the preview
6+
# under xvfb for a few seconds to catch runtime type-assignment warnings.
7+
#
8+
# Usage: ./scripts/lint-qml.sh
9+
#
10+
# Exit codes:
11+
# 0 All checks passed
12+
# 1 qmllint found issues or runtime errors detected
13+
14+
set -euo pipefail
15+
16+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
17+
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
18+
19+
cd "$PROJECT_DIR"
20+
21+
# ── Locate Qt 6 tools ────────────────────────────────────────────
22+
# Binary names and paths vary across distros:
23+
# Arch: qmllint, qml6 (on PATH)
24+
# Ubuntu: qmllint, qml (in /usr/lib/qt6/bin)
25+
for candidate in /usr/lib/qt6/bin /usr/lib64/qt6/bin; do
26+
[[ -d "$candidate" ]] && export PATH="$candidate:$PATH"
27+
done
28+
29+
find_tool() {
30+
for name in "$@"; do
31+
if command -v "$name" &>/dev/null; then
32+
echo "$name"
33+
return
34+
fi
35+
done
36+
echo ""
37+
}
38+
39+
QMLLINT=$(find_tool qmllint qmllint6)
40+
QML_RUNTIME=$(find_tool qml6 qml)
41+
42+
FAILED=0
43+
44+
# ── Static analysis with qmllint ──────────────────────────────────
45+
echo "=== qmllint: static analysis ==="
46+
47+
if [[ -z "$QMLLINT" ]]; then
48+
echo "SKIP: qmllint not found."
49+
else
50+
QML_FILES=$(find . -name '*.qml' -not -path './.git/*')
51+
echo "Checking: $QML_FILES"
52+
echo ""
53+
54+
# qmllint emits warnings for SDDM context properties (sddm, config,
55+
# userModel, etc.) that only exist at runtime. These are expected and
56+
# unavoidable. We capture the output and only fail on actual errors
57+
# (syntax errors, unknown components from our own code), not warnings
58+
# about unqualified/unresolved access to SDDM injected globals.
59+
LINT_OUTPUT=$($QMLLINT $QML_FILES 2>&1) || true
60+
if echo "$LINT_OUTPUT" | grep -qiE '^Error:'; then
61+
echo "$LINT_OUTPUT"
62+
echo "FAIL: qmllint found errors."
63+
FAILED=1
64+
else
65+
echo "PASS: qmllint clean (warnings only)."
66+
fi
67+
fi
68+
echo ""
69+
70+
# ── Runtime type-error check ──────────────────────────────────────
71+
echo "=== Runtime: checking for type errors ==="
72+
73+
if [[ -z "$QML_RUNTIME" ]]; then
74+
echo "SKIP: qml runtime not found (tried qml6, qml)."
75+
echo ""
76+
exit $FAILED
77+
fi
78+
79+
# Use the Basic style to avoid Breeze/Plasma-specific errors that only
80+
# occur outside a full Plasma session (e.g. T.Overlay in ComboBox).
81+
export QT_QUICK_CONTROLS_STYLE=Basic
82+
83+
STDERR_LOG=$(mktemp)
84+
trap 'rm -f "$STDERR_LOG"' EXIT
85+
86+
# Run preview for 3 seconds under a virtual framebuffer, capture stderr.
87+
if command -v xvfb-run &>/dev/null; then
88+
timeout 3 xvfb-run -a "$QML_RUNTIME" preview/Preview.qml 2>"$STDERR_LOG" || true
89+
elif [ -n "${DISPLAY:-}" ] || [ -n "${WAYLAND_DISPLAY:-}" ]; then
90+
timeout 3 "$QML_RUNTIME" preview/Preview.qml 2>"$STDERR_LOG" || true
91+
else
92+
echo "SKIP: no display and xvfb-run not available."
93+
echo ""
94+
exit $FAILED
95+
fi
96+
97+
# Filter for errors we care about (type assignment, ReferenceError, TypeError).
98+
if grep -E 'Unable to assign|ReferenceError|TypeError' "$STDERR_LOG" \
99+
| grep -v 'Cannot open:' \
100+
| grep -q .; then
101+
echo "FAIL: runtime type errors detected:"
102+
grep -E 'Unable to assign|ReferenceError|TypeError' "$STDERR_LOG" \
103+
| grep -v 'Cannot open:'
104+
FAILED=1
105+
else
106+
echo "PASS: no runtime type errors."
107+
fi
108+
echo ""
109+
110+
exit $FAILED

scripts/preview.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@ set -euo pipefail
1313
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1414
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
1515

16+
ENTR_PID=""
17+
18+
cleanup() {
19+
trap - SIGINT SIGTERM # prevent re-entry
20+
[[ -n "$ENTR_PID" ]] && kill "$ENTR_PID" 2>/dev/null && wait "$ENTR_PID" 2>/dev/null
21+
echo ""
22+
echo "Preview stopped."
23+
exit 0
24+
}
25+
trap cleanup SIGINT SIGTERM
26+
27+
# Force the Basic Qt Quick Controls style so the standalone preview doesn't
28+
# load Breeze, which depends on Plasma-specific overlay types that are
29+
# unavailable outside a full Plasma session.
30+
export QT_QUICK_CONTROLS_STYLE=Basic
31+
1632
echo "=== KDE Lockscreen Builder — Live Preview ==="
1733
echo "Project: $PROJECT_DIR"
1834
echo "Press Ctrl+C to stop"
@@ -22,5 +38,8 @@ cd "$PROJECT_DIR"
2238

2339
while true; do
2440
find . \( -name '*.qml' -o -name '*.conf' -o -name '*.jpg' -o -name '*.png' -o -name '*.svg' \) \
25-
| entr -d -r qml6 preview/Preview.qml
41+
| entr -d -r qml6 preview/Preview.qml &
42+
ENTR_PID=$!
43+
wait "$ENTR_PID" || true
44+
ENTR_PID=""
2645
done

0 commit comments

Comments
 (0)