prefer for #43 and #45

This commit is contained in:
Artem Anufrij 2017-11-08 23:13:17 +01:00
parent 0acf8f77ba
commit 41375f154c
4 changed files with 68 additions and 38 deletions

View file

@ -31,8 +31,6 @@ namespace Webpin {
static WebpinApp _instance = null; static WebpinApp _instance = null;
public GLib.List<WebWindow> app_list;
public static WebpinApp instance { public static WebpinApp instance {
get { get {
if (_instance == null) if (_instance == null)
@ -47,7 +45,6 @@ namespace Webpin {
application_id = "com.github.artemanufrij.webpin"; application_id = "com.github.artemanufrij.webpin";
app_launcher = application_id + ".desktop"; app_launcher = application_id + ".desktop";
flags |= GLib.ApplicationFlags.HANDLES_OPEN; flags |= GLib.ApplicationFlags.HANDLES_OPEN;
app_list = new GLib.List<WebWindow> ();
var open_web_app = new SimpleAction ("open-web-app", GLib.VariantType.STRING); var open_web_app = new SimpleAction ("open-web-app", GLib.VariantType.STRING);
add_action (open_web_app); add_action (open_web_app);
@ -64,6 +61,7 @@ namespace Webpin {
protected override void activate () { protected override void activate () {
if (mainwindow != null) { if (mainwindow != null) {
mainwindow.present (); mainwindow.present ();
return; return;
} }
@ -73,32 +71,31 @@ namespace Webpin {
} }
public override void open (File[] files, string hint) { public override void open (File[] files, string hint) {
debug ("%s", files [0].get_uri ());
start_webapp (files [0].get_uri ()); start_webapp (files [0].get_uri ());
} }
public void start_webapp (string url) { public void start_webapp (string url) {
foreach (var item in app_list) { if (mainwindow != null ) {
debug ("running webapp: %s", item.desktop_file.url); mainwindow.present ();
if (item.desktop_file.url == url) {
debug ("open runing app: %s", url);
item.present ();
return; return;
} }
}
debug ("create a new web app: %s", url);
var app_info = Webpin.DesktopFile.get_app_by_url (url); var app_info = Webpin.DesktopFile.get_app_by_url (url);
var desktop_file = new Webpin.DesktopFile.from_desktopappinfo(app_info); var desktop_file = new Webpin.DesktopFile.from_desktopappinfo(app_info);
var app = new WebWindow (desktop_file); mainwindow = new WebWindow (desktop_file);
app_list.append (app); mainwindow.set_application (this);
app.destroy.connect (() => { app_list.remove (app); });
app.set_application (this);
} }
} }
} }
static int main (string[] args) { static int main (string[] args) {
Gtk.init (ref args); Gtk.init (ref args);
var app = Webpin.WebpinApp.instance; var app = Webpin.WebpinApp.instance;
if (args.length > 1) {
var checksum = new GLib.Checksum (GLib.ChecksumType.MD5);
checksum.update (args[1].data, args[1].length);
var id = "a" + checksum.get_string ().substring (0, 5) + "a.artemanufrij.webpin";
app.application_id = id;
} else {
app.application_id = "com.github.artemanufrij.webpin";
}
return app.run (args); return app.run (args);
} }

View file

@ -63,6 +63,26 @@ namespace Webpin {
} }
} }
public Gdk.RGBA? color {
get {
Gdk.RGBA return_value = {0, 0, 0, 255};
this.file = new GLib.KeyFile();
try {
file.load_from_file (info.filename, KeyFileFlags.NONE);
var property = file.get_string ("Desktop Entry", "WebpinPrimaryColor");
if (property == "" || !return_value.parse (property)) {
return null;
}
} catch (Error e) {
warning (e.message);
return null;
}
return return_value;
} set {
edit_propertie ("WebpinPrimaryColor", value.to_string ());
}
}
public bool mute_notifications { public bool mute_notifications {
get { get {
this.file = new GLib.KeyFile(); this.file = new GLib.KeyFile();
@ -114,6 +134,8 @@ namespace Webpin {
} }
} }
public bool edit_propertie (string propertie, string val) { public bool edit_propertie (string propertie, string val) {
bool return_value = false; bool return_value = false;
try { try {

View file

@ -41,6 +41,9 @@ namespace Webpin {
public WebWindow (DesktopFile desktop_file) { public WebWindow (DesktopFile desktop_file) {
this.desktop_file = desktop_file; this.desktop_file = desktop_file;
this.events |= Gdk.EventMask.STRUCTURE_MASK; this.events |= Gdk.EventMask.STRUCTURE_MASK;
if (desktop_file.color != null) {
Granite.Widgets.Utils.set_color_primary (this, desktop_file.color);
}
set_wmclass (desktop_file.url, desktop_file.url); set_wmclass (desktop_file.url, desktop_file.url);
web_app = new WebApp (desktop_file.url); web_app = new WebApp (desktop_file.url);

View file

@ -34,19 +34,20 @@ namespace Webpin {
public signal void application_created (GLib.DesktopAppInfo? new_file); public signal void application_created (GLib.DesktopAppInfo? new_file);
public signal void application_edited (GLib.DesktopAppInfo? new_file); public signal void application_edited (GLib.DesktopAppInfo? new_file);
private Gtk.Label message; Gtk.Label message;
private Gtk.Button icon_button; Gtk.Button icon_button;
private Gtk.Entry app_name_entry; Gtk.Entry app_name_entry;
private Gtk.Entry app_url_entry; Gtk.Entry app_url_entry;
private Gtk.Entry icon_name_entry; Gtk.Entry icon_name_entry;
private Gtk.CheckButton save_cookies_check; Gtk.CheckButton save_cookies_check;
private Gtk.CheckButton save_password_check; Gtk.CheckButton save_password_check;
private Gtk.CheckButton stay_open_when_closed; Gtk.CheckButton stay_open_when_closed;
private Gtk.Popover icon_selector_popover; Gtk.Popover icon_selector_popover;
private Gtk.FileChooserDialog file_chooser; Gtk.FileChooserDialog file_chooser;
private Gtk.Button accept_button; Gtk.Button accept_button;
private GLib.Regex protocol_regex; Gtk.ColorButton primary_color_button;
private Gee.HashMap<string, GLib.AppInfo> apps; GLib.Regex protocol_regex;
Gee.HashMap<string, GLib.AppInfo> apps;
private string default_app_icon = "artemanufrij.webpin"; private string default_app_icon = "artemanufrij.webpin";
@ -107,6 +108,9 @@ namespace Webpin {
icon_selector_popover.add (popover_box); icon_selector_popover.add (popover_box);
primary_color_button = new Gtk.ColorButton.with_rgba ({ 222, 222, 222, 255 });
primary_color_button.use_alpha = false;
//TODO: categories //TODO: categories
//combobox //combobox
@ -128,6 +132,7 @@ namespace Webpin {
var app_info_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 5); var app_info_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 5);
app_info_box.pack_start (icon_button, false, false, 3); app_info_box.pack_start (icon_button, false, false, 3);
app_info_box.pack_start (app_input_box, false, false, 3); app_info_box.pack_start (app_input_box, false, false, 3);
app_info_box.pack_start (primary_color_button, false, false, 3);
app_info_box.halign = Gtk.Align.CENTER; app_info_box.halign = Gtk.Align.CENTER;
//app options //app options
@ -212,8 +217,8 @@ namespace Webpin {
} catch (GLib.Error err) { } catch (GLib.Error err) {
warning ("Getting selection-checked icon from theme failed"); warning ("Getting selection-checked icon from theme failed");
} }
} finally { }
if (pix != null) if (pix != null) {
icon_button.set_image (new Gtk.Image.from_pixbuf (pix)); icon_button.set_image (new Gtk.Image.from_pixbuf (pix));
} }
} else { } else {
@ -247,7 +252,6 @@ namespace Webpin {
preview.valign = Gtk.Align.START; preview.valign = Gtk.Align.START;
file_chooser.update_preview.connect ( ()=> { file_chooser.update_preview.connect ( ()=> {
string filename = file_chooser.get_preview_filename(); string filename = file_chooser.get_preview_filename();
Gdk.Pixbuf pix = null; Gdk.Pixbuf pix = null;
@ -309,6 +313,7 @@ namespace Webpin {
if (app_icon_valid && app_name_valid && app_url_valid) { if (app_icon_valid && app_name_valid && app_url_valid) {
var desktop_file = new DesktopFile (name, url, icon, stay_open); var desktop_file = new DesktopFile (name, url, icon, stay_open);
desktop_file.color = primary_color_button.rgba;
switch (mode) { switch (mode) {
case assistant_mode.new_app: case assistant_mode.new_app:
application_created (desktop_file.save_to_file ()); application_created (desktop_file.save_to_file ());
@ -327,6 +332,9 @@ namespace Webpin {
app_url_entry.text = desktop_file.url.replace ("%%", "%"); app_url_entry.text = desktop_file.url.replace ("%%", "%");
icon_name_entry.text = desktop_file.icon; icon_name_entry.text = desktop_file.icon;
stay_open_when_closed.active = desktop_file.hide_on_close; stay_open_when_closed.active = desktop_file.hide_on_close;
if (desktop_file.color != null) {
primary_color_button.set_rgba (desktop_file.color);
}
update_app_icon (); update_app_icon ();
} }
} }