Skip to content

Commit 6090097

Browse files
committed
[chrome] add VITE_PUTER_BRANDING flag
1 parent e28ad3d commit 6090097

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

devserver.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ const CHROME_PORT = process.env.CHROME_PORT || 6767;
3333
const WISP_PORT = process.env.WISP_PORT || 6768;
3434
const ISOLATION_PORT = process.env.ISOLATION_PORT || 5233;
3535

36-
process.env.VITE_WISP_URL =
37-
process.env.VITE_WISP_URL || `ws://localhost:${WISP_PORT}/`;
38-
process.env.VITE_ISOLATION_ORIGIN =
39-
process.env.VITE_ISOLATION_ORIGIN || `http://localhost:${ISOLATION_PORT}`;
36+
const puterBranding = Boolean(process.env.VITE_PUTER_BRANDING);
37+
38+
if (puterBranding) {
39+
process.env.VITE_ISOLATION_ORIGIN ||= `https://puter.zone`;
40+
} else {
41+
process.env.VITE_WISP_URL ||= `ws://localhost:${WISP_PORT}/`;
42+
process.env.VITE_ISOLATION_ORIGIN ||= `http://localhost:${ISOLATION_PORT}`;
43+
}
4044

4145
const sandboxRoot = path.resolve("./packages/sandbox");
4246

@@ -77,7 +81,7 @@ const lines = [
7781
),
7882
black()(
7983
`${accent("wisp")} ${connector} ${urlColor(
80-
process.env.VITE_WISP_URL ?? ""
84+
process.env.VITE_WISP_URL ?? "(puter)"
8185
)}`
8286
),
8387
black()(

packages/chrome/index.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>Browser</title>
88

9-
<script src="https://js.puter.com/v2/"></script>
10-
119
<!--ssr-head-->
1210
</head>
1311

packages/chrome/src/Browser.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,10 @@ export async function saveBrowserState() {
292292

293293
let ser = browser.serialize();
294294

295-
if (import.meta.env.VITE_LOCAL) {
296-
localStorage["browserstate"] = JSON.stringify(ser);
297-
} else {
295+
if (import.meta.env.VITE_PUTER_BRANDING) {
298296
await puter.kv.set("browserstate", JSON.stringify(ser));
297+
} else {
298+
localStorage["browserstate"] = JSON.stringify(ser);
299299
}
300300

301301
// if (!import.meta.env.VITE_LOCAL) {
@@ -319,10 +319,10 @@ export async function initBrowser() {
319319
// }
320320

321321
let de;
322-
if (import.meta.env.VITE_LOCAL) {
323-
de = localStorage["browserstate"];
324-
} else {
322+
if (import.meta.env.VITE_PUTER_BRANDING) {
325323
de = await puter.kv.get("browserstate");
324+
} else {
325+
de = localStorage["browserstate"];
326326
}
327327
if (de) {
328328
try {

packages/chrome/src/main.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,18 @@ import { App } from "./App";
1111
import { css } from "dreamland/core";
1212
import { setWispUrl } from "./IsolatedFrame";
1313

14-
export const isPuter = !import.meta.env.VITE_LOCAL && puter.env == "app";
14+
// load puter sdk
15+
if (import.meta.env.VITE_PUTER_BRANDING) {
16+
let script = <script src="https://js.puter.com/v2/"></script>;
17+
document.head.appendChild(script);
18+
19+
await new Promise((resolve) => {
20+
script.onload = () => resolve(null);
21+
});
22+
}
23+
24+
export const isPuter =
25+
import.meta.env.VITE_PUTER_BRANDING && puter.env == "app";
1526

1627
export function LoadInterstitial(s: { status: string }) {
1728
return (
@@ -60,7 +71,7 @@ export async function mount(): Promise<HTMLElement> {
6071
e.preventDefault();
6172
});
6273

63-
if (!import.meta.env.VITE_LOCAL) {
74+
if (import.meta.env.VITE_PUTER_BRANDING) {
6475
if (!puter.auth.isSignedIn()) {
6576
await puter.auth.signIn();
6677
return;

packages/chrome/src/vite-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/// <reference types="@mercuryworkshop/scramjet" />
33

44
interface ImportMetaEnv {
5-
readonly VITE_LOCAL: boolean;
5+
readonly VITE_PUTER_BRANDING: boolean;
66
readonly VITE_ISOLATION_ORIGIN: string;
77
readonly VITE_WISP_URL: string;
88
}

0 commit comments

Comments
 (0)