From e8c47e0fd81152e2ce8a2a9bef2a6e108628b42d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=AD=90=E6=A5=9A=5Czhuzi?= Date: Sat, 13 Apr 2024 21:30:23 +0800 Subject: [PATCH] update --- example/qml/page/T_Theme.qml | 2 +- src/FluTheme.cpp | 19 ++++++++++++------- src/FluTheme.h | 2 ++ src/FluTools.cpp | 12 ++++++++++++ 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/example/qml/page/T_Theme.qml b/example/qml/page/T_Theme.qml index 308c1e92..fbd255e6 100644 --- a/example/qml/page/T_Theme.qml +++ b/example/qml/page/T_Theme.qml @@ -13,7 +13,7 @@ FluScrollablePage{ FluFrame{ Layout.fillWidth: true - Layout.preferredHeight: 400 + Layout.preferredHeight: 420 padding: 10 ColumnLayout{ diff --git a/src/FluTheme.cpp b/src/FluTheme.cpp index 6ac16cb3..d28b7e90 100644 --- a/src/FluTheme.cpp +++ b/src/FluTheme.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "Def.h" #include "FluentIconDef.h" #include "FluColors.h" @@ -91,14 +92,18 @@ bool FluTheme::dark() const { } void FluTheme::updateDesktopImage(){ - auto path = FluTools::getInstance()->getWallpaperFilePath(); - if(_desktopImagePath != path){ - if(!_desktopImagePath.isEmpty()){ - _watcher.removePath(_desktopImagePath); + QThreadPool::globalInstance()->start([=]() { + _mutex.lock(); + auto path = FluTools::getInstance()->getWallpaperFilePath(); + if(_desktopImagePath != path){ + if(!_desktopImagePath.isEmpty()){ + _watcher.removePath(_desktopImagePath); + } + desktopImagePath(path); + _watcher.addPath(path); } - desktopImagePath(path); - _watcher.addPath(path); - } + _mutex.unlock(); + }); } void FluTheme::timerEvent(QTimerEvent *event) diff --git a/src/FluTheme.h b/src/FluTheme.h index 2d95a39b..a0f98814 100644 --- a/src/FluTheme.h +++ b/src/FluTheme.h @@ -8,6 +8,7 @@ #include #include #include +#include #include "FluAccentColor.h" #include "stdafx.h" #include "singleton.h" @@ -70,6 +71,7 @@ SINGLETON(FluTheme) private: bool _systemDark; QFileSystemWatcher _watcher; + QMutex _mutex; }; #endif // FLUTHEME_H diff --git a/src/FluTools.cpp b/src/FluTools.cpp index d6a8f680..bae664c3 100644 --- a/src/FluTools.cpp +++ b/src/FluTools.cpp @@ -281,6 +281,18 @@ QString FluTools::getWallpaperFilePath() { return path; } } +#elif defined(Q_OS_MACOS) + QProcess process; + QStringList args; + args << "-e"; + args << R"(tell application "Finder" to get POSIX path of (desktop picture as alias))"; + process.start("osascript", args); + process.waitForFinished(); + QByteArray result = process.readAllStandardOutput().trimmed(); + if(result.isEmpty()){ + return "/System/Library/CoreServices/DefaultDesktop.heic"; + } + return result; #else return {}; #endif