From 9ee4b14aa22bfb35e3764131376030e2bfa79294 Mon Sep 17 00:00:00 2001 From: vslg Date: Fri, 4 Sep 2020 17:26:01 -0300 Subject: [PATCH] Add watcher for .show file in config directory Draw attention when the .show file is created. It is created when attempting to open another instance of Mirage with the same configuration. --- src/gui/Window.qml | 20 +++++++++++++++++++- src/main.cpp | 23 +++++++++++++---------- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/gui/Window.qml b/src/gui/Window.qml index 66df915c..3887b98c 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 Qt.labs.platform 1.1 +import Qt.labs.folderlistmodel 2.12 import "Base" import "PythonBridge" @@ -23,7 +24,7 @@ ApplicationWindow { property var uiState: ({}) property var history: ({}) property var theme: null - property bool closing: false + property string configDir readonly property var visibleMenus: ({}) readonly property var visiblePopups: ({}) @@ -142,4 +143,21 @@ ApplicationWindow { } } } + + FolderListModel { + id: showUpWatcher + folder: window.configDir + showDirs: false + showHidden: true + nameFilters: [".show"] + + onCountChanged: { + if (count) { + window.drawAttention() + py.importModule("os", () => { + py.call("os.remove", [get(0, "filePath")]) + }) + } + } + } } diff --git a/src/main.cpp b/src/main.cpp index fddfbeaa..12edee29 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -93,14 +93,9 @@ void onExitSignal(int signum) { } -bool setLockFile() { - QString customConfigDir(qEnvironmentVariable("MIRAGE_CONFIG_DIR")); - QDir configDir( - customConfigDir.isEmpty() ? - QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) - + "/" + QCoreApplication::applicationName() : - customConfigDir - ); +bool setLockFile(QString configPath) { + + QDir configDir(configPath); if (! configDir.mkpath(".")) { qFatal("Could not create config file."); @@ -139,7 +134,15 @@ int main(int argc, char *argv[]) { QApplication::setApplicationVersion("0.6.2"); QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - if (! setLockFile()) return EXIT_SUCCESS; + QString customConfigDir(qEnvironmentVariable("MIRAGE_CONFIG_DIR")); + QString configDir( + customConfigDir.isEmpty() ? + QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + + "/" + QCoreApplication::applicationName() : + customConfigDir + ); + + if (! setLockFile(configDir)) return EXIT_SUCCESS; QApplication app(argc, argv); // Register handlers for quit signals, e.g. SIGINT/Ctrl-C in unix terminals @@ -243,7 +246,7 @@ int main(int argc, char *argv[]) { app.exit(EXIT_FAILURE); } - component.create(objectContext); + component.create(objectContext)->setProperty("configDir", configDir); // Finally, execute the app. Return its exit code after clearing the lock. int exit_code = app.exec();