Modify: Unified create-shortcut Script
This commit is contained in:
1 parent
f2877386c8
commit
46cfe71c32
1 file changed
+63
-10
@@ -9,19 +9,20 @@ let cwd = process.cwd();
|
||||
let dirs = cwd.split(path.sep);
|
||||
let name = dirs[dirs.length - 2];
|
||||
|
||||
// Windows Shortcuts
|
||||
if (os.platform() == "win32") {
|
||||
// Paths and Icon for Windows shortcuts
|
||||
let target = path.join( process.cwd(), "launch-windows.bat")
|
||||
let icon = path.join( process.cwd(), "superalgos.ico")
|
||||
let ShortcutPaths = [
|
||||
let target = path.join( process.cwd(), "launch-windows.bat");
|
||||
let icon = path.join( process.cwd(), "superalgos.ico");
|
||||
let shortcutPaths = [
|
||||
path.join( os.homedir(), "Desktop", `${name}.lnk`),
|
||||
path.join( os.homedir(), "AppData", "Roaming", "Microsoft", "Windows", "Start Menu", "Programs", "Superalgos.lnk")
|
||||
]
|
||||
|
||||
// Place Shortcuts using powershell
|
||||
let dir;
|
||||
for (dir in ShortcutPaths) {
|
||||
let command = `$ws = New-Object -ComObject WScript.Shell; $s = $ws.CreateShortcut("${ShortcutPaths[dir]}"); $S.TargetPath = "${target}"; $S.IconLocation = "${icon}"; $S.Save()`;
|
||||
for (dir in shortcutPaths) {
|
||||
let command = `$ws = New-Object -ComObject WScript.Shell; $s = $ws.CreateShortcut("${shortcutPaths[dir]}"); $S.TargetPath = "${target}"; $S.IconLocation = "${icon}"; $S.Save()`;
|
||||
|
||||
exec( command,
|
||||
{
|
||||
@@ -37,16 +38,68 @@ if (os.platform() == "win32") {
|
||||
return;
|
||||
} else {
|
||||
console.log('');
|
||||
console.log("A shortcut added successfully!");
|
||||
console.log("Shortcut added successfully!");
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
// Linux Shortcuts
|
||||
} else if (os.platform() == "linux") {
|
||||
// Paths and Icon for Windows shortcuts
|
||||
console.log("still working on linux")
|
||||
// Check for Ubuntu
|
||||
let version = os.version();
|
||||
if (version.includes("Ubuntu")) {
|
||||
// Paths and Icon for Ubuntu shortcuts
|
||||
let icon = path.join( process.cwd(),"..", "/Projects/Superalgos/Icons/superalgos.png");
|
||||
let shortcutPaths = [
|
||||
path.join( os.homedir(), "Desktop/" ),
|
||||
path.join( os.homedir(), "local/share/applications/" )
|
||||
]
|
||||
|
||||
// Create .desktop shortcut file
|
||||
console.log("still working on linux", icon, shortcutPaths)
|
||||
fs.writeFileSync( `${name}.desktop`,
|
||||
`[Desktop Entry]
|
||||
Type=Application
|
||||
Encoding=UTF-8
|
||||
Name=${name}
|
||||
Comment=Launch Shortcut for Superalgos
|
||||
Path=${process.cwd()}
|
||||
Exec=gnome-terminal -e ${process.cwd()}/launch-linux.sh
|
||||
Terminal=true
|
||||
Icon=${icon}
|
||||
Categories=Application;`,
|
||||
);
|
||||
|
||||
// Set shortcut as executable
|
||||
fs.chmodSync( `${name}.desktop`, "775" );
|
||||
|
||||
// Place shortcut in proper folders
|
||||
let command = `cp ${name}.desktop ~/Desktop/${name}.desktop & cp ${name}.desktop ~/.local/share/applications/${name}.desktop`
|
||||
exec( command,
|
||||
function ( error, stdout ){
|
||||
if (error) {
|
||||
console.log('');
|
||||
console.log("There was an error installing a shortcut: ");
|
||||
console.log('');
|
||||
console.log( error );
|
||||
return;
|
||||
} else {
|
||||
console.log('');
|
||||
console.log("Shortcuts added successfully!");
|
||||
}
|
||||
// Remove temporary .desktop file
|
||||
fs.unlinkSync( `${name}.desktop` )
|
||||
});
|
||||
|
||||
} else {
|
||||
console.log( "Automatic shortcut creation is not yet supported on your flavor of linux. If you would like to see this feature add, message @harrellbm on telegram or discord to ask how you can help!")
|
||||
}
|
||||
|
||||
// Mac Shortcuts
|
||||
} else if (os.platform() == "darwin") {
|
||||
console.log( "Automatic shortcut creation is not currently supported on mac yet. If you would like to see this feature add, ask the devs on telegram or discord!")
|
||||
console.log( "Automatic shortcut creation is not yet supported on Mac. If you would like to see this feature add, message @harrellbm on telegram or discord to ask how you can help!")
|
||||
|
||||
// Misc Operating System
|
||||
} else {
|
||||
console.log("Automatic shortcut creation is not currently supported on your operating system. If you would like to see your operating system added please reachout on discord or telegram to let the devs know.")
|
||||
}
|
||||
Reference in new issue
Block a user