Skip to content

Commit

Permalink
refactor: redirect websocket connection outside webview
Browse files Browse the repository at this point in the history
  • Loading branch information
mslxl committed Apr 9, 2024
1 parent 4e4c201 commit 50d6dc6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ fn main() {
.setup(|app| {
// provlegisto state
CONFIG_DIR
.set(dunce::canonicalize(app.path_resolver().app_config_dir().unwrap()).unwrap())
.set(util::fs::canonicalize(app.path_resolver().app_config_dir().unwrap()).unwrap())
.unwrap();
RESOURCE_DIR
.set(
dunce::canonicalize(app.path_resolver().app_local_data_dir().unwrap()).unwrap(),
util::fs::canonicalize(app.path_resolver().app_local_data_dir().unwrap()).unwrap(),
)
.unwrap();
app.manage(LSPState::default());
Expand Down
8 changes: 8 additions & 0 deletions src-tauri/src/util/fs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use std::path::{Path, PathBuf};

pub fn canonicalize<P: AsRef<Path>>(p: P)-> std::io::Result<PathBuf>{
if !p.as_ref().exists() {
std::fs::create_dir_all(&p)?;
}
dunce::canonicalize(p)
}
1 change: 1 addition & 0 deletions src-tauri/src/util/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod console;
pub mod error;
pub mod keylock;
pub mod fs;

pub fn append_env_var(name: &str, value: String) -> String {
let origin = std::env::var(name);
Expand Down
2 changes: 1 addition & 1 deletion src/components/collab/connected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function Connected(props: ConnectedProps) {
return (
<div className={clsx(props.className, "h-full select-none flex flex-col min-h-0 min-w-0")} ref={panelRef}>
<div className="shadow-sm flex pl-2 top-0 bg-accent">
<span className="truncate font-semibold">Online Users</span>
<span className="truncate font-semibold">ONLINE USERS</span>
<span className="flex-1"></span>
<button className={clsx("p-1 hover:bg-neutral-200", {hidden: !isHover})} onClick={exitRoom}>
<ImExit />
Expand Down
7 changes: 5 additions & 2 deletions src/lib/net/WebsocketTauriPolyfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@ class WebsocketTauriPolyfill implements WebSocket {
this.ws?.send(data)
} else if (data instanceof Blob) {
data.arrayBuffer().then((buff) => this.send(buff))
} else if (data instanceof ArrayBuffer || data instanceof SharedArrayBuffer) {
} else if (data instanceof ArrayBuffer) {
this.send(new Int8Array(data))
} else if (data instanceof Int8Array) {
} else if (data instanceof Int8Array || data instanceof Uint8Array) {
this.ws?.send(Array.from(data))
}else{
console.log(data)
throw new Error("Unsupported data type")
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/store/source/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as log from "tauri-plugin-log-api"
import { atomWithObservable } from "jotai/utils"
import { map } from "lodash/fp"
import { normalizeColor } from "@/lib/utils"
import WebsocketTauriPolyfill from "@/lib/net/WebsocketTauriPolyfill"

export const docProviderAtom = atom<null | WebsocketProvider>(null)

Expand Down Expand Up @@ -88,7 +89,7 @@ export const connectProviderAtom = atom(

const doc = get(docAtom)
const wsProvider = new WebsocketProvider(address, roomName, doc, {
// WebSocketPolyfill : WebsocketTauriPolyfill,
WebSocketPolyfill : WebsocketTauriPolyfill as any, // fuck, this is executable, through "anyscript"
awareness: awareness,
})
if (user) {
Expand Down

0 comments on commit 50d6dc6

Please sign in to comment.