Add CLI arguments parsing + --start-in-tray
- Loading a QML file in place of src/gui/UI.qml is now possible via -l / --load-qml instead of taking the first positional argument - New option to start application in tray without showing a window - --help and --version
This commit is contained in:
parent
50d4aae188
commit
fda5bc0039
|
@ -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."""
|
||||
|
||||
|
|
57
src/gui/ArgumentParser.qml
Normal file
57
src/gui/ArgumentParser.qml
Normal file
|
@ -0,0 +1,57 @@
|
|||
// Copyright Mirage authors & contributors <https://github.com/mirukana/mirage>
|
||||
// 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
|
||||
}
|
||||
}
|
|
@ -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 } }
|
||||
}
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
singleton ModelStore 0.1 ModelStore.qml
|
||||
singleton ArgumentParser 0.1 ArgumentParser.qml
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user