Skip to content

Commit 6b9cc9e

Browse files
committed
Use native user temporary directory path for the browser socket in macOS
1 parent ce28e2a commit 6b9cc9e

6 files changed

Lines changed: 33 additions & 8 deletions

File tree

src/browser/BrowserShared.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020 KeePassXC Team <team@keepassxc.org>
2+
* Copyright (C) 2026 KeePassXC Team <team@keepassxc.org>
33
*
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -24,6 +24,9 @@
2424
#if defined(KEEPASSXC_DIST_SNAP)
2525
#include <QProcessEnvironment>
2626
#endif
27+
#if defined(Q_OS_MACOS)
28+
#include "gui/osutils/macutils/MacUtils.h"
29+
#endif
2730

2831
namespace BrowserShared
2932
{
@@ -53,7 +56,11 @@ namespace BrowserShared
5356
#elif defined(Q_OS_WIN)
5457
// Windows uses named pipes
5558
return serverName + "_" + qgetenv("USERNAME");
56-
#else // Q_OS_MACOS and others
59+
#elif defined(Q_OS_MACOS)
60+
// In macOS QStandardPaths::TempLocation can be overridden with $TMPDIR. Use the location provided by the OS.
61+
// Otherwise the socket will be created to incorrect path, and connection with the browser extension breaks.
62+
return macUtils()->getTemporaryDirectory() + serverName;
63+
#else
5764
return QStandardPaths::writableLocation(QStandardPaths::TempLocation) + serverName;
5865
#endif
5966
}

src/gui/osutils/macutils/AppKit.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
2+
* Copyright (C) 2026 KeePassXC Team <team@keepassxc.org>
33
* Copyright (C) 2016 Lennart Glauer <mail@lennart-glauer.de>
44
*
55
* This program is free software: you can redistribute it and/or modify
@@ -48,6 +48,7 @@ class AppKit : public QObject
4848
void toggleForegroundApp(bool foreground);
4949
void setWindowSecurity(QWindow* window, bool state);
5050
void configureWindowAndHelpMenus(QMainWindow* mainWindow, QMenu* helpMenu);
51+
NSString* getTemporaryDirectory();
5152

5253
signals:
5354
void userSwitched();

src/gui/osutils/macutils/AppKitImpl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2+
* Copyright (C) 2026 KeePassXC Team <team@keepassxc.org>
23
* Copyright (C) 2016 Lennart Glauer <mail@lennart-glauer.de>
3-
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -43,5 +43,6 @@
4343
- (void) toggleForegroundApp:(bool) foreground;
4444
- (void) setWindowSecurity:(NSWindow*) window state:(bool) state;
4545
- (void) configureWindowAndHelpMenus:(QMainWindow*) mainWindow helpMenu:(QMenu*) helpMenu;
46+
- (NSString*) getTemporaryDirectory;
4647

4748
@end

src/gui/osutils/macutils/AppKitImpl.mm

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024 KeePassXC Team <team@keepassxc.org>
2+
* Copyright (C) 2026 KeePassXC Team <team@keepassxc.org>
33
* Copyright (C) 2016 Lennart Glauer <mail@lennart-glauer.de>
44
*
55
* This program is free software: you can redistribute it and/or modify
@@ -253,6 +253,11 @@ - (void) configureWindowAndHelpMenus:(QMainWindow*) mainWindow helpMenu:(QMenu*)
253253
NSApp.helpMenu = helpMenu->toNSMenu();
254254
}
255255

256+
- (NSString*) getTemporaryDirectory
257+
{
258+
return NSTemporaryDirectory();
259+
}
260+
256261
@end
257262

258263

@@ -314,6 +319,10 @@ - (void) configureWindowAndHelpMenus:(QMainWindow*) mainWindow helpMenu:(QMenu*)
314319
return [static_cast<id>(self) isStatusBarDark];
315320
}
316321

322+
NSString* AppKit::getTemporaryDirectory()
323+
{
324+
return [static_cast<id>(self) getTemporaryDirectory];
325+
}
317326

318327
bool AppKit::enableAccessibility()
319328
{

src/gui/osutils/macutils/MacUtils.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2023 KeePassXC Team <team@keepassxc.org>
2+
* Copyright (C) 2026 KeePassXC Team <team@keepassxc.org>
33
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
44
*
55
* This program is free software: you can redistribute it and/or modify
@@ -20,11 +20,11 @@
2020
#include <QApplication>
2121
#include <QDir>
2222
#include <QFile>
23+
#include <QMenu>
2324
#include <QSettings>
2425
#include <QStandardPaths>
2526
#include <QTimer>
2627
#include <QWindow>
27-
#include <QMenu>
2828

2929
#include <ApplicationServices/ApplicationServices.h>
3030

@@ -103,6 +103,12 @@ bool MacUtils::enableScreenRecording()
103103
return m_appkit->enableScreenRecording();
104104
}
105105

106+
QString MacUtils::getTemporaryDirectory()
107+
{
108+
const auto temporaryDirectory = m_appkit->getTemporaryDirectory();
109+
return QString::fromNSString(temporaryDirectory);
110+
}
111+
106112
bool MacUtils::isDarkMode() const
107113
{
108114
return m_appkit->isDarkMode();

src/gui/osutils/macutils/MacUtils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2025 KeePassXC Team <team@keepassxc.org>
2+
* Copyright (C) 2026 KeePassXC Team <team@keepassxc.org>
33
* Copyright (C) 2012 Felix Geyer <debfx@fobos.de>
44
*
55
* This program is free software: you can redistribute it and/or modify
@@ -51,6 +51,7 @@ class MacUtils : public OSUtilsBase
5151
bool isHidden();
5252
bool enableAccessibility();
5353
bool enableScreenRecording();
54+
QString getTemporaryDirectory();
5455
void toggleForegroundApp(bool foreground);
5556

5657
void registerNativeEventFilter() override;

0 commit comments

Comments
 (0)