summaryrefslogtreecommitdiff
path: root/addWindow.html
blob: 2a1a1158bed022d0fc5ac09caf9c20478394a0bf (plain) (blame)
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
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Specify Path</title>
  <link rel="stylesheet" href="login.css">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.10/css/all.css" integrity="sha384-+d0P83n9kaQMCwj8F4RJB66tzIwOKmrdb46+porD/OvrJ+37WqIM7UoBtwHO6Nlg">
</head>
<body>
  <div class="controls"></div>
  <div class="path-container">
    <h1>Game Path</h1>
    <p>Specify the path to your 'Wizard101' folder</p>
    <input type="text" id="game-path" class="keyBox"/>
    <button id="browse">Browse</button>
    <div class="buttons">
      <div class="roundBtn is-light-gray" id="save"><i class="far fa-save"></i>
Save</div>
      <div class="roundBtn is-red" id="reset"><i class="fas fa-sync-alt"></i>
Reset</div>
    </div>
    

  </div>

  <script>
    const electron = require('electron');
    const {ipcRenderer} = electron;
    const { remote } = require('electron')
    
    const browseBtn = document.getElementById('browse');
    const pathInput = document.getElementById('game-path');
    const save = document.getElementById('save');
    const reset = document.getElementById('reset');
    
    let resetPath = "N/A";
    let currentPath = "N/A";

    // Request some stuff from the main process when window loads
    document.addEventListener('DOMContentLoaded', function () {
        ipcRenderer.send('request:reset');
        ipcRenderer.send('request:current');
    });

    // Get original path for reset
    ipcRenderer.on('reset:path', function(e, path) {
      resetPath = path;
    });

    // Get current path
    ipcRenderer.on('current:path', function(e, path) {
      currentPath = path;
      pathInput.value = currentPath;
    });

    browseBtn.addEventListener('click', function(e) {
      e.preventDefault();
      const pathArray = remote.dialog.showOpenDialog({ properties: ['openDirectory'] })
      pathInput.value = pathArray;
    });

    save.addEventListener('click', function(e) {
      let newPath = pathInput.value;
      if (newPath.length == 0) {
        alert("Path is empty");
      }
      else {
        newPath = newPath.replace(" ", "\\ ");
        newPath = newPath.replace("\\\\", "\\");
        newPath = newPath.replace("101/", "101");
        ipcRenderer.send('path:change', newPath);
        let notif = new Notification('Configuration Updated', {
          body: 'New game path successfully saved',
          icon: 'https://i.imgur.com/FQNnvrd.png',
          image: 'https://i.imgur.com/FQNnvrd.png'
        });
      }
    });
    
    reset.addEventListener('click', function(e) {
      pathInput.value = resetPath;
    });
  </script>

</body>
</html>