This commit is contained in:
bleakgrey 2018-05-03 11:56:04 +03:00
parent 8408a92646
commit fffde86a9b
4 changed files with 35 additions and 14 deletions

View File

@ -108,5 +108,12 @@ public class Tootle.AccountManager : Object{
Tootle.settings.access_token = "null";
switched (null);
}
public void init (){
if(has_access_token())
update_current ();
else
switched (null);
}
}

View File

@ -4,7 +4,7 @@ using Granite;
namespace Tootle{
public static Application app;
public static MainWindow window;
public static MainWindow? window;
public static SettingsManager settings;
public static AccountManager accounts;
@ -19,7 +19,7 @@ namespace Tootle{
construct {
application_id = "com.github.bleakgrey.tootle";
flags = ApplicationFlags.FLAGS_NONE;
program_name = "Toot";
program_name = "Tootle";
build_version = "0.1.0";
settings = new SettingsManager ();
accounts = new AccountManager ();
@ -28,6 +28,7 @@ namespace Tootle{
}
public static int main (string[] args) {
Gtk.init (ref args);
app = new Application ();
return app.run (args);
}
@ -39,12 +40,14 @@ namespace Tootle{
}
protected override void activate () {
window.present ();
var has_token = Tootle.accounts.has_access_token();
if(has_token)
Tootle.accounts.update_current ();
else
Tootle.accounts.switched (null);
if (window != null) {
window.present ();
Tootle.accounts.init ();
}
else {
window = new MainWindow (this);
window.present ();
}
}
}

View File

@ -114,5 +114,12 @@ public class Tootle.MainWindow: Gtk.Window {
message_dialog.run ();
message_dialog.destroy ();
}
public override bool delete_event (Gdk.EventAny event) {
var do_not_exit = Tootle.network.is_active_in_background ();
if (do_not_exit)
hide ();
return do_not_exit;
}
}

View File

@ -2,7 +2,7 @@ using Soup;
using GLib;
using Json;
public class Tootle.NetManager : GLib.Object{
public class Tootle.NetManager : GLib.Object {
public abstract signal void started();
public abstract signal void finished();
@ -11,7 +11,7 @@ public class Tootle.NetManager : GLib.Object{
private int requests_processing = 0;
private Soup.Session session;
construct{
construct {
session = new Soup.Session ();
session.request_unqueued.connect (() => {
requests_processing--;
@ -24,11 +24,11 @@ public class Tootle.NetManager : GLib.Object{
session.timeout = 25;
}
public NetManager(){
public NetManager() {
GLib.Object();
}
public Soup.Message queue(Soup.Message msg, Soup.SessionCallback? cb = null){
public Soup.Message queue(Soup.Message msg, Soup.SessionCallback? cb = null) {
requests_processing++;
started ();
@ -58,7 +58,7 @@ public class Tootle.NetManager : GLib.Object{
return msg;
}
public Json.Object parse(Soup.Message msg) throws GLib.Error{
public Json.Object parse(Soup.Message msg) throws GLib.Error {
// stdout.printf ("Status Code: %u\n", msg.status_code);
// stdout.printf ("Message length: %lld\n", msg.response_body.length);
// stdout.printf ("Object: \n%s\n", (string) msg.response_body.data);
@ -68,7 +68,7 @@ public class Tootle.NetManager : GLib.Object{
return parser.get_root ().get_object ();
}
public Json.Array parse_array(Soup.Message msg) throws GLib.Error{
public Json.Array parse_array(Soup.Message msg) throws GLib.Error {
// stdout.printf ("Status Code: %u\n", msg.status_code);
// stdout.printf ("Message length: %lld\n", msg.response_body.length);
// stdout.printf ("Array: \n%s\n", (string) msg.response_body.data);
@ -77,5 +77,9 @@ public class Tootle.NetManager : GLib.Object{
parser.load_from_data ((string) msg.response_body.flatten ().data, -1);
return parser.get_root ().get_array ();
}
public bool is_active_in_background () {
return false;
}
}