diff --git a/package.json b/package.json index 47e0af8..4dd468e 100644 --- a/package.json +++ b/package.json @@ -185,6 +185,7 @@ "bufferutil": "^4.0.1", "clipboardy": "^2.1.0", "discord-rpc": "discordjs/RPC", + "register-scheme": "devsnek/node-register-scheme", "utf-8-validate": "^5.0.2", "vsls": "^0.3.1291" }, diff --git a/src/extension.ts b/src/extension.ts index d393129..ed33067 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -2,6 +2,7 @@ import { commands, ExtensionContext, StatusBarAlignment, StatusBarItem, window, import RPCClient from './client/RPCClient'; import Logger from './structures/Logger'; import { GitExtension } from './git'; +const { register } = require('discord-rpc'); // eslint-disable-line const sleep = (wait: number) => new Promise(resolve => setTimeout(resolve, wait)); let loginTimeout: NodeJS.Timer; @@ -10,6 +11,7 @@ const statusBarIcon: StatusBarItem = window.createStatusBarItem(StatusBarAlignme statusBarIcon.text = '$(pulse) Connecting to Discord...'; const config = workspace.getConfiguration('discord'); +register(config.get('clientID')!); const rpc = new RPCClient(config.get('clientID')!, statusBarIcon); export async function activate(context: ExtensionContext) { @@ -41,22 +43,6 @@ export async function activate(context: ExtensionContext) { } } - if (!isWorkspaceExcluded && config.get('enabled')) { - statusBarIcon.show(); - try { - await rpc.login(); - } catch (error) { - Logger.log(`Encountered following error after trying to login:\n${error}`); - await rpc.dispose(); - if (!config.get('silent')) { - if (error.message.includes('ENOENT')) window.showErrorMessage('No Discord Client detected!'); - else window.showErrorMessage(`Couldn't connect to Discord via RPC: ${error.toString()}`); - } - rpc.statusBarIcon.text = '$(pulse) Reconnect to Discord'; - rpc.statusBarIcon.command = 'discord.reconnect'; - } - } - const enabler = commands.registerCommand('discord.enable', async () => { await rpc.dispose(); config.update('enabled', true); @@ -118,6 +104,22 @@ export async function activate(context: ExtensionContext) { allowJoinRequests, disableJoinRequests, ); + + if (!isWorkspaceExcluded && config.get('enabled')) { + statusBarIcon.show(); + try { + await rpc.login(); + } catch (error) { + Logger.log(`Encountered following error after trying to login:\n${error}`); + await rpc.dispose(); + if (!config.get('silent')) { + if (error.message.includes('ENOENT')) window.showErrorMessage('No Discord Client detected!'); + else window.showErrorMessage(`Couldn't connect to Discord via RPC: ${error.toString()}`); + } + rpc.statusBarIcon.text = '$(pulse) Reconnect to Discord'; + rpc.statusBarIcon.command = 'discord.reconnect'; + } + } } export async function deactivate() { diff --git a/yarn.lock b/yarn.lock index 544702b..095c80e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -588,6 +588,13 @@ binary-extensions@^1.0.0: resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.13.1.tgz#598afe54755b2868a5330d2aff9d4ebb53209b65" integrity sha512-Un7MIEDdUC5gNpcGDV97op1Ywk748MpHcFTHoYs6qnj1Z3j7I53VG3nwZhKzoBZmbdRNnb6WRdFlwl7tSDuZGw== +bindings@^1.3.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df" + integrity sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ== + dependencies: + file-uri-to-path "1.0.0" + bluebird@^3.5.5: version "3.7.1" resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.1.tgz#df70e302b471d7473489acf26a93d63b53f874de" @@ -1641,6 +1648,11 @@ file-entry-cache@^5.0.1: dependencies: flat-cache "^2.0.1" +file-uri-to-path@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd" + integrity sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw== + fill-range@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-4.0.0.tgz#d544811d428f98eb06a63dc402d2403c328c38f7" @@ -2937,6 +2949,11 @@ nice-try@^1.0.4: resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366" integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ== +node-addon-api@^1.3.0: + version "1.7.1" + resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-1.7.1.tgz#cf813cd69bb8d9100f6bdca6755fc268f54ac492" + integrity sha512-2+DuKodWvwRTrCfKOeR24KIc5unKjOh8mz17NCzVnHWfjAdDqbfbjqh7gUT+BkXBRQM52+xCHciKWonJ3CbJMQ== + node-fetch@2.6.0: version "2.6.0" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd" @@ -3653,6 +3670,13 @@ regexpp@^2.0.1: resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-2.0.1.tgz#8d19d31cf632482b589049f8281f93dbcba4d07f" integrity sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw== +register-scheme@devsnek/node-register-scheme: + version "0.0.2" + resolved "https://codeload.github.com/devsnek/node-register-scheme/tar.gz/e7cc9a63a1f512565da44cb57316d9fb10750e17" + dependencies: + bindings "^1.3.0" + node-addon-api "^1.3.0" + remark-math@1.0.6: version "1.0.6" resolved "https://registry.yarnpkg.com/remark-math/-/remark-math-1.0.6.tgz#49eb3dd15d298734c9ae21673115389793af4d1b"