parent
0acf8f77ba
commit
41375f154c
4 changed files with 68 additions and 38 deletions
|
@ -31,8 +31,6 @@ namespace Webpin {
|
|||
|
||||
static WebpinApp _instance = null;
|
||||
|
||||
public GLib.List<WebWindow> app_list;
|
||||
|
||||
public static WebpinApp instance {
|
||||
get {
|
||||
if (_instance == null)
|
||||
|
@ -47,7 +45,6 @@ namespace Webpin {
|
|||
application_id = "com.github.artemanufrij.webpin";
|
||||
app_launcher = application_id + ".desktop";
|
||||
flags |= GLib.ApplicationFlags.HANDLES_OPEN;
|
||||
app_list = new GLib.List<WebWindow> ();
|
||||
|
||||
var open_web_app = new SimpleAction ("open-web-app", GLib.VariantType.STRING);
|
||||
add_action (open_web_app);
|
||||
|
@ -64,6 +61,7 @@ namespace Webpin {
|
|||
protected override void activate () {
|
||||
if (mainwindow != null) {
|
||||
mainwindow.present ();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -73,32 +71,31 @@ namespace Webpin {
|
|||
}
|
||||
|
||||
public override void open (File[] files, string hint) {
|
||||
debug ("%s", files [0].get_uri ());
|
||||
start_webapp (files [0].get_uri ());
|
||||
}
|
||||
|
||||
public void start_webapp (string url) {
|
||||
foreach (var item in app_list) {
|
||||
debug ("running webapp: %s", item.desktop_file.url);
|
||||
if (item.desktop_file.url == url) {
|
||||
debug ("open runing app: %s", url);
|
||||
item.present ();
|
||||
return;
|
||||
}
|
||||
if (mainwindow != null ) {
|
||||
mainwindow.present ();
|
||||
return;
|
||||
}
|
||||
|
||||
debug ("create a new web app: %s", url);
|
||||
var app_info = Webpin.DesktopFile.get_app_by_url (url);
|
||||
var desktop_file = new Webpin.DesktopFile.from_desktopappinfo(app_info);
|
||||
var app = new WebWindow (desktop_file);
|
||||
app_list.append (app);
|
||||
app.destroy.connect (() => { app_list.remove (app); });
|
||||
app.set_application (this);
|
||||
mainwindow = new WebWindow (desktop_file);
|
||||
mainwindow.set_application (this);
|
||||
}
|
||||
}
|
||||
}
|
||||
static int main (string[] args) {
|
||||
Gtk.init (ref args);
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
get {
|
||||
this.file = new GLib.KeyFile();
|
||||
|
@ -114,6 +134,8 @@ namespace Webpin {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public bool edit_propertie (string propertie, string val) {
|
||||
bool return_value = false;
|
||||
try {
|
||||
|
|
|
@ -41,6 +41,9 @@ namespace Webpin {
|
|||
public WebWindow (DesktopFile desktop_file) {
|
||||
this.desktop_file = desktop_file;
|
||||
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);
|
||||
web_app = new WebApp (desktop_file.url);
|
||||
|
|
|
@ -34,19 +34,20 @@ namespace Webpin {
|
|||
public signal void application_created (GLib.DesktopAppInfo? new_file);
|
||||
public signal void application_edited (GLib.DesktopAppInfo? new_file);
|
||||
|
||||
private Gtk.Label message;
|
||||
private Gtk.Button icon_button;
|
||||
private Gtk.Entry app_name_entry;
|
||||
private Gtk.Entry app_url_entry;
|
||||
private Gtk.Entry icon_name_entry;
|
||||
private Gtk.CheckButton save_cookies_check;
|
||||
private Gtk.CheckButton save_password_check;
|
||||
private Gtk.CheckButton stay_open_when_closed;
|
||||
private Gtk.Popover icon_selector_popover;
|
||||
private Gtk.FileChooserDialog file_chooser;
|
||||
private Gtk.Button accept_button;
|
||||
private GLib.Regex protocol_regex;
|
||||
private Gee.HashMap<string, GLib.AppInfo> apps;
|
||||
Gtk.Label message;
|
||||
Gtk.Button icon_button;
|
||||
Gtk.Entry app_name_entry;
|
||||
Gtk.Entry app_url_entry;
|
||||
Gtk.Entry icon_name_entry;
|
||||
Gtk.CheckButton save_cookies_check;
|
||||
Gtk.CheckButton save_password_check;
|
||||
Gtk.CheckButton stay_open_when_closed;
|
||||
Gtk.Popover icon_selector_popover;
|
||||
Gtk.FileChooserDialog file_chooser;
|
||||
Gtk.Button accept_button;
|
||||
Gtk.ColorButton primary_color_button;
|
||||
GLib.Regex protocol_regex;
|
||||
Gee.HashMap<string, GLib.AppInfo> apps;
|
||||
|
||||
private string default_app_icon = "artemanufrij.webpin";
|
||||
|
||||
|
@ -107,6 +108,9 @@ namespace Webpin {
|
|||
|
||||
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
|
||||
//combobox
|
||||
|
||||
|
@ -128,6 +132,7 @@ namespace Webpin {
|
|||
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 (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 options
|
||||
|
@ -204,17 +209,17 @@ namespace Webpin {
|
|||
try {
|
||||
pix = new Gdk.Pixbuf.from_file_at_size (icon, 48, 48);
|
||||
app_icon_valid = true;
|
||||
} catch (GLib.Error error) {
|
||||
} catch (GLib.Error error) {
|
||||
app_icon_valid = false;
|
||||
try {
|
||||
Gtk.IconTheme icon_theme = Gtk.IconTheme.get_default ();
|
||||
pix = icon_theme.load_icon ("image-missing", 48, Gtk.IconLookupFlags.FORCE_SIZE);
|
||||
} catch (GLib.Error err) {
|
||||
warning ("Getting selection-checked icon from theme failed");
|
||||
warning ("Getting selection-checked icon from theme failed");
|
||||
}
|
||||
} finally {
|
||||
if (pix != null)
|
||||
icon_button.set_image (new Gtk.Image.from_pixbuf (pix));
|
||||
}
|
||||
if (pix != null) {
|
||||
icon_button.set_image (new Gtk.Image.from_pixbuf (pix));
|
||||
}
|
||||
} else {
|
||||
icon_button.set_image (new Gtk.Image.from_icon_name (icon, Gtk.IconSize.DIALOG) );
|
||||
|
@ -247,16 +252,15 @@ namespace Webpin {
|
|||
preview.valign = Gtk.Align.START;
|
||||
|
||||
file_chooser.update_preview.connect ( ()=> {
|
||||
|
||||
string filename = file_chooser.get_preview_filename();
|
||||
Gdk.Pixbuf pix = null;
|
||||
|
||||
if (filename != null) {
|
||||
try {
|
||||
pix = new Gdk.Pixbuf.from_file_at_size (filename, 128, 128);
|
||||
} catch (GLib.Error error) {
|
||||
} catch (GLib.Error error) {
|
||||
warning ("There was a problem loading preview.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pix != null){
|
||||
|
@ -309,6 +313,7 @@ namespace Webpin {
|
|||
|
||||
if (app_icon_valid && app_name_valid && app_url_valid) {
|
||||
var desktop_file = new DesktopFile (name, url, icon, stay_open);
|
||||
desktop_file.color = primary_color_button.rgba;
|
||||
switch (mode) {
|
||||
case assistant_mode.new_app:
|
||||
application_created (desktop_file.save_to_file ());
|
||||
|
@ -327,6 +332,9 @@ namespace Webpin {
|
|||
app_url_entry.text = desktop_file.url.replace ("%%", "%");
|
||||
icon_name_entry.text = desktop_file.icon;
|
||||
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 ();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue