3a6c213ae2469bb988c02fb48655ba7897be798c
[DeezloaderRemix.git] / app / public / js / appBase.js
1 if(typeof require !== "undefined"){
2         var shell = require('electron').shell;
3         var remote = require('electron').remote;
4         var dialog = remote.dialog;
5         var packageFile = remote.require('./package.json');
6         var mainApp = remote.require('./app');
7         var path = remote.require('path');
8 }
9 const version = (typeof packageFile === 'undefined') ? $("#appVersionFallback").text() : packageFile.version;
10
11 (function () {
12         //open links externally by default
13         $(document).on('click', 'a[href^="http"]', function (event) {
14                 event.preventDefault();
15                 shell.openExternal(this.href);
16         });
17
18         // selectAll-"feature"...its really crappy to wait for document change
19         // but since the materialize modal initialization is a fucking callback hell,
20         // this is pretty much the only option...will (hopefully) be refactored in
21         // version 2.4.0 when the entire rendering is switched to vue's...
22         $(document).on('change', 'input:checkbox.selectAll', function(){
23                 $('input:checkbox.trackCheckbox').prop('checked', $(this).prop('checked'));
24         });
25
26         // Open DevTools when F12 is pressed
27         // Reload page when F5 is pressed
28         document.addEventListener("keydown", function (e) {
29                 if (e.which === 123) {
30                         if(typeof require !== "undefined"){
31                                 remote.getCurrentWindow().toggleDevTools();
32                         }
33                 }
34
35                 if (e.which === 116) {
36                         if(typeof require !== "undefined"){
37                                 remote.getCurrentWindow().reload();
38                         }
39                 }
40         });
41
42         // Function to make title-bar work
43         function initTitleBar() {
44                 let $mainEl = $('#title-bar');
45                 if(typeof require !== "undefined"){
46                         const window = remote.getCurrentWindow();
47
48                         $mainEl.find('#min-btn').on('click', function () {
49                                 window.minimize();
50                         });
51
52                         $mainEl.find('#max-btn').on('click', function () {
53                                 if (!window.isMaximized()) {
54                                         window.maximize();
55                                 } else {
56                                         window.unmaximize();
57                                 }
58                         });
59
60                         $mainEl.find('#close-btn').on('click', function () {
61                                 window.close();
62                         });
63                 }else{
64                         $mainEl.css('display','none');
65                         $('nav').css('top','0');
66                         $('nav').css('margin-top','0');
67                 }
68                 $mainEl.find('#application_version').text(version);
69         }
70
71         // Ready state of the page
72         document.onreadystatechange = function () {
73                 if (document.readyState == "complete") {
74                         initTitleBar();
75                         $('#application_version_about').text(version);
76                         $('#application_version_logo').text(version.replace(/\.[^/.]+$/, ""));
77
78                         $('#modal_settings_input_downloadTracksLocation').on('click', function () {
79                                 if(typeof require !== "undefined"){
80                                         $(this).val(dialog.showOpenDialog({
81                                                 properties: ['openDirectory']
82                                         }));
83                                 }
84                         });
85                 }
86         };
87 })(jQuery);