fix(macos): check quicklook registration state before registering
This commit is contained in:
@@ -1804,11 +1804,12 @@ void MainWindow::delayedStartup()
|
||||
#ifdef Q_OS_MAC
|
||||
void MainWindow::registerQuickLookExtensions()
|
||||
{
|
||||
// Check if we've already registered extensions to avoid repeated registration
|
||||
static bool quickLookRegistered = false;
|
||||
if (quickLookRegistered) {
|
||||
// Only check once per session
|
||||
static bool quickLookChecked = false;
|
||||
if (quickLookChecked) {
|
||||
return;
|
||||
}
|
||||
quickLookChecked = true;
|
||||
|
||||
// Get the path to FreeCAD.app/Contents/PlugIns
|
||||
QString appPath = QApplication::applicationDirPath();
|
||||
@@ -1818,26 +1819,39 @@ void MainWindow::registerQuickLookExtensions()
|
||||
QString previewExt = plugInsPath + "/FreeCADPreviewExtension.appex";
|
||||
|
||||
// Check if extensions exist before attempting registration
|
||||
if (QFileInfo::exists(thumbnailExt) && QFileInfo::exists(previewExt)) {
|
||||
// Register extensions with pluginkit
|
||||
QProcess::execute("pluginkit", QStringList() << "-a" << thumbnailExt);
|
||||
QProcess::execute("pluginkit", QStringList() << "-a" << previewExt);
|
||||
|
||||
// Activate extensions
|
||||
QProcess::execute(
|
||||
"pluginkit",
|
||||
QStringList() << "-e" << "use" << "-i" << "org.freecad.FreeCAD.quicklook.thumbnail"
|
||||
);
|
||||
QProcess::execute(
|
||||
"pluginkit",
|
||||
QStringList() << "-e" << "use" << "-i" << "org.freecad.FreeCAD.quicklook.preview"
|
||||
);
|
||||
|
||||
quickLookRegistered = true;
|
||||
|
||||
// Optional: Log successful registration (will appear in system notification)
|
||||
Base::Console().log("QuickLook extensions registered successfully\n");
|
||||
if (!QFileInfo::exists(thumbnailExt) || !QFileInfo::exists(previewExt)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if extensions are already registered with pluginkit
|
||||
QProcess checkProcess;
|
||||
checkProcess.start("pluginkit", QStringList() << "-m");
|
||||
checkProcess.waitForFinished();
|
||||
QString registeredPlugins = QString::fromUtf8(checkProcess.readAllStandardOutput());
|
||||
|
||||
const QString thumbnailId = QStringLiteral("org.freecad.FreeCAD.quicklook.thumbnail");
|
||||
const QString previewId = QStringLiteral("org.freecad.FreeCAD.quicklook.preview");
|
||||
|
||||
bool thumbnailRegistered = registeredPlugins.contains(thumbnailId);
|
||||
bool previewRegistered = registeredPlugins.contains(previewId);
|
||||
|
||||
if (thumbnailRegistered && previewRegistered) {
|
||||
Base::Console().log("QuickLook extensions already registered\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Register and activate only the extensions that are not yet registered
|
||||
if (!thumbnailRegistered) {
|
||||
QProcess::execute("pluginkit", QStringList() << "-a" << thumbnailExt);
|
||||
QProcess::execute("pluginkit", QStringList() << "-e" << "use" << "-i" << thumbnailId);
|
||||
}
|
||||
|
||||
if (!previewRegistered) {
|
||||
QProcess::execute("pluginkit", QStringList() << "-a" << previewExt);
|
||||
QProcess::execute("pluginkit", QStringList() << "-e" << "use" << "-i" << previewId);
|
||||
}
|
||||
|
||||
Base::Console().log("QuickLook extensions registered successfully\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user