-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsync_status.js
183 lines (167 loc) · 6.45 KB
/
sync_status.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
const St = imports.gi.St;
const Lang = imports.lang;
const Panel = imports.ui.panel;
const Clutter = imports.gi.Clutter;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const DBus = Me.imports.dbus;
const EverpadProgressBar = Me.imports.progress_bar;
const Constants = Me.imports.constants;
const EverpadSyncStatus = new Lang.Class({
Name: "EverpadSyncStatus",
_init: function() {
this.actor = new St.Table({
homogeneous: false
});
this._spinner = new Panel.AnimatedIcon('process-working.svg', 24);
this.actor.add(this._spinner.actor, {
row: 0,
col: 1,
expand: false,
x_fill: false,
y_fill: false,
x_align: St.Align.START,
y_align: St.Align.MIDDLE
});
this._sync_button = new St.Button({
style_class: 'everpad-sync-icon-button-box'
})
this._sync_button_icon = new St.Icon({
icon_name: "emblem-synchronizing-symbolic",
style_class: 'everpad-sync-icon-button'
});
this._sync_button.add_actor(this._sync_button_icon);
this._sync_button.connect("clicked", Lang.bind(this,
this._on_button_clicked
));
this.actor.add(this._sync_button, {
row: 0,
col: 1,
expand: false,
x_fill: false,
y_fill: false,
x_align: St.Align.START,
y_align: St.Align.MIDDLE
});
this._label = new St.Label({
style_class: "everpad-sync-status-label"
});
this.actor.add(this._label, {
row: 0,
col: 0,
expand: false,
x_fill: false,
y_fill: false,
x_align: St.Align.MIDDLE,
y_align: St.Align.MIDDLE
});
this.show_message(
"<span color='white' font='12' weight='bold'>" +
"Last sync: no data</span>",
false,
true
)
this.progress_bar = new EverpadProgressBar.EverpadProgressBar();
this.progress_bar.hide();
this.actor.add(this.progress_bar.actor, {
row: 1,
col: 0,
col_span: 2,
expand: true,
x_fill: true,
y_fill: false,
x_align: St.Align.MIDDLE,
y_align: St.Align.MIDDLE
});
},
_on_button_clicked: function() {
DBus.get_everpad_provider().syncRemote();
},
check_status: function() {
DBus.get_everpad_provider().is_first_syncedRemote(
Lang.bind(this, function([result], error) {
if(result != null) {
let is_first_synced = result;
DBus.get_everpad_provider().get_statusRemote(
Lang.bind(this, function([result], error) {
if(result != null) {
let status = result;
if(is_first_synced) {
if(status === Constants.STATUS_SYNC) {
this.show_message(
"<span color='white' font='10' font-style='italic'>" +
"Sync in progress...</span>",
true,
false
);
}
else {
DBus.get_everpad_provider().get_last_syncRemote(
Lang.bind(this, function([result], error) {
if(result !== null) {
this.show_message(
"<span color='white' font='12' weight='bold'>" +
"Last sync: %s</span>".format(result),
false,
true
);
}
else {
log(error);
}
})
);
}
}
else {
if(status === Constants.STATUS_SYNC) {
this.show_message(
"<span color='white' font='8'>Wait, first sync in " +
"progress...</span>",
true,
false
);
}
else {
let msg =
"<span color='red' font-style='italic' font='10'>" +
"Please perform first sync.</span>"
this.show_message(msg, false, true);
}
}
}
else {
log(error);
}
})
);
}
else {
log(error);
}
})
);
},
show_message: function(text, show_spinner, show_sync_button) {
show_spinner = show_spinner || false;
show_sync_button = show_sync_button || false;
this._label.clutter_text.set_markup(text);
if(show_spinner) {
this._spinner.actor.show();
}
else {
this._spinner.actor.hide();
}
if(show_sync_button) {
this._sync_button.show();
}
else {
this._sync_button.hide();
}
},
destroy: function() {
this.progress_bar.destroy();
this._spinner = null;
this.actor.destroy();
}
});