Skip to content

Commit

Permalink
Try fix MSVC build.
Browse files Browse the repository at this point in the history
Some minor improvements and fixes.
  • Loading branch information
SpartanJ committed Feb 11, 2025
1 parent 6652d90 commit 378a28a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
21 changes: 14 additions & 7 deletions src/tools/ecode/plugins/discordRPC/discordRPCplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,24 @@ void DiscordRPCplugin::load( PluginManager* pluginManager ) {

if ( getUISceneNode() ) {
mIPC.UIReady = true;
if ( mIPC.tryConnect() ) {
DiscordIPCActivity a = mIPC.getActivity();
a.largeImage = DISCORDRPC_DEFAULT_ICON;
mIPC.setActivity( std::move( a ) );
}
initIPC();
} else {
mIPC.IsReconnectScheduled = true;
}

mReady = true;
fireReadyCbs();
setReady( clock.getElapsedTime() );
}

void DiscordRPCplugin::initIPC() {
if ( mIPC.tryConnect() ) {
DiscordIPCActivity a = mIPC.getActivity();
a.largeImage = DISCORDRPC_DEFAULT_ICON;
mIPC.setActivity( std::move( a ) );
}
}

PluginRequestHandle DiscordRPCplugin::processMessage( const PluginMessage& msg ) {
switch ( msg.type ) {
case PluginMessageType::WorkspaceFolderChanged: {
Expand All @@ -123,7 +129,8 @@ PluginRequestHandle DiscordRPCplugin::processMessage( const PluginMessage& msg )

if ( mIPC.IsReconnectScheduled ) {
Log::debug( "Running scheduled reconnect" );
mIPC.tryConnect();

getUISceneNode()->getThreadPool()->run( [this] { initIPC(); } );
}
}
default:
Expand Down Expand Up @@ -153,7 +160,7 @@ void DiscordRPCplugin::onRegisterListeners( UICodeEditor* editor, std::vector<Ui
auto filename = doc.getFilename();

if ( filename != mLastFile ) {
this->mLastFile = filename;
mLastFile = filename;

Log::debug( "dcIPC: Activity in new file. lang = %s",
doc.getSyntaxDefinition().getLanguageName() );
Expand Down
2 changes: 2 additions & 0 deletions src/tools/ecode/plugins/discordRPC/discordRPCplugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class DiscordRPCplugin : public PluginBase {
virtual void onUnregisterEditor( UICodeEditor* editor ) override;

DiscordRPCplugin( PluginManager* pluginManager, bool sync );

void initIPC();
};

} // namespace ecode
Expand Down
12 changes: 8 additions & 4 deletions src/tools/ecode/plugins/discordRPC/sdk/ipc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ bool DiscordIPC::tryConnect() {
std::string ipcPath = basePath + "discord-ipc-" + std::to_string( i );

// Check if exists
DWORD attributes = GetFileAttributes( ipcPath.c_str() );
DWORD attributes = GetFileAttributesA( ipcPath.c_str() );
if ( attributes != INVALID_FILE_ATTRIBUTES ) {
Log::debug( "dcIPC: IPC path found! - %s", ipcPath );
mIpcPath = ipcPath;

mSocket = CreateFile( mIpcPath.c_str(), GENERIC_READ | GENERIC_WRITE, 0, nullptr,
OPEN_EXISTING, 0, nullptr );
mSocket = CreateFileA( mIpcPath.c_str(), GENERIC_READ | GENERIC_WRITE, 0, nullptr,
OPEN_EXISTING, 0, nullptr );

if ( mSocket != INVALID_HANDLE_VALUE ) {
doHandshake();
Expand Down Expand Up @@ -221,7 +221,11 @@ void DiscordIPC::setActivity( DiscordIPCActivity&& a ) {
} },
{ "nonce", "-" } };

mActivity = std::move( a );
{
Lock l( mActivityMutex );
mActivity = std::move( a );
}

sendPacket( DiscordIPCOpcodes::Frame, j );
}

Expand Down
4 changes: 4 additions & 0 deletions src/tools/ecode/plugins/discordRPC/sdk/ipc.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include <eepp/config.hpp>
#include <eepp/system/mutex.hpp>

#include <nlohmann/json.hpp>

using namespace EE::System;

// 2^8 = 256s ~4.3min
#define DISCORDIPC_BACKOFF_MAX 8

Expand Down Expand Up @@ -68,6 +71,7 @@ class DiscordIPC {
false; // Not quite a mutex because I want to lock any attempts if one is already waiting

DiscordIPCActivity mActivity;
Mutex mActivityMutex;

#if defined( EE_PLATFORM_POSIX )
int mSocket = -1;
Expand Down

0 comments on commit 378a28a

Please sign in to comment.