-
Notifications
You must be signed in to change notification settings - Fork 20
/
join.js
2153 lines (2085 loc) · 63.6 KB
/
join.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
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
chrome.commands.onCommand.addListener(async function (command) {
console.log('Command:', command);
if (command == "popup") {
createPushClipboardWindowAndCloseAfterCommand();
} else if (command == "repeat-last-command") {
repeatLastCommand();
} else if (command == "favorite-command") {
var favoriteCommand = getFavoriteCommand();
favoriteCommand = getDeviceCommands().first(function (command) { return command.label == favoriteCommand; });
if (!favoriteCommand) {
favoriteCommand = deviceCommands[0];
}
var favoriteCommandDevice = getFavoriteCommandDevice();
if (favoriteCommand && favoriteCommandDevice) {
favoriteCommand.func(favoriteCommandDevice, true, getFavoriteCommandText());
}
} else if (command == "notifications-popup") {
showNotificationsPopup();
} else if (command == "voice-command") {
if (!getVoiceEnabled()) {
return;
}
if (back.UtilsVoice.voiceRecognizer != null && back.UtilsVoice.voiceRecognizer.getAlwaysListeningEnabled()) {
back.console.log("Not starting because it's on continuous");
return;
}
try {
const prompt = await UtilsVoice.doVoiceCommand(devices);
showNotification("Join", prompt)
} catch (error) {
showNotification("Join Voice Command", `Error recognizing: ${error}`);
console.log("Error recognizing!")
console.log(error);
}
}
});
async function registerInEventBus(callback) {
eventBus.register(callback);
}
var eventBus = new EventBusCrossContext();
var repeatLastCommand = function () {
if (localStorage["lastpush"]) {
var deviceId = localStorage["lastpush"];
var lastPushFunc = localStorage["lastpushtype"];
if (lastPushFunc.indexOf(LAST_PUSH_CUSTOM_COMMAND) == 0) {
new TaskerCommands().performCommand(deviceId, lastPushFunc.split("=:=")[1], true);
} else {
window[lastPushFunc](deviceId, true);
}
} else {
createPushClipboardWindowAndCloseAfterCommand();
}
}
var getNotificationPopupHeight = function () {
var height = Math.min(Math.round((203 * notifications.length) + 80), screen.height * 0.75);
if (notifications.length == 0) {
height = 150;
}
return height;
}
var getNotificationPopupWidth = function () {
return 375;
}
var notificationsWindow = null;
var showNotificationsPopup = function (tab) {
if (!tab) {
tab = "notifications";
}
if (notificationsWindow != null) {
return;
}
var height = getNotificationPopupHeight();
var width = getNotificationPopupWidth();
chrome.windows.create({ "focused": false, url: 'devices.html?tab=' + tab + '&closeOnEmpty=true', type: 'popup', left: screen.width - width, top: Math.round((screen.height / 2) - (height / 2)), width: width, height: height }, function (win) {
notificationsWindow = win;
});
}
var createPushClipboardWindowAndCloseAfterCommand = function () {
createPushClipboardWindow(null, null, null, true);
}
var createPushClipboardWindow = function (tab, params, paramsIfClosed, closeAfterCommand) {
if (!tab) {
tab = "devices";
}
var url = 'devices.html?tab=' + tab + '&popup=1' + (closeAfterCommand ? '&closeAfterCommand=1' : '');
if (params) {
var addParams = function (params) {
if (!params) {
return;
}
for (var prop in params) {
var value = params[prop];
if (value) {
url += "&" + prop + "=" + encodeURIComponent(value);
}
}
}
addParams(params);
if (!popupWindowClipboard) {
addParams(paramsIfClosed);
}
}
if (!devices || devices.length == 0) {
alert("Join doesn't have any other devices available to send stuff to. Please log in on the same account on other devices to make them appear here.");
return;
}
if (popupWindowClipboard) {
var tab = popupWindowClipboard.tabs[0];
chrome.tabs.update(tab.id, { "url": url });
chrome.windows.update(popupWindowClipboardId, { "focused": true });
} else {
/*var height = Math.min(Math.round((88 * devices.length) + 100), screen.height * 0.75);
height = Math.max(height, (deviceCommands.length * 25) + 100);*/
var width = parseInt(localStorage.popoutWidth);
if (!width) {
width = 456;
}
var height = parseInt(localStorage.popoutHeight);
if (!height) {
height = 606;
}
chrome.windows.create({ url: url, type: 'popup', left: screen.width - 230, top: Math.round((screen.height / 2) - (height / 2)), width: width, height: height }, function (clipboardWindow) {
popupWindowClipboard = clipboardWindow;
popupWindowClipboardId = clipboardWindow.id;
});
}
}
var popupWindowClipboard = null;
var popupWindowClipboardId = null;
chrome.windows.onRemoved.addListener(function (windowId) {
// If the window getting closed is the popup we created
if (windowId === popupWindowClipboardId) {
// Set popupId to undefined so we know the popups not open
popupWindowClipboard = null;
}
});
var clipboardWindows = [];
var clearClipboardWindows = function () {
for (var i = 0; i < clipboardWindows.length; i++) {
var win = clipboardWindows[i];
chrome.windows.remove(win.id);
};
clipboardWindows = [];
}
var getToken = async function (callback, token) {
const tokenAwaited = token ? token : await getAuthTokenPromise(false, token);
if (callback) {
callback(tokenAwaited);
}
return tokenAwaited;
/*chrome.identity.getAuthToken({ 'interactive': true }, function(token) {
callback(token);
});*/
}
var isDoingAuth = false;
var waitingForAuthCallbacks = [];
/*var getAuthToken = function(callback, selectAccount){
if(selectAccount){
removeAuthToken();
}
//removeAuthToken();
if(localStorage.accessToken && localStorage.authExpires && new Date(new Number(localStorage.authExpires)) > new Date()){
if(callback){
callback(localStorage.accessToken);
}
}else{
if(!isDoingAuth){
isDoingAuth = true;
var url = getAuthUrl(selectAccount);
chrome.identity.launchWebAuthFlow({'url': url, 'interactive': true},function(redirect_url) {
var token = null;
if(redirect_url){
token = getAuthTokenFromUrl(redirect_url);
var expiresIn = new Number(getURLParameter(redirect_url,"expires_in"));
localStorage.authExpires = new Date().getTime() + ((expiresIn - 120) * 1000);
localStorage.accessToken = token;
console.log(token+":"+expiresIn);
}
if(callback){
callback(token);
}
waitingForAuthCallbacks.doForAll(function(waitingCallback){
waitingCallback(token)
});
waitingForAuthCallbacks = [];
isDoingAuth = false;
});
}else{
if(callback){
waitingForAuthCallbacks.push(callback);
}
}
}
}*/
var getAuthTokenBackground = async function (callback, selectAccount) {
if (isLocalAccessTokenValid()) {
if (callback) {
callback(localStorage.accessToken)
}
return;
}
var authUrl = await getAuthUrl(selectAccount, true);
if (localStorage.userinfo) {
var userinfo = JSON.parse(localStorage.userinfo);
if (userinfo.email) {
authUrl += "&login_hint=" + userinfo.email;
}
}
fetch(authUrl, { "redirect": 'manual', "credentials": 'include' }).then(function (response) {
return response.text();
}).then(function (response) {
var tokenIndex = response.indexOf("access_token=");
if (tokenIndex > 0) {
var token = response.substring(tokenIndex + 13)
token = token.substring(0, token.indexOf("&"))
var expiresIn = response.substring(response.indexOf("expires_in=") + 11);
expiresIn = expiresIn.substring(0, expiresIn.indexOf("\""));
expiresIn = parseInt(expiresIn.match(/\d+/)[0]);
setLocalAccessToken(token, expiresIn);
console.log(token);
console.log(expiresIn);
if (callback) {
callback(token);
}
} else {
getAuthTokenFromTab(callback, selectAccount);
}
}).catch(function (error) {
console.log('There has been a problem with your fetch operation: ' + error.message);
if (callback) {
callback(null);
}
});
}
var authTabId = null;
var isLocalAccessTokenValid = function () {
return localStorage.accessToken && localStorage.authExpires && new Date(new Number(localStorage.authExpires)) > new Date();
}
var setLocalAccessToken = function (token, expiresIn) {
localStorage.authExpires = new Date().getTime() + ((expiresIn - 120) * 1000);
localStorage.accessToken = token;
}
var getAuthTokenFromTab = async function (callback, selectAccount) {
if (getDontPromptUserLogin()) {
callback(localStorage.accessToken);
return;
}
if (selectAccount) {
removeAuthToken();
}
//removeAuthToken();
if (isLocalAccessTokenValid()) {
if (callback) {
callback(localStorage.accessToken);
}
} else {
var focusOnAuthTabId = async function () {
if (authTabId) {
await chrome.tabs.update(authTabId, { "active": true });
if (!localStorage.warnedLogin) {
localStorage.warnedLogin = true;
alert("Please login to use Join");
}
} else {
//alert("Something went wrong. Please reload the Join extension.");
}
}
if (!isDoingAuth) {
isDoingAuth = true;
var url = await getAuthUrl(selectAccount);
if (localStorage.userinfo) {
var userinfo = JSON.parse(localStorage.userinfo);
if (userinfo.email) {
url += "&login_hint=" + userinfo.email;
}
}
var closeListener = async function (tabId, removeInfo) {
if (authTabId && tabId == authTabId) {
await finisher(tabId);
}
}
var authListener = async function (tabId, changeInfo, tab) {
if (tab?.url && tab.url.indexOf(await getCliendId()) > 0) {
authTabId = tabId;
await focusOnAuthTabId();
}
if (tab && tab.url && tab.url.indexOf(AUTH_CALLBACK_URL) == 0) {
var redirect_url = tab.url;
var token = getAuthTokenFromUrl(redirect_url);
await finisher(tabId, token, redirect_url);
}
}
var finisher = async function (tabId, token, redirect_url) {
authTabId = null;
await chrome.tabs.onUpdated.removeListener(authListener);
await chrome.tabs.onRemoved.removeListener(closeListener);
console.log("Auth token found from tab: " + token);
await chrome.tabs.remove(tabId);
var finshCallback = function (token) {
if (callback) {
callback(token);
}
waitingForAuthCallbacks.doForAll(function (waitingCallback) {
waitingCallback(token)
});
waitingForAuthCallbacks = [];
isDoingAuth = false;
}
if (token && redirect_url) {
var expiresIn = new Number(getURLParameter(redirect_url, "expires_in"));
setLocalAccessToken(token, expiresIn);
console.log("Token expires in " + expiresIn + " seconds");
getUserInfo(function (userInfoFromStorage) {
console.log("Logged in with: " + userInfoFromStorage.email);
finshCallback(token);
}, true, token);
} else {
finshCallback(null);
}
}
await chrome.tabs.onUpdated.addListener(authListener);
await chrome.tabs.onRemoved.addListener(closeListener)
openTab(url, { selected: false, active: false }, function (tab) {
console.log("Tab auth created");
console.log(tab);
});
} else {
if (callback) {
waitingForAuthCallbacks.push(callback);
await focusOnAuthTabId();
}
}
}
}
var getAuthTokenFromChrome = function (callback) {
}
var getAuthTokenPromise = function (selectAccount, token) {
return new Promise(function (resolve) {
getAuthToken(resolve, selectAccount, token);
});
}
var getAuthToken = function (callback, selectAccount, token) {
if (token) {
if (callback) {
callback(token);
}
return;
}
if (selectAccount) {
getAuthTokenFromTab(callback, selectAccount);
return;
}
chrome.identity.getProfileUserInfo(function (userInfoFromChrome) {
if (localStorage.userinfo) {
var userInfoFromStorage = JSON.parse(localStorage.userinfo);
if (userInfoFromStorage.email && userInfoFromStorage.email != userInfoFromChrome.email) {
getAuthTokenBackground(callback, selectAccount);
return;
}
}
if (!userInfoFromChrome.email) {
getAuthTokenFromTab(callback, selectAccount);
return;
}
chrome.identity.getAuthToken({ 'interactive': true }, function (token) {
if (callback) {
callback(token.token);
}
});
});
}
var getAuthTokenFromUrl = function (url) {
if (url.indexOf("#access_token=") > 0) {
return url.substring(url.indexOf("#") + "#access_token=".length, url.indexOf("&"));
}
}
var removeAuthToken = function (callback) {
delete localStorage.accessToken;
delete localStorage.authExpires;
delete localStorage.userinfo;
}
var doGetWithAuthAsyncRequest = function (endpointRequest, endpointGet, deviceId, callback, callbackError) {
doRequestWithAuth("GET", joinserver + "messaging/v1/" + endpointRequest + "?deviceId=" + deviceId, null, function (response) {
var requestId = response.requestId;
if (requestId) {
doGetWithAuthAsyncRequestGetResponse(joinserver + "messaging/v1/" + endpointGet + "?requestId=" + requestId, callback, callbackError);
} else {
callbackError({ "error": "didn't get request id" });
}
}, callbackError);
}
var doGetWithAuthAsyncRequestGetResponse = function (urlGet, callback, callbackError, count) {
if (count > 5) {
callbackError({ "error": "couldn't contact device" });
return;
}
setTimeout(function () {
if (!count) {
count = 0;
}
doRequestWithAuth("GET", urlGet, null, function (responseGet) {
if (responseGet.responseAvailable) {
callback(responseGet);
} else {
doGetWithAuthAsyncRequestGetResponse(urlGet, callback, callbackError, ++count);
}
}, callbackError);
}, 2000);
}
var getURLParameter = function (url, name) {
if (url == null) {
url = window.location.href;
}
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(url) || [, ""])[1].replace(/\+/g, '%20')) || null
}
var removeCachedAuthToken = async function (callback) {
removeAuthToken();
if (callback) {
callback();
}
/*chrome.identity.getAuthToken({ 'interactive': true }, function(token) {
chrome.identity.removeCachedAuthToken({ 'token': token }, function(){
console.log("cached token removed");
if(callback){
callback();
}
});
});*/
}
/****************************OPTIONS********************************/
// var getOptionType = function (option) {
// if (option.attributes.type) {
// return option.attributes.type.textContent;
// } else {
// return option.localName;
// }
// }
// var getOptionDelayed = function (option) {
// if (option.attributes.delayed) {
// return true;
// } else {
// return false;
// }
// }
// var isOptionUndefined = function (value) {
// return !value || value == "undefined" || value == "null" || value == "";
// }
// var optionSavers = [
// {
// "type": "text",
// "saveevent": "keyup",
// "save": function (option) {
// localStorage[option.id] = option.value;
// },
// "load": function (option) {
// option.value = this.getValue(option, getDefaultValue(option));
// },
// "getValue": function (option, defaultValue) {
// var id = null;
// if (typeof option == "string") {
// id = option;
// } else {
// id = option.id;
// }
// var value = localStorage[id];
// if (isOptionUndefined(value)) {
// if (!defaultValue) {
// defaultValue = "";
// }
// value = defaultValue;
// this.save(id, defaultValue);
// }
// return value;
// }, "setDefaultValue": function (option) {
// if (!option.value) {
// var defaultValue = getDefaultValue(option);
// if (!isOptionUndefined(defaultValue)) {
// option.value = defaultValue;
// }
// }
// }
// },
// {
// "type": "textarea",
// "saveevent": "keyup",
// "save": function (option) {
// localStorage[option.id] = option.value;
// },
// "load": function (option) {
// option.value = this.getValue(option, getDefaultValue(option));
// },
// "getValue": function (option, defaultValue) {
// var id = null;
// if (typeof option == "string") {
// id = option;
// } else {
// id = option.id;
// }
// var value = localStorage[id];
// if (isOptionUndefined(value)) {
// if (!defaultValue) {
// defaultValue = "";
// }
// value = defaultValue;
// this.save(id, defaultValue);
// }
// return value;
// }, "setDefaultValue": function (option) {
// if (!option.value) {
// var defaultValue = getDefaultValue(option);
// if (!isOptionUndefined(defaultValue)) {
// option.value = defaultValue;
// }
// }
// }
// }, {
// "type": "checkbox",
// "saveevent": "click",
// "save": function (option, value) {
// var id = null;
// if (typeof option == "string") {
// id = option;
// } else {
// id = option.id;
// value = option.checked;
// }
// localStorage[id] = value;
// var onSaveFunc = window["on" + id + "save"];
// if (onSaveFunc) {
// onSaveFunc(option, value);
// }
// },
// "load": function (option) {
// option.checked = this.getValue(option, getDefaultValue(option));
// },
// "getValue": function (option, defaultValue) {
// var id = null;
// if (typeof option == "string") {
// id = option;
// } else {
// id = option.id;
// }
// var value = localStorage[id];
// if (isOptionUndefined(value)) {
// value = defaultValue;
// this.save(id, defaultValue);
// } else if (value == "false") {
// value = false;
// } else {
// value = true;
// }
// return value;
// }, "setDefaultValue": function (option) {
// if (this.getValue(option, null) == null) {
// var defaultValue = getDefaultValue(option);
// option.checked = defaultValue;
// }
// }
// }, {
// "type": "select",
// "saveevent": "change",
// "save": function (option) {
// localStorage[option.id] = option.value;
// },
// "load": function (option) {
// option.value = this.getValue(option, getDefaultValue(option));
// if (option.funcOnChange) {
// option.funcOnChange();
// }
// },
// "getValue": function (option, defaultValue) {
// var id = null;
// if (typeof option == "string") {
// id = option;
// } else {
// id = option.id;
// }
// var value = localStorage[id];
// if (isOptionUndefined(value)) {
// if (!defaultValue) {
// defaultValue = "";
// }
// value = defaultValue;
// this.save(id, defaultValue);
// }
// return value;
// }, "setDefaultValue": function (option) {
// if (!option.value) {
// var defaultValue = getDefaultValue(option);
// if (!isOptionUndefined(defaultValue)) {
// option.value = defaultValue;
// }
// }
// }
// }, {
// "type": "color",
// "saveevent": "change",
// "save": function (option) {
// localStorage[option.id] = option.value;
// },
// "load": function (option) {
// option.value = this.getValue(option, getDefaultValue(option));
// if (option.funcOnChange) {
// option.funcOnChange();
// }
// },
// "getValue": function (option, defaultValue) {
// var id = null;
// if (typeof option == "string") {
// id = option;
// } else {
// id = option.id;
// }
// var value = localStorage[id];
// if (isOptionUndefined(value)) {
// if (!defaultValue) {
// defaultValue = "";
// }
// value = defaultValue;
// this.save(id, defaultValue);
// }
// return value;
// }, "setDefaultValue": function (option) {
// if (!option.value) {
// var defaultValue = getDefaultValue(option);
// if (!isOptionUndefined(defaultValue)) {
// option.value = defaultValue;
// }
// }
// }
// }
// ];
// var getOptionSaver = function (option) {
// for (var i = 0; i < optionSavers.length; i++) {
// var optionSaver = optionSavers[i];
// var type = typeof option == "string" ? option : getOptionType(option);
// if (optionSaver.type == type) {
// return optionSaver;
// }
// }
// }
// var deviceSufix = "=:=DeviceAutoClipboard=:=";
// var getDeviceIdsToSendAutoClipboard = function () {
// var deviceIds = [];
// for (var i = 0; i < devices.length; i++) {
// var device = devices[i];
// if (device.deviceId == localStorage.deviceId) {
// continue;
// }
// if (UtilsDevices.isDeviceGroup(device) || UtilsDevices.isDeviceShare(device)) {
// continue;
// }
// var key = device.deviceId + deviceSufix;
// var enabled = localStorage[key] == null || localStorage[key] == "true";
// if (enabled) {
// deviceIds.push(device.deviceId);
// }
// };
// return deviceIds;
// }
// var getOptionValue = function (type, id, defaultValue) {
// if (!defaultValue) {
// defaultValue = getDefaultValue(id);
// }
// var optionSaver = getOptionSaver(type);
// return optionSaver.getValue(id, defaultValue);
// }
// var saveOptionValue = function (type, id, value) {
// var optionSaver = getOptionSaver(type);
// return optionSaver.save(id, value);
// }
// var getDownloadScreenshotsEnabled = function () {
// return getOptionValue("checkbox", "downloadscreenshots");
// }
// var getOpenLinksEnabled = function () {
// return getOptionValue("checkbox", "autoopenlinks");
// }
// var getDownloadVideosEnabled = function () {
// return getOptionValue("checkbox", "downloadvideos");
// }
// var get12HourFormat = function () {
// return getOptionValue("checkbox", "12hrformat");
// }
// var getTheme = function () {
// return getOptionValue("select", "theme");
// }
// var getAutoClipboard = function () {
// return getOptionValue("checkbox", "autoclipboard");
// }
// var getClipboardNotificationShowContents = function () {
// return getOptionValue("checkbox", "clipboardnotificationshowcontents");
// }
// var getAutoClipboardNotification = function () {
// return getOptionValue("checkbox", "autoclipboardnotification");
// }
// var getFavoriteCommand = function () {
// return getOptionValue("select", "select_favourite_command");
// }
// var getFavoriteCommandDevice = function () {
// return getOptionValue("select", "select_favourite_command_device");
// }
// var getNotificationSeconds = function () {
// return getOptionValue("text", "notificationseconds");
// }
// var getNotificationIgnoreOldPushes = function () {
// return getOptionValue("text", "notificationignoreoldpushes");
// }
// var getNotificationRequireInteraction = function () {
// return getOptionValue("checkbox", "notificationrequireinteraction");
// }
// var getAddDismissEverywhereButton = function () {
// return getOptionValue("checkbox", "adddimisseverywherebutton");
// }
// var getNeverShowSimilarNotifications = function () {
// return getOptionValue("checkbox", "nevershowsimilarnotifications");
// }
// var getBetaEnabled = function () {
// return getOptionValue("checkbox", "showbetafeatures");
// }
// var getNotificationSound = function () {
// return getOptionValue("text", "notificationsound");
// }
// var getNotificationWebsites = function () {
// return getOptionValue("textarea", "notificationwebsites");
// }
// var getNotificationNoPopupPackages = function () {
// return getOptionValue("textarea", "notificationnopopuppackages");
// }
// var getShowChromeNotifications = function () {
// return getOptionValue("checkbox", "chromenotifications");
// }
// var setShowChromeNotifications = function (value) {
// saveOptionValue("checkbox", "chromenotifications", value);
// }
// var getPrefixTaskerCommands = function () {
// return getOptionValue("checkbox", "prefixtaskercommands");
// }
// var getHideNotificationText = function () {
// return getOptionValue("checkbox", "hidenotificationtext");
// }
// var getPlayNotificationSound = function () {
// return getOptionValue("checkbox", "playnotificationsound");
// }
// var getAlternativePopupIcon = function () {
// return getOptionValue("checkbox", "alternativeicon");
// }
// var getHideNotificationCount = function () {
// return getOptionValue("checkbox", "hidenotificationcount");
// }
// var getHideContextMenu = function () {
// return getOptionValue("checkbox", "hidecontextmenu");
// }
// var getDontPromptUserLogin = function () {
// return getOptionValue("checkbox", "dontpromptuserlogin");
// }
// var getShowInfoNotifications = function () {
// return getOptionValue("checkbox", "showinfonotifications");
// }
// var getEventghostPort = function () {
// return getOptionValue("text", "eventghostport");
// }
// var getEventghostServer = function () {
// return getOptionValue("text", "eventghostserver");
// }
// var getRedirectFullPush = function () {
// return getOptionValue("checkbox", "redirectionfullpush");
// }
// var getFavoriteCommandText = function () {
// return getOptionValue("text", "text_favourite_command");
// }
// var getVoiceEnabled = function () {
// return getOptionValue("checkbox", "voiceenabled");
// }
// var getVoiceContinuous = function () {
// return getOptionValue("checkbox", "voicecontinuous");
// }
// var getVoiceWakeup = function () {
// return getOptionValue("text", "voicewakeup");
// }
// var getThemeAccentColor = function () {
// return getOptionValue("color", "themeColorPicker");
// }
// var getDefaultTab = function () {
// return getOptionValue("select", "defaulttabb");
// }
// var onvoiceenabledsave = UtilsObject.async(function* (option, value) {
// if (!option) {
// return;
// }
// if (!option.ownerDocument) {
// return;
// }
// var continuousOption = option.ownerDocument.querySelector("#voicecontinuous");
// var continuousSection = option.ownerDocument.querySelector("#continuoussection");
// if (!value) {
// setVoiceContinuous(false);
// continuousOption.checked = false;
// continuousSection.classList.add("hidden");
// } else {
// continuousSection.classList.remove("hidden");
// }
// });
// var setVoiceContinuous = function (enabled) {
// saveOptionValue("checkbox", "voicecontinuous", enabled);
// }
// var onvoicecontinuoussave = async function (option, value) {
// console.log("Continuous: " + value);
// var callbackPromptFunc = (prompt, notificationTime) => {
// return new Promise(function (resolve, reject) {
// if (UtilsObject.isString(prompt)) {
// chrome.tts.speak(prompt, {
// "lang": 'en-US',
// "onEvent": function (event) {
// if (event.type == 'end' || event.type == 'error' || event.type == 'interrupted' || event.type == 'cancelled') {
// resolve();
// }
// }
// });
// showNotification("Voice", prompt, notificationTime);
// } else {
// console.error("Prompt is not text");
// console.error(prompt);
// }
// });
// };
// var errorFunc = error => {
// callbackPromptFunc(error, 10000);
// };
// if (value) {
// try {
// await UtilsVoice.voiceRecognizer.isMicAvailable();
// } catch (error) {
// setVoiceContinuous(false);
// chrome.tts.speak("Click the generated notification to enable your mic");
// var chromeNotification = new ChromeNotification({
// "id": "micnotavailable",
// "title": "Error",
// "text": "Click here to allow Join to access your microphone",
// "url": "chrome-extension://flejfacjooompmliegamfbpjjdlhokhj/options.html"
// });
// chromeNotification.notify();
// }
// }
// UtilsVoice.toggleContinuous(() => devices, getVoiceWakeup, getVoiceContinuous, callbackPromptFunc, null, errorFunc);
// };
// var onautoclipboardsave = function (option, value) {
// console.log("Auto clipboard: " + value);
// if (handleAutoClipboard) {
// handleAutoClipboard();
// }
// }
var updateContextMenu = async () => await contextMenu.update(devices, getHideContextMenu());
var updateContextMenuDevices = async (devices) => await contextMenu.update(devices);
async function getContextMenuContexts() {
return contextMenu.contexts;
}
var onchromenotificationssave = async function (option, value) {
console.log("Changed chrome notification popup setting: " + value);
await updateContextMenu();
}
var onshowbetafeaturessave = function (option, value) {
if (!option) {
return;
}
if (!option.ownerDocument) {
return;
}
back.console.log("Changed beta setting: " + value);
option.ownerDocument.location.reload();
}
// var getDefaultValue = function (option) {
// var id = null;
// if (typeof option == "string") {
// id = option;
// } else {
// id = option.id;
// }
// return defaultValues[id];
// }
// var defaultValues = {
// "downloadscreenshots": true,
// "downloadvideos": false,
// "12hrformat": false,
// "autoclipboard": false,
// "clipboardnotificationshowcontents": true,
// "autoclipboardnotification": true,
// "chromenotifications": true,
// "notificationwebsites": JSON.stringify(notificationPages, null, 1),
// "notificationnopopuppackages": "",
// "prefixtaskercommands": false,
// "hidenotificationtext": false,
// "hidenotificationcount": false,
// "hidecontextmenu": false,
// "dontpromptuserlogin": false,
// "playnotificationsound": true,
// "showinfonotifications": true,
// "autoopenlinks": true,
// "notificationrequireinteraction": false,
// "adddimisseverywherebutton": true,
// "showbetafeatures": false,
// "voiceenabled": false,
// "voicecontinuous": false,
// "voicewakeup": "computer",
// "themeColorPicker": "#FF9800",
// "theme": "auto",
// "defaulttabb": "auto",
// "favoritepageOpenenable": true,
// "favoriteselectionPasteenable": true,
// "favoritelinkOpenenable": true,
// "favoriteimageDownloadenable": true,
// "favoritevideoDownloadenable": true,
// "favoriteaudioDownloadenable": true
// };
if (getVoiceContinuous()) {
onvoicecontinuoussave(null, true);
}
//setShowChromeNotifications(true);
/******************************************************************************/
/*************************************************************************************/
/**************************************************************************************/
setPopupIcon(getAlternativePopupIcon());
var popupWindow = null;
updateBadgeText();
var refreshNotificationsPopup = function () {
updateBadgeText();
dispatch("notificationsupdated");
/*if(popupWindow){
try{
popupWindow.writeNotifications();
}catch(e){
popupWindow = null;
}
}*/
}
var refreshDevicesPopup = function () {
dispatch("devicesupdated");
/*if(popupWindow){
try{
popupWindow.writeDevices();
}catch(e){
popupWindow = null;
}
}*/
}
async function downloadFile(fileId) {
if (!fileId) {
return null;
}
try {
const accessToken = await getToken();
const options = {
headers: { 'Authorization': `Bearer ${accessToken}` }
}
const response = await fetch(`https://www.googleapis.com/drive/v2/files/${fileId}?alt=media`, options);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.text();
return data;
} catch (error) {
console.error('Failed to download file:', error);
return null;
}
}
/**************************************************************************************/
function extractNotificationDetails(notification) {
// List of properties to extract from the Notification instance
const properties = [
'id',
'title',
'body',