Skip to content

Commit 01cdfad

Browse files
committed
[frontend] implement internal puter:// pages
1 parent e41925a commit 01cdfad

File tree

3 files changed

+70
-5
lines changed

3 files changed

+70
-5
lines changed

frontend/src/components/Shell.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export const Shell: Component<{
1313
<div
1414
class={`container ${cx.id}`}
1515
class:active={use(this.activetab).map((t) => t === tab)}
16+
class:showframe={use(tab.internalpage).map((t) => !t)}
1617
>
18+
{use(tab.internalpage)}
1719
{tab.frame.frame}
1820
</div>
1921
);
@@ -48,5 +50,9 @@ Shell.css = `
4850
width: 100%;
4951
height: 100%;
5052
border: none;
53+
display: none;
54+
}
55+
.showframe iframe{
56+
display: block;
5157
}
5258
`;

frontend/src/history.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class History {
1212

1313
constructor(private tab: Tab) {}
1414

15-
push(url: URL, state: any, navigate: boolean = true): HistoryState {
15+
push(url: URL, state: any = null, navigate: boolean = true): HistoryState {
1616
this.states.push({ url, state });
1717
this.index++;
1818

@@ -60,8 +60,9 @@ export class History {
6060
}
6161
}
6262

63-
export function injectHistoryEmulation(frame: ScramjetFrame, tab: Tab) {
63+
export function addHistoryListeners(frame: ScramjetFrame, tab: Tab) {
6464
frame.addEventListener("navigate", (e) => {
65+
console.log("History push from navigate", e, tab.history.states);
6566
// this event is fired whenever location.href is set, or similar
6667
// importantly not fired when replaceState is called (we overwrite it ourselves in injectContext)
6768

@@ -71,12 +72,14 @@ export function injectHistoryEmulation(frame: ScramjetFrame, tab: Tab) {
7172

7273
console.log("History push from navigate", url, tab.history.states);
7374
});
74-
frame.frame.addEventListener("beforeunload", (e: BeforeUnloadEvent) => {
75+
}
76+
77+
export function injectHistoryEmulation(client: ScramjetClient, tab: Tab) {
78+
// this is extremely problematic in terms of security but whatever
79+
client.global.addEventListener("beforeunload", (e: BeforeUnloadEvent) => {
7580
console.log("History beforeunload", e);
7681
});
77-
}
7882

79-
function injectContext(client: ScramjetClient, tab: Tab) {
8083
client.Proxy("History.prototype.pushState", {
8184
apply(ctx) {
8285
console.log("STATE PUSH", ctx.args);

frontend/src/pages/NewTab.tsx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import type { Component } from "dreamland/core";
2+
import type { Tab } from "../Tab";
3+
4+
export const NewTab: Component<
5+
{
6+
tab: Tab;
7+
},
8+
{}
9+
> = function (cx) {
10+
return (
11+
<div>
12+
<div class="main">
13+
<h1>Puter Browser</h1>
14+
<input
15+
on:keydown={(e: KeyboardEvent) => {
16+
if (e.key === "Enter") {
17+
e.preventDefault();
18+
this.tab.history.push(new URL(e.target!.value));
19+
}
20+
}}
21+
placeholder="Search Google or type A URL"
22+
></input>
23+
</div>
24+
</div>
25+
);
26+
};
27+
NewTab.css = `
28+
:scope {
29+
width: 100%;
30+
height: 100%;
31+
display: flex;
32+
justify-content: center;
33+
font-family: sans-serif;
34+
}
35+
36+
.main {
37+
width: 70%;
38+
display: flex;
39+
flex-direction: column;
40+
align-items: center;
41+
}
42+
43+
input {
44+
width: 100%;
45+
height: 2em;
46+
font-size: 1.5em;
47+
border: 2px solid #ccc;
48+
outline: none;
49+
border-radius: 4px;
50+
}
51+
52+
.main {
53+
position: relative;
54+
top: 10em;
55+
}
56+
`;

0 commit comments

Comments
 (0)