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

Exporting/Importing the history #444

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

Exporting/Importing the history #444

wants to merge 6 commits into from

Conversation

Cook-I-T
Copy link

Once this PR is fully done exporting and importing the history should be easily possible.

Exporting the history to JSON is fully working, first try! :)
I mostly copied what exporting Bookmarks does, which meant I had to add a sealed History class with a Entry data class to WebPage, which caused problems in SuggestionsAdapter's "when (webPage)", which I fixed by adding it also as an (unused) "is History" case, which shouldn't make any problems down the road hopefully.

Perhaps it could be cleaned up a little bit, with better names for example.

Next step would be to allow importing the history from a backup, a private addHistoryEntry function already exists which I could reuse for this. What has to be decided first is do I just replace the history (after warning the user) or do I offer a choice between replacing it or appending the history to the already existing one (this could be done by exporting both, combining the JSONs and importing that so it's not that important).
@Cook-I-T
Copy link
Author

Cook-I-T commented Mar 18, 2023

I've opened this draft PR so this functionality hopefully gets added to the official version (when finished and thoroughly tested) as I lost a lot of tabs lately because I didn't know about issue #193 and hope to recover at least some of them through the history, additionally this serves to get some feedback, as while this should work without problems I've never worked with Kotlin before so I'm missing the experience for this language.

Also I've got a question regarding the importing of the history, should the user be asked if they want to append the history or replace it, or should it just always be replaced (with a warning of course)?

Thanks in advance!

@Slion
Copy link
Owner

Slion commented Mar 25, 2023

@Cook-I-T Sorry you fell victim of #193. We really ought to fix it at some point.

hope to recover at least some of them through the history

You should be able to do that without import or export right? Just go to history and open the pages you want, done. You could also save the history page as PDF through the print option and refer to it later.

Also I've got a question regarding the importing of the history, should the user be asked if they want to append the history or replace it, or should it just always be replaced (with a warning of course)?

Not sure why user would want to import history.

Apologize if my comments feel dismissive of your contribution. I think it's awesome that you try to solve your issue by going into the code 🥳That's what open source is all about. I'm also not saying I don't want to merge that functionality in one form or another. Just trying to have an open mind about it that's all. So the first step is to put my product architect hat on ask myself do we need that new functionality or is it just going to add more bloat to an already bloated product? 😁

@Cook-I-T
Copy link
Author

Cook-I-T commented Mar 25, 2023

You should be able to do that without import or export right? Just go to history and open the pages you want, done. You could also save the history page as PDF through the print option and refer to it later.

Well some of the tabs haven't been loaded in... quite some time so being limited to seeing the last 100 entries in the history is not enough... yeah I really shouldn't have such a backlog of stuff in the first place but that's a bad habit I ain't gonna loose anytime soon XD

Not sure why user would want to import history.

Yeah I thought about asking if such a feature would be needed, but then decided not to. My thought behind that was that it would allow users to export their stuff and save it as a backup in case something happens and also allow easy transfer to a new phone. And as there is already a bookmark export and import function I though also allowing to import the history back would make sense.
Also you said "History backup and restore." yourself in #123 ;)

So I'm happy to try to also implement importing the history (by sticking to what importing bookmarks does once I figure out how to create dialog boxes) as I'd say it's useful enough to warrant it's inclusion.

@Slion
Copy link
Owner

Slion commented Mar 25, 2023

so being limited to seeing the last 100 entries in the history is not enough

How do you export more than the last 100 entries? Can you tap in the actual WebView history?

@Slion
Copy link
Owner

Slion commented Mar 25, 2023

So I'm happy to try to also implement importing the tabs

Not sure what you mean by that. You know you can backup your sessions right?

@Cook-I-T
Copy link
Author

Cook-I-T commented Mar 25, 2023

Not sure what you mean by that. You know you can backup your sessions right?

Sorry mistyped I meant history not tabs, changed it. That's what I would've done regularly if I had known of #193 XD

How do you export more than the last 100 entries? Can you tap in the actual WebView history?

I get the history directly from the database it gets written to, using a copy of (the seemingly unused) getAllHistoryEntries() function which returns a list inside a single via the getAllHistoryEntriesAsSingle() interface. The export functionality of my fork is already fully working if you want to test it.
I've attached a sample export of me clicking wildly through wikipedia and I do indeed get more than 100 entries:
FulgurisHistory-2023-03-25-(21_58_21).txt
Forgot to change the extension to .json but that's already fixed.
It seems to still attach .txt at the end, have to look deeper into that.
Fixed. :)

Renamed some comments and changed file extension from .txt to .json
File gets properly exported to .json now instead of .json.txt by changing the mime type from "text/plain" to "application/json"
Importing the history from a JSON file is fully functional. Still has to be tested.
@Cook-I-T
Copy link
Author

So, importing is now fully implemented and working (but untested at the moment), now the question remains if I should add a dialog before that to allow the user to choose between deleting their history before importing it or not.

Currently it gets deleted in the same transaction as it gets imported, which should prevent it from being completely deleted should something go wrong. With an if statement in there I could prevent the deletion, the only question is how do I access a bool set at BackupSettingsFragment from HistoryDatabase? This is where I lack the deeper knowledge on what Kotlin offers for solving that (or if there even is an elegant solution).

I'd say it's not that important as the history can always get combined outside of Fulguris if really needed (one simple ctrl+c & ctrl+v) but some warning for the user would be nice. Perhaps name it "Replace current history with backup" or something along those lines?

@Slion
Copy link
Owner

Slion commented Mar 26, 2023

For now I would not delete the history while importing. User could still do that through the settings before importing.

@Slion
Copy link
Owner

Slion commented Mar 26, 2023

That's what I would've done regularly if I had known of #193 XD

You can also just save a copy of your session without exporting it.

@Slion Slion added the feature New feature or request label Mar 26, 2023
No more resetting the history on importing, also does the same check as visitHistoryEntry now, therefore updating existing entries rather than duplicating them. Also fixed some comments.
@Cook-I-T
Copy link
Author

So import should now be fully functional. I renamed the Import option to "Add history from backup" as I hope that reflects enough about what it does to the user.

Now the question is if I should replace the already existing entries or just leave them and do nothing. Currently it updates them to what is in the JSON, but that could potentially make the history confusing if that page got visited later and then suddenly jumps "back in time" after the import.

Prevents entries jumping back to the time saved in the backup.
@Wjxfi
Copy link

Wjxfi commented Jul 9, 2023

@Cook-I-T Hi I'm really looking forward to this feature when will you do it? 🙃

@Cook-I-T
Copy link
Author

@Cook-I-T Hi I'm really looking forward to this feature when will you do it? 🙃

Hey, sorry for my long absence, life's been too busy to work on this and now after all those months there are additionally merge conflicts to resolve which takes even more time (also I never had to deal with merge conflicts before so I have no clue what to do, yet).
Perhaps I'll find some time, some time, but until then I'd say this PR is dead unless someone else can fix&finalize it :(

Best regards
Cook I.T!

@Slion
Copy link
Owner

Slion commented Oct 21, 2023

Sorry about the conflicts I just did some major refactoring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants