Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #186: Introduced Tab Restoration on Restart #1048

Merged
merged 2 commits into from
Mar 30, 2024

Conversation

ShaopengLin
Copy link
Collaborator

@ShaopengLin ShaopengLin commented Mar 7, 2024

Changes:

  • Pop-up to prompt users whether they want to restore the tabs. If not, start a new session. Added a checkbox in settings for users to toggle whether they want tab restoration or not.
  • Tab order is preserved.
  • Tab closures are recorded.
  • Tab navigation URL is preserved.
  • Blank/Settings tabs are recorded but not opened again on startup.

Fix-up Changes:

  • Does not open zim files that are deleted from the File System.
  • Pop-ups replaced with toggle option in settings.
  • Writes to a separate file than the program settings registry.
  • Simplifies session commit strategy.

Fix #186

@kelson42
Copy link
Collaborator

kelson42 commented Mar 8, 2024

@ShaopengLin Thank you very much for PR. I will check from a user perspective. One thing which should probably be changed is creating a dedicated settings to manage this behaviour (not in favour of popup at start).

@ShaopengLin
Copy link
Collaborator Author

Like an option for either restoring automatucally or have a pop-up for it? For automatic restoration it would be good to have a short-small notification about it as well.

@kelson42
Copy link
Collaborator

kelson42 commented Mar 8, 2024

Yes, a basic boolean setting "Restore tabs at start". I will lokk how FF and Chrome exactly work...

@ShaopengLin
Copy link
Collaborator Author

Just found we have a settingsmanager.cpp. Will move code over there to refactor a commit.

@ShaopengLin ShaopengLin force-pushed the Issue#186-remember-tabs-opened branch from 2a7f6ca to b1911ed Compare March 10, 2024 05:13
@kelson42
Copy link
Collaborator

kelson42 commented Mar 10, 2024

Yes, a basic boolean setting "Restore tabs at start". I will lokk how FF and Chrome exactly work...

I confirm, we should have a "Open previous tabs at startup" checkbox in the settings. Per default unchecked.

@ShaopengLin
Copy link
Collaborator Author

Yes, a basic boolean setting "Restore tabs at start". I will lokk how FF and Chrome exactly work...

I confirm, we should have a "Open previous tabs at startup" checkbox in the settings. Per default unchecked.

I think currently I set it as default checked, simple change. Will wait for reviewer comment and change in a batch.

@kelson42
Copy link
Collaborator

@ShaopengLin Option not visible in the settings,
image

@ShaopengLin
Copy link
Collaborator Author

Weird. I will test it using Qt6 as well. I was still developing on the Qt5 build. Might be some differences in building UI?

@kelson42
Copy link
Collaborator

@ShaopengLin Sorry, me doing a wrong manipulation. Seems to work fine... but setting wording is NOK. SHould be "Open previous tabs at startup"

@ShaopengLin
Copy link
Collaborator Author

Is there a way for me to update i18n for the text?

@kelson42
Copy link
Collaborator

@ShaopengLin You should put only the string in English

@ShaopengLin
Copy link
Collaborator Author

ShaopengLin commented Mar 10, 2024

@kelson42 I just put it like this?
ui->reopenTabLabel->setText(gt("open-previous-tabs-on-startup"));

src/settingsmanager.h Outdated Show resolved Hide resolved
src/tabbar.cpp Outdated Show resolved Hide resolved
@ShaopengLin
Copy link
Collaborator Author

ShaopengLin commented Mar 12, 2024

I will update this PR after merge of #1057 and on resolution of the comments: comment on text translation and comment on session

src/kiwixapp.cpp Outdated Show resolved Hide resolved
@ShaopengLin ShaopengLin force-pushed the Issue#186-remember-tabs-opened branch 2 times, most recently from fd80447 to 3f986b8 Compare March 22, 2024 17:58
Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a little concerned with the new calls to Kiwix::instance(), but I think that I'd rather address it separately in a dedicated design improvement PR.

Apart from fixing the issues outlined in the review comments, please split this PR in two commits:

  1. Add unconditional reopening of tabs from previous session;
  2. Introduce a setting that controls that behaviour.

src/tabbar.cpp Outdated Show resolved Hide resolved
src/tabbar.cpp Outdated Show resolved Hide resolved
src/tabbar.cpp Outdated Show resolved Hide resolved
src/tabbar.cpp Outdated Show resolved Hide resolved
src/kiwixapp.h Outdated Show resolved Hide resolved
src/kiwixapp.cpp Outdated Show resolved Hide resolved
@ShaopengLin
Copy link
Collaborator Author

@veloman-yunkan Could you tag me when you start the refactoring work? I am a GSOC student so seeing practical design patterns being applied is great learning for me as well. I am guessing something like dependency injection or complete functions.

@ShaopengLin ShaopengLin force-pushed the Issue#186-remember-tabs-opened branch 2 times, most recently from 34edb31 to 2fae684 Compare March 24, 2024 21:56
@@ -166,12 +166,13 @@ QWebEngineView* WebView::createWindow(QWebEnginePage::WebWindowType type)

void WebView::onUrlChanged(const QUrl& url) {
auto zimId = getZimIdFromUrl(url);
auto app = KiwixApp::instance();
app->saveListOfOpenTabs();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced the previous call on webpage.cpp as I found that was a bad choice. No need for the acceptNavigationRequest. onUrlChanged is indeed called on in-page URL navigations.

Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case the number of new comments makes you think that I am not happy with the progress you will be wrong. The fact is that we are much closer to having this PR merged and I am just paying attention to more mundane details. 😉

src/kiwixapp.cpp Outdated Show resolved Hide resolved
src/kiwixapp.cpp Outdated Show resolved Hide resolved
src/kiwixapp.cpp Outdated

/* Place session file in our global library path */
QDir dir(m_libraryDirectory);
this->mp_session = new QSettings(dir.filePath("user.session"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, we better name kiwix-desktop's session file kiwix-desktop.session. @kelson42 Do you agree?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the modification just in case.

src/kiwixapp.cpp Outdated Show resolved Hide resolved
src/tabbar.h Outdated Show resolved Hide resolved
src/kiwixapp.cpp Outdated Show resolved Hide resolved
Comment on lines -41 to +47
void SettingsView::init(int zoomPercent, const QString &downloadDir, const QString &monitorDir, const bool moveToTrash)
void SettingsView::init(int zoomPercent, const QString &downloadDir,
const QString &monitorDir, const bool moveToTrash,
bool reopentab)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is comment for myself. The trend of the parameter list of SettingsView::init() growing over time is obvious, but the need for that function is not. For a slightly different design the initialization of SettingsView could be performed via the existing update mechanism via signal-slot connections.

@veloman-yunkan
Copy link
Collaborator

@veloman-yunkan Could you tag me when you start the refactoring work? I am a GSOC student so seeing practical design patterns being applied is great learning for me as well. I am guessing something like dependency injection or complete functions.

🤝

I will. Can't promise that your expectations for design patterns will be met since I am mostly refactoring based on my sense of aesthetics, but if you notice in the resulting code anything familiar from your computer science study I will be glad to learn its name 😄

@ShaopengLin ShaopengLin force-pushed the Issue#186-remember-tabs-opened branch from 2fae684 to e66cfeb Compare March 27, 2024 02:11
Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question to @kelson42 and @mgautierfr - in the current implementation the list of open tabs is saved every time it changes even if the "reopen-tabs" setting is disabled. Is that ok?

src/settingsview.cpp Outdated Show resolved Hide resolved
@ShaopengLin ShaopengLin force-pushed the Issue#186-remember-tabs-opened branch from e66cfeb to 9430e3f Compare March 27, 2024 15:15
@ShaopengLin ShaopengLin force-pushed the Issue#186-remember-tabs-opened branch from 9430e3f to f133b70 Compare March 27, 2024 18:22
Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (but note my so far unanswered question in the previous review).

@mgautierfr
Copy link
Member

We may want to save (and restore) also the which tab is the current one.
But it may be done in another PR (open a issue in this case). Else nothing to add.

@ShaopengLin
Copy link
Collaborator Author

ShaopengLin commented Mar 30, 2024

We may want to save (and restore) also the which tab is the current one. But it may be done in another PR (open a issue in this case). Else nothing to add.

@mgautierfr It's rather a simple change that makes this feature complete. I will just add it here. Sorry for the delayed response.

Actually no, it is not a 'simple' task and it would be better to have some discussion on the behaviors. I will open an issue once this is merged.

@kelson42
Copy link
Collaborator

@ShaopengLin Thank you very much for this PR. Please don't forget to open the ticket like agreed. Merging...

Users can now restore tabs opened before close in the same order and same url. Fix kiwix#186
Added a checkbox in settings where user can define if they want the tab reopening feature to be active. Fix kiwix#186
@kelson42 kelson42 force-pushed the Issue#186-remember-tabs-opened branch from f133b70 to 01a6698 Compare March 30, 2024 09:47
@kelson42 kelson42 merged commit 0205db4 into kiwix:main Mar 30, 2024
4 checks passed
ShaopengLin added a commit that referenced this pull request Jun 9, 2024
The change in #1048 prevented opening of blank tab and urls that are no longer valid. Now, we will need to open them as well, as we will need the exact number of tabs to reopen in order to correctly restore current tab index.
ShaopengLin added a commit that referenced this pull request Jun 15, 2024
The change in #1048 prevented opening of blank tab and urls that are no longer valid. Now, we will need to open them as well, as we will need the exact number of tabs to reopen in order to correctly restore current tab index.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remember open tabs over restart
4 participants