chore: prepare for web target

This commit is contained in:
Ren Amamiya
2026-03-31 08:45:35 +07:00
parent c8034642c5
commit b0ba2549d7
6 changed files with 277 additions and 70 deletions

View File

@@ -0,0 +1,43 @@
[package]
name = "coop_web"
version.workspace = true
edition.workspace = true
publish.workspace = true
[dependencies]
assets = { path = "../assets" }
ui = { path = "../ui" }
theme = { path = "../theme" }
common = { path = "../common" }
state = { path = "../state" }
device = { path = "../device" }
chat = { path = "../chat" }
chat_ui = { path = "../chat_ui" }
settings = { path = "../settings" }
person = { path = "../person" }
relay_auth = { path = "../relay_auth" }
gpui.workspace = true
gpui_web.workspace = true
gpui_platform.workspace = true
gpui_tokio.workspace = true
nostr-connect.workspace = true
nostr-sdk.workspace = true
anyhow.workspace = true
serde.workspace = true
serde_json.workspace = true
itertools.workspace = true
log.workspace = true
smallvec.workspace = true
smol.workspace = true
futures.workspace = true
oneshot.workspace = true
webbrowser.workspace = true
tracing-subscriber = { version = "0.3.18", features = ["fmt", "env-filter"] }
console_error_panic_hook = "0.1"
tracing-wasm = "0.2"
console_log = "1.0"
wasm-bindgen = "0.2"

View File

@@ -0,0 +1,26 @@
use gpui::*;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn run() -> Result<(), JsValue> {
console_error_panic_hook::set_once();
// Initialize logging to browser console
console_log::init_with_level(log::Level::Info).expect("Failed to initialize logger");
// Also initialize tracing for WASM
tracing_wasm::set_as_global_default();
#[cfg(target_family = "wasm")]
gpui_platform::web_init();
#[cfg(not(target_family = "wasm"))]
let app = gpui_platform::application();
#[cfg(target_family = "wasm")]
let app = gpui_platform::single_threaded_web();
app.run(|_cx| {});
Ok(())
}

View File

@@ -0,0 +1,77 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Coop</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family:
-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue",
sans-serif;
overflow: hidden;
width: 100vw;
height: 100vh;
}
#app {
width: 100%;
height: 100%;
position: relative;
}
#canvas {
display: block;
width: 100%;
height: 100%;
}
#loading {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
.spinner {
border: 4px solid rgba(0, 0, 0, 0.1);
border-left-color: #000;
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
margin: 0 auto 16px;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
.error {
color: #d32f2f;
padding: 20px;
text-align: center;
}
</style>
</head>
<body>
<div id="app">
<canvas id="canvas"></canvas>
<div id="loading">
<div class="spinner"></div>
<p>Loading Coop...</p>
</div>
</div>
<script type="module" src="/src/main.js"></script>
</body>
</html>