Skip to content

Commit

Permalink
fix: store IPC file in application directory (#5226)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz authored Mar 3, 2024
1 parent 3c13e0c commit 449c539
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- Minor: Allow theming of tab live and rerun indicators. (#5188)
- Minor: Added a fallback theme field to custom themes that will be used in case the custom theme does not contain a color Chatterino needs. If no fallback theme is specified, we'll pull the color from the included Dark or Light theme. (#5198)
- Minor: Image links now reflect the scale of their image instead of an internal label. (#5201)
- Minor: IPC files are now stored in the Chatterino directory instead of system directories on Windows. (#5226)
- Minor: 7TV emotes now have a 4x image rather than a 3x image. (#5209)
- Bugfix: Fixed an issue where certain emojis did not send to Twitch chat correctly. (#4840)
- Bugfix: Fixed capitalized channel names in log inclusion list not being logged. (#4848)
Expand Down
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "singletons/Settings.hpp"
#include "singletons/Updates.hpp"
#include "util/AttachToConsole.hpp"
#include "util/IpcQueue.hpp"

#include <QApplication>
#include <QCommandLineParser>
Expand Down Expand Up @@ -62,6 +63,7 @@ int main(int argc, char **argv)
box.exec();
return 1;
}
ipc::initPaths(paths.get());

const Args args(a, *paths);

Expand Down
7 changes: 7 additions & 0 deletions src/singletons/Paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ void Paths::initSubDirectories()
this->pluginsDirectory = makePath("Plugins");
this->themesDirectory = makePath("Themes");
this->crashdumpDirectory = makePath("Crashes");
#ifdef Q_OS_WIN
this->ipcDirectory = makePath("IPC");
#else
// NOTE: We do *NOT* use IPC on non-Windows platforms.
// If we start, we should re-consider this directory.
this->ipcDirectory = "/tmp";
#endif
}

} // namespace chatterino
5 changes: 5 additions & 0 deletions src/singletons/Paths.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class Paths
// Custom themes live here. <appDataDirectory>/Themes
QString themesDirectory;

// Directory for shared memory files.
// <appDataDirectory>/IPC on Windows
// /tmp elsewhere
QString ipcDirectory;

bool createFolder(const QString &folderPath);
[[deprecated("use Modes::instance().portable instead")]] bool isPortable()
const;
Expand Down
43 changes: 43 additions & 0 deletions src/util/IpcQueue.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,59 @@
#include "util/IpcQueue.hpp"

#include "common/QLogging.hpp"
#include "singletons/Paths.hpp"

#define BOOST_INTERPROCESS_SHARED_DIR_FUNC
#include <boost/interprocess/ipc/message_queue.hpp>
#include <QByteArray>
#include <QString>
#include <QtGlobal>

namespace boost_ipc = boost::interprocess;

namespace {

static const chatterino::Paths *PATHS = nullptr;

} // namespace

namespace boost::interprocess::ipcdetail {

void get_shared_dir(std::string &shared_dir)
{
if (!PATHS)
{
assert(false && "PATHS not set");
qCCritical(chatterinoNativeMessage)
<< "PATHS not set for shared directory";
return;
}
shared_dir = PATHS->ipcDirectory.toStdString();
}

#ifdef BOOST_INTERPROCESS_WINDOWS
void get_shared_dir(std::wstring &shared_dir)
{
if (!PATHS)
{
assert(false && "PATHS not set");
qCCritical(chatterinoNativeMessage)
<< "PATHS not set for shared directory";
return;
}
shared_dir = PATHS->ipcDirectory.toStdWString();
}
#endif

} // namespace boost::interprocess::ipcdetail

namespace chatterino::ipc {

void initPaths(const Paths *paths)
{
PATHS = paths;
}

void sendMessage(const char *name, const QByteArray &data)
{
try
Expand Down
8 changes: 8 additions & 0 deletions src/util/IpcQueue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@
class QByteArray;
class QString;

namespace chatterino {

class Paths;

} // namespace chatterino

namespace chatterino::ipc {

void initPaths(const Paths *paths);

void sendMessage(const char *name, const QByteArray &data);

class IpcQueuePrivate;
Expand Down

0 comments on commit 449c539

Please sign in to comment.