Implement icon setting; Fixed invalid json in config

This commit is contained in:
Bytequill
2025-02-11 19:42:50 +01:00
parent 6ef43968f6
commit fadb3b9879
4 changed files with 23 additions and 7 deletions

View File

@@ -66,7 +66,7 @@
"objective-c": "https://github.com/vyfor/icons/raw/master/icons/onyx/c.png",
"ocaml": "https://github.com/vyfor/icons/raw/master/icons/onyx/ocaml.png",
"odin": "https://github.com/vyfor/icons/raw/master/icons/onyx/odin.png",
"openscad": "https://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/Openscad.svg/1024px-Openscad.svg.png"
"openscad": "https://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/Openscad.svg/1024px-Openscad.svg.png",
"pascal": "https://github.com/vyfor/icons/raw/master/icons/onyx/pascal.png",
"perl": "https://github.com/vyfor/icons/raw/master/icons/onyx/perl.png",
"php": "https://github.com/vyfor/icons/raw/master/icons/onyx/php.png",
@@ -74,7 +74,7 @@
"plaintext": "https://github.com/vyfor/icons/raw/master/icons/onyx/text.png",
"po": "https://github.com/vyfor/icons/raw/master/icons/onyx/gnu.png",
"pony": "https://avatars.githubusercontent.com/u/12997238",
"postgresql": "https://upload.wikimedia.org/wikipedia/commons/thumb/2/29/Postgresql_elephant.svg/1024px-Postgresql_elephant.svg.png"
"postgresql": "https://upload.wikimedia.org/wikipedia/commons/thumb/2/29/Postgresql_elephant.svg/1024px-Postgresql_elephant.svg.png",
"powershell": "https://github.com/vyfor/icons/raw/master/icons/onyx/powershell.png",
"python": "https://github.com/vyfor/icons/raw/master/icons/onyx/python.png",
"r": "https://github.com/vyfor/icons/raw/master/icons/onyx/r.png",
@@ -103,7 +103,7 @@
"xml": "https://github.com/vyfor/icons/raw/master/icons/onyx/xml.png",
"xtend": "https://github.com/vyfor/icons/raw/master/icons/onyx/java.png",
"yaml": "https://github.com/vyfor/icons/raw/master/icons/onyx/yaml.png",
"zig": "https://github.com/vyfor/icons/raw/master/icons/onyx/zig.png",
"zig": "https://github.com/vyfor/icons/raw/master/icons/onyx/zig.png"
}
},
"keybindings" : {

View File

@@ -52,7 +52,7 @@ void DiscordRPCplugin::load( PluginManager* pluginManager ) {
if ( FileSystem::fileExists( path ) ||
FileSystem::fileWrite(path, "{\n \"config\":{},\n \"keybindings\":{}\n}\n") ) {
mConfigPath = path;
paths.emplace_back( path );
paths.emplace_back( path );
}
std::string data;
if ( !FileSystem::fileGet( path, data ) )
@@ -74,6 +74,7 @@ void DiscordRPCplugin::load( PluginManager* pluginManager ) {
if ( j.contains( "config" ) ) {
auto& config = j["config"];
mcLangBindings = config["iconBindings"];
if ( config.contains( "appID" ) ) {
mIPC.mcClientID = config.value( "appID", "1335730393948749898" );
} else {
@@ -93,7 +94,7 @@ void DiscordRPCplugin::load( PluginManager* pluginManager ) {
mIPC.tryConnect();
DiscordIPCActivity* a = mIPC.getActivity();
a->largeImage = "https://github.com/SpartanJ/eepp/blob/develop/bin/assets/icon/ecode.png?raw=true";
a->largeImage = DISCORDRPC_DEFAULT_ICON;
mIPC.setActivity(*a);
@@ -125,6 +126,12 @@ PluginRequestHandle DiscordRPCplugin::processMessage( const PluginMessage& msg )
return PluginRequestHandle::empty();
}
void DiscordRPCplugin::onRegisterDocument( TextDocument* doc ){
doc->setCommand( "discordrpc-reconnect", [this] {
mIPC.reconnect();
} );
}
void DiscordRPCplugin::onRegisterListeners( UICodeEditor* editor, std::vector<Uint32>& listeners ) {
listeners.push_back( editor->on( Event::OnFocus, [this, editor]( const Event* ) {
// `this` in the scope of the lambda is the parent `DiscordRPCplugin`
@@ -137,7 +144,7 @@ void DiscordRPCplugin::onRegisterListeners( UICodeEditor* editor, std::vector<Ui
if ( filename != mLastFile ) {
this->mLastFile = filename;
Log::debug( "Activity in new file. lang = %s",
Log::debug( "dcIPC: Activity in new file. lang = %s",
doc.getSyntaxDefinition().getLanguageName() );
DiscordIPCActivity* a = this->mIPC.getActivity();
@@ -148,6 +155,11 @@ void DiscordRPCplugin::onRegisterListeners( UICodeEditor* editor, std::vector<Ui
a->state = String::format(i18n( "dc_editing", "Editing %s, a %s file" ).toUtf8(),
filename, doc.getSyntaxDefinition().getLanguageName() );
a->start = time( nullptr ); // Time spent in this specific file
std::string name = doc.getSyntaxDefinition().getLSPName();
if (!name.empty()) {
a->largeImage = mcLangBindings.value(name, DISCORDRPC_DEFAULT_ICON);
}
this->mIPC.setActivity( *a );
}

View File

@@ -18,6 +18,7 @@ using namespace EE::System;
using namespace EE::UI;
using namespace EE::UI::Doc;
#define DISCORDRPC_DEFAULT_ICON "https://github.com/SpartanJ/eepp/blob/develop/bin/assets/icon/ecode.png?raw=true"
namespace ecode {
@@ -49,12 +50,15 @@ class DiscordRPCplugin : public PluginBase {
DiscordIPC mIPC;
std::string mLastFile;
std::string mProjectName;
nlohmann::json mcLangBindings;
void load ( PluginManager* pluginManager );
PluginRequestHandle processMessage( const PluginMessage& msg );
virtual void onRegisterListeners(UICodeEditor* editor, std::vector<Uint32>& listeners ) override;
virtual void onRegisterDocument( TextDocument* doc ) override;
DiscordRPCplugin( PluginManager* pluginManager, bool sync );
};

View File

@@ -50,6 +50,7 @@ class DiscordIPC {
// false - FileNotFound/OSNotSupported
// true - Success
bool tryConnect();
void reconnect();
void setActivity( DiscordIPCActivity a );
DiscordIPCActivity *getActivity() { return &mActivity; }
@@ -77,7 +78,6 @@ class DiscordIPC {
#endif
void doHandshake();
void reconnect();
void sendPacket( DiscordIPCOpcodes opcode, nlohmann::json j );
};