-
Notifications
You must be signed in to change notification settings - Fork 22
/
appdashboard.js
726 lines (680 loc) · 27.8 KB
/
appdashboard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
import { ControlLogs } from "./log/controllog.js";
import { Logs, Log } from "./log/log.js";
import { EventBus } from "./v2/eventbus.js";
import { UtilDOM } from "./v2/utildom.js";
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, SettingClipboardCommand, SettingCustomActions, SettingUseNativeNotifications, SettingNotificationTimeout, SettingRequireEncryptionForCommandLine, SettingKeyboardShortcutSkipSong, SettingKeyboardShortcutPreviousSong, SettingKeyboardShortcutPlayPause, SettingThemeBackgroundColor, SettingThemeBackgroundPanelColor, SettingThemeTextColor, SettingThemeTextColorOnAccent, SettingAutoLaunch, SettingLaunchMinimized, SettingNotificationsDisplay, SettingShowLinksAsNotificationsOnly, SettingHideTextInNotifications } 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";
import { ControlTabs, Tab } from "./v2/tabs/controltabs.js";
class ResultNotificationAction{
constructor(success){
this.success = success;
}
}
class AuthToken{
constructor(authToken){
this.authToken = authToken;
}
}
export class CurrentGoogleUserChanged{
constructor(googleUser){
this.googleUser = googleUser;
}
}
const currentUserKey = "currentUser";
class GoogleAccountDashboard{
constructor(){
EventBus.register(this);
window.api.receive("authToken", async data => {
EventBus.post(new AuthToken(data));
});
}
get authToken(){
return (async () => {
window.api.send("authToken");
const result = await EventBus.waitFor(AuthToken,5000);
const token = result.authToken;
await this.refreshCurrentUserIfNeeded(token);
return token;
})();
}
get isSignedIn(){
return (async()=>{
if(!AppContext.context.getMyDeviceId()) return false;
const authToken = await this.authToken;
return authToken ? true : false;
})();
}
static async resetUser(){
AppContext.context.localStorage.delete(currentUserKey);
}
async refreshCurrentUserIfNeeded(token){
if(this.currentUser) return this.currentUser;
this.currentUser = AppContext.context.localStorage.getObject(currentUserKey);
if(this.currentUser && this.currentUser.email) return this.currentUser;
const user = await UtilWeb.get({url:"https://www.googleapis.com/oauth2/v1/userinfo?alt=json",token})
if(!user.email) return null;
this.currentUser = user;
AppContext.context.localStorage.setObject(currentUserKey,this.currentUser);
return this.currentUser;
}
async getCurrentUser(){
const token = await this.authToken;
const result = this.currentUser;
if(!result) return null;
result.token = token;
result.imageUrl = result.picture;
EventBus.postSticky(new CurrentGoogleUserChanged(result));
return result;
}
async signOut(){
await GoogleAccountDashboard.signIn(true);
}
static async signIn(signOutFirst){
if(signOutFirst){
await GoogleAccountDashboard.resetUser();
await ControlDialogOk.showAndWait({title:"Signing Out",text:"Please sign in to another account on the Join website."});
}
const setting = new SettingCompanionAppPortToReceive();
let value = await setting.value;
if(!value){
value = 9876;
setting.value = value;
}
await ServerSetting.set(SettingCompanionAppPortToReceive.id,value);
await UtilDOM.createElement({
type:"div",
id:"signinviaapp",
content: `Please wait while Join signs you in...`,
parent: this.contentElement
});
if(!signOutFirst){
await ControlDialogOk.showAndWait({title:"Not Signed In",text:"Join will now sign you in via the Join website..."});
}
let url = `${self.joinServer}?settings&connectoport=${value}`;
if(signOutFirst){
url += "&signOutCompanion=1";
}
ServerCommands.openPage(url);
}
}
class FCMClientDashboard{
getToken(){
return null;
}
async showNotification(notification,gcm){
//delete notification.data;
// delete notification.icon;
// delete notification.badge;
// Object.assign(notification.data,await gcm.gcmRaw);
const gcmRaw = await gcm.gcmRawNoEncryption;
const {SettingUseNativeNotifications} = await import("./v2/settings/setting.js");
notification.native = await new SettingUseNativeNotifications().value;
const {SettingNotificationTimeout} = await import("./v2/settings/setting.js");
notification.timeout = await new SettingNotificationTimeout().value;
if(notification.timeout){
notification.timeout = notification.timeout * 1000;
notification.requireInteraction = false;
}
return window.api.send("notification",{notification,gcmRaw});
}
}
class ServerCommands{
static async openPage(url){
window.api.send("openurl",url);
}
}
class ServerSetting{
static async set(key,value){
await window.api.send("setting",{key,value})
}
}
export class ServerEventBus{
static async post(object){
try{
await window.api.send('eventbus', {data:object,className:object.constructor.name});
}catch{
let data = {data:object,className:object.constructor.name};
data = JSON.stringify(data);
data = JSON.parse(data);
await window.api.send('eventbus', data);
}
}
static async postAndWaitForResponse(object,repsonseClzz,timeout){
const responsePromise = EventBus.waitFor(repsonseClzz,timeout);
ServerEventBus.post(object);
return responsePromise;
}
}
export class AppHelperSettingsDashboard extends AppHelperSettings{
constructor(args = {app}){
super(args);
this.app = args.app;
}
get settingsList(){
return (async () => {
const devices = await this.app.devicesFromDb;
const autoLaunchState = await this.app.autoLaunchState;
const displays = await this.app.displayList;
console.log("AutoLaunch state",autoLaunchState);
console.log("Displays",displays);
return new ControlTabs([
new Tab({title:"Theme",controlContent:new ControlSettings([
new SettingTheme(),
new SettingThemeAccentColor(),
new SettingThemeBackgroundColor(),
new SettingThemeBackgroundPanelColor(),
new SettingThemeTextColor(),
new SettingThemeTextColorOnAccent(),
])}),
new Tab({title:"Shortcuts",controlContent:new ControlSettings([
new SettingKeyboardShortcutLastCommand(),
new SettingKeyboardShortcutShowWindow(),
new SettingKeyboardShortcutSkipSong(),
new SettingKeyboardShortcutPreviousSong(),
new SettingKeyboardShortcutPlayPause(),
])}),
new Tab({title:"Actions",controlContent:new ControlSettings([
new SettingCustomActions({devices,canRunCommandLineCommands:true}),
])}),
new Tab({title:"Clipboard Sync",controlContent:new ControlSettings([
new SettingClipboardSync({devices})
// new SettingClipboardCommand()
])}),
new Tab({title:"Automation",controlContent:new ControlSettings([
new SettingEventGhostNodeRedPort(),
])}),
new Tab({title:"General",controlContent:new ControlSettings([
new SettingCompanionAppPortToReceive(),
new SettingShowLinksAsNotificationsOnly(autoLaunchState),
new SettingHideTextInNotifications(autoLaunchState),
new SettingEncryptionPassword(),
new SettingRequireEncryptionForCommandLine(),
new SettingAutoLaunch(autoLaunchState),
new SettingLaunchMinimized(),
new SettingUseNativeNotifications(),
new SettingNotificationTimeout(),
new SettingNotificationsDisplay(displays),
])}),
]);
// return new ControlSettings([
// new SettingCompanionAppPortToReceive(),
// new SettingEventGhostNodeRedPort(),
// new SettingEncryptionPassword(),
// new SettingTheme(),
// new SettingThemeAccentColor(),
// new SettingKeyboardShortcutLastCommand(),
// new SettingKeyboardShortcutShowWindow(),
// new SettingClipboardSync({devices:(await this.app.devicesFromDb)})
// ]);
})();
}
async load(){
await super.load();
this.setOpenWebAppListener();
}
setOpenWebAppListener(){
document.querySelector("#linkopenwebapp").onclick = () => ServerCommands.openPage(`${self.joinServer}?settings`);
}
async onSettingSaved(settingSaved){
const setting = settingSaved.setting;
let value = settingSaved.value;
if(!setting) return;
if(setting.id == SettingCompanionAppPortToReceive.id && value){
value = parseInt(value);
await ServerSetting.set(SettingCompanionAppPortToReceive.id,value);
}
if(setting.id == SettingHideTextInNotifications.id){
await ServerSetting.set(SettingHideTextInNotifications.id,value);
}
await super.onSettingSaved(settingSaved);
this.setOpenWebAppListener();
}
}
class RequestRunCommandLineCommand{
constructor(args = {command,args}){
Object.assign(this,args);
}
}
class ResponseRunCommandLineCommand{}
export class AppGCMHandlerDashboard extends AppGCMHandler{
async handleGCMPush({gcm, push, notification}){
if(push.clipboard){
notification.text = push.clipboard;
}
if(push.commandLine){
const needsToBeEncrypted = await new SettingRequireEncryptionForCommandLine().value;
if(needsToBeEncrypted && !gcm.wasEncrypted){
this.app.showToast({text:"Didn't run command line command. Not encrypted.",isError:true});
return;
}
const {CustomAction} = await import("./v2/customactions/customactions.js")
const {command,args} = CustomAction.getCommandToExecuteFromCommandText(push.text);
const response = await EventBus.postAndWaitForResponse(new RequestRunCommandLineCommand({command,args}),ResponseRunCommandLineCommand,10000);
if(push.commandName){
notification.text = push.commandName;
}
if(push.commandResponse){
const sender = await this.app.getDevice(push.senderId);
if(sender){
const command = `${push.commandResponse}=:=${response.out.trim()}`
console.log("Sending command response",command,sender)
await sender.sendPush({text:command});
}
}
return false;
}
return true;
}
}
class RequestToggleDevOptions{}
class RequestClipboard{}
class RequestSetClipboard{
constructor(text){
this.text = text;
}
}
class ResponseClipboard{}
class RequestAutoLaunchState{}
class ResponseAutoLaunchState{}
class RequestListDisplays{}
class ResponseListDisplays{}
class RequestListenForShortcuts{
constructor(shortcuts){
this.shortcuts = shortcuts;
}
}
class RequestFocusWindow{}
class RequestAppVersion{}
class ResponseAppVersion{}
class RequestDownloadAndOpenFile{
constructor(url){
this.url = url;
}
}
class RequestInstallLatestUpdate{}
class RequestToggleAutoLaunch{
constructor(enable){
this.enable = enable;
}
}
class RequestChangeNotificationDisplay{
constructor(displayId){
this.displayId = displayId;
}
}
class Changes{
static async getAll(){
const info = await UtilWeb.get("changes.json");
return info.changes;
}
static async get(version){
const changes = await Changes.getAll();
const change = changes.find(change => change.version == version);
if(!change) return null;
return change;
}
}
export class AppDashboard extends App{
constructor(contentElement){
super(contentElement);
}
async load(){
AppContext.context.allowUnsecureContent = true;
window.oncontextmenu = () => ServerEventBus.post(new RequestToggleDevOptions());
// AppGCMHandler.handlePushUrl = (push)=> {
// const url = push.url;
// if(!url) return;
// console.log("Ignoring url because it was handled in server")
// }
Util.openWindow = url => {
ServerCommands.openPage(url);
return true;
}
Util.getClipboardText = async () => {
const result = EventBus.waitFor(ResponseClipboard,3000);
ServerEventBus.post(new RequestClipboard());
return result.then(response=>response.text);
}
Util.setClipboardText = async text => {
await ServerEventBus.post(new RequestSetClipboard(text));
}
self["prompt"] = async (title,initialText,timeout) => await ControlDialogInput.showAndWait({title,initialText: (initialText ? initialText : ""),placeholder:"",timeout: (timeout ? timeout : null) });
self["alert"] = async text => await ControlDialogOk.showAndWait({text,title:"Join"});
window.api.receive("log", async data => {
//this.controlLogs.addLog(new Log(data));
});
window.api.receive("sendpush", async push => {
const device = await this.getDevice(push.deviceId);
await device.sendPush(push);
});
window.api.receive("eventbus", async ({data,className}) => {
await EventBus.post(data,className);
});
window.api.receive("usersignedin", async () => {
location.reload();
});
UtilDOM.addScriptFile("./v2/utilweb.js");
UtilDOM.addScriptFile("./v2/db.js");
UtilDOM.addScriptFile("./v2/google/drive/googledrive.js");
await this.loadAppContext();
const query = Util.getQueryObject();
const doIt = async () =>{
if(!query.notificationpopup){
await this.minimizeIfNeeded();
await super.load();
await this.showNewVersionInfo();
await this.uploadIpAddressesFile();
}else{
await this.loadEssentials();
this.onRequestReplyMessage = null;
const {AppDashboardNotifications} = await import("./appdashboardhelpernotifications.js");
const helperNotifications = new AppDashboardNotifications(this);
await helperNotifications.load();
}
}
try{
await doIt();
}catch(error){
await ControlDialogOk.showAndWait({title:"Error Loading Join Desktop",text:`Couldn't load the app. (${error}). Please check your connection and try again.`,timeout:30000})
}
}
applyTheme(theme,accent){
super.applyTheme(theme,accent);
EventBus.post({},"ThemeApplied");
}
get autoLaunchState(){
return ServerEventBus.postAndWaitForResponse(new RequestAutoLaunchState(),ResponseAutoLaunchState,5000);
}
get displayList(){
return (async()=>{
const result = await ServerEventBus.postAndWaitForResponse(new RequestListDisplays(),ResponseListDisplays,5000);
return result.displays;
})();
}
async minimizeIfNeeded(){
const settingLaunchMinimizes = new SettingLaunchMinimized();
const shouldMinimize = await settingLaunchMinimizes.value;
if(!shouldMinimize) return;
this.onMinimizeToTaskBarAppClicked(new MinimizeToTaskBarAppClicked({"hideWindowIfWindows":true}));
}
async uploadIpAddressesFile(){
const deviceId = this.myDeviceId;
if(!deviceId) return;
const appInfo = await this.appInfo;
const serverAddress = appInfo.serverAddress;
if(!serverAddress) return;
const googleDrive = new GoogleDrive(async ()=>await this.getAuthToken());
const result = await googleDrive.uploadContent({
ignoreFolderForGetFile: true,
//getParents:true,
fileName: `serveraddresses=:=${deviceId}`,
content: {serverAddress,senderId:deviceId},
folderName: `${GoogleDrive.getBaseFolderForMyDevice()}/Settings Files`,
overwrite: true
});
console.log(result);
}
async showNewVersionInfo(){
const appInfo = await this.appInfo;
this.controlTop.versionNumber = appInfo.version;
const key = "lastupdatelogshown";
const lastVersionShown = parseFloat(AppContext.context.localStorage.get(key))
if(lastVersionShown && lastVersionShown >= parseFloat(appInfo.version)) return;
const info = await Changes.get(appInfo.version);
if(!info) return;
let liTag = `<li style="padding: 8px;">`
let text = info.log.join(`</li>${liTag}`);
text = `<ul>${liTag}${text}</li></ul>`;
const title = `Changes for version ${appInfo.version}`;
const timeout = 999999999;
try{
if(info.demo){
const buttons = ["OK","Demo"]
const buttonsDisplayFunc = button=>button;
const button = await ControlDialogOk.showAndWait({title,text,timeout,buttons,buttonsDisplayFunc});
if(button.button != "Demo") return;
Util.openWindow(info.demo);
}else{
await ControlDialogOk.showAndWait({title,text,timeout});
}
}finally{
AppContext.context.localStorage.set(key,appInfo.version);
}
}
get newGcmHandlerInstance(){
return new AppGCMHandlerDashboard(this);
}
get appInfo(){
return ServerEventBus.postAndWaitForResponse(new RequestAppVersion(),ResponseAppVersion,5000);
}
async onUpdateAvailable(request){
const result = await ControlDialogOk.showAndWaitOkCancel({title:"New Version Available",text:`Version ${request.version} of the app is available. Download now?`})
if(!result.isOk) return;
await ControlDialogOk.showAndWait({title:"Downloading now!",text:`Ok will now download the new version!<br/><br/> Will automatically update the app once downloaded.`,timeout:30000})
await ServerEventBus.post(new RequestInstallLatestUpdate());
}
get areShortcutsGlobal(){
return true;
}
async loadShortcuts(){
const {DBKeyboardShortcut} = await import("./v2/keyboard/keyboardshortcut.js");
const dbShortcut = new DBKeyboardShortcut(this.db);
const configured = await dbShortcut.getAll();
ServerEventBus.post(new RequestListenForShortcuts(configured.map(shortcutAndCommand=>shortcutAndCommand.shortcut)));
}
async onRequestExecuteGCMOnPage({gcmRaw}){
await GCMBase.executeGcmFromJson(gcmRaw.type,gcmRaw.json);
}
async onRequestHandleNotificationClickGCMOnPage({gcmRaw,action}){
const gcm = await GCMBase.getGCMFromJson(gcmRaw.type,gcmRaw.json);
if(!gcm || !gcm.handleNotificationClick) return;
await gcm.handleNotificationClick(action);
}
async onShortcutPressed(shortcutPressed){
try{
let shortcut = shortcutPressed.shortcut;
if(!shortcut) return;
const command = await this.getKeyboardShortcutCommand(shortcut);
if(!command) return;
if(!command.needsFocus) return;
ServerEventBus.post(new RequestFocusWindow());
}finally{
await super.onShortcutPressed(shortcutPressed);
}
}
async onRequestFocusWindow(){
ServerEventBus.post(new RequestFocusWindow());
}
async onRequestReplyMessageFromServer(request){
EventBus.post(request,"RequestReplyMessage");
}
async onRequestNotificationAction(request){
let success = false;
try{
const resultPromise = EventBus.waitFor(ResultNotificationAction,3000);
// request = JSON.parse(JSON.stringify(request))
ServerEventBus.post(request);
const result = await resultPromise;
success = result.success;
}catch{}
if(success) return;
await super.onRequestNotificationAction(request);
}
async onNotificationsCleared(notificationsCleared){
await ServerEventBus.post(notificationsCleared);
}
async onGCMNotificationClear(gcm){
await ServerEventBus.post(gcm);
}
onRequestStoredNotifications(request){
ServerEventBus.post(request);
}
showCloseButton(){
return true;
}
redirectToHttpsIfNeeded(){}
get hideBookmarklets(){
return true;
}
async onCompanionHostConnected(info){
this.myDeviceId = info.companionBrowserId;
}
async onWebSocketGCM(webSocketGCM){
const gcmRaw = webSocketGCM.gcmRaw;
//await GCMBase.executeGcmFromJson(gcmRaw.type,gcmRaw.json);
//Need to decrypt possible encrypted fields so convert to gcm first
const gcm = await GCMBase.getGCMFromJson(webSocketGCM.gcmRaw.type,webSocketGCM.gcmRaw.json)
const raw = await gcm.gcmRawNoEncryption;
window.api.send("gcm",raw);
}
async onDevices(devices){
devices = JSON.stringify(devices);
devices = JSON.parse(devices);
window.api.send("devices",devices);
}
async onCloseAppClicked(closeAppClicked){
ServerEventBus.post(closeAppClicked)
}
async onMinimizeAppClicked(clicked){
ServerEventBus.post(clicked)
}
async onMinimizeToTaskBarAppClicked(clicked){
ServerEventBus.post(clicked)
}
async loadWhenNotSignedIn(){
GoogleAccountDashboard.signIn(false);
}
async loadApiLoader(){
const googleAccount = await this.googleAccount;
console.log("Loaded user",await googleAccount.getCurrentUser())
return true;
}
get googleAccount(){
if(this._googleAccount) return this._googleAccount;
return (async()=>{
this._googleAccount = new GoogleAccountDashboard();
return this._googleAccount;
})();
}
async getAuthToken(){
const googleAccount = await this.googleAccount;
return await googleAccount.authToken;
}
async loadFcmClient(){
if(this.fcmClient) return this.fcmClient;
window.api.receive("gcm", async data => {
console.log("Received gcm",data);
await GCMBase.executeGcmFromJson(data.type,JSON.stringify(data));
});
this.fcmClient = new FCMClientDashboard();
/*if ('serviceWorker' in navigator) {
try{
const registration = await navigator.serviceWorker.register('./sw.js');
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}catch(error){
console.log('ServiceWorker registration failed: ', error);
}
}*/
return this.fcmClient;
}
async onGCMAutoClipboard(gcm){
gcm.text = await Encryption.decrypt(gcm.text);
ServerEventBus.post(gcm);
}
async onClipboardChanged(clipboardChanged){
const setting = new SettingClipboardSync({devices:(await this.devicesFromDb)});
const deviceIdsToSendTo = await setting.value;
if(deviceIdsToSendTo.length == 0) return;
const { GCMAutoClipboard } = await import("./v2/gcm/gcmapp.js");
const gcm = new GCMAutoClipboard();
gcm.text = await Encryption.encrypt(clipboardChanged.text);
const devices = await this.getDevices(deviceIdsToSendTo);
console.log("Sending auto clipboard", gcm, devices);
await devices.send(gcm);
// const settingClipboardCommand = new SettingClipboardCommand();
// const clipboardCommand = await settingClipboardCommand.value;
// if(clipboardCommand){
// await devices.sendPush({text:clipboardCommand})
// }
}
async onRequestRunCommandLineCommand(request){
await ServerEventBus.post(request);
}
async onRequestAutoLaunchChanged(request){
console.log("Enabling autolaunch: " + request.enabled)
await ServerEventBus.post(new RequestToggleAutoLaunch(request.enabled));
}
async onRequestNotificationDisplayChanged(request){
const displays = await this.displayList;
const displayToShowNotificationsOn = displays.find(display=>display.id == request.displayId);
if(!displayToShowNotificationsOn){
console.error("Can't change notifications to display with id",request.displayId);
return;
}
console.log("Notification display changed: ",displayToShowNotificationsOn)
await ServerEventBus.post(new RequestChangeNotificationDisplay(request.displayId));
}
get isBrowserRegistered(){
return true;
}
async registerBrowser({force}){
await EventBus.post(new RequestLoadDevicesFromServer());
}
get allowUnsecureContent(){
return true;
}
get helperSettingsFile(){
return '../appdashboard.js';
}
get helperSettingsClassName(){
return 'AppHelperSettingsDashboard';
}
// async load(){
// EventBus.register(this);
// this.contentElement.innerHTML = "";
// this.controlTop = new ControlTop();
// await this.addElement(this.controlTop);
// this.controlTop.appName = "Join Companion App";
// this.controlTop.hideHomeImage();
// this.controlTop.loading = false;
// this.controlTop.shouldAlwaysShowImageRefresh = false;
// this.controlLogs = new ControlLogs(new Logs());
// await this.addElement(this.controlLogs);
// window.api.receive("gcm", async data => {
// await GCMBase.executeGcmFromJson(data.type,JSON.stringify(data));
// });
// window.api.receive("log", async data => {
// this.controlLogs.addLog(new Log(data));
// });
// window.api.receive("authToken", async data => {
// EventBus.post(new AuthToken(data));
// });
// await UtilDOM.addStyleFromFile("./v2/global.css");
// console.log("App loaded");
// console.log("Auth Token", await this.getAuthToken());
// }
// async addElement(control,parent=null){
// const render = await control.render();
// if(!parent){
// parent = this.contentElement;
// }
// parent.appendChild(render);
// }
// async onGCMPush(gcm){
// console.log("Received push",gcm);
// const notificationInfo = gcm.notificationInfo;
// this.controlLogs.addLog(new Log(notificationInfo));
// }
}
class MinimizeAppClicked{}
class MinimizeToTaskBarAppClicked{
constructor(args){
Object.assign(this,args);
}
}