autoStart
This commit is contained in:
parent
0cf2aa12c6
commit
dd20bdea75
|
@ -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();
|
||||
}
|
|
@ -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")*/
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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');
|
21
src/index.ts
21
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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue