/
renderer.js
9599 lines (8811 loc) · 333 KB
/
renderer.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
//////////////////////////////////
// Import required modules
//////////////////////////////////
const fs = require("fs-extra");
const os = require("os");
const path = require("path");
const { ipcRenderer, BrowserWindow } = require("electron");
const Editor = require("@toast-ui/editor");
const remote = require("@electron/remote");
const { Notyf } = require("notyf");
const imageDataURI = require("image-data-uri");
const log = require("electron-log");
require("v8-compile-cache");
const Tagify = require("@yaireo/tagify");
const https = require("https");
const electron = require("electron");
const bootbox = require("bootbox");
const DragSelect = require("dragselect");
const excelToJson = require("convert-excel-to-json");
const csvToJson = require("convert-csv-to-json");
const Jimp = require("jimp");
const { JSONStorage } = require("node-localstorage");
const tippy = require("tippy.js").default;
const introJs = require("intro.js");
const selectpicker = require("bootstrap-select");
const { homedir } = require("os");
const diskCheck = require("check-disk-space").default;
const validator = require("validator");
const doiRegex = require("doi-regex");
const lottie = require("lottie-web");
const select2 = require("select2")();
const DragSort = require("@yaireo/dragsort");
const spawn = require("child_process").spawn;
const execFile = require("child_process").execFile;
// TODO: Test with a build
const { datasetUploadSession } = require("./scripts/others/analytics/upload-session-tracker");
const {
logCurationErrorsToAnalytics,
logCurationSuccessToAnalytics,
} = require("./scripts/others/analytics/curation-analytics");
const { determineDatasetLocation } = require("./scripts/others/analytics/analytics-utils");
const {
clientError,
userErrorMessage,
} = require("./scripts/others/http-error-handler/error-handler");
const { hasConnectedAccountWithPennsieve } = require("./scripts/others/authentication/auth");
const api = require("./scripts/others/api/api");
const axios = require("axios").default;
const DatePicker = require("tui-date-picker"); /* CommonJS */
const excel4node = require("excel4node");
const { backOff } = require("exponential-backoff");
// const prevent_sleep_id = "";
// const electron_app = electron.app;
const app = remote.app;
const Clipboard = electron.clipboard;
var nextBtnDisabledVariable = true;
var reverseSwalButtons = false;
var datasetStructureJSONObj = {
folders: {},
files: {},
type: "",
};
let introStatus = {
organizeStep3: true,
submission: false,
subjects: false,
samples: false,
};
//////////////////////////////////
// App launch actions
//////////////////////////////////
// Log file settings //
log.transports.console.level = false;
log.transports.file.maxSize = 1024 * 1024 * 10;
const homeDirectory = app.getPath("home");
const SODA_SPARC_API_KEY = "SODA-Pennsieve";
// get port number from the main process
log.info("Requesting the port");
const port = ipcRenderer.sendSync("get-port");
log.info("Port is: " + port);
// set to true once the SODA server has been connected to
let sodaIsConnected = false;
// set to true once the API version has been confirmed
let apiVersionChecked = false;
//log user's OS version //
log.info("User OS:", os.type(), os.platform(), "version:", os.release());
console.log("User OS:", os.type(), os.platform(), "version:", os.release());
// Check current app version //
const appVersion = app.getVersion();
console.log(appVersion);
log.info("Current SODA version:", appVersion);
console.log("Current SODA version:", appVersion);
// Here is where the splash screen lotties are created and loaded.
// A mutation observer watches for when the overview tab element has
// a class change to 'is-shown' to know when to load and unload the lotties
let over_view_section = document.getElementById("getting_started-section");
let column1 = document.getElementById("lottie1");
let column2 = document.getElementById("lottie2");
let column3 = document.getElementById("lottie3");
let heart_lottie = document.getElementById("heart_lottie");
var column1_lottie = lottie.loadAnimation({
container: column1,
animationData: column1Lottie /*(json js variable, (view src/assets/lotties)*/,
renderer: "svg",
loop: true /*controls looping*/,
autoplay: true,
});
var column2_lottie = lottie.loadAnimation({
container: column2,
animationData: column2Lottie /*(json js variable, (view src/assets/lotties)*/,
renderer: "svg",
loop: true /*controls looping*/,
autoplay: true,
});
var column3_lottie = lottie.loadAnimation({
container: column3,
animationData: column3Lottie,
renderer: "svg",
loop: true,
autoplay: true,
});
var heart_container = lottie.loadAnimation({
container: heart_lottie,
animationData: heartLottie,
renderer: "svg",
loop: true,
autoplay: true,
});
var overview_observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
var attributeValue = $(mutation.target).prop(mutation.attributeName);
if (attributeValue.includes("is-shown") == true) {
//add lotties
column1_lottie.play();
column2_lottie.play();
column3_lottie.play();
heart_container.play();
} else {
column1_lottie.stop();
column2_lottie.stop();
column3_lottie.stop();
heart_container.stop();
}
});
});
overview_observer.observe(over_view_section, {
attributes: true,
attributeFilter: ["class"],
});
document.getElementById("getting_starting_tab").click();
let launchAnnouncement = false;
ipcRenderer.on("checkForAnnouncements", (event, index) => {
launchAnnouncement = true;
let nodeStorage = new JSONStorage(app.getPath("userData"));
nodeStorage.setItem("announcements", false);
});
//////////////////////////////////
// Connect to Python back-end
//////////////////////////////////
let client = null;
// get port number from the main process
// TODO: change the default port so it is based off the discovered port in Main.js
client = axios.create({
baseURL: `http://127.0.0.1:${port}/`,
timeout: 300000,
});
const notyf = new Notyf({
position: { x: "right", y: "bottom" },
dismissible: true,
ripple: false,
types: [
{
type: "checking_server_is_live",
background: "grey",
icon: {
className: "fas fa-wifi",
tagName: "i",
color: "white",
},
duration: 1000,
},
{
type: "checking_server_api_version",
background: "grey",
icon: {
className: "fas fa-wifi",
tagName: "i",
color: "white",
},
duration: 1000,
},
{
type: "loading_internet",
background: "grey",
icon: {
className: "fas fa-wifi",
tagName: "i",
color: "white",
},
duration: 10000,
},
{
type: "ps_agent",
background: "grey",
icon: {
className: "fas fa-cogs",
tagName: "i",
color: "white",
},
duration: 5000,
},
{
type: "app_update",
background: "grey",
icon: {
className: "fas fa-sync-alt",
tagName: "i",
color: "white",
},
duration: 0,
},
{
type: "api_key_search",
background: "grey",
icon: {
className: "fas fa-users-cog",
tagName: "i",
color: "white",
},
duration: 0,
},
{
type: "success",
background: "#13716D",
icon: {
className: "fas fa-check-circle",
tagName: "i",
color: "white",
},
duration: 800,
},
{
type: "final",
background: "#13716D",
icon: {
className: "fas fa-check-circle",
tagName: "i",
color: "white",
},
duration: 3000,
},
{
type: "warning",
background: "#fa8c16",
icon: {
className: "fas fa-exclamation-triangle",
tagName: "i",
color: "white",
},
duration: 3000,
},
{
type: "info",
background: "#13716D",
icon: {
className: "fas fa-info-circle",
tagName: "i",
color: "white",
},
duration: 3000,
},
{
type: "app_update_warning",
background: "#fa8c16",
icon: {
className: "fas fa-tools",
tagName: "i",
color: "white",
},
duration: 0,
},
{
type: "error",
background: "#B80D49",
icon: {
className: "fas fa-times-circle",
tagName: "i",
color: "white",
},
duration: 3000,
},
],
});
let connected_to_internet = false;
let update_available_notification = "";
let update_downloaded_notification = "";
// utility function for async style set timeout
const wait = async (delay) => {
return new Promise((resolve) => setTimeout(resolve, delay));
};
// check that the client connected to the server using exponential backoff
// verify the api versions match
const startupServerAndApiCheck = async () => {
// wait for SWAL to be loaded in
await wait(2000);
// notify the user that the application is starting connecting to the server
Swal.fire({
icon: "info",
title: `Initializing SODA's background services...`,
heightAuto: false,
backdrop: "rgba(0,0,0, 0.4)",
confirmButtonText: "Restart now",
allowOutsideClick: false,
allowEscapeKey: false,
didOpen: () => {
Swal.showLoading();
},
});
// Darwin executable starts slowly
// use an exponential backoff to wait for the app server to be ready
// this will give Mac users more time before receiving a backend server error message
// ( during the wait period the server should start )
// Bonus: doesn't stop Windows and Linux users from starting right away
// NOTE: backOff is bad at surfacing errors to the console
//while variable is false keep requesting, if time exceeds two minutes break
let status = false;
let time_start = new Date();
let error = "";
while (true) {
try {
status = await serverIsLiveStartup();
} catch (e) {
error = e;
status = false;
}
time_pass = new Date() - time_start;
if (status) break;
if (time_pass > 120000) break; //break after two minutes
await wait(2000);
}
if (!status) {
//two minutes pass then handle connection error
// SWAL that the server needs to be restarted for the app to work
clientError(error);
ipcRenderer.send("track-event", "Error", "Establishing Python Connection", error);
await Swal.fire({
icon: "error",
html: `Something went wrong while initializing SODA's background services. Please restart SODA and try again. If this issue occurs multiple times, please email <a href='mailto:help@fairdataihub.org'>help@fairdataihub.org</a>.`,
heightAuto: false,
backdrop: "rgba(0,0,0, 0.4)",
confirmButtonText: "Restart now",
allowOutsideClick: false,
allowEscapeKey: false,
});
// Restart the app
app.relaunch();
app.exit();
}
console.log("Connected to Python back-end successfully");
log.info("Connected to Python back-end successfully");
ipcRenderer.send("track-event", "Success", "Establishing Python Connection");
// inform observers that the app is connected to the server
sodaIsConnected = true;
// dismiss the Swal
Swal.close();
// check if the API versions match
try {
await apiVersionsMatch();
} catch (e) {
// api versions do not match
app.exit();
}
// let nodeStorage = new JSONStorage(app.getPath("userData"));
// launchAnnouncement = nodeStorage.getItem("announcements");
if (launchAnnouncement) {
// nodeStorage.setItem("announcements", false);
await checkForAnnouncements("announcements");
launchAnnouncement = false;
nodeStorage.setItem("announcements", false);
}
apiVersionChecked = true;
};
startupServerAndApiCheck();
// Check if we are connected to the Pysoda server
// Check app version on current app and display in the side bar
// Also check the core systems to make sure they are all operational
ipcRenderer.on("run_pre_flight_checks", async (event, arg) => {
// run pre flight checks once the server connection is confirmed
// wait until soda is connected to the backend server
while (!sodaIsConnected || !apiVersionChecked) {
await wait(1000);
}
log.info("Done with startup");
// check integrity of all the core systems
await run_pre_flight_checks();
log.info("Running pre flight checks finished");
// get apps base path
const basepath = app.getAppPath();
const resourcesPath = process.resourcesPath;
// set the templates path
try {
await client.put("prepare_metadata/template_paths", {
basepath: basepath,
resourcesPath: resourcesPath,
});
} catch (error) {
clientError(error);
ipcRenderer.send("track-event", "Error", "Setting Templates Path");
return;
}
ipcRenderer.send("track-event", "Success", "Setting Templates Path");
});
const getPennsieveAgentPath = () => {
if (process.platform === "win32" || process.platform === "cygwin") {
const bit64Path = path.join("C:\\Program Files\\Pennsieve\\pennsieve.exe");
if (fs.existsSync(bit64Path)) {
return bit64Path;
}
const bit32Path = path.join("C:\\Program Files (x86)\\Pennsieve\\pennsieve.exe");
if (fs.existsSync(bit32Path)) {
return bit32Path;
}
} else {
const unixPath = "/usr/local/bin/pennsieve";
if (fs.existsSync(unixPath)) {
return unixPath;
}
}
throw new Error(`Cannot find pennsieve agent executable`);
};
const stopPennsieveAgent = async (pathToPennsieveAgent) => {
return new Promise((resolve, reject) => {
try {
const agentStopSpawn = spawn(pathToPennsieveAgent, ["agent", "stop"]);
agentStopSpawn.stdout.on("data", (data) => {
log.info(data.toString());
resolve();
});
agentStopSpawn.stderr.on("data", (data) => {
log.info(data.toString());
reject(new Error(data.toString()));
});
} catch (error) {
log.info(error);
reject(error);
}
});
};
const startPennsieveAgent = async (pathToPennsieveAgent) => {
return new Promise((resolve, reject) => {
try {
const agentStartSpawn = spawn(pathToPennsieveAgent, ["agent", "start"]);
agentStartSpawn.stdout.on("data", (data) => {
log.info(data.toString());
resolve();
});
agentStartSpawn.stderr.on("data", (data) => {
log.info(data.toString());
reject(new Error(data.toString()));
});
} catch (error) {
log.error(error);
reject(error);
}
});
};
const getPennsieveAgentVersion = async (pathToPennsieveAgent) => {
return new Promise((resolve, reject) => {
try {
// Timeout if the agent was not able to be retrieved within 7 seconds
const versionCheckTimeout = setTimeout(() => {
reject(
new Error(
"Timeout Error: The agent version was not able to be verified in the allotted time"
)
);
}, 7000);
const agentVersionSpawn = execFile(pathToPennsieveAgent, ["version"]);
agentVersionSpawn.stdout.on("data", (data) => {
log.info(data.toString());
const versionResult = {};
const regex = /(\w+ Version)\s*:\s*(\S+)/g;
let match;
while ((match = regex.exec(data)) !== null) {
versionResult[match[1]] = match[2];
}
// If we were able to extract the version from the stdout, resolve the promise
if (versionResult["Agent Version"]) {
clearTimeout(versionCheckTimeout);
resolve(versionResult);
}
});
agentVersionSpawn.stderr.on("data", (data) => {
clearTimeout(versionCheckTimeout);
log.info(data.toString());
reject(new Error(data.toString()));
});
} catch (error) {
log.error(error);
reject(error);
}
});
};
// Start the Pennsieve agent and check the version
// If any of the mandatory steps fail, the user will be notified on how to alleviate the issue
// and the promise will be rejected
const startPennsieveAgentAndCheckVersion = async () => {
return new Promise(async (resolve, reject) => {
// First get the latest Pennsieve agent version on GitHub
// This is to ensure the user has the latest version of the agent
let browser_download_url;
let latest_agent_version;
try {
[browser_download_url, latest_agent_version] = await get_latest_agent_version();
} catch (error) {
await Swal.fire({
icon: "error",
text: "We are unable to get the latest version of the Pennsieve Agent. Please try again later. If this issue persists please contact the SODA team at help@fairdataihub.org",
heightAuto: false,
backdrop: "rgba(0,0,0, 0.4)",
showCancelButton: true,
confirmButtonText: "Ok",
showClass: {
popup: "animate__animated animate__zoomIn animate__faster",
},
hideClass: {
popup: "animate__animated animate__zoomOut animate__faster",
},
});
log.error(error);
reject(error);
}
// Get the path to the Pennsieve agent
// If the path that the Pennsieve agent should be at is not found,
// alert the user and open the download page for the Pennsieve agent
try {
agentPath = getPennsieveAgentPath();
} catch (error) {
const { value: result } = await Swal.fire({
icon: "error",
title: "Pennsieve Agent Not Found",
text: "It looks like the Pennsieve Agent is not installed on your computer. Please download the latest version of the Pennsieve Agent and install it. Once you have installed the Pennsieve Agent, please restart SODA.",
heightAuto: false,
backdrop: "rgba(0,0,0, 0.4)",
showCancelButton: true,
reverseButtons: reverseSwalButtons,
confirmButtonText: "Download now",
cancelButtonText: "Skip for now",
});
if (result) {
shell.openExternal(browser_download_url);
shell.openExternal("https://docs.pennsieve.io/docs/uploading-files-programmatically");
}
log.error(error);
reject(error);
}
// Stop the Pennsieve agent if it is running
// This is to ensure that the agent is not running when we try to start it so no funny business happens
try {
await stopPennsieveAgent(agentPath);
} catch (error) {
// If the agent is not running then we can ignore this error
// But it shouldn't throw if the agent is running or not
log.error(error);
}
// Start the Pennsieve agent
try {
await startPennsieveAgent(agentPath);
} catch (error) {
log.error(error);
reject(error);
}
// Get the version of the Pennsieve agent
let pennsieveAgentVersion;
try {
pennsieveAgentVersionObj = await getPennsieveAgentVersion(agentPath);
pennsieveAgentVersion = pennsieveAgentVersionObj["Agent Version"];
} catch (error) {
log.error(error);
reject(error);
}
if (pennsieveAgentVersion !== latest_agent_version) {
let { value: result } = await Swal.fire({
icon: "warning",
text: "It appears that you are not running the latest version of the Pensieve Agent. Please download the latest version of the Pennsieve Agent and install it. Once you have installed the Pennsieve Agent, please restart SODA.",
heightAuto: false,
backdrop: "rgba(0,0,0, 0.4)",
showCancelButton: true,
confirmButtonText: "Download now",
cancelButtonText: "Skip for now",
reverseButtons: reverseSwalButtons,
showClass: {
popup: "animate__animated animate__zoomIn animate__faster",
},
hideClass: {
popup: "animate__animated animate__zoomOut animate__faster",
},
});
if (result) {
shell.openExternal(browser_download_url);
shell.openExternal("https://docs.pennsieve.io/docs/uploading-files-programmatically");
}
reject("The installed version of the Pennsieve agent is not the latest version.");
}
// The Pennsieve agent is now running so we can now resolve the promise
resolve();
});
};
// Run a set of functions that will check all the core systems to verify that a user can upload datasets with no issues.
const run_pre_flight_checks = async (check_update = true) => {
log.info("Running pre flight checks");
let connection_response = "";
let account_present = false;
// Check the internet connection and if available check the rest.
connection_response = await check_internet_connection();
if (!connection_response) {
await Swal.fire({
title: "No Internet Connection",
icon: "success",
text: "It appears that your computer is not connected to the internet. You may continue, but you will not be able to use features of SODA related to Pennsieve and especially none of the features located under the 'Manage Datasets' section.",
heightAuto: false,
backdrop: "rgba(0,0,0, 0.4)",
confirmButtonText: "I understand",
showConfirmButton: true,
showClass: {
popup: "animate__animated animate__zoomIn animate__faster",
},
hideClass: {
popup: "animate__animated animate__zoomOut animate__faster",
},
});
return false;
}
// TODO: Remove? Test first.
await wait(500);
// TODO: Start the agent here or while determining installation and agent version.
// Check for an API key pair first. Calling the agent check without a config file, causes it to crash.
account_present = await check_api_key();
// TODO: Reimplement this section to work with the new agent
if (!account_present) {
if (check_update) {
checkNewAppVersion();
}
// If there is no API key pair, show the warning and let them add a key. Messages are dissmisable.
let { value: result } = await Swal.fire({
icon: "warning",
text: "It seems that you have not connected your Pennsieve account with SODA. We highly recommend you do that since most of the features of SODA are connected to Pennsieve. Would you like to do it now?",
heightAuto: false,
backdrop: "rgba(0,0,0, 0.4)",
confirmButtonText: "Yes",
showCancelButton: true,
reverseButtons: reverseSwalButtons,
cancelButtonText: "I'll do it later",
showClass: {
popup: "animate__animated animate__zoomIn animate__faster",
},
hideClass: {
popup: "animate__animated animate__zoomOut animate__faster",
},
});
// TODO: Especially test this part cuz its getting tricky in the conversion
if (result) {
await openDropdownPrompt(null, "bf");
return false;
} else {
return true;
}
}
// an account is present
// Check for an installed Pennsieve agent
let pennsieveAgentCheckNotyf;
try {
// Open a notyf to let the user know that we are checking for the agent that closes only if the agent is found.
pennsieveAgentCheckNotyf = notyf.open({
type: "info",
message: "Checking to make sure the latest Pennsieve Agent is installed...",
duration: 0, // 0 means it will not close automatically
});
await startPennsieveAgentAndCheckVersion();
notyf.dismiss(pennsieveAgentCheckNotyf);
notyf.open({
type: "success",
message: "The latest Pennsieve Agent is installed.",
});
} catch (error) {
notyf.dismiss(pennsieveAgentCheckNotyf);
notyf.open({
type: "error",
message: "Unable to start the Pennsieve Agent.",
});
log.error(error);
return false;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (check_update) {
checkNewAppVersion();
}
await wait(500);
notyf.open({
type: "final",
message: "You're all set!",
});
// let nodeStorage = new JSONStorage(app.getPath("userData"));
// launchAnnouncement = nodeStorage.getItem("announcements");
if (launchAnnouncement) {
// nodeStorage.setItem("announcements", false);
await checkForAnnouncements("announcements");
launchAnnouncement = false;
}
return true;
};
// Check if the Pysoda server is live
const serverIsLiveStartup = async () => {
let echoResponseObject;
try {
echoResponseObject = await client.get("/startup/echo?arg=server ready");
} catch (error) {
throw error;
}
let echoResponse = echoResponseObject.data;
return echoResponse === "server ready" ? true : false;
};
// Check if the Pysoda server API version and the package.json versions match
const apiVersionsMatch = async () => {
// notyf that tells the user that the server is checking the versions
let notification = notyf.open({
message: "Checking API Version",
type: "checking_server_api_version",
});
let responseObject;
try {
responseObject = await client.get("/startup/minimum_api_version");
} catch (e) {
clientError(e);
ipcRenderer.send("track-event", "Error", "Verifying App Version", userErrorMessage(e));
await Swal.fire({
icon: "error",
html: `Something went wrong while initializing SODA's background services. Please try restarting your computer and reinstalling the latest version of SODA. If this issue occurs multiple times, please email <a href='mailto:help@fairdataihub.org'>help@fairdataihub.org</a>.`,
heightAuto: false,
backdrop: "rgba(0,0,0, 0.4)",
confirmButtonText: "Close now",
allowOutsideClick: false,
allowEscapeKey: false,
});
throw e;
}
let serverAppVersion = responseObject.data.version;
log.info(`Server version is ${serverAppVersion}`);
if (serverAppVersion !== appVersion) {
log.info("Server version does not match client version");
console.error("Server version does not match client version");
ipcRenderer.send(
"track-event",
"Error",
"Verifying App Version",
"Server version does not match client version"
);
await Swal.fire({
icon: "error",
html: `${appVersion} ${serverAppVersion}The minimum app versions do not match. Please try restarting your computer and reinstalling the latest version of SODA or check to see if a previous version is running in the background with the instructions on our <a href='https://docs.sodaforsparc.io/docs/common-errors/pennsieve-agent-is-already-running' target='_blank'>documentation page.</a> If this issue occurs multiple times, please email <a href='mailto:help@fairdataihub.org'>help@fairdataihub.org</a>.`,
heightAuto: false,
backdrop: "rgba(0,0,0, 0.4)",
confirmButtonText: "Close now",
allowOutsideClick: false,
allowEscapeKey: false,
});
//await checkForAnnouncements("update")
throw new Error();
}
ipcRenderer.send("track-event", "Success", "Verifying App Version");
notyf.dismiss(notification);
// create a success notyf for api version check
notyf.open({
message: "API Versions match",
type: "success",
});
//Load Default/global Pennsieve account if available
if (hasConnectedAccountWithPennsieve()) {
updateBfAccountList();
}
checkNewAppVersion(); // Added so that version will be displayed for new users
};
const check_internet_connection = async (show_notification = true) => {
let notification = null;
if (show_notification) {
notification = notyf.open({
type: "loading_internet",
message: "Checking Internet status...",
});
}
await wait(800);
return require("dns").resolve("www.google.com", async (err) => {
if (err) {
console.error("No internet connection");
log.error("No internet connection");
ipcRenderer.send("warning-no-internet-connection");
if (show_notification) {
notyf.dismiss(notification);
notyf.open({
type: "error",
message: "Not connected to internet",
});
}
connected_to_internet = false;
return connected_to_internet;
} else {
console.log("Connected to the internet");
log.info("Connected to the internet");
if (show_notification) {
notyf.dismiss(notification);
notyf.open({
type: "success",
message: "Connected to the internet",
});
}
connected_to_internet = true;
return connected_to_internet;
}
});
};
const check_api_key = async () => {
let notification = null;
notification = notyf.open({
type: "api_key_search",
message: "Checking for Pennsieve account...",
});
await wait(800);
// If no accounts are found, return false.
let responseObject;
if (!hasConnectedAccountWithPennsieve()) {
notyf.dismiss(notification);
notyf.open({
type: "error",
message: "No account was found",
});
return false;
}
try {
responseObject = await client.get("manage_datasets/bf_account_list");
} catch (e) {
notyf.dismiss(notification);
notyf.open({
type: "error",
message: "No account was found",
});
return false;
}
let res = responseObject.data["accounts"];
log.info("Found a set of valid API keys");
if (res[0] === "Select" && res.length === 1) {
//no api key found
notyf.dismiss(notification);
notyf.open({
type: "error",
message: "No account was found",
});
return false;
} else {
notyf.dismiss(notification);
notyf.open({
type: "success",
message: "Connected to Pennsieve",
});
return true;
}
};
// return the agent version or an error if the agent is not installed
const check_agent_installed = async () => {
let notification = null;
notification = notyf.open({
type: "ps_agent",
message: "Searching for Pennsieve Agent...",
});
try {
responseObject = await client.get("/manage_datasets/check_agent_install");
} catch (error) {
clientError(error);
notyf.dismiss(notification);
notyf.open({
type: "error",
message: "Pennsieve agent not found",
});
log.warn("Pennsieve agent not found");
return [false, userErrorMessage(error)];
}
let { agent_version } = responseObject.data;
notyf.dismiss(notification);
notyf.open({
type: "success",
message: "Pennsieve agent found",
});
log.info("Pennsieve agent found");