Skip to content

Commit 6003303

Browse files
phponymoson-mo
andcommitted
Check mount state
Co-authored-by: moson-mo <[email protected]>
1 parent 6a486aa commit 6003303

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

meson.build

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ deps = [
66
dependency('glib-2.0'),
77
dependency('gobject-2.0'),
88
dependency('gio-2.0'),
9+
dependency('gio-unix-2.0'),
910
dependency('gee-0.8'),
1011
dependency('gtk+-3.0'),
1112
dependency('json-glib-1.0')
@@ -32,4 +33,4 @@ executable('cryptor',
3233
dependencies: deps,
3334
sources: src,
3435
vala_args: [],
35-
install: true)
36+
install: true)

resources/ui/CryptorWindow.ui

+24
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,30 @@
124124
</child>
125125
</object>
126126
</child>
127+
<child>
128+
<object class="GtkMenuItem">
129+
<property name="visible">True</property>
130+
<property name="can-focus">False</property>
131+
<property name="label" translatable="yes">_View</property>
132+
<property name="use-underline">True</property>
133+
<child type="submenu">
134+
<object class="GtkMenu">
135+
<property name="visible">True</property>
136+
<property name="can-focus">False</property>
137+
<child>
138+
<object class="GtkImageMenuItem" id="mi_refresh">
139+
<property name="label">gtk-refresh</property>
140+
<property name="visible">True</property>
141+
<property name="can-focus">False</property>
142+
<property name="use-underline">True</property>
143+
<property name="use-stock">True</property>
144+
<signal name="activate" handler="on_mi_refresh_activate" swapped="no"/>
145+
</object>
146+
</child>
147+
</object>
148+
</child>
149+
</object>
150+
</child>
127151
<child>
128152
<object class="GtkMenuItem">
129153
<property name="visible">True</property>

src/ui/CryptorWindow.vala

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Gtk;
22
using Cryptor.Data;
3+
using GLib;
34

45
namespace Cryptor.UI {
56
[GtkTemplate (ui = "/org/moson/cryptor/ui/CryptorWindow.ui")]
@@ -55,7 +56,6 @@ namespace Cryptor.UI {
5556
}
5657
}
5758
this.delete_event.connect (save_before_quit);
58-
5959
show_tray_icon ();
6060
}
6161

@@ -186,6 +186,11 @@ namespace Cryptor.UI {
186186
show_vault_window (-1);
187187
}
188188

189+
[GtkCallback]
190+
private void on_mi_refresh_activate (Gtk.MenuItem mi) {
191+
sync_treeview_from_conf ();
192+
}
193+
189194
private void show_tray_icon () {
190195
if (!config.show_tray_icon) {
191196
if (tray != null) {
@@ -201,6 +206,7 @@ namespace Cryptor.UI {
201206
this.hide ();
202207
} else {
203208
this.show_all ();
209+
sync_treeview_from_conf ();
204210
}
205211
} else if (ev.button == 3) {
206212
var menu = new Gtk.Menu ();
@@ -211,6 +217,7 @@ namespace Cryptor.UI {
211217
this.hide ();
212218
} else {
213219
this.show_all ();
220+
sync_treeview_from_conf ();
214221
}
215222
});
216223
menu.append (show);
@@ -241,15 +248,13 @@ namespace Cryptor.UI {
241248
}
242249
try {
243250
Gocrypt.mount_vault (vault.path, vault.mount_point, password, (vault.mode == "r"), vault.reverse, vault.custom_options);
244-
vault.is_mounted = true;
245251
sync_treeview_from_conf ();
246252
} catch (Error e) {
247253
if (e.message.contains ("fusermount exited with code 256")) {
248254
if (Utils.show_question (this, "%s\n\n%s\n%s".printf (e.message, _("Vault might be mounted already."), _("Shall I retry unmounting it first?"))) == ResponseType.YES) {
249255
try {
250256
Gocrypt.unmount_vault (vault.mount_point);
251257
Gocrypt.mount_vault (vault.path, vault.mount_point, password, (vault.mode == "r"), vault.reverse, vault.custom_options);
252-
vault.is_mounted = true;
253258
sync_treeview_from_conf ();
254259
} catch (Error e) {
255260
Utils.show_error (this, "%s\n%s".printf (_("Error re-mounting vault:"), e.message));
@@ -262,7 +267,6 @@ namespace Cryptor.UI {
262267
} else {
263268
try {
264269
Gocrypt.unmount_vault (vault.mount_point);
265-
vault.is_mounted = false;
266270
sync_treeview_from_conf ();
267271
} catch (Error e) {
268272
Utils.show_error (this, "%s\n%s".printf (_("Error unmounting vault:"), e.message));
@@ -340,6 +344,10 @@ namespace Cryptor.UI {
340344
}
341345

342346
private void sync_treeview_from_conf () {
347+
foreach (var vault in config.vaults) {
348+
var entry = new UnixMountEntry (vault.mount_point, null);
349+
vault.is_mounted = entry != null;
350+
}
343351
list_store.clear ();
344352
foreach (var v in config.vaults) {
345353
TreeIter iter;

0 commit comments

Comments
 (0)