fix web performance
This commit is contained in:
@@ -31,6 +31,8 @@ tracing-wasm = "0.2"
|
||||
console_log = "1.0"
|
||||
wasm-bindgen = "0.2"
|
||||
wasm-bindgen-futures = "0.4"
|
||||
js-sys = "0.3"
|
||||
web-sys = { version = "0.3", features = ["Window", "Performance"] }
|
||||
universal-time = { git = "https://github.com/shadowylab/universal-time" }
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
|
||||
+10
-2
@@ -11,13 +11,21 @@ struct CustomTimeProvider;
|
||||
|
||||
impl WallClock for CustomTimeProvider {
|
||||
fn system_time(&self) -> SystemTime {
|
||||
SystemTime::from_unix_duration(instant::Duration::from_secs(0))
|
||||
// Browser wall clock: milliseconds since the Unix epoch.
|
||||
let millis = js_sys::Date::now();
|
||||
SystemTime::from_unix_duration(instant::Duration::from_millis(millis as u64))
|
||||
}
|
||||
}
|
||||
|
||||
impl MonotonicClock for CustomTimeProvider {
|
||||
fn instant(&self) -> Instant {
|
||||
Instant::from_ticks(instant::Duration::from_secs(0))
|
||||
// `performance.now()` is monotonic; fall back to the wall clock if
|
||||
// it's unavailable.
|
||||
let millis = web_sys::window()
|
||||
.and_then(|window| window.performance())
|
||||
.map(|performance| performance.now())
|
||||
.unwrap_or_else(js_sys::Date::now);
|
||||
Instant::from_ticks(instant::Duration::from_millis(millis as u64))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,11 +10,11 @@ export default defineConfig({
|
||||
viteStaticCopy({
|
||||
targets: [
|
||||
{
|
||||
src: path.resolve(__dirname, "../../../assets/icons"),
|
||||
src: path.resolve(__dirname, "../../assets/icons"),
|
||||
dest: "assets",
|
||||
},
|
||||
{
|
||||
src: path.resolve(__dirname, "../../../assets/brand"),
|
||||
src: path.resolve(__dirname, "../../assets/brand"),
|
||||
dest: "assets",
|
||||
},
|
||||
],
|
||||
@@ -25,7 +25,7 @@ export default defineConfig({
|
||||
server.middlewares.use(
|
||||
"/assets",
|
||||
(req, res, next) => {
|
||||
const assetsPath = path.resolve(__dirname, "../../../assets");
|
||||
const assetsPath = path.resolve(__dirname, "../../assets");
|
||||
const filePath = path.join(
|
||||
assetsPath,
|
||||
req.url.replace("/assets", ""),
|
||||
|
||||
Reference in New Issue
Block a user