From f632de28d2b6ddc4254dc8321e7449155cb2396e Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Thu, 24 Aug 2017 17:02:11 +0800 Subject: [PATCH] GitMonitor.vala --- GitMonitor.vala | 100 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 34 deletions(-) diff --git a/GitMonitor.vala b/GitMonitor.vala index a2ec6e8a..12ae53ba 100644 --- a/GitMonitor.vala +++ b/GitMonitor.vala @@ -177,6 +177,32 @@ public class GitMonitor : Monitor public GitMonitor () { this.queue = new Array(); GitMonitor.gitmonitor = this; + + Timeout.add_full(Priority.LOW, 1000, () => { + + //print("TIMEOUT queue length = %d, is_runing = %s\n", (int)this.queue.length , this.queueRunning ? "Y" : "N"); + + //stdout.printf("QL %u: QR: %d\n", this.queue.length, this.queueRunning ? 1 : 0); + if (this.queue.length < 1 || this.queueRunning) { + return true; + } + + var last = -1 * this.lastAdd.difference(new DateTime.now(new TimeZone.local())); + + // stdout.printf("LAST RUN: %s (expect %s) \n" , + // last.to_string(), (5 * TimeSpan.SECOND).to_string() ); + + if (last < 5 * TimeSpan.SECOND) { // wait 5 seconds before running. ???? + return true; + } + //_this.lastAdd = new Date(); + //return 1; + + this.runQueue(); + return true; // + }); + + } public new void pauseError(string failure) @@ -191,13 +217,30 @@ public class GitMonitor : Monitor notification.set_timeout(60); // show errros for longer notification.show(); - + + + + this.paused = true; + this.queueRunning = false; // what does this do to the old one... this.queue = new Array (); this.stop(); StatusIconA.statusicon.pauseError(); + + var m = new Gtk.MessageDialog(null, Gtk.DialogFlags.MODAL,Gtk.MessageType.ERROR,Gtk.ButtonsType.CLOSE, + "A Serious problem occured running git, you will probably have to resolve this manually\n" + + "Committing is paused now, so fix the problem, close this window, then press start again\n\n\n" + + failure + ); + m.set_keep_above(true); + m.show(); + m.set_position(Gtk.WindowPosition.CENTER); + m.response.connect( (id_pressed) => { + m.hide(); + }); + } public new void pause() { @@ -259,28 +302,7 @@ public class GitMonitor : Monitor }); - Timeout.add_full(Priority.LOW, 1000, () => { - //TIMEOUT", _this.queue.length , _this.queueRunning].join(', ')); - - //stdout.printf("QL %u: QR: %d\n", this.queue.length, this.queueRunning ? 1 : 0); - if (this.queue.length < 1 || this.queueRunning) { - return true; - } - - var last = -1 * this.lastAdd.difference(new DateTime.now(new TimeZone.local())); - - // stdout.printf("LAST RUN: %s (expect %s) \n" , - // last.to_string(), (5 * TimeSpan.SECOND).to_string() ); - - if (last < 5 * TimeSpan.SECOND) { // wait 5 seconds before running. ???? - return true; - } - //_this.lastAdd = new Date(); - //return 1; - this.runQueue(); - return true; // - }); } @@ -492,7 +514,11 @@ public class GitMonitor : Monitor // make sure monitoring is paused so it does not recursively pick up // deletions + this.paused = true; + + try { + repo.pull(); } catch(Error e) { this.pauseError(e.message); @@ -500,8 +526,7 @@ public class GitMonitor : Monitor //print("Pull failed:\n"); return; } - - + // -- DO STUFF.. try { repo.add(add_files_f); @@ -520,7 +545,7 @@ public class GitMonitor : Monitor print("Remove failed:\n"); } - this.paused = false; + try { @@ -531,12 +556,15 @@ public class GitMonitor : Monitor success += repo.push(); } catch(Error e) { + this.paused = false; this.pauseError(e.message); + return; - failure += e.message; - print("Push failed:\n"); + //failure += e.message; + //print("Push failed:\n"); } + this.paused = false; } @@ -585,7 +613,7 @@ public class GitMonitor : Monitor public override void onChanged(MonitorNamePathDir src) { - print("GitMonitor.onChanged\n"); + //print("GitMonitor.onChanged\n"); return; // always ignore this..? //this.parsePath(src); } @@ -598,11 +626,11 @@ public class GitMonitor : Monitor */ public override void onChangesDoneHint(MonitorNamePathDir src) { - print("GitMonitor.onChangedHint\n"); + if (this.paused) { return; } - + print("GitMonitor.onChangedHint\n"); this.lastAdd = new DateTime.now(new TimeZone.local()); var cmd = new GitMonitorQueue(src); @@ -639,10 +667,11 @@ public class GitMonitor : Monitor } public override void onDeleted(MonitorNamePathDir src) { - print("GitMonitor.onDeleted\n"); + if (this.paused) { return; } + print("GitMonitor.onDeleted\n"); this.lastAdd = new DateTime.now(new TimeZone.local()); var cmd = new GitMonitorQueue(src); if (cmd.shouldIgnore()) { @@ -662,10 +691,11 @@ public class GitMonitor : Monitor } public override void onCreated(MonitorNamePathDir src) { - print("GitMonitor.onCreated\n"); + if (this.paused) { return; } + print("GitMonitor.onCreated\n"); this.lastAdd = new DateTime.now(new TimeZone.local()); var cmd = new GitMonitorQueue(src); if (cmd.shouldIgnore()) { @@ -692,10 +722,11 @@ public class GitMonitor : Monitor } public override void onAttributeChanged(MonitorNamePathDir src) { - print("GitMonitor.onAttributeChanged\n"); + if (this.paused) { return; } + print("GitMonitor.onAttributeChanged\n"); if (src.dir == GitMonitor.gitlive) { return; // attribute on top level.. } @@ -716,10 +747,11 @@ public class GitMonitor : Monitor public override void onMoved(MonitorNamePathDir src,MonitorNamePathDir dest) { - print("GitMonitor.onMoved\n"); + if (this.paused) { return; } + print("GitMonitor.onMoved\n"); this.lastAdd = new DateTime.now(new TimeZone.local()); var cmd_s = new GitMonitorQueue(src); -- 2.39.2