added 'run in background' option
This commit is contained in:
parent
e3eb20b97b
commit
a1157abcef
4 changed files with 89 additions and 48 deletions
|
@ -31,6 +31,8 @@ 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)
|
||||||
|
@ -40,10 +42,12 @@ namespace Webpin {
|
||||||
}
|
}
|
||||||
|
|
||||||
construct {
|
construct {
|
||||||
program_name = "Image Burner";
|
program_name = "Webpin";
|
||||||
exec_name = "com.github.artemanufrij.webpin";
|
exec_name = "com.github.artemanufrij.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;
|
||||||
|
app_list = new GLib.List<WebWindow> ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gtk.Window mainwindow;
|
public Gtk.Window mainwindow;
|
||||||
|
@ -55,23 +59,34 @@ namespace Webpin {
|
||||||
}
|
}
|
||||||
|
|
||||||
mainwindow = new MainWindow ();
|
mainwindow = new MainWindow ();
|
||||||
|
mainwindow.destroy.connect (() => { mainwindow = null; });
|
||||||
mainwindow.set_application(this);
|
mainwindow.set_application(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void open (File[] files, string hint) {
|
||||||
|
debug (files [0].get_uri ());
|
||||||
|
start_webapp (files [0].get_uri ());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start_webapp (string url) {
|
||||||
|
foreach (var item in app_list) {
|
||||||
|
if (item.desktop_file.url == url) {
|
||||||
|
item.present ();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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.destroy.connect (() => { app_list.remove (app); });
|
||||||
|
app.set_application (this);
|
||||||
|
app_list.append (app);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static int main (string[] args) {
|
static int main (string[] args) {
|
||||||
|
|
||||||
Gtk.init (ref args);
|
Gtk.init (ref args);
|
||||||
|
var app = Webpin.WebpinApp.instance;
|
||||||
if (args.length < 2 || args[1] == "--about" || args[1] == "-d") {
|
return app.run (args);
|
||||||
var app = Webpin.WebpinApp.instance;
|
|
||||||
return app.run (args);
|
|
||||||
} else {
|
|
||||||
var app_info = Webpin.DesktopFile.get_app_by_url (args[1]);
|
|
||||||
var app = new Webpin.WebWindow(app_info.get_display_name (), args[1]);
|
|
||||||
app.show_all ();
|
|
||||||
}
|
|
||||||
|
|
||||||
Gtk.main ();
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,15 +45,30 @@ namespace Webpin {
|
||||||
WebpinThemeColor=none""";
|
WebpinThemeColor=none""";
|
||||||
|
|
||||||
private GLib.KeyFile file;
|
private GLib.KeyFile file;
|
||||||
|
public DesktopAppInfo info { get; set; }
|
||||||
|
|
||||||
public string name { get; private set; }
|
public string name { get; private set; }
|
||||||
public string url { get; private set; }
|
public string url { get; private set; }
|
||||||
public string icon { get; private set; }
|
public string icon { get; private set; }
|
||||||
|
public bool stay_open { get; private set; }
|
||||||
|
public bool hide_on_close {
|
||||||
|
get {
|
||||||
|
this.file = new GLib.KeyFile();
|
||||||
|
try {
|
||||||
|
file.load_from_file (info.filename, KeyFileFlags.NONE);
|
||||||
|
return file.get_string ("Desktop Entry", "WebpinStayOpen") == "true";
|
||||||
|
} catch (Error e) {
|
||||||
|
warning (e.message);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public DesktopFile (string name, string url, string icon) {
|
public DesktopFile (string name, string url, string icon, bool stay_open) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.url = url.replace ("%", "%%");
|
this.url = url.replace ("%", "%%");
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
|
this.stay_open = stay_open;
|
||||||
|
|
||||||
file = new GLib.KeyFile();
|
file = new GLib.KeyFile();
|
||||||
try {
|
try {
|
||||||
|
@ -68,10 +83,12 @@ namespace Webpin {
|
||||||
file.set_string ("Desktop Entry", "Exec", "com.github.artemanufrij.webpin " + url);
|
file.set_string ("Desktop Entry", "Exec", "com.github.artemanufrij.webpin " + url);
|
||||||
file.set_string ("Desktop Entry", "Icon", icon);
|
file.set_string ("Desktop Entry", "Icon", icon);
|
||||||
file.set_string ("Desktop Entry", "StartupWMClass", url);
|
file.set_string ("Desktop Entry", "StartupWMClass", url);
|
||||||
|
file.set_string ("Desktop Entry", "WebpinStayOpen", stay_open.to_string ());
|
||||||
}
|
}
|
||||||
|
|
||||||
public DesktopFile.from_desktopappinfo(GLib.DesktopAppInfo info) {
|
public DesktopFile.from_desktopappinfo(GLib.DesktopAppInfo info) {
|
||||||
file = new GLib.KeyFile();
|
this.info = info;
|
||||||
|
this.file = new GLib.KeyFile();
|
||||||
try {
|
try {
|
||||||
file.load_from_file (info.filename, KeyFileFlags.NONE);
|
file.load_from_file (info.filename, KeyFileFlags.NONE);
|
||||||
} catch (Error e) {
|
} catch (Error e) {
|
||||||
|
@ -81,6 +98,7 @@ namespace Webpin {
|
||||||
this.icon = info.get_icon ().to_string ();
|
this.icon = info.get_icon ().to_string ();
|
||||||
try {
|
try {
|
||||||
this.url = file.get_string ("Desktop Entry", "Exec").substring (31);
|
this.url = file.get_string ("Desktop Entry", "Exec").substring (31);
|
||||||
|
this.stay_open = file.get_string ("Desktop Entry", "WebpinStayOpen") == "true";
|
||||||
} catch (Error e) {
|
} catch (Error e) {
|
||||||
warning (e.message);
|
warning (e.message);
|
||||||
}
|
}
|
||||||
|
@ -111,19 +129,18 @@ namespace Webpin {
|
||||||
} catch (Error e) {
|
} catch (Error e) {
|
||||||
warning (e.message);
|
warning (e.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool delete_file () {
|
public bool delete_file () {
|
||||||
try {
|
try {
|
||||||
string filename = GLib.Environment.get_user_data_dir () + "/applications/" +file.get_string("Desktop Entry", "Name") + "-webpin.desktop";
|
string filename = GLib.Environment.get_user_data_dir () + "/applications/" +file.get_string("Desktop Entry", "Name") + "-webpin.desktop";
|
||||||
File file = File.new_for_path (filename);
|
File file = File.new_for_path (filename);
|
||||||
file.delete ();
|
file.delete ();
|
||||||
} catch (Error e) {
|
} catch (Error e) {
|
||||||
print(e.message + "\n");
|
print(e.message + "\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Webpin {
|
namespace Webpin {
|
||||||
public class WebWindow : Gtk.ApplicationWindow {
|
public class WebWindow : Gtk.Window {
|
||||||
|
|
||||||
private bool is_full_screen = false;
|
private bool is_full_screen = false;
|
||||||
|
|
||||||
|
@ -38,13 +38,17 @@ namespace Webpin {
|
||||||
|
|
||||||
Gtk.Spinner spinner;
|
Gtk.Spinner spinner;
|
||||||
|
|
||||||
public WebWindow (string webapp_name, string webapp_uri) {
|
public DesktopFile desktop_file { get; private set; }
|
||||||
|
|
||||||
set_wmclass(webapp_uri, webapp_uri);
|
public WebWindow (DesktopFile desktop_file) {
|
||||||
web_app = new WebApp(webapp_name, webapp_uri);
|
this.desktop_file = desktop_file;
|
||||||
|
this.events |= Gdk.EventMask.STRUCTURE_MASK;
|
||||||
|
|
||||||
|
set_wmclass(desktop_file.url, desktop_file.url);
|
||||||
|
web_app = new WebApp(desktop_file.name, desktop_file.url);
|
||||||
|
|
||||||
var headerbar = new Gtk.HeaderBar ();
|
var headerbar = new Gtk.HeaderBar ();
|
||||||
headerbar.title = webapp_name;
|
headerbar.title = desktop_file.name;
|
||||||
headerbar.show_close_button = true;
|
headerbar.show_close_button = true;
|
||||||
|
|
||||||
spinner = new Gtk.Spinner ();
|
spinner = new Gtk.Spinner ();
|
||||||
|
@ -61,7 +65,7 @@ namespace Webpin {
|
||||||
headerbar.get_style_context ().add_provider (style_provider, -1);
|
headerbar.get_style_context ().add_provider (style_provider, -1);
|
||||||
Gtk.Settings.get_default ().set ("gtk-application-prefer-dark-theme", should_use_dark_theme (web_app.ui_color));
|
Gtk.Settings.get_default ().set ("gtk-application-prefer-dark-theme", should_use_dark_theme (web_app.ui_color));
|
||||||
} catch (GLib.Error err) {
|
} catch (GLib.Error err) {
|
||||||
warning("Loading style failed");
|
warning("Loading style failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,17 +78,16 @@ namespace Webpin {
|
||||||
headerbar.get_style_context ().add_provider (style_provider, -1);
|
headerbar.get_style_context ().add_provider (style_provider, -1);
|
||||||
Gtk.Settings.get_default ().set ("gtk-application-prefer-dark-theme", should_use_dark_theme (color));
|
Gtk.Settings.get_default ().set ("gtk-application-prefer-dark-theme", should_use_dark_theme (color));
|
||||||
} catch (GLib.Error err) {
|
} catch (GLib.Error err) {
|
||||||
warning("Loading style failed");
|
warning("Loading style failed");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.set_titlebar (headerbar);
|
this.set_titlebar (headerbar);
|
||||||
|
|
||||||
var info = DesktopFile.get_app_by_url(webapp_uri);
|
var width = desktop_file.info.get_string ("WebpinWindowWidth");
|
||||||
var width = info.get_string ("WebpinWindowWidth");
|
var height = desktop_file.info.get_string ("WebpinWindowHeight");
|
||||||
var height = info.get_string ("WebpinWindowHeight");
|
var state = desktop_file.info.get_string ("WebpinWindowMaximized");
|
||||||
var state = info.get_string ("WebpinWindowMaximized");
|
var zoom = desktop_file.info.get_string ("WebpinWindowZoom");
|
||||||
var zoom = info.get_string ("WebpinWindowZoom");
|
|
||||||
|
|
||||||
if (width != null && height != null) {
|
if (width != null && height != null) {
|
||||||
set_default_size (int.parse(width), int.parse(height));
|
set_default_size (int.parse(width), int.parse(height));
|
||||||
|
@ -102,11 +105,12 @@ namespace Webpin {
|
||||||
|
|
||||||
this.delete_event.connect (() => {
|
this.delete_event.connect (() => {
|
||||||
update_window_state(this.get_allocated_width (), this.get_allocated_height (), this.is_maximized);
|
update_window_state(this.get_allocated_width (), this.get_allocated_height (), this.is_maximized);
|
||||||
return false;
|
if (desktop_file.hide_on_close) {
|
||||||
|
this.hide ();
|
||||||
|
}
|
||||||
|
return desktop_file.hide_on_close;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.destroy.connect(Gtk.main_quit);
|
|
||||||
|
|
||||||
web_app.external_request.connect ((action) => {
|
web_app.external_request.connect ((action) => {
|
||||||
debug ("Web app external request: %s", action.get_request ().uri);
|
debug ("Web app external request: %s", action.get_request ().uri);
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -41,6 +41,7 @@ namespace Webpin {
|
||||||
private Gtk.Entry icon_name_entry;
|
private Gtk.Entry icon_name_entry;
|
||||||
private Gtk.CheckButton save_cookies_check;
|
private Gtk.CheckButton save_cookies_check;
|
||||||
private Gtk.CheckButton save_password_check;
|
private Gtk.CheckButton save_password_check;
|
||||||
|
private Gtk.CheckButton stay_open_when_closed;
|
||||||
private Gtk.Popover icon_selector_popover;
|
private Gtk.Popover icon_selector_popover;
|
||||||
private Gtk.FileChooserDialog file_chooser;
|
private Gtk.FileChooserDialog file_chooser;
|
||||||
private Gtk.Button accept_button;
|
private Gtk.Button accept_button;
|
||||||
|
@ -114,6 +115,8 @@ namespace Webpin {
|
||||||
save_cookies_check.active = true;
|
save_cookies_check.active = true;
|
||||||
save_password_check = new Gtk.CheckButton.with_label (_("Save login information"));
|
save_password_check = new Gtk.CheckButton.with_label (_("Save login information"));
|
||||||
save_password_check.active = false;
|
save_password_check.active = false;
|
||||||
|
stay_open_when_closed = new Gtk.CheckButton.with_label (_("Run in background when closed"));
|
||||||
|
stay_open_when_closed.active = false;
|
||||||
|
|
||||||
//app information section
|
//app information section
|
||||||
var app_input_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 5);
|
var app_input_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 5);
|
||||||
|
@ -131,9 +134,9 @@ namespace Webpin {
|
||||||
var app_options_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 5);
|
var app_options_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 5);
|
||||||
app_options_box.pack_start (save_cookies_check, true, false, 0);
|
app_options_box.pack_start (save_cookies_check, true, false, 0);
|
||||||
app_options_box.pack_start (save_password_check, true, false, 0);
|
app_options_box.pack_start (save_password_check, true, false, 0);
|
||||||
|
app_options_box.pack_start (stay_open_when_closed, true, false, 0);
|
||||||
app_options_box.halign = Gtk.Align.CENTER;
|
app_options_box.halign = Gtk.Align.CENTER;
|
||||||
|
|
||||||
|
|
||||||
//create button
|
//create button
|
||||||
accept_button = new Gtk.Button.with_label(_("Save app"));
|
accept_button = new Gtk.Button.with_label(_("Save app"));
|
||||||
accept_button.halign = Gtk.Align.END;
|
accept_button.halign = Gtk.Align.END;
|
||||||
|
@ -221,17 +224,17 @@ namespace Webpin {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void on_icon_chooser_activate () {
|
private void on_icon_chooser_activate () {
|
||||||
var filter = new Gtk.FileFilter ();
|
var filter = new Gtk.FileFilter ();
|
||||||
|
|
||||||
filter.set_filter_name (_("Images"));
|
filter.set_filter_name (_("Images"));
|
||||||
filter.add_pattern ("*.png");
|
filter.add_pattern ("*.png");
|
||||||
filter.add_pattern ("*.svg");
|
filter.add_pattern ("*.svg");
|
||||||
filter.add_pattern ("*.jpg");
|
filter.add_pattern ("*.jpg");
|
||||||
filter.add_pattern ("*.jpeg");
|
filter.add_pattern ("*.jpeg");
|
||||||
filter.add_pattern ("*.PNG");
|
filter.add_pattern ("*.PNG");
|
||||||
filter.add_pattern ("*.SVG");
|
filter.add_pattern ("*.SVG");
|
||||||
filter.add_pattern ("*.JPG");
|
filter.add_pattern ("*.JPG");
|
||||||
filter.add_pattern ("*.JPEG");
|
filter.add_pattern ("*.JPEG");
|
||||||
|
|
||||||
file_chooser = new Gtk.FileChooserDialog ("", null,
|
file_chooser = new Gtk.FileChooserDialog ("", null,
|
||||||
Gtk.FileChooserAction.OPEN,
|
Gtk.FileChooserAction.OPEN,
|
||||||
|
@ -299,12 +302,13 @@ namespace Webpin {
|
||||||
string icon = icon_name_entry.get_text ();
|
string icon = icon_name_entry.get_text ();
|
||||||
string name = app_name_entry.get_text ();
|
string name = app_name_entry.get_text ();
|
||||||
string url = app_url_entry.get_text ().replace ("%", "%%");
|
string url = app_url_entry.get_text ().replace ("%", "%%");
|
||||||
|
bool stay_open = stay_open_when_closed.active;
|
||||||
|
|
||||||
if (icon == "")
|
if (icon == "")
|
||||||
icon = default_app_icon;
|
icon = default_app_icon;
|
||||||
|
|
||||||
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);
|
var desktop_file = new DesktopFile (name, url, icon, stay_open);
|
||||||
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 ());
|
||||||
|
@ -322,6 +326,7 @@ namespace Webpin {
|
||||||
app_name_entry.set_sensitive (false);
|
app_name_entry.set_sensitive (false);
|
||||||
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.stay_open;
|
||||||
update_app_icon ();
|
update_app_icon ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue