Full screen modals for mobile view
[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         if (typeof require !== "undefined"){
29                 if (remote.process.env.NODE_ENV == 'development'){
30                         document.addEventListener("keydown", function (e) {
31                                 if (e.which === 123) {
32                                         remote.getCurrentWindow().toggleDevTools()
33                                 }
34                                 if (e.which === 116) {
35                                         remote.getCurrentWindow().reload()
36                                 }
37                         });
38                 }
39         }
40
41         // Function to make title-bar work
42         function initTitleBar() {
43                 let $mainEl = $('#title-bar')
44                 if(typeof require !== "undefined"){
45                         const window = remote.getCurrentWindow()
46                         $mainEl.find('#min-btn').on('click', function () {
47                                 window.minimize()
48                         })
49                         $mainEl.find('#max-btn').on('click', function () {
50                                 if (!window.isMaximized()) {
51                                         window.maximize()
52                                 } else {
53                                         window.unmaximize()
54                                 }
55                         })
56                         $mainEl.find('#close-btn').on('click', function () {
57                                 window.close()
58                         })
59                 }else{
60                         $mainEl.css('display','none')
61                         $('nav').css('top','0')
62                         $('nav').css('margin-top','0')
63                         $('#main_icon').css('margin-top','0')
64                         document.documentElement.style.setProperty('--appbar-height', "0px")
65                 }
66                 $mainEl.find('#application_version').text(version)
67         }
68
69         // Ready state of the page
70         document.onreadystatechange = function () {
71                 if (document.readyState == "complete") {
72                         initTitleBar()
73                         $('#application_version_about').text(version)
74                         $('#application_version_logo').text(version.replace(/\.[^/.]+$/, ""))
75                         if(typeof require !== "undefined"){
76                                 $('#modal_settings_input_downloadTracksLocation').on('click', function () {
77                                         let originalValue = $(this).val()
78                                         let newValue = dialog.showOpenDialog({
79                                                 properties: ['openDirectory']
80                                         })
81                                         if (typeof newValue !== 'undefined'){
82                                                 $(this).val(newValue)
83                                         }
84                                 })
85                         }else{
86                                 $("#openDownloadsFolder").parent().hide()
87                                 $("#cancelAllTable").parent().removeClass("m4").addClass("m6")
88                                 $("#clearTracksTable").parent().removeClass("m4").addClass("m6")
89                                 $("#modal_settings_cbox_minimizeToTray").parent().parent().hide()
90                         }
91                 }
92         };
93 })(jQuery)