aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/lib.rs b/src/lib.rs
index e90202d..bb0fc76 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -4,6 +4,7 @@ use std::rc::Rc;
use futures::channel::mpsc;
use futures::prelude::*;
+use gloo::storage::{LocalStorage, Storage as _};
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use wasm_bindgen_futures::*;
@@ -48,7 +49,7 @@ fn update_target_marker(
width: &Rc<Cell<u32>>,
height: &Rc<Cell<u32>>,
video: &HtmlVideoElement,
- queue_position: &Rc<Cell<(u32, u32)>>,
+ queue_position: &QueuePosition,
) {
let (real_x, real_y) = queue_position.get();
let real_width = width.get() as f64;
@@ -74,13 +75,38 @@ fn update_target_marker(
.unwrap();
}
+#[derive(Clone)]
+struct QueuePosition {
+ inner: Rc<Cell<(u32, u32)>>,
+}
+
+impl QueuePosition {
+ const STORAGE_KEY: &'static str = "queue-position";
+
+ fn new() -> Self {
+ let values = LocalStorage::get(Self::STORAGE_KEY).unwrap_or((920, 520));
+ Self {
+ inner: Rc::new(Cell::new(values)),
+ }
+ }
+
+ fn set(&self, data: (u32, u32)) {
+ LocalStorage::set(Self::STORAGE_KEY, data).unwrap();
+ self.inner.replace(data);
+ }
+
+ fn get(&self) -> (u32, u32) {
+ self.inner.get()
+ }
+}
+
async fn do_boot() {
let width = Rc::new(Cell::new(0));
let height = Rc::new(Cell::new(0));
let streaming = Rc::new(Cell::new(false));
- let queue_position = Rc::new(Cell::new((920u32, 520u32)));
+ let queue_position = QueuePosition::new();
let document = gloo::utils::document();
@@ -124,7 +150,7 @@ async fn do_boot() {
let fake_height = video.offset_height() as f64;
let real_x = mouse_x / fake_width * real_width - QUEUE_SIZE_WIDTH as f64 / 2.0;
let real_y = mouse_y / fake_height * real_height - QUEUE_SIZE_HEIGHT as f64 / 2.0;
- queue_position.replace((real_x.round() as u32, real_y.round() as u32));
+ queue_position.set((real_x.round() as u32, real_y.round() as u32));
update_target_marker(&target_marker, &width, &height, &video, &queue_position);
spawn_local(async move { manual_update_tx.send(()).await.unwrap() });
})