gemenon

[ACTIVE] The Safari of the Gemini ecosystem
git clone git://git.figbert.com/gemenon.git
Log | Files | Refs

commit 25314131ae1515877569d17dd1c5ff6d3bac56e6
parent b5d0cf5b52b2b11191117629782c5ff8d8ded73e
Author: FIGBERT <figbert@figbert.com>
Date:   Fri, 21 Oct 2022 09:41:43 -0700

Keep a maximum of five response bodies in memory

As you click links on pages, navigate with the URL bar, or traverse
history with the back and forward buttons, the response bodies three
forward and backward from the current tab are pruned.

This keeps memory usage low, as we don't keep all data accessed in a
browsing session in memory. For example, if a user navigates to a large
video and then continues their session, the video no longer takes up RAM
for the duration of the session.

The buffer of two tabs in each direction from the current tab should
hopefully serve to prevent loadin for the most frequent actions.

Diffstat:
MShared/BrowserFunctions.swift | 17+++++++++++++++--
MShared/ContentView.swift | 4++--
2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/Shared/BrowserFunctions.swift b/Shared/BrowserFunctions.swift @@ -29,13 +29,25 @@ extension BrowserData { guard !self.tab.home else { return } self.tab = Tab(prev: self.tab) } - func goBack() { + func goBack() async { guard self.tab.prev != nil else { return } + if self.tab.prev?.response == nil { + self.loading = true + self.tab.prev?.response = try! await self.engine.request((self.tab.prev?.url)!) + self.loading = false + } self.tab = self.tab.prev! + self.tab.next?.next?.next?.response = nil } - func goForward() { + func goForward() async { guard self.tab.next != nil else { return } + if self.tab.next?.response == nil { + self.loading = true + self.tab.next?.response = try! await self.engine.request((self.tab.next?.url)!) + self.loading = false + } self.tab = self.tab.next! + self.tab.prev?.prev?.prev?.response = nil } } @@ -45,6 +57,7 @@ extension BrowserData { let response = try! await self.engine.request(url) self.tab = Tab(url, prev: self.tab, response: response) self.tab.prev?.next = self.tab + self.tab.prev?.prev?.prev?.response = nil self.currentView = .Capsule self.loading = false } diff --git a/Shared/ContentView.swift b/Shared/ContentView.swift @@ -64,14 +64,14 @@ struct ContentView: View { } } ToolbarItem(placement: .navigation) { - Button(action: { data.goBack() }) { + Button(action: { Task { await data.goBack() } }) { Label("Back", systemImage: "chevron.backward") .labelStyle(.iconOnly) } .disabled(data.tab.prev == nil) } ToolbarItem(placement: .navigation) { - Button(action: { data.goForward() }) { + Button(action: { Task { await data.goForward() } }) { Label("Forward", systemImage: "chevron.forward") .labelStyle(.iconOnly) }