menu.html 5.68 KB
Newer Older
1
2
3
4
5
6
<!DOCTYPE html>
<html>
<head><title>GUI for Agkyra Pithos+ Syncing Client</title></head>
<body>
    <script src="protocol.js"></script>
    <script src="settings.js"></script>
7
    <script src="static/js/jquery.js"></script>
8
9
    <script type="text/javascript">

10
var DEBUG = true;
11
12

// Setup GUI
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
var windows = {
  "settings": null,
  "about": null,
  "index": gui.Window.get()
}
function closeWindows() {
  for (win in windows) if (windows[win]) windows[win].close();
}

// GUI components
var tray = new gui.Tray({
  title: 'Agkyra syncs with Pithos+',
  icon: 'images/tray.png'
});

var menu = new gui.Menu();

// Progress and Pause
var start_syncing = 'Start Syncing';
var start_icon = 'images/play.png';
var pause_syncing = 'Pause Syncing';
var paused = true;

progress_item = new gui.MenuItem({
  // progress menu item
  label: 'Initializing',
  type: 'normal',
  enabled: false
});
menu.append(progress_item);
menu.append(new gui.MenuItem({type: 'separator'}));
pause_item = new gui.MenuItem({
  // pause menu item
  icon: 'images/play_pause.png',
47
  label: 'NOT READY',
48
49
50
51
52
53
54
55
56
  type: 'normal',
  click: function() {
    if (paused) {post_start(socket);} else {post_pause(socket);}
  }
});
pause_item.enabled = false;
menu.append(pause_item);

// Menu actions contents
57
var local_folder_menu = new gui.MenuItem({
58
59
  label: 'Open local folder',
  icon: 'images/folder.png',
60
  enabled: false,
61
62
  click: function () {
    var dir = globals['settings']['directory'];
63
    if (DEBUG) console.log('Open ' + dir);
64
65
    gui.Shell.showItemInFolder(dir);
  }
66
67
})
menu.append(local_folder_menu);
68

69
var pithos_page_menu = new gui.MenuItem({
70
71
  label: 'Launch Pithos+ page',
  icon: 'images/pithos.png',
72
  enabled: false,
73
  click: function () {
74
    if (DEBUG) console.log('Visit ' + get_pithos_ui());
75
    gui.Shell.openExternal(get_pithos_ui());
76
  }
77
78
});
menu.append(pithos_page_menu);
79
80
81

// Settings and About
menu.append(new gui.MenuItem({type: 'separator'}));
82
var settings_menu = new gui.MenuItem({
83
84
  label: 'Settings',
  icon: 'images/settings.png',
85
  enabled: false,
86
87
88
  click: function () {
    export_settings(globals.settings);
    if (windows['settings']) windows['settings'].close();
89
90
    var old_settings = {};
    $.each(globals.settings, function(key, val) {old_settings[key]=val;});
91
92
    windows['settings'] = gui.Window.open("settings.html", {
      toolbar: false, focus: true,
93
      width: 841, height: 520
94
95
    });
    windows['settings'].on('closed', function() {
96
      if (DEBUG) console.log('Settings windows is closed');
97
98
99
      var new_settings = import_settings();
      $.each(new_settings, function(key, setting) {
        if (old_settings[key] !== setting) {
100
          if (DEBUG) console.log('Settings have been modified - updating...');
101
102
103
104
105
106
          put_settings(socket, new_settings);
          get_status(socket);
          get_settings(socket);
          return false;
        }
      });
107
108
    });
  },
109
110
});
menu.append(settings_menu);
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

menu.append(new gui.MenuItem({
  label: 'About',
  icon: 'images/about.png',
  click: function () {
    if (windows['about']) windows['about'].close();
    windows['about'] = gui.Window.open("about.html", {
      toolbar: false, resizable: false, focus: true,
      width: 679, height: 420
    });
  }
}));

// Quit
menu.append(new gui.MenuItem({type: 'separator'}));
menu.append(new gui.MenuItem({
  label: 'Quit Agkyra',
  icon: 'images/exit.png',
  click: function() {post_shutdown(socket);}
}));

132
133
134
135

// Update progress
var client_ready = false;
window.setInterval(function() {
136
137
138
139
140
  if (globals.open_settings) {
    globals.open_settings = false;
    settings_menu.click();
  }

141
  var menu_modified = false;
142
  if (!client_ready) {
143
144
    if (!globals.authenticated) return;
    client_ready = true;
145
146
147
  }

  if (client_ready) {
148
149
150
151
152
153
    if (!settings_menu.enabled) {
      if (globals.settings.url) refresh_endpoints(globals.settings.url);
      settings_menu.enabled = true;
      tray.menu = menu;
    }
    if (globals.settings.url && !pithos_page_menu.enabled) {
154
155
156
      if (get_pithos_ui() != null) {
        pithos_page_menu.enabled = true;
        tray.menu = menu;
157
      } else { refresh_endpoints(globals.settings.url); }
158
159
160
161
    }
    if (!local_folder_menu.enabled) {
      if (globals.settings.directory) {
        local_folder_menu.enabled = true;
162
        tray.menu = menu;
163
164
165
166
167
168
169
      }
    }
  }

  var status = globals['status'];
  var new_progress = progress_item.label;
  var new_pause = pause_item.label;
170
171
172
173
  if (!status.can_sync) {
    new_progress = 'Incomplete settings'
    new_pause = 'inactive'
    pause_item.enabled = false;
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
  } else {
    if (status.paused !== null) {
      switch(pause_item.label) {
        case pause_syncing: if (status.paused) {
            // Update to "Paused - start syncing"
            paused = true;
            new_pause = start_syncing;
            menu_modified = true;
          } // else continue syncing
        break;
        case start_syncing: if (!status.paused) {
            //update to "Syncing - pause syncing"
            paused = false;
            new_pause = pause_syncing;
            menu_modified = true;
          }
        break;
        default:
          if (status.paused) {new_pause = start_syncing; paused=true;}
          else {new_pause = pause_syncing; paused=false;}
          pause_item.enabled = true;
195
          menu_modified = true;
196
      }
197
    }
198
    new_progress = status.synced + ' of ' + status.unsynced + ' synced';
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
  }
  if (new_pause != pause_item.label) {
    pause_item.label = new_pause;
    menu_modified = true;
  }
  if (new_progress != progress_item.label) {
    progress_item.label = new_progress;
    menu_modified = true;
  }
  if (menu_modified) {
    if (paused) progress_item.label += ' - paused';
    tray.menu = menu;
  }
  get_status(socket);
}, 1500);

215
216
217
218
tray.menu = menu;

    </script>
</body>
219
</html>