diff --git a/package.json b/package.json index 1013553..9598c86 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "premid", "productName": "PreMiD", - "description": "Discord Rich Presence for websites.", - "version": "2.1.1", + "description": "Discord Rich Presence for web services.", + "version": "2.1.2", "repository": "https://github.com/PreMiD/PreMiD", "scripts": { "init": "tsc --skipLibCheck && tsc pkg util/prepare util/zip && devScript --copyOnly", @@ -25,7 +25,7 @@ "@types/request-promise-native": "1.0.17", "@types/rimraf": "2.0.3", "@types/socket.io": "2.1.4", - "@types/ssh2-sftp-client": "4.1.2", + "@types/ssh2-sftp-client": "4.1.3", "@types/unzipper": "^0.10.1", "archiver": "3.1.1", "chalk": "3.0.0", @@ -39,8 +39,8 @@ "rimraf": "3.0.1", "ssh2-sftp-client": "5.0.2", "typescript": "3.7.5", - "unzipper": "0.10.7", - "yarn": "1.21.1" + "unzipper": "0.10.8", + "yarn": "1.22.0" }, "dependencies": { "auto-launch": "5.0.5", diff --git a/src/managers/discordManager.ts b/src/managers/discordManager.ts index f450866..5752a6a 100644 --- a/src/managers/discordManager.ts +++ b/src/managers/discordManager.ts @@ -26,12 +26,18 @@ class RPCClient { this.clientReady = true; this.setActivity(); }); - // @ts-ignore - this.client.once("disconnected", this.destroy); + this.client.once( + // @ts-ignore + "disconnected", + () => + (rpcClients = rpcClients.filter( + client => client.clientId !== this.clientId + )) + ); - this.client.login({ clientId: this.clientId }).catch(this.destroy); + this.client.login({ clientId: this.clientId }).catch(() => this.destroy()); - console.log("Create client"); + info(`Create RPC client (${this.clientId})`); } setActivity(presenceData?: PresenceData) { @@ -42,7 +48,9 @@ class RPCClient { if (presenceData.trayTitle) trayManager.tray.setTitle(presenceData.trayTitle); - this.client.setActivity(presenceData.presenceData).catch(this.destroy); + this.client + .setActivity(presenceData.presenceData) + .catch(() => this.destroy()); info("setActivity"); } @@ -51,15 +59,21 @@ class RPCClient { if (!this.clientReady) return; - this.client.clearActivity().catch(this.destroy); + this.client.clearActivity().catch(() => this.destroy()); trayManager.tray.setTitle(""); } - destroy() { - console.log("Destroy client", this.clientId); - if (this.client) this.client.destroy().catch(() => {}); - rpcClients = rpcClients.filter(client => client.clientId !== this.clientId); - trayManager.tray.setTitle(""); + async destroy() { + try { + info(`Destroy RPC client (${this.clientId})`); + this.client.clearActivity(); + this.client.destroy(); + + trayManager.tray.setTitle(""); + rpcClients = rpcClients.filter( + client => client.clientId !== this.clientId + ); + } catch (err) {} } } @@ -86,9 +100,7 @@ export function clearActivity(clientId: string = undefined) { if (clientId) { let client = rpcClients.find(c => c.clientId === clientId); client.clearActivity(); - } else { - rpcClients.forEach(c => c.clearActivity()); - } + } else rpcClients.forEach(c => c.clearActivity()); } export async function getDiscordUser() { @@ -98,6 +110,7 @@ export async function getDiscordUser() { return user.user; } -app.once("will-quit", () => { - rpcClients.map(c => c.destroy()); -}); +app.once( + "will-quit", + async () => await Promise.all(rpcClients.map(c => c.destroy())) +); diff --git a/src/managers/launchManager.ts b/src/managers/launchManager.ts index a6d6f31..f34eb78 100644 --- a/src/managers/launchManager.ts +++ b/src/managers/launchManager.ts @@ -5,25 +5,25 @@ import { info } from "../util/debug"; //* Create autoLaunch object let autoLaunch = new AutoLaunch({ - name: app.name, - isHidden: true + name: app.name, + isHidden: true }); /** * Updates autoLaunch */ export async function update() { - //* If app not packaged return - //* Either enable/disable autolaunch - if (!app.isPackaged) { - //* Show debug - //* Return - info("Skipping autoLaunch."); - return; - } - if (settings.get("autoLaunch", true)) - //* Enable if not enabled - autoLaunch.enable(); - //* Disable if enabled - else autoLaunch.disable(); + //* If app not packaged return + //* Either enable/disable autolaunch + if (!app.isPackaged) { + //* Show debug + //* Return + info("Skipping autoLaunch."); + return; + } + if (settings.get("autoLaunch", true)) + //* Enable if not enabled + autoLaunch.enable(); + //* Disable if enabled + else autoLaunch.disable(); } diff --git a/src/managers/presenceDevManager.ts b/src/managers/presenceDevManager.ts index 72920ca..9ddabe3 100644 --- a/src/managers/presenceDevManager.ts +++ b/src/managers/presenceDevManager.ts @@ -1,4 +1,4 @@ -import { readdirSync, readFileSync, unwatchFile, watchFile } from "fs"; +import { readdirSync, readFileSync, unwatchFile } from "fs"; import { dialog, app } from "electron"; import { socket } from "./socketManager"; import { extname } from "path"; diff --git a/src/managers/trayManager.ts b/src/managers/trayManager.ts index 39a244e..1121c63 100644 --- a/src/managers/trayManager.ts +++ b/src/managers/trayManager.ts @@ -52,7 +52,7 @@ export class TrayManager { }, { label: "Check for Updates...", - click: () => checkForUpdate(), + click: () => checkForUpdate(false, true), visible: !updateAvailable }, { diff --git a/src/util/debug.ts b/src/util/debug.ts index ae1f830..b2645a6 100644 --- a/src/util/debug.ts +++ b/src/util/debug.ts @@ -5,28 +5,28 @@ if (!app.isPackaged) var chalk = require("chalk"); * Show info message in console * */ export function info(message: string) { - //* Return if app packaged - //* Show debug - if (app.isPackaged) return; - console.log(`${chalk.bgBlue(chalk.white(" INFO "))} ${message}`); + //* Return if app packaged + //* Show debug + if (app.isPackaged) return; + console.log(`${chalk.bgBlue(chalk.white(" INFO "))} ${message}`); } /** * Show success message in console * */ export function success(message: string) { - //* Return if app packaged - //* Show debug - if (app.isPackaged) return; - console.log(`${chalk.bgGreen(" SUCCESS ")} ${message}`); + //* Return if app packaged + //* Show debug + if (app.isPackaged) return; + console.log(`${chalk.bgGreen(" SUCCESS ")} ${message}`); } /** * Show error message in console * */ export function error(message: string) { - //* Return if app packaged - //* Show debug - if (app.isPackaged) return; - console.log(`${chalk.bgRed(" ERROR ")} ${message}`); + //* Return if app packaged + //* Show debug + if (app.isPackaged) return; + console.log(`${chalk.bgRed(" ERROR ")} ${message}`); } diff --git a/src/util/updateChecker.ts b/src/util/updateChecker.ts index 9de0fa9..9086915 100644 --- a/src/util/updateChecker.ts +++ b/src/util/updateChecker.ts @@ -1,5 +1,5 @@ -import { exec, execFile } from "child_process"; -import { resolve, dirname } from "path"; +import { exec } from "child_process"; +import { resolve } from "path"; import { error, info } from "./debug"; import { app, dialog, shell } from "electron"; import { platform } from "os"; @@ -11,7 +11,7 @@ import { createWriteStream, existsSync, unlinkSync } from "fs"; export let updateAvailable = false; let initialNotification = true; -export async function checkForUpdate(autoUpdate = false) { +export async function checkForUpdate(autoUpdate = false, manual = false) { //* Skip Update checker if unsupported OS / not packaged if (!app.isPackaged || !["darwin", "win32"].includes(platform())) { //* Show debug @@ -24,7 +24,14 @@ export async function checkForUpdate(autoUpdate = false) { let latestAppVersion = ( await axios.get("https://api.premid.app/v2/versions") ).data.app; - if (app.getVersion() >= latestAppVersion) return; + if (app.getVersion() >= latestAppVersion) { + if (manual) + dialog.showMessageBox(null, { + message: "There are currently no updates available.", + type: "info" + }); + return; + } if (autoUpdate) { updateTray(); update(); diff --git a/tsconfig.json b/tsconfig.json index 095bc3f..d6db4c6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,11 +3,13 @@ "module": "commonjs", "target": "es2018", "moduleResolution": "node", - "sourceMap": true, + "inlineSourceMap": true, "outDir": "dist/app", "removeComments": true, "esModuleInterop": true, - "skipLibCheck": true + "skipLibCheck": true, + "noUnusedParameters": true, + "noUnusedLocals": true }, "include": ["src/**/*"], "exclude": [ diff --git a/yarn.lock b/yarn.lock index d887e92..ff7b90d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -175,10 +175,10 @@ dependencies: "@types/node" "*" -"@types/ssh2-sftp-client@4.1.2": - version "4.1.2" - resolved "https://registry.yarnpkg.com/@types/ssh2-sftp-client/-/ssh2-sftp-client-4.1.2.tgz#2cc20f6b398cb2a9d6895ab774c4eb89213c0e86" - integrity sha512-h+hagttBBiqRHKRmWH6bVleJ0kk2xktSxY+3mwckzncn4LLW9usBEnvUSFbYI02Ox1mMIR1JmeZcCWtnzUYfbg== +"@types/ssh2-sftp-client@4.1.3": + version "4.1.3" + resolved "https://registry.yarnpkg.com/@types/ssh2-sftp-client/-/ssh2-sftp-client-4.1.3.tgz#f1d9c57d5876971eca18b227b29aab76b75c70de" + integrity sha512-x52g1JmebxlmFKrfMQFMbg0JxYTO4LVjGu36AyX7wtLvCJzVBQCcQ40vXg/qqMN5v4q5ef5Wz7veacXNQN9HiA== dependencies: "@types/ssh2" "*" "@types/ssh2-streams" "*" @@ -778,7 +778,7 @@ cookie@0.3.1: resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb" integrity sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s= -core-js@^3.4.1: +core-js@^3.6.4: version "3.6.4" resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.6.4.tgz#440a83536b458114b9cb2ac1580ba377dc470647" integrity sha512-4paDGScNgZP2IXXilaffL9X7968RuvwlkK3xWtZRVqgd8SYNiVKRJvkFd1aqqEuPfN7E68ZHEp9hDj6lHj4Hyw== @@ -1310,16 +1310,16 @@ glob@^7.1.3, glob@^7.1.4: path-is-absolute "^1.0.0" global-agent@^2.0.2: - version "2.1.7" - resolved "https://registry.yarnpkg.com/global-agent/-/global-agent-2.1.7.tgz#12d7bc2b07cd862d0fa76b0f1b2c48cd5ffcf150" - integrity sha512-ooK7eqGYZku+LgnbfH/Iv0RJ74XfhrBZDlke1QSzcBt0bw1PmJcnRADPAQuFE+R45pKKDTynAr25SBasY2kvow== + version "2.1.8" + resolved "https://registry.yarnpkg.com/global-agent/-/global-agent-2.1.8.tgz#99d153662b2c04cbc1199ffbc081a3aa656ac50f" + integrity sha512-VpBe/rhY6Rw2VDOTszAMNambg+4Qv8j0yiTNDYEXXXxkUNGWLHp8A3ztK4YDBbFNcWF4rgsec6/5gPyryya/+A== dependencies: boolean "^3.0.0" - core-js "^3.4.1" + core-js "^3.6.4" es6-error "^4.1.1" - matcher "^2.0.0" - roarr "^2.14.5" - semver "^6.3.0" + matcher "^2.1.0" + roarr "^2.15.2" + semver "^7.1.2" serialize-error "^5.0.0" global-dirs@^0.1.0: @@ -1339,7 +1339,7 @@ global-tunnel-ng@^2.7.1: npm-conf "^1.1.3" tunnel "^0.0.6" -globalthis@^1.0.0: +globalthis@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/globalthis/-/globalthis-1.0.1.tgz#40116f5d9c071f9e8fb0037654df1ab3a83b7ef9" integrity sha512-mJPRTc/P39NH/iNG4mXa9aIhNymaQikTrnspeCa2ZuJ+mH2QN/rXwtX3XwKrHqWgUQFbNZKtHM105aHzJalElw== @@ -1741,7 +1741,7 @@ make-dir@^3.0.0: dependencies: semver "^6.0.0" -matcher@^2.0.0: +matcher@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/matcher/-/matcher-2.1.0.tgz#64e1041c15b993e23b786f93320a7474bf833c28" integrity sha512-o+nZr+vtJtgPNklyeUKkkH42OsK8WAfdgaJE2FNxcjLPg+5QbeEoT6vRj8Xq/iv18JlQ9cmKsEu0b94ixWf1YQ== @@ -2210,9 +2210,9 @@ registry-url@^3.0.3: rc "^1.0.1" resolve@^1.1.6, resolve@^1.10.0: - version "1.15.0" - resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.15.0.tgz#1b7ca96073ebb52e741ffd799f6b39ea462c67f5" - integrity sha512-+hTmAldEGE80U2wJJDC1lebb5jWqvTYAfm3YZ1ckk1gBr0MnCqUKlwK1e+anaFljIl+F5tR5IoZcm4ZDA1zMQw== + version "1.15.1" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.15.1.tgz#27bdcdeffeaf2d6244b95bb0f9f4b4653451f3e8" + integrity sha512-84oo6ZTtoTUpjgNEr5SJyzQhzL72gaRodsSfyxC/AXRvwu0Yse9H8eF9IpGo7b8YetZhlI6v7ZQ6bKBFV/6S7w== dependencies: path-parse "^1.0.6" @@ -2255,14 +2255,14 @@ rimraf@3.0.1, rimraf@^3.0.0: dependencies: glob "^7.1.3" -roarr@^2.14.5: - version "2.14.6" - resolved "https://registry.yarnpkg.com/roarr/-/roarr-2.14.6.tgz#cebe8ad7ecbfd15bfa37b02dacf00809dd633912" - integrity sha512-qjbw0BEesKA+3XFBPt+KVe1PC/Z6ShfJ4wPlx2XifqH5h2Lj8/KQT5XJTsy3n1Es5kai+BwKALaECW3F70B1cg== +roarr@^2.15.2: + version "2.15.2" + resolved "https://registry.yarnpkg.com/roarr/-/roarr-2.15.2.tgz#34f6229ae3c8c12167c4ae60f58fe75e79a1e394" + integrity sha512-jmaDhK9CO4YbQAV8zzCnq9vjAqeO489MS5ehZ+rXmFiPFFE6B+S9KYO6prjmLJ5A0zY3QxVlQdrIya7E/azz/Q== dependencies: boolean "^3.0.0" detect-node "^2.0.4" - globalthis "^1.0.0" + globalthis "^1.0.1" json-stringify-safe "^5.0.1" semver-compare "^1.0.0" sprintf-js "^1.1.2" @@ -2311,11 +2311,16 @@ semver-diff@^2.0.0: resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== -semver@^6.0.0, semver@^6.2.0, semver@^6.3.0: +semver@^6.0.0, semver@^6.2.0: version "6.3.0" resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d" integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw== +semver@^7.1.2: + version "7.1.2" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.1.2.tgz#847bae5bce68c5d08889824f02667199b70e3d87" + integrity sha512-BJs9T/H8sEVHbeigqzIEo57Iu/3DG6c4QoqTfbQB3BPA4zgzAomh/Fk9E7QtjWQ8mx2dgA9YCfSF4y9k9bHNpQ== + serialize-error@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/serialize-error/-/serialize-error-5.0.0.tgz#a7ebbcdb03a5d71a6ed8461ffe0fc1a1afed62ac" @@ -2691,10 +2696,10 @@ unzip-response@^2.0.1: resolved "https://registry.yarnpkg.com/unzip-response/-/unzip-response-2.0.1.tgz#d2f0f737d16b0615e72a6935ed04214572d56f97" integrity sha1-0vD3N9FrBhXnKmk17QQhRXLVb5c= -unzipper@0.10.7: - version "0.10.7" - resolved "https://registry.yarnpkg.com/unzipper/-/unzipper-0.10.7.tgz#ed5d72d12337f66f790d42fef47eb9f9de0a0906" - integrity sha512-0ltrg7/F12h3KqY1zBfZB6bVnPTVlzhdK1iu2xCaGxGMF/Es9ETMAS0M89CnCB4hemPb/AoTWtj+62l7XFZKqQ== +unzipper@0.10.8: + version "0.10.8" + resolved "https://registry.yarnpkg.com/unzipper/-/unzipper-0.10.8.tgz#d7e898f572009128692641331c29b398ff3e5f16" + integrity sha512-CZRd20MbyAfWL1Xc+lqgNFYDj5e/HaH9pLEWZgseQWCvEtNfX0wOjnhaJ6PcGpNnDvifSW1ZNSCHX6GoNliR0A== dependencies: big-integer "^1.6.17" binary "~0.3.0" @@ -2864,10 +2869,10 @@ yargs-parser@^16.0.0: camelcase "^5.0.0" decamelize "^1.2.0" -yarn@1.21.1: - version "1.21.1" - resolved "https://registry.yarnpkg.com/yarn/-/yarn-1.21.1.tgz#1d5da01a9a03492dc4a5957befc1fd12da83d89c" - integrity sha512-dQgmJv676X/NQczpbiDtc2hsE/pppGDJAzwlRiADMTvFzYbdxPj2WO4PcNyriSt2c4jsCMpt8UFRKHUozt21GQ== +yarn@1.22.0: + version "1.22.0" + resolved "https://registry.yarnpkg.com/yarn/-/yarn-1.22.0.tgz#acf82906e36bcccd1ccab1cfb73b87509667c881" + integrity sha512-KMHP/Jq53jZKTY9iTUt3dIVl/be6UPs2INo96+BnZHLKxYNTfwMmlgHTaMWyGZoO74RI4AIFvnWhYrXq2USJkg== yauzl@2.4.1: version "2.4.1"