diff --git a/autoreload.py b/autoreload.py index b789be08..bd1dcdd9 100755 --- a/autoreload.py +++ b/autoreload.py @@ -5,6 +5,7 @@ Automatically rebuild and restart the application when source files change. CONFIG+=dev will be passed to qmake, see mirage.pro. The application will be launched with `-name dev`, which sets the first part of the WM_CLASS as returned by xprop on Linux. +Any other arguments will be passed to the app, see `mirage --help`. Use `pip3 install --user -U requirements-dev.txt` before running this.""" diff --git a/src/gui/ArgumentParser.qml b/src/gui/ArgumentParser.qml new file mode 100644 index 00000000..e596991f --- /dev/null +++ b/src/gui/ArgumentParser.qml @@ -0,0 +1,57 @@ +// Copyright Mirage authors & contributors +// SPDX-License-Identifier: LGPL-3.0-or-later + +pragma Singleton +import QtQuick 2.12 + +QtObject { + + property bool startInTray: false + property string loadQml: "" + + readonly property string help: `Usage: ${Qt.application.name} [options] + + Options: + -t, --start-in-tray Start in the system tray, without a visible window + -l, --load-qml PATH Override the file to be loaded as src/gui/UI.qml + -V, --version Show the application's version and exit + -h, --help Show this help and exit + + Environment variables: + MIRAGE_CONFIG_DIR Override the default configuration folder + MIRAGE_DATA_DIR Override the default application data folder + MIRAGE_CACHE_DIR Override the default cache and downloads folder + ` + + readonly property bool ready: { + const passedArguments = Qt.application.arguments.slice(1) + + while (passedArguments.length) { + switch (passedArguments.shift()) { + case "-h": + case "--help": + print("\n\n" + help.replace(/^ {4}/gm, "")) + Qt.quit() + break + + case "-v": + case "--version": + print(Qt.application.version) + Qt.quit() + break + + case "-t": + case "--start-in-tray": + startInTray = true + break + + case "-l": + case "--load-qml": + loadQml = passedArguments.shift() + break + } + } + + return true + } +} diff --git a/src/gui/Window.qml b/src/gui/Window.qml index 9370d7b4..f96b47c4 100644 --- a/src/gui/Window.qml +++ b/src/gui/Window.qml @@ -3,6 +3,7 @@ import QtQuick 2.12 import QtQuick.Controls 2.12 +import "." import "Base" import "PythonBridge" @@ -97,7 +98,7 @@ ApplicationWindow { minimumHeight: theme ? theme.minimumSupportedHeight : 120 width: Math.min(screen.width, 1152) height: Math.min(screen.height, 768) - visible: true + visible: ArgumentParser.ready && ! ArgumentParser.startInTray color: "transparent" onClosing: { @@ -121,7 +122,10 @@ ApplicationWindow { anchors.fill: parent focus: true scale: py.ready ? 1 : 0.5 - source: py.ready ? (Qt.application.arguments[1] || "UI.qml") : "" + source: + ArgumentParser.ready && py.ready ? + (ArgumentParser.loadQml || "UI.qml") : + "" Behavior on scale { HNumberAnimation { overshoot: 3; factor: 1.2 } } } diff --git a/src/gui/qmldir b/src/gui/qmldir index c46000b8..cfa35aef 100644 --- a/src/gui/qmldir +++ b/src/gui/qmldir @@ -1 +1,2 @@ singleton ModelStore 0.1 ModelStore.qml +singleton ArgumentParser 0.1 ArgumentParser.qml diff --git a/src/main.cpp b/src/main.cpp index d9362b76..76360595 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -186,7 +186,9 @@ int main(int argc, char *argv[]) { QQmlContext *objectContext = new QQmlContext(engine.rootContext()); // To able to use Qt.quit() from QML side - QObject::connect(&engine, &QQmlEngine::quit, &QApplication::quit); + QObject::connect( + &engine, &QQmlEngine::quit, &app, &QApplication::quit, Qt::QueuedConnection + ); // Set the debugMode properties depending of if we're running in debug mode // or not (`qmake CONFIG+=dev ...`, default in autoreload.py)