Skip to content

Commit 36c5982

Browse files
committed
[chrome] store current tab
1 parent bb4d316 commit 36c5982

File tree

5 files changed

+16
-18
lines changed

5 files changed

+16
-18
lines changed

packages/chrome/src/Browser.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class Browser extends StatefulClass {
9494

9595
settings: Stateful<Settings> = createState({
9696
theme: "system",
97-
startupPage: "new-tab",
97+
startupPage: "continue",
9898
defaultZoom: 100,
9999
showBookmarksBar: true,
100100
defaultSearchEngine: "google",
@@ -219,24 +219,24 @@ export class Browser extends StatefulClass {
219219

220220
if (de.settings.startupPage === "continue") {
221221
for (let detab of de.tabs) {
222-
let tab = this.newTab();
222+
let tab = this.newTab(undefined, false, detab.id);
223223
tab.deserialize(detab);
224224
tab.history.justTriggeredNavigation = true;
225225
tab.history.go(0, false);
226226
}
227+
this.activetab = this.tabs.find((t) => t.id == de.activetab)!;
227228
} else {
228229
this.tabs[0] = this.newTab();
230+
this.activetab = this.tabs[0];
229231
}
230-
this.activetab = this.tabs[0];
231232
this.bookmarks = de.bookmarks.map(createState);
232233
this.globalDownloadHistory = de.globalDownloadHistory.map(createState);
233234
this.settings = createState(de.settings);
234235
this.cookieJar.load(de.cookiedump);
235-
// this.activetab = this.tabs.find((t) => t.id == de.activetab)!;
236236
}
237237

238-
newTab(url?: URL, focusomnibox: boolean = false) {
239-
let tab = new Tab(url);
238+
newTab(url?: URL, focusomnibox: boolean = false, id?: number) {
239+
let tab = new Tab(url, id);
240240
pushTab(tab);
241241
this.tabs = [...this.tabs, tab];
242242
this.activetab = tab;

packages/chrome/src/History.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ export class History {
145145
}
146146

147147
let newstate = this.states[this.index];
148-
console.error("going", newstate);
149148

150149
if (current.virtual) {
151150
sendFrame(this.tab, "popstate", {

packages/chrome/src/Tab.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { PlaygroundPage } from "./pages/PlaygroundPage";
77
import { AboutPage } from "./pages/AboutPage";
88
import { HistoryPage } from "./pages/HistoryPage";
99
import { SettingsPage } from "./pages/SettingsPage";
10-
import { serviceWorkerReady } from "./main";
1110
import { DownloadsPage } from "./pages/DownloadsPage";
1211
import { ProxyFrame } from "./proxy/ProxyFrame";
1312
import { defaultFaviconUrl } from "./assets/favicon";
@@ -20,9 +19,8 @@ export type SerializedTab = {
2019
history: SerializedHistory;
2120
};
2221

23-
let id = 100;
22+
let idcnt = 100;
2423
export class Tab extends StatefulClass {
25-
id: number;
2624
title: string | null;
2725
frame: ProxyFrame;
2826
devtoolsFrame: any;
@@ -48,10 +46,12 @@ export class Tab extends StatefulClass {
4846
onChobitsuMessage: ((message: string) => void) | null = null;
4947
waitForChobitsuInit: Promise<void>;
5048

51-
constructor(public url: URL = new URL("puter://newtab")) {
49+
constructor(
50+
public url: URL = new URL("puter://newtab"),
51+
public id = idcnt++
52+
) {
5253
super(createState(Object.create(Tab.prototype)));
53-
54-
this.id = id++;
54+
if (id >= idcnt) idcnt = id + 1;
5555

5656
this.title = null;
5757
this.internalpage = null;

packages/chrome/src/main-client.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { jsxDEV } from "dreamland/jsx-runtime";
44
import { mount } from "./main";
55

66
mount().then((h) => {
7-
console.log("hdyurating", h);
87
hydrate(
98
() => h,
109
document.querySelector("#app")!,

packages/chrome/src/storage.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ export async function getSerializedBrowserState(): Promise<string | null> {
2525
}
2626
}
2727

28-
setInterval(() => {
28+
setInterval(async () => {
2929
if (dirty) {
30-
saveBrowserState();
30+
await saveBrowserState();
3131
dirty = false;
3232
}
3333
}, 3000);
3434

3535
// just in case
36-
setInterval(() => {
37-
saveBrowserState();
36+
setInterval(async () => {
37+
await saveBrowserState();
3838
dirty = false;
3939
}, 10000);
4040

0 commit comments

Comments
 (0)