From 154b8fc5a431aca9d6ce24d1ba4014a21c1145e8 Mon Sep 17 00:00:00 2001 From: Andrew Kwon Date: Wed, 5 May 2021 23:18:04 -0700 Subject: [PATCH] Skip Discord events if IPC socket is nil - Update README - Improve logs when canceling activity --- README.md | 36 ++++++++++++++++++------------------ lua/presence/init.lua | 9 +++++++-- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 99f134a..d0caf1a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ presence.nvim​ -=== -Discord [Rich Presence](https://discord.com/rich-presence) plugin for Neovim +**[Features](#features)** | **[Installation](#installation)** | **[Configuration](#configuration)** | **[Troubleshooting](#troubleshooting)** | **[Contributing](#contributing)** + +> Discord [Rich Presence](https://discord.com/rich-presence) plugin for Neovim demo.gif @@ -19,12 +20,10 @@ Use your favorite plugin manager #### Notes * Requires [Neovim nightly](https://github.com/neovim/neovim/releases/tag/nightly) (0.5) -* Windows is partially supported - * Can update Rich Presence as expected - * Does not yet properly handle multiple running nvim instances +* Windows is [partially supported](https://github.com/andweeb/presence.nvim/projects/1#card-60537963), WSL is [not yet supported](https://github.com/andweeb/presence.nvim/projects/1#card-60537961) ## Configuration -Rich Presence works right out of the box after installation by default, so configuration is optional. For those that do want to override default behaviors, however, configuration options are available in both Lua and VimL. +Rich Presence works right out of the box after installation, so configuration is optional. For those that do want to override default behaviors, however, configuration options are available in either Lua or VimL. ### Lua Require the plugin and call `setup` with a config table with any of the following keys: @@ -56,16 +55,17 @@ let g:presence_log_level let g:presence_debounce_timeout = 15 ``` -## Contributing -Pull requests are very welcome, feel free to open an issue! Here some open todo items: -- [x] Manage workspace state across multiple nvim instances (e.g. tmux) -- [x] Set activity on other autocommands (`TextChanged`, `VimLeavePre`) -- [x] Use named pipes to support Windows -- [ ] Set idle activity (track using `CursorMoved`) -- [ ] Expose file assets table as a configurable option -- [ ] Fix peer-to-peer nvim instance communication in Windows -- [ ] Manage activity properly in buffers in windows and tabs -- [ ] Retry connection after initial setup or a closed pipe (i.e. after quitting Discord app) -- [ ] Attempt to connect to a range of pipes from `discord-ipc-0` to `discord-ipc-9` (see [note](https://github.com/discord/discord-rpc/blob/master/documentation/hard-mode.md#notes)) +## Troubleshooting +* Ensure that Discord is running +* Ensure that your Neovim version is on v0.5 +* Ensure Game Activity is enabled in your Discord settings +* Enable logging and inspect the logs after opening a buffer + * Set the `log_level` setup option or `g:presence_log_level` to `"debug"` + * Load a file and see the logs with `:messages` +* If there is a `Failed to get Discord IPC socket` error, your particular OS may not yet be supported + * Create a [new issue](https://github.com/andweeb/presence.nvim/issues/new) if one does not exist for your OS yet -Asset additions and changes are also welcome! Supported file types can be found in [`file_assets.lua`](lua/presence/file_assets.lua) and their assets can be found [in this folder](https://www.dropbox.com/sh/j8913f0gav3toeh/AADxjn0NuTprGFtv3Il1Pqz-a?dl=0). +## Contributing +Pull requests are very welcome, feel free to open an issue to work on any of the open [todo items](https://github.com/andweeb/presence.nvim/projects/1?add_cards_query=is%3Aopen)! + +Asset additions and changes are also welcome! Supported file types can be found in [`file_assets.lua`](lua/presence/file_assets.lua) and their referenced asset files can be found [in this folder](https://www.dropbox.com/sh/j8913f0gav3toeh/AADxjn0NuTprGFtv3Il1Pqz-a?dl=0). diff --git a/lua/presence/init.lua b/lua/presence/init.lua index 621fb67..bc0ae80 100644 --- a/lua/presence/init.lua +++ b/lua/presence/init.lua @@ -171,11 +171,11 @@ function Presence:cancel() self.discord:set_activity(nil, function(err) if err then - self.log:error("Failed to set nil activity in Discord: "..err) + self.log:error(string.format("Failed to cancel activity in Discord: %s", err)) return end - self.log:info("Sent nil activity to Discord") + self.log:info("Canceled Discord presence") end) end @@ -391,6 +391,11 @@ end -- Wrap calls to Discord that require prior connection and authorization function Presence.discord_event(on_ready) return function(self, ...) + if not self.discord.ipc_socket then + self.log:debug("Discord IPC socket not found, skipping...") + return + end + local args = {...} local callback = function() on_ready(self, unpack(args)) end