diff options
author | Jan-Michael Brummer <jan.brummer@tabos.org> | 2021-08-09 15:53:59 +0200 |
---|---|---|
committer | Marge Bot <marge-bot@gnome.org> | 2021-08-09 20:51:57 +0000 |
commit | e3472435fcab791a4017ee9a5a26d8abfd34b4be (patch) | |
tree | c1dafc558707190c0a2583a14573846f09bee159 | |
parent | ce4ebd6f7909a6fa3e5a5cb8262cfe22029db2b0 (diff) | |
download | epiphany-e3472435fcab791a4017ee9a5a26d8abfd34b4be.tar.gz |
Always save pinned tabs in session
When policy is set the NEVER we obviously never write a session file. With
the pinned tabs option this does not seems to be a good option, so let's mimic
other browsers and store them even if policy is set to NEVER.
Fixes: https://gitlab.gnome.org/GNOME/epiphany/-/issues/1508
Part-of: <https://gitlab.gnome.org/GNOME/epiphany/-/merge_requests/997>
-rw-r--r-- | data/org.gnome.epiphany.gschema.xml | 2 | ||||
-rw-r--r-- | lib/ephy-prefs.h | 1 | ||||
-rw-r--r-- | src/ephy-session.c | 63 |
3 files changed, 41 insertions, 25 deletions
diff --git a/data/org.gnome.epiphany.gschema.xml b/data/org.gnome.epiphany.gschema.xml index a82713bda..3e6cd82c3 100644 --- a/data/org.gnome.epiphany.gschema.xml +++ b/data/org.gnome.epiphany.gschema.xml @@ -49,7 +49,7 @@ <key name="restore-session-policy" enum="org.gnome.Epiphany.EphyPrefsRestoreSessionPolicy"> <default>'always'</default> <summary>Whether to automatically restore the last session</summary> - <description>Defines how the session will be restored during startup. Allowed values are “always” (the previous state of the application is always restored), “crashed” (the session is only restored if the application crashes) and “never” (the homepage is always shown).</description> + <description>Defines how the session will be restored during startup. Allowed values are “always” (the previous state of the application is always restored) and “crashed” (the session is only restored if the application crashes).</description> </key> <key type="b" name="restore-session-delaying-loads"> <default>true</default> diff --git a/lib/ephy-prefs.h b/lib/ephy-prefs.h index dc7d491f5..a52e1ab4e 100644 --- a/lib/ephy-prefs.h +++ b/lib/ephy-prefs.h @@ -38,7 +38,6 @@ typedef enum typedef enum { EPHY_PREFS_RESTORE_SESSION_POLICY_ALWAYS, - EPHY_PREFS_RESTORE_SESSION_POLICY_NEVER, EPHY_PREFS_RESTORE_SESSION_POLICY_CRASHED } EphyPrefsRestoreSessionPolicy; diff --git a/src/ephy-session.c b/src/ephy-session.c index c483ace61..815498e98 100644 --- a/src/ephy-session.c +++ b/src/ephy-session.c @@ -494,8 +494,6 @@ ephy_session_class_init (EphySessionClass *class) void ephy_session_close (EphySession *session) { - EphyPrefsRestoreSessionPolicy policy; - g_assert (EPHY_IS_SESSION (session)); LOG ("ephy_session_close"); @@ -510,12 +508,7 @@ ephy_session_close (EphySession *session) session->closing = TRUE; - policy = g_settings_get_enum (EPHY_SETTINGS_MAIN, EPHY_PREFS_RESTORE_SESSION_POLICY); - if (policy == EPHY_PREFS_RESTORE_SESSION_POLICY_ALWAYS) { - ephy_session_save_now (session); - } else { - session_delete (session); - } + ephy_session_save_now (session); session->dont_save = TRUE; } @@ -789,6 +782,24 @@ write_ephy_window (xmlTextWriterPtr writer, { GList *l; int ret; + EphyPrefsRestoreSessionPolicy policy; + int last_pinned_tab = -1; + gboolean only_pinned_tabs = FALSE; + + policy = g_settings_get_enum (EPHY_SETTINGS_MAIN, EPHY_PREFS_RESTORE_SESSION_POLICY); + only_pinned_tabs = policy == EPHY_PREFS_RESTORE_SESSION_POLICY_CRASHED; + + if (only_pinned_tabs) { + for (l = window->tabs; l != NULL; l = l->next, last_pinned_tab++) { + SessionTab *tab = (SessionTab *)l->data; + + if (!tab->pinned) + break; + } + + if (last_pinned_tab == -1) + return 0; + } ret = xmlTextWriterStartElement (writer, (xmlChar *)"window"); if (ret < 0) @@ -798,6 +809,9 @@ write_ephy_window (xmlTextWriterPtr writer, if (ret < 0) return ret; + if (last_pinned_tab != -1 && window->active_tab >= last_pinned_tab) + window->active_tab = last_pinned_tab + 1; + ret = xmlTextWriterWriteFormatAttribute (writer, (const xmlChar *)"active-tab", "%d", window->active_tab); if (ret < 0) @@ -805,6 +819,10 @@ write_ephy_window (xmlTextWriterPtr writer, for (l = window->tabs; l != NULL; l = l->next) { SessionTab *tab = (SessionTab *)l->data; + + if (only_pinned_tabs && !tab->pinned) + break; + ret = write_tab (writer, tab); if (ret < 0) break; @@ -812,6 +830,19 @@ write_ephy_window (xmlTextWriterPtr writer, if (ret < 0) return ret; + if (only_pinned_tabs && last_pinned_tab != -1) { + /* We are in EPHY_PREFS_RESTORE_SESSION_POLICY_NEVER with pinned tabs + * Create a new overview page after the pinned tab + */ + SessionTab *new_session_tab = g_new0 (SessionTab, 1); + + new_session_tab->url = g_strdup ("about:overview"); + new_session_tab->title = g_strdup (""); + + write_tab (writer, new_session_tab); + session_tab_free (new_session_tab); + } + ret = xmlTextWriterEndElement (writer); /* window */ return ret; } @@ -1014,8 +1045,6 @@ ephy_session_save_timeout_cb (EphySession *session) void ephy_session_save (EphySession *session) { - EphyPrefsRestoreSessionPolicy policy; - g_assert (EPHY_IS_SESSION (session)); if (session->save_source_id) @@ -1024,10 +1053,6 @@ ephy_session_save (EphySession *session) if (session->dont_save) return; - policy = g_settings_get_enum (EPHY_SETTINGS_MAIN, EPHY_PREFS_RESTORE_SESSION_POLICY); - if (policy == EPHY_PREFS_RESTORE_SESSION_POLICY_NEVER) - return; - /* Schedule the save to occur one second in the future to ensure we don't * repeatedly write to disk when opening or closing many tabs at once. */ @@ -1722,7 +1747,6 @@ ephy_session_resume (EphySession *session, { GTask *task; gboolean has_session_state; - EphyPrefsRestoreSessionPolicy policy; EphyShell *shell; LOG ("ephy_session_resume"); @@ -1731,20 +1755,13 @@ ephy_session_resume (EphySession *session, has_session_state = session_state_file_exists (session); - policy = g_settings_get_enum (EPHY_SETTINGS_MAIN, - EPHY_PREFS_RESTORE_SESSION_POLICY); - shell = ephy_shell_get_default (); /* If we are auto-resuming, and we never want to * restore the session, clobber the session state * file. */ - if (policy == EPHY_PREFS_RESTORE_SESSION_POLICY_NEVER) - session_delete (session); - - if (has_session_state == FALSE || - policy == EPHY_PREFS_RESTORE_SESSION_POLICY_NEVER) { + if (has_session_state == FALSE) { session_maybe_open_window (session, user_time); } else if (ephy_shell_get_n_windows (shell) == 0) { ephy_session_load (session, SESSION_STATE, user_time, cancellable, |