From 68a055681e278a3dc8d5d254e91cae85bbe43c21 Mon Sep 17 00:00:00 2001 From: Zack Rauen Date: Thu, 21 Oct 2021 17:03:24 -0400 Subject: [PATCH] Change sorting to descending Select the first of the array and not worry about size by using descending sort --- src/renderer/actions/paths.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/renderer/actions/paths.js b/src/renderer/actions/paths.js index 9850fc50..cdccdb70 100644 --- a/src/renderer/actions/paths.js +++ b/src/renderer/actions/paths.js @@ -10,7 +10,7 @@ const getDiscordPath = function(releaseChannel) { if (process.platform === "win32") { const basedir = path.join(process.env.LOCALAPPDATA, releaseChannel.replace(/ /g, "")); if (!fs.existsSync(basedir)) return ""; - const version = fs.readdirSync(basedir).filter(f => fs.lstatSync(path.join(basedir, f)).isDirectory() && f.split(".").length > 1).sort()[0]; + const version = fs.readdirSync(basedir).filter(f => fs.lstatSync(path.join(basedir, f)).isDirectory() && f.split(".").length > 1).sort().reverse()[0]; if (!version) return ""; resourcePath = path.join(basedir, version, "resources"); } @@ -20,7 +20,7 @@ const getDiscordPath = function(releaseChannel) { else { const basedir = path.join(remote.app.getPath("userData"), "..", releaseChannel.toLowerCase().replace(" ", "")); if (!fs.existsSync(basedir)) return ""; - const version = fs.readdirSync(basedir).filter(f => fs.lstatSync(path.join(basedir, f)).isDirectory() && f.split(".").length > 1).sort()[0]; + const version = fs.readdirSync(basedir).filter(f => fs.lstatSync(path.join(basedir, f)).isDirectory() && f.split(".").length > 1).sort().reverse()[0]; if (!version) return ""; resourcePath = path.join(basedir, version, "modules", "discord_desktop_core"); } @@ -55,7 +55,7 @@ const validateWindows = function(channel, proposedPath) { const selected = path.basename(proposedPath); const isBaseDir = selected === channelName; if (isBaseDir) { - const version = fs.readdirSync(proposedPath).filter(f => fs.lstatSync(path.join(proposedPath, f)).isDirectory() && f.split(".").length > 1).sort()[0]; + const version = fs.readdirSync(proposedPath).filter(f => fs.lstatSync(path.join(proposedPath, f)).isDirectory() && f.split(".").length > 1).sort().reverse()[0]; if (!version) return ""; resourcePath = path.join(proposedPath, version, "resources"); } @@ -90,7 +90,7 @@ const validateLinux = function(channel, proposedPath) { let resourcePath = ""; const selected = path.basename(proposedPath); if (selected === channelName) { - const version = fs.readdirSync(proposedPath).filter(f => fs.lstatSync(path.join(proposedPath, f)).isDirectory() && f.split(".").length > 1).sort()[0]; + const version = fs.readdirSync(proposedPath).filter(f => fs.lstatSync(path.join(proposedPath, f)).isDirectory() && f.split(".").length > 1).sort().reverse()[0]; if (!version) return ""; resourcePath = path.join(proposedPath, version, "modules", "discord_desktop_core"); }