Skip to content

Commit

Permalink
Added option to auto-launch app on boot
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomgcd committed Jun 24, 2021
1 parent 3041455 commit 9438484
Showing 6 changed files with 104 additions and 2 deletions.
20 changes: 19 additions & 1 deletion appdashboard.js
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import './v2/extensions.js';
import { App,RequestLoadDevicesFromServer } from "./v2/app.js";
import {AppHelperSettings} from "./v2/settings/apphelpersettings.js"
import { ControlSettings } from "./v2/settings/controlsetting.js";
import { SettingEncryptionPassword, SettingTheme, SettingThemeAccentColor,SettingCompanionAppPortToReceive, SettingKeyboardShortcutLastCommand, SettingKeyboardShortcutShowWindow, SettingEventGhostNodeRedPort, SettingClipboardSync, SettingCustomActions, SettingUseNativeNotifications, SettingNotificationTimeout, SettingRequireEncryptionForCommandLine, SettingKeyboardShortcutSkipSong, SettingKeyboardShortcutPreviousSong, SettingKeyboardShortcutPlayPause, SettingThemeBackgroundColor, SettingThemeBackgroundPanelColor, SettingThemeTextColor, SettingThemeTextColorOnAccent } from "./v2/settings/setting.js";
import { SettingEncryptionPassword, SettingTheme, SettingThemeAccentColor,SettingCompanionAppPortToReceive, SettingKeyboardShortcutLastCommand, SettingKeyboardShortcutShowWindow, SettingEventGhostNodeRedPort, SettingClipboardSync, SettingCustomActions, SettingUseNativeNotifications, SettingNotificationTimeout, SettingRequireEncryptionForCommandLine, SettingKeyboardShortcutSkipSong, SettingKeyboardShortcutPreviousSong, SettingKeyboardShortcutPlayPause, SettingThemeBackgroundColor, SettingThemeBackgroundPanelColor, SettingThemeTextColor, SettingThemeTextColorOnAccent, SettingAutoLaunch } from "./v2/settings/setting.js";
import { AppGCMHandler } from "./v2/gcm/apphelpergcm.js";
import { ControlDialogInput, ControlDialogOk } from "./v2/dialog/controldialog.js";
import { AppContext } from "./v2/appcontext.js";
@@ -167,6 +167,8 @@ export class AppHelperSettingsDashboard extends AppHelperSettings{
get settingsList(){
return (async () => {
const devices = await this.app.devicesFromDb;
const autoLaunchState = await this.app.autoLaunchState;
console.log("AutoLaunch state",autoLaunchState);
return new ControlTabs([
new Tab({title:"Theme",controlContent:new ControlSettings([
new SettingTheme(),
@@ -196,6 +198,7 @@ export class AppHelperSettingsDashboard extends AppHelperSettings{
new SettingCompanionAppPortToReceive(),
new SettingEncryptionPassword(),
new SettingRequireEncryptionForCommandLine(),
new SettingAutoLaunch(autoLaunchState),
new SettingUseNativeNotifications(),
new SettingNotificationTimeout(),
])}),
@@ -278,6 +281,8 @@ class RequestSetClipboard{
}
}
class ResponseClipboard{}
class RequestAutoLaunchState{}
class ResponseAutoLaunchState{}
class RequestListenForShortcuts{
constructor(shortcuts){
this.shortcuts = shortcuts;
@@ -292,6 +297,12 @@ class RequestDownloadAndOpenFile{
}
}
class RequestInstallLatestUpdate{}

class RequestToggleAutoLaunch{
constructor(enable){
this.enable = enable;
}
}
class Changes{
static async getAll(){
const info = await UtilWeb.get("changes.json");
@@ -374,6 +385,9 @@ export class AppDashboard extends App{
super.applyTheme(theme,accent);
EventBus.post({},"ThemeApplied");
}
get autoLaunchState(){
return ServerEventBus.postAndWaitForResponse(new RequestAutoLaunchState(),ResponseAutoLaunchState,5000);
}
async uploadIpAddressesFile(){
const deviceId = this.myDeviceId;
if(!deviceId) return;
@@ -589,6 +603,10 @@ export class AppDashboard extends App{
async onRequestRunCommandLineCommand(request){
await ServerEventBus.post(request);
}
async onRequestAutoLaunchChanged(request){
console.log("Enabling autolaunch: " + request.enabled)
await ServerEventBus.post(new RequestToggleAutoLaunch(request.enabled));
}
get isBrowserRegistered(){
return true;
}
7 changes: 7 additions & 0 deletions changes.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"changes":[
{
"version": "1.0.1",
"log":[
"First public release",
"Added Auto Launch option"
]
} ,
{
"version": "0.5.1",
"log":[
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
"name": "com.joaomgcd.join",
"productName": "Join Desktop",
"homepage": "https://joaoapps.com/join/desktop",
"version": "1.0.0",
"version": "1.0.1",
"description": "A companion app for the Join website",
"main": "main_esm.js",
"scripts": {
@@ -35,6 +35,7 @@
"electron-builder-squirrel-windows": "^22.7.0"
},
"dependencies": {
"auto-launch": "^5.0.5",
"electron-squirrel-startup": "^1.0.0",
"esm": "^3.2.25",
"http-terminator": "2.0.3",
35 changes: 35 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@ import { CommandLine } from './commandline.js';

const path = require('path')
const Store = require('./store.js');
const AutoLaunch = require('auto-launch');

const storeWindowBounds = new Store({
configName: 'window',
defaults: {}
@@ -145,6 +147,12 @@ class Server{
this.sendToPageEventBus(new ClipboardChanged(text));
});
this.clipboardChecker.start();
const appPath = process.execPath;
console.log(`Instancing AutoLaunch for path ${appPath}`);
this.autoLaunch = new AutoLaunch({
name: 'Join Desktop',
path: appPath,
});



@@ -229,6 +237,27 @@ class Server{
async onRequestSetClipboard(request){
this.clipboardChecker.setClipboardText(request.text);
}
async onRequestAutoLaunchState(){
const isEnabled = await this.autoLaunch.isEnabled();
this.sendToPageEventBus(new ResponseAutoLaunchState(isEnabled,process.execPath))
}
async onRequestToggleAutoLaunch(request){
const enableRequest = request.enable;
if(enableRequest === null || enableRequest === undefined) return;

console.log(`Requested autolaunch: ${enableRequest}`);
const isEnabled = await this.autoLaunch.isEnabled();
console.log(`Was autolaunch enabled: ${isEnabled}`);
if (isEnabled == enableRequest) return;

if(enableRequest){
console.log(`Enabling autolaunch`);
await this.autoLaunch.enable();
}else{
console.log(`Disabling autolaunch`);
await this.autoLaunch.disable();
}
}
async onRequestToggleDevOptions(){
this.window.webContents.toggleDevTools()
}
@@ -412,6 +441,12 @@ class ResponseClipboard{
this.text = text;
}
}
class ResponseAutoLaunchState{
constructor(enabled,execPath){
this.enabled = enabled;
this.execPath = execPath;
}
}
class ResponseSystemTheme{
constructor(isDark){
this.isDark = isDark;
7 changes: 7 additions & 0 deletions v2/settings/controlsetting.js
Original file line number Diff line number Diff line change
@@ -278,6 +278,13 @@ export class ControlSettingContentColorBoolean extends ControlSettingContent{
</div>
`
}
getStyle(){
return `
.settingboolean, input{
cursor: pointer;
}
`
}

async renderSpecific({root}){
this.settingElement = root;
34 changes: 34 additions & 0 deletions v2/settings/setting.js
Original file line number Diff line number Diff line change
@@ -620,4 +620,38 @@ export class SettingCustomActions extends Setting{
this.value = customActions;
}
}

export class SettingAutoLaunch extends SettingBoolean{
static get id(){
return "SettingAutoLaunch";
}
constructor({enabled}){
super({
id:SettingAutoLaunch.id,
label:"Auto-Launch",
subtext:`If set, app will automatically launch when you boot up your system.`
})
if(enabled === null || enabled === undefined) return;

super.value = enabled;
}
get isDbSetting(){
return false;
}
get value(){
return (async ()=>{
const value = await super.value;
return value == true || value == "true";
})()
}
set value(v){
super.value = v
EventBus.post(new RequestAutoLaunchChanged(v));
}
}
class RequestRefreshSettings{}
class RequestAutoLaunchChanged{
constructor(enabled){
this.enabled = enabled;
}
}

0 comments on commit 9438484

Please sign in to comment.