diff --git a/node/add-to-path.js b/node/add-to-path.js index abfbe6eed2..4c616b46df 100644 --- a/node/add-to-path.js +++ b/node/add-to-path.js @@ -1,10 +1,10 @@ // add-to-path.js // This is a Node-side script to add Oni2 to their path. // This is done in node, to get sudo-prompt. -const fs = require("fs"); -const os = require("os"); -const path = require("path"); -const sudo = require("sudo-prompt"); +const fs = require("fs") +const os = require("os") +const path = require("path") +const sudo = require("sudo-prompt") const isWindows = () => os.platform() === "win32" const isMac = () => os.platform() === "darwin" @@ -14,63 +14,92 @@ const getLinkPath = () => (isMac() || isLinux() ? "/usr/local/bin/oni2" : "") const isAddedToPath = () => { try { - fs.lstatSync(getLinkPath()); + fs.lstatSync(getLinkPath()) } catch (_) { return false } return true } -const removeFromPath = () => { + +const getAppDirectory = () => { + if (isMac()) { + // Valid for an install from a dmg. + return path.join(path.dirname(process.mainModule.filename), "..") + } else { + // Valid path for an AppImage or Linux tar.gz + return path.join(path.dirname(process.mainModule.filename), "..", "..") + } +} + +const getOptions = () => { + let appDirectory = getAppDirectory() + + // Valid for an install from a dmg. + let imgPath = path.join(appDirectory, "Onivim2.icns") + + if (!fs.existsSync(imgPath)) { + // Valid path when in a development build. + imgPath = path.join(appDirectory, "assets", "images", "Onivim2.icns") + } + + if (!fs.existsSync(imgPath)) { + // Valid path for an AppImage or Linux tar.gz + imgPath = path.join(appDirectory, "..", "Onivim2.icns") + } + + const options = { name: "Oni2", icns: imgPath } + + return options +} + +const removeFromPath = async () => { if (isAddedToPath() && !isWindows()) { - fs.unlinkSync(getLinkPath()) + await runSudoCommand(`rm ${getLinkPath()}`, getOptions()) } } const addToPath = async () => { if (!isAddedToPath() && !isWindows()) { - const appDirectory = path.join(path.dirname(process.mainModule.filename), ".."); - let imgPath = path.join(appDirectory, "Onivim2.icns"); - - // TODO: Check this is valid for all use cases. - if (!fs.existsSync(imgPath)) { - imgPath = path.join(appDirectory, "assets", "images", "Onivim2.icns"); - } - - const options = { name: "Oni2", icns: imgPath }; - let linkDest = ""; + let appDirectory = getAppDirectory() + let linkDest = "" if (isMac()) { - linkDest = path.join(appDirectory, "run.sh"); + // Valid for an install from a dmg. + linkDest = path.join(appDirectory, "run.sh") + } else if (process.env.APPIMAGE) { + // Valid path for an AppImage. + linkDest = process.env.APPIMAGE } else { - linkDest = ""; // TODO. + // Valid path for Linux tar.gz + linkDest = path.join(appDirectory, "..", "AppRun") } if (!fs.existsSync(linkDest)) { return } - await runSudoCommand(`ln -fs ${linkDest} ${getLinkPath()}`, options); + await runSudoCommand(`ln -fs ${linkDest} ${getLinkPath()}`, getOptions()) } } const runSudoCommand = async (command, options) => { return new Promise(resolve => { sudo.exec(command, options, (error, stdout, stderr) => { - resolve({ error, stdout, stderr }); - }); - }); + resolve({ error, stdout, stderr }) + }) + }) } const toggleAddToPath = async () => { if (isAddedToPath()) { - removeFromPath() + await removeFromPath() } else { await addToPath() } } -(async () => { +;(async () => { try { - await Promise.resolve(toggleAddToPath()); + await Promise.resolve(toggleAddToPath()) } catch (_) {} -})(); +})() diff --git a/scripts/linux/package-linux.sh b/scripts/linux/package-linux.sh index bc826d3379..982ad16b95 100755 --- a/scripts/linux/package-linux.sh +++ b/scripts/linux/package-linux.sh @@ -29,6 +29,7 @@ cp scripts/linux/Onivim2.desktop _release/Onivim2.AppDir/Onivim2.desktop cp scripts/linux/AppRun _release/Onivim2.AppDir/AppRun chmod +x _release/Onivim2.AppDir/AppRun cp assets/images/icon512.png _release/Onivim2.AppDir/Onivim2.png +cp assets/images/Onivim2.icns _release/Onivim2.AppDir/Onivim2.icns cp Outrun-Labs-EULA-v1.1.md _release/Onivim2.AppDir/EULA.md cp ThirdPartyLicenses.txt _release/Onivim2.AppDir/ThirdPartyLicenses.txt diff --git a/src/Store/CommandStoreConnector.re b/src/Store/CommandStoreConnector.re index 4c8b1c6eaa..7ffa0fdee9 100644 --- a/src/Store/CommandStoreConnector.re +++ b/src/Store/CommandStoreConnector.re @@ -5,7 +5,10 @@ open Oni_Model.Actions; let pathSymlinkEnabled = (~addingLink) => ( - Revery.Environment.os == Revery.Environment.Mac + ( + Revery.Environment.os == Revery.Environment.Mac + || Revery.Environment.os == Revery.Environment.Linux + ) && !Sys.file_exists("/usr/local/bin/oni2") ) == addingLink;