Skip to content

Commit

Permalink
Show welcome dialog in AppRunner process
Browse files Browse the repository at this point in the history
Nuvola Lite does not have Master Process.

Issue: #371

Signed-off-by: Jiří Janoušek <[email protected]>
  • Loading branch information
jiri-janousek committed Jan 14, 2018
1 parent 72ac4bb commit f39830a
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 17 deletions.
34 changes: 33 additions & 1 deletion src/nuvolakit-runner/AppRunnerController.vala
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace Actions
public const string GO_RELOAD = "go-reload";
public const string GO_LOAD_URL = "go-load-url";
public const string PREFERENCES = "preferences";
public const string WELCOME = "welcome";
public const string TOGGLE_SIDEBAR = "toggle-sidebar";
public const string ZOOM_IN = "zoom-in";
public const string ZOOM_OUT = "zoom-out";
Expand Down Expand Up @@ -98,6 +99,7 @@ public class AppRunnerController: Drtgtk.Application
private URLBar? url_bar = null;
private HashTable<string, Gtk.InfoBar> info_bars;
private MainLoopAdaptor? mainloop = null;
private WelcomeDialog? welcome_dialog = null;

public AppRunnerController(
Drt.Storage storage, WebApp web_app, WebAppStorage app_storage,
Expand Down Expand Up @@ -247,6 +249,7 @@ public class AppRunnerController: Drtgtk.Application
ah.simple_action("main", "app", Actions.ACTIVATE, "Activate main window", null, null, null, do_activate),
ah.simple_action("main", "app", Actions.QUIT, "Quit", "_Quit", "application-exit", "<ctrl>Q", do_quit),
ah.simple_action("main", "app", Actions.ABOUT, "About", "_About", null, null, do_about),
ah.simple_action("main", "app", Actions.WELCOME, "Welcome screen", null, null, null, do_show_welcome_dialog),
ah.simple_action("main", "app", Actions.HELP, "Help", "_Help", null, "F1", do_help),
};
actions.add_actions(actions_spec);
Expand Down Expand Up @@ -425,6 +428,7 @@ public class AppRunnerController: Drtgtk.Application
/* It is necessary to init WebEngine after format support check because WebKitPluginProcess2
* must not be terminated during plugin discovery process. Issue: tiliado/nuvolaruntime#354 */
web_engine.init();
show_welcome_screen();
}

private void init_app_runner()
Expand All @@ -442,7 +446,7 @@ public class AppRunnerController: Drtgtk.Application

private void load_app()
{
set_app_menu_items({Actions.PREFERENCES, Actions.HELP, Actions.ABOUT, Actions.QUIT});
set_app_menu_items({Actions.PREFERENCES, Actions.HELP, Actions.WELCOME, Actions.ABOUT, Actions.QUIT});
main_window.set_menu_button_items({
Actions.ZOOM_IN, Actions.ZOOM_OUT, Actions.ZOOM_RESET, "|",
Actions.TOGGLE_SIDEBAR, "|", Actions.GO_LOAD_URL});
Expand Down Expand Up @@ -637,6 +641,34 @@ public class AppRunnerController: Drtgtk.Application
dialog.destroy();
}

private void do_show_welcome_dialog() {
if (welcome_dialog == null) {
var welcome_screen = new WelcomeScreen(this, storage, webkit_options.default_context);
welcome_dialog = new WelcomeDialog(main_window, welcome_screen);
welcome_dialog.response.connect(on_dialog_response);
}
welcome_dialog.present();
}

/**
* Show welcome screen only if criteria are met.
*/
private void show_welcome_screen() {
var config = this.master_config ?? this.config;
if (config.get_string("nuvola.welcome_screen") != get_welcome_screen_name()) {
do_show_welcome_dialog();
config.set_string("nuvola.welcome_screen", get_welcome_screen_name());
}
}

private void on_dialog_response(Gtk.Dialog dialog, int response_id) {
if (dialog == welcome_dialog) {
welcome_dialog = null;
}
dialog.response.disconnect(on_dialog_response);
dialog.destroy();
}

private void do_toggle_sidebar()
{
var sidebar = main_window.sidebar;
Expand Down
16 changes: 0 additions & 16 deletions src/nuvolakit-runner/MasterController.vala
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public class MasterController : Drtgtk.Application {
public override void activate() {
hold();
get_ui().show_main_window();
show_welcome_screen();
release();
}

Expand Down Expand Up @@ -321,7 +320,6 @@ public class MasterController : Drtgtk.Application {
DBusProxyFlags.DO_NOT_CONNECT_SIGNALS|DBusProxyFlags.DO_NOT_LOAD_PROPERTIES);
app_api.activate();
debug("DBus activation of %s succeeded.", uid);
show_welcome_screen();
Timeout.add_seconds(5, () => {release(); return false;});
}
catch (GLib.Error e) {
Expand Down Expand Up @@ -378,22 +376,9 @@ public class MasterController : Drtgtk.Application {
} else {
app_runners_map[app_id] = runner;
}
show_welcome_screen();
#endif
}

/**
* Show welcome screen only if criteria are met.
*
* Otherwise, no welcome screen is shown and the GUI is even not initialized.
*/
private void show_welcome_screen() {
if (config.get_string("nuvola.welcome_screen") != get_welcome_screen_name()) {
get_ui().show_main_window(MasterUserInterface.PAGE_WELCOME);
config.set_string("nuvola.welcome_screen", get_welcome_screen_name());
}
}

public bool start_app_from_dbus(string app_id, string dbus_id, out string token) {
token = null;
hold();
Expand Down Expand Up @@ -423,7 +408,6 @@ public class MasterController : Drtgtk.Application {
} else {
app_runners_map[app_id] = runner;
}
show_welcome_screen();
return true;
}

Expand Down
38 changes: 38 additions & 0 deletions src/nuvolakit-runner/gui/WelcomeDialog.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2014-2018 Jiří Janoušek <[email protected]>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

namespace Nuvola {

public class WelcomeDialog : Gtk.Dialog {
public WelcomeDialog(Gtk.Window? parent, WelcomeScreen screen) {
GLib.Object(title: "Welcome", transient_for: parent);
set_default_size(800, 600);
add_button("_Close", Gtk.ResponseType.CLOSE);
var box = get_content_area();
box.add(screen);
screen.show();
}
}

} // namespace Nuvola

0 comments on commit f39830a

Please sign in to comment.