diff --git a/src/autoStart/darwin.ts b/src/autoStart/darwin.ts deleted file mode 100644 index d418d23..0000000 --- a/src/autoStart/darwin.ts +++ /dev/null @@ -1,14 +0,0 @@ -export function install(callback){ - return callback() -} -export function update(callback) { - return callback(); -} - -export function isInstalled(callback) { - return callback(false); -} - -export function uninstall(callback) { - return callback(); -} \ No newline at end of file diff --git a/src/autoStart/index.ts b/src/autoStart/index.ts index 84e7352..f503878 100644 --- a/src/autoStart/index.ts +++ b/src/autoStart/index.ts @@ -5,33 +5,20 @@ const autoStart = new autoLaunch({ }) export default { - install(callback){ + install(callback:(err?:Error|void) => void){ autoStart.enable() .then(callback, callback) }, - isInstalled(callback){ + isInstalled(callback:(isInstalled:boolean)=>void){ autoStart.isEnabled() .then(callback) }, - uninstall(callback){ + uninstall(callback:(err?:Error|void) => void){ autoStart.disable() .then(callback, callback) }, - update(callback){ + update(callback:(err?:Error|void) => void){ autoStart.enable() .then(callback, callback) } -} - -/* - -let autoStart -if(process.platform === "win32"){ - autoStart = require("./win32") -}else if(process.platform === "darwin"){ - autoStart = require("./darwin") -}else{ - autoStart = require("./linux") -} - -export default autoStart as typeof import("./win32")*/ \ No newline at end of file +} \ No newline at end of file diff --git a/src/autoStart/linux.ts b/src/autoStart/linux.ts deleted file mode 100644 index 3fd523b..0000000 --- a/src/autoStart/linux.ts +++ /dev/null @@ -1,67 +0,0 @@ -import * as fs from "fs" -import * as path from "path" -import * as electron from "electron" -import * as buildInfo from "../buildInfo" - -// TODO: We should use Constant's APP_NAME, but only once -// we set up backwards compat with this. -const appName = path.basename(process.execPath, '.exe'); -const exePath = electron.app.getPath('exe'); -const exeDir = path.dirname(exePath); -const iconPath = path.join(exeDir, 'discord.png'); -const autostartDir = path.join(electron.app.getPath('appData'), 'autostart'); -const electronAppName = electron.app.name ? electron.app.name : electron.app.getName(); -const autostartFileName = path.join(autostartDir, electronAppName + '-' + buildInfo.releaseChannel + '.desktop'); -const desktopFile = `[Desktop Entry] -Type=Application -Exec=${exePath} -Hidden=false -NoDisplay=false -Name=${appName} -Icon=${iconPath} -Comment=Text and voice chat for gamers. -X-GNOME-Autostart-enabled=true -`; - -function ensureDir() { - try { - fs.mkdirSync(autostartDir); - return true; - } catch (e) { - // catch for when it already exists. - } - return false; -} - -export function install(callback) { - // TODO: This could fail. We should read its return value - ensureDir(); - try { - return fs.writeFile(autostartFileName, desktopFile, callback); - } catch (e) { - // I guess we don't autostart then - return callback(); - } -} - -export function update(callback) { - // TODO: We might need to implement this later on - return callback(); -} - -export function isInstalled(callback) { - try { - fs.stat(autostartFileName, (err, stats) => { - if (err) { - return callback(false); - } - return callback(stats.isFile()); - }); - } catch (e) { - return callback(false); - } -} - -export function uninstall(callback) { - return fs.unlink(autostartFileName, callback); -} \ No newline at end of file diff --git a/src/autoStart/win32.ts b/src/autoStart/win32.ts deleted file mode 100644 index bc0775e..0000000 --- a/src/autoStart/win32.ts +++ /dev/null @@ -1,46 +0,0 @@ - -export function install(callback) { - const startMinimized = settings.get('START_MINIMIZED', false); - let { execPath } = process; - if (startMinimized) { - execPath = `${execPath} --start-minimized`; - } - const queue = [['HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run', '/v', appName, '/d', execPath]]; - - windowsUtils.addToRegistry(queue, callback); -} -export function update(callback) { - isInstalled(installed => { - if (installed) { - install(callback); - } else { - callback(); - } - }); -} -export function isInstalled(callback) { - const queryValue = ['HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run', '/v', appName]; - queryValue.unshift('query'); - windowsUtils.spawnReg(queryValue, (error, stdout) => { - const doesOldKeyExist = stdout.indexOf(appName) >= 0; - callback(doesOldKeyExist); - }); -} -export function uninstall(callback) { - const queryValue = ['HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run', '/v', appName, '/f']; - queryValue.unshift('delete'); - windowsUtils.spawnReg(queryValue, (error, stdout) => { - callback(); - }); -} - -import * as path from "path" -import * as windowsUtils from "../windowsUtils" -import appSettings from "../appSettings" - - -const settings = appSettings.getSettings(); - -// TODO: We should use Constant's APP_NAME, but only once -// we set up backwards compat with this. -const appName = path.basename(process.execPath, '.exe'); \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 803bfc5..6f3beae 100644 --- a/src/index.ts +++ b/src/index.ts @@ -62,14 +62,15 @@ function hasArgvFlag(flag) { if (process.argv.includes("--should-create-shortcut")) { console.log(`Creating shortcuts.`); if (process.platform === "win32") { + let options = { + appUserModelId: Constants.APP_ID, + description: Constants.packageJSON.description, + target: process.execPath, + } electron.shell.writeShortcutLink( join(homedir(), "Desktop", "Lightcord.lnk"), "create", - { - appUserModelId: Constants.APP_ID, - description: Constants.packageJSON.description, - target: process.execPath, - } + options ); electron.shell.writeShortcutLink( join( @@ -81,12 +82,12 @@ function hasArgvFlag(flag) { "Lightcord.lnk" ), "create", - { - appUserModelId: Constants.APP_ID, - description: Constants.packageJSON.description, - target: process.execPath, - } + options ); + autoStart.isInstalled((installed) => { + if(installed)return + autoStart.install(console.log) + }) } }