Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(other): add oni2 command to PATH - Linux #1202

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 56 additions & 27 deletions node/add-to-path.js
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 }
Copy link
Member Author

@CrossR CrossR Jan 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to check this (the icon)...its not showing up in my VM, but that could just be the weird flavour of Ubuntu I'm running...should try in regular ol Ubuntu or something like CentOS or Arch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this doesn't matter, since I can't get an icon to show up on Ubuntu at all (I can't see anywhere one would go). Its set correctly for the valid locations at least.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what you're doing and I could be completely off, but .icns isn't a supported format in Desktop Entries, so maybe that also applies here.


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 (_) {}
})();
})()
1 change: 1 addition & 0 deletions scripts/linux/package-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/Store/CommandStoreConnector.re
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down