From ea3e9db92c2a79637c8f4a062e07327bd8ef2a8d Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Thu, 13 Sep 2018 23:41:45 +0200 Subject: Implement web app mode (#55) The (web) app mode is a way to open a website like its own application via the `--app/ -a` switch. This change doesn't address creation of a launcher or management of data. Fixes: #48 --- core/app.vala | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'core/app.vala') diff --git a/core/app.vala b/core/app.vala index 46b2baa5..fd2a2dff 100644 --- a/core/app.vala +++ b/core/app.vala @@ -18,12 +18,14 @@ namespace Midori { public class App : Gtk.Application { public File? exec_path { get; protected set; default = null; } + static string? app = null; [CCode (array_length = false, array_null_terminated = true)] static string[]? execute = null; static bool help_execute = false; public static bool incognito = false; static bool version = false; const OptionEntry[] options = { + { "app", 'a', 0, OptionArg.STRING, ref app, N_("Run ADDRESS as a web application"), N_("ADDRESS") }, { "execute", 'e', 0, OptionArg.STRING_ARRAY, ref execute, N_("Execute the specified command"), null }, { "help-execute", 0, 0, OptionArg.NONE, ref help_execute, N_("List available commands to execute with -e/ --execute"), null }, { "private", 'p', 0, OptionArg.NONE, ref incognito, N_("Private browsing, no changes are saved"), null }, @@ -321,6 +323,7 @@ namespace Midori { } // Propagate options processed in the primary instance + options.insert_value ("app", app ?? ""); options.insert_value ("execute", execute); options.insert_value ("help-execute", help_execute); options.insert_value ("private", incognito); @@ -332,6 +335,7 @@ namespace Midori { // Retrieve values for options passed from another process var options = command_line.get_options_dict (); + app = options.lookup_value ("app", VariantType.STRING).get_string (); execute = options.lookup_value ("execute", VariantType.STRING_ARRAY).dup_strv (); help_execute = options.lookup_value ("help-execute", VariantType.BOOLEAN).get_boolean (); incognito = options.lookup_value ("private", VariantType.BOOLEAN).get_boolean (); @@ -348,9 +352,20 @@ namespace Midori { } } + if (app != "") { + var browser = new Browser (this); + browser.is_locked = true; + var tab = new Tab (null, browser.web_context, app); + tab.pinned = true; + browser.add (tab); + browser.show (); + } + uint argc = command_line.get_arguments ().length; if (argc <= 1) { - activate (); + if (active_window == null) { + activate (); + } } else { var files = new File[argc - 1]; uint i = 0; -- cgit v1.2.1