// compile with valac network-change.vala --pkg gio-2.0 --pkg libnotify

public static int main(string [] argv) {
    print("Connecting callbacks...\n");
    Notify.init("network-change");

    NetworkMonitor nm = NetworkMonitor.get_default();
    nm.network_changed.connect(on_network_changed);
    nm.notify["network-available"].connect(on_network_available_changed);
    var loop = new MainLoop();
    loop.run();
    return 0;
}

private void notif(string summary) {
    print(@"$(new DateTime.now_local()) - $(summary)\n");

    Notify.Notification notification = (Notify.Notification) GLib.Object.new(
        typeof (Notify.Notification),
        "icon-name", "geary",
        "summary", GLib.Environment.get_application_name());

    notification.set("summary", summary);
    notification.set("body", @"$(new DateTime.now_local())");
    try {
        notification.show();
    } catch (Error e) {
        print(@"Cannot show notif: $(e.message)\n");
    }
}

private void on_network_changed(bool available) {
    notif(@"on_network_changed $(available)");
}
private void on_network_available_changed() {
    notif(@"on_network_available_changed");
}
