Compare commits
No commits in common. "master" and "old" have entirely different histories.
|
@ -1,2 +1,2 @@
|
|||
[alias]
|
||||
prisma = "run -p prisma-cli --"
|
||||
[registries.crates-io]
|
||||
protocol = "sparse"
|
||||
|
|
2
.dockerignore
Normal file
|
@ -0,0 +1,2 @@
|
|||
./docker-data
|
||||
./target
|
3
.envrc
|
@ -1 +1,2 @@
|
|||
export DATABASE_URL="postgresql://postgres:postgres@localhost:5432/mraow?schema=public"
|
||||
dotenv .env
|
||||
use flake
|
||||
|
|
4
.gitignore
vendored
|
@ -1 +1,5 @@
|
|||
.direnv
|
||||
sytest
|
||||
node_modules
|
||||
/target
|
||||
docker-data
|
||||
|
|
|
@ -1 +1 @@
|
|||
frontend/pnpm-lock.yaml
|
||||
package-lock.json
|
||||
|
|
1
.vscode/settings.json
vendored
|
@ -1 +0,0 @@
|
|||
{}
|
5250
Cargo.lock
generated
|
@ -1,2 +1,6 @@
|
|||
workspace.members = ["backend", "common", "frontend/src-tauri", "prisma-cli"]
|
||||
workspace.resolver = "2"
|
||||
[workspace]
|
||||
members = [
|
||||
"common",
|
||||
"server",
|
||||
"client/src-tauri",
|
||||
]
|
||||
|
|
22
README.md
|
@ -1,22 +0,0 @@
|
|||
# mraow
|
||||
|
||||
## Roadmap
|
||||
|
||||
- [x] send messages from one client to another
|
||||
- [ ] rooms
|
||||
- [ ] permission model
|
||||
- [ ] save connection info to local storage db
|
||||
- [ ] get rid of unwraps
|
||||
- [x] handle disconnect correctly
|
||||
- [ ] user accounts
|
||||
- [ ] retrieve history
|
||||
- [ ] notifications
|
||||
- [ ] multiple clients
|
||||
- [ ] send files (s3 backend interop)
|
||||
|
||||
distant future shit
|
||||
|
||||
- [ ] irc interop
|
||||
- [ ] matrix interop
|
||||
- [ ] having a spec
|
||||
- [ ] e2e encryption
|
5
backend/.gitignore
vendored
|
@ -1,5 +0,0 @@
|
|||
node_modules
|
||||
# Keep environment variables out of version control
|
||||
.env
|
||||
|
||||
src/prisma.rs
|
|
@ -1,22 +0,0 @@
|
|||
[package]
|
||||
name = "backend"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
common = { path = "../common" }
|
||||
|
||||
anyhow = { version = "1.0.76", features = ["backtrace"] }
|
||||
axum = { version = "0.7.2", features = ["http2", "multipart", "macros", "ws"] }
|
||||
dashmap = "5.5.3"
|
||||
ed25519-compact = "2.0.6"
|
||||
futures = "0.3.30"
|
||||
k256 = "0.13.2"
|
||||
lazy_static = "1.4.0"
|
||||
prisma-client-rust = { git = "https://github.com/Brendonovich/prisma-client-rust", tag = "0.6.10" }
|
||||
rand = "0.8.5"
|
||||
ring = "0.17.7"
|
||||
serde = "1.0.193"
|
||||
serde_json = "1.0.108"
|
||||
tokio = { version = "1.35.1", features = ["full"] }
|
||||
chrono = { version = "0.4.31", features = ["serde"] }
|
|
@ -1,47 +0,0 @@
|
|||
// This is your Prisma schema file,
|
||||
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||||
|
||||
generator client {
|
||||
provider = "cargo prisma"
|
||||
output = "../src/prisma.rs"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
model User {
|
||||
pubKey String @id
|
||||
displayName String
|
||||
|
||||
accountCreatedAt DateTime @default(now())
|
||||
|
||||
messages Message[]
|
||||
}
|
||||
|
||||
model Auth {
|
||||
token String @id @default(uuid())
|
||||
name String
|
||||
pubKey String
|
||||
active Boolean
|
||||
createdAt DateTime @default(now())
|
||||
expiresAt DateTime?
|
||||
}
|
||||
|
||||
model Room {
|
||||
id String @id
|
||||
}
|
||||
|
||||
model Message {
|
||||
id String @id
|
||||
type String
|
||||
content String
|
||||
|
||||
authorPubKey String
|
||||
author User @relation(fields: [authorPubKey], references: [pubKey])
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@index([type])
|
||||
}
|
|
@ -1,127 +0,0 @@
|
|||
#[macro_use]
|
||||
extern crate serde;
|
||||
|
||||
#[allow(unused_imports, dead_code)]
|
||||
mod prisma;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::Result;
|
||||
use axum::{
|
||||
extract::{
|
||||
ws::{Message as WsMessage, WebSocket},
|
||||
Query, State, WebSocketUpgrade,
|
||||
},
|
||||
response::Response,
|
||||
routing::{get, post},
|
||||
Json, Router,
|
||||
};
|
||||
use chrono::Utc;
|
||||
use common::{ClientMessage, Message};
|
||||
use dashmap::DashMap;
|
||||
use prisma::PrismaClient;
|
||||
use serde_json::{json, Value};
|
||||
use tokio::{
|
||||
select,
|
||||
sync::broadcast::{self, Sender},
|
||||
};
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref AUTH_CHALLENGES: DashMap<String, String> = DashMap::new();
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct AppState {
|
||||
room_tx: Sender<Message>,
|
||||
client: Arc<PrismaClient>,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
let client = PrismaClient::_builder().build().await?;
|
||||
let (room_tx, _room_rx) = broadcast::channel::<Message>(10_000);
|
||||
|
||||
let state = AppState {
|
||||
client: Arc::new(client),
|
||||
room_tx,
|
||||
};
|
||||
|
||||
let app = Router::new()
|
||||
.route("/v1/message", post(send_message))
|
||||
.route("/v1/events", get(event_stream_init))
|
||||
.with_state(state);
|
||||
|
||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:1551").await?;
|
||||
axum::serve(listener, app).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct SendMessageRequest {
|
||||
#[serde(flatten)]
|
||||
message: ClientMessage,
|
||||
}
|
||||
|
||||
async fn send_message(
|
||||
State(state): State<AppState>,
|
||||
Json(request): Json<SendMessageRequest>,
|
||||
) -> Json<Value> {
|
||||
let wrapped_message = Message {
|
||||
inner: request.message,
|
||||
server_timestamp: Utc::now(),
|
||||
};
|
||||
state.room_tx.send(wrapped_message).unwrap();
|
||||
println!("Got message from client, forwarding to room...");
|
||||
|
||||
Json(json!({}))
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct EventStreamRequest {
|
||||
name: String,
|
||||
}
|
||||
|
||||
async fn event_stream_init(
|
||||
ws: WebSocketUpgrade,
|
||||
Query(request): Query<EventStreamRequest>,
|
||||
State(state): State<AppState>,
|
||||
) -> Response {
|
||||
println!("Username: {}", request.name);
|
||||
ws.on_upgrade(|socket| event_stream(socket, request, state))
|
||||
}
|
||||
|
||||
async fn event_stream(
|
||||
mut socket: WebSocket,
|
||||
request: EventStreamRequest,
|
||||
state: AppState,
|
||||
) {
|
||||
let room_tx = state.room_tx.clone();
|
||||
let mut room_rx = room_tx.subscribe();
|
||||
|
||||
loop {
|
||||
select! {
|
||||
result = room_rx.recv() => {
|
||||
let whatever = result.unwrap();
|
||||
println!("Received message: {whatever:?}");
|
||||
let payload = serde_json::to_string(&whatever).unwrap();
|
||||
match socket.send(WsMessage::Text(payload)).await {
|
||||
Ok(_) => {}
|
||||
Err(err) => {
|
||||
eprintln!("Error: {err}")
|
||||
}
|
||||
}
|
||||
}
|
||||
socket_read = socket.recv() => {
|
||||
match socket_read {
|
||||
Some(_) => {}
|
||||
None => {
|
||||
// The client disconnected, handle gracefully
|
||||
// TODO: Is there any cleanup to do here
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
9
client/.gitignore
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
*.o
|
||||
*.qmake*
|
||||
Makefile
|
||||
|
||||
/build
|
||||
.cache
|
||||
/result*
|
||||
/target
|
||||
node_modules
|
17
client/default.nix
Normal file
|
@ -0,0 +1,17 @@
|
|||
{ toolchain, makeRustPlatform, nix-gitignore, installShellFiles }:
|
||||
|
||||
let rustPlatform = makeRustPlatform { inherit (toolchain) cargo rustc; };
|
||||
|
||||
in rustPlatform.buildRustPackage {
|
||||
name = "garbage";
|
||||
|
||||
src = nix-gitignore.gitignoreSource [ ./.gitignore ] ./.;
|
||||
cargoLock = { lockFile = ./Cargo.lock; };
|
||||
|
||||
nativeBuildInputs = [ installShellFiles ];
|
||||
|
||||
meta = {
|
||||
description = "CLI tool to interact with the FreeDesktop trash API.";
|
||||
mainProgram = "garbage";
|
||||
};
|
||||
}
|
3
client/index.html
Normal file
|
@ -0,0 +1,3 @@
|
|||
<div id="app"></div>
|
||||
|
||||
<script type="module" src="/src/main.tsx"></script>
|
1436
client/package-lock.json
generated
Normal file
24
client/package.json
Normal file
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"scripts": {
|
||||
"build": "vite build",
|
||||
"dev": "vite"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tauri-apps/cli": "^1.3.0",
|
||||
"@types/react-dom": "^18.2.4",
|
||||
"@types/uuid": "^9.0.1",
|
||||
"sass": "^1.62.1",
|
||||
"scss": "^0.2.4",
|
||||
"vite": "^4.3.4",
|
||||
"vite-plugin-sass-dts": "^1.3.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@reduxjs/toolkit": "^1.9.5",
|
||||
"@tauri-apps/api": "^1.3.0",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-redux": "^8.0.5",
|
||||
"ts-proto": "^1.147.1",
|
||||
"uuid": "^9.0.0"
|
||||
}
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/target/
|
||||
|
3582
client/src-tauri/Cargo.lock
generated
Normal file
31
client/src-tauri/Cargo.toml
Normal file
|
@ -0,0 +1,31 @@
|
|||
[package]
|
||||
name = "mraow-client"
|
||||
version = "0.1.0"
|
||||
description = "A Tauri App"
|
||||
authors = ["you"]
|
||||
license = ""
|
||||
repository = ""
|
||||
default-run = "mraow-client"
|
||||
edition = "2021"
|
||||
rust-version = "1.60"
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "1.3.0", features = [] }
|
||||
|
||||
[dependencies]
|
||||
serde_json = "1.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
tauri = { version = "1.3.0", features = [] }
|
||||
|
||||
mraow-common = { path = "../../common" }
|
||||
tokio = { version = "1.28.0", features = ["full"] }
|
||||
anyhow = "1.0.71"
|
||||
tonic = "0.9.2"
|
||||
uuid = { version = "1.3.2", features = ["v4"] }
|
||||
|
||||
[features]
|
||||
default = ["mraow-common/client"]
|
||||
# this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled.
|
||||
# If you use cargo directly instead of tauri's cli you can use this feature flag to switch between tauri's `dev` and `build` modes.
|
||||
# DO NOT REMOVE!!
|
||||
custom-protocol = ["tauri/custom-protocol"]
|
3
client/src-tauri/build.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
BIN
client/src-tauri/icons/128x128.png
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
client/src-tauri/icons/128x128@2x.png
Normal file
After Width: | Height: | Size: 23 KiB |
BIN
client/src-tauri/icons/32x32.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
client/src-tauri/icons/Square107x107Logo.png
Normal file
After Width: | Height: | Size: 9 KiB |
BIN
client/src-tauri/icons/Square142x142Logo.png
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
client/src-tauri/icons/Square150x150Logo.png
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
client/src-tauri/icons/Square284x284Logo.png
Normal file
After Width: | Height: | Size: 25 KiB |
BIN
client/src-tauri/icons/Square30x30Logo.png
Normal file
After Width: | Height: | Size: 2 KiB |
BIN
client/src-tauri/icons/Square310x310Logo.png
Normal file
After Width: | Height: | Size: 28 KiB |
BIN
client/src-tauri/icons/Square44x44Logo.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
client/src-tauri/icons/Square71x71Logo.png
Normal file
After Width: | Height: | Size: 5.9 KiB |
BIN
client/src-tauri/icons/Square89x89Logo.png
Normal file
After Width: | Height: | Size: 7.4 KiB |
BIN
client/src-tauri/icons/StoreLogo.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
client/src-tauri/icons/icon.icns
Normal file
BIN
client/src-tauri/icons/icon.ico
Normal file
After Width: | Height: | Size: 37 KiB |
BIN
client/src-tauri/icons/icon.png
Normal file
After Width: | Height: | Size: 49 KiB |
109
client/src-tauri/src/main.rs
Normal file
|
@ -0,0 +1,109 @@
|
|||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
use std::{sync::Arc, thread};
|
||||
|
||||
use anyhow::Result;
|
||||
use mraow_common::chat_proto::{
|
||||
chat_client::ChatClient, ChatMessage, ReceiveMsgsRequest, RoomAction,
|
||||
};
|
||||
use serde_json::json;
|
||||
use tauri::{
|
||||
async_runtime::{Mutex, TokioHandle},
|
||||
Manager, State,
|
||||
};
|
||||
use tonic::{transport::channel::Channel, IntoRequest};
|
||||
use uuid::Uuid;
|
||||
|
||||
type MyChatClient = Arc<Mutex<ChatClient<Channel>>>;
|
||||
|
||||
pub struct UserId(Uuid);
|
||||
|
||||
#[tauri::command]
|
||||
async fn send_message(
|
||||
state: State<'_, MyChatClient>,
|
||||
user_id: State<'_, UserId>,
|
||||
message: String,
|
||||
) -> Result<(), ()> {
|
||||
println!("SHIET {state:?}");
|
||||
|
||||
let mut client = state.lock().await;
|
||||
|
||||
let user_id = user_id.inner();
|
||||
let resp = client
|
||||
.send_msg(ChatMessage {
|
||||
from_user_id: user_id.0.to_string(),
|
||||
to_room_id: "general".to_string(),
|
||||
content: message,
|
||||
..Default::default()
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
println!("Sent message to server. {resp:?}");
|
||||
|
||||
/* client
|
||||
.say_hello(HelloRequest {
|
||||
message,
|
||||
..Default::default()
|
||||
})
|
||||
.await; */
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
tauri::async_runtime::set(TokioHandle::current());
|
||||
|
||||
let uuid = Uuid::new_v4();
|
||||
let user_id = UserId(uuid.clone());
|
||||
|
||||
let chat_client = ChatClient::connect("http://[::1]:50051").await?;
|
||||
let chat_client = Arc::new(Mutex::new(chat_client));
|
||||
let chat_client2 = chat_client.clone();
|
||||
|
||||
tauri::Builder::default()
|
||||
.setup(move |app| {
|
||||
let main_window = app.get_window("main").unwrap();
|
||||
|
||||
tokio::spawn(async move {
|
||||
let mut client = chat_client2.lock().await;
|
||||
client
|
||||
.room_action(RoomAction {
|
||||
room_id: "general".to_string(),
|
||||
user_id: uuid.to_string(),
|
||||
action: "join".to_string(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let stream = client
|
||||
.receive_msgs(ReceiveMsgsRequest {
|
||||
user_id: uuid.to_string(),
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
std::mem::drop(client);
|
||||
|
||||
let mut stream = stream.into_inner();
|
||||
while let Ok(Some(message)) = stream.message().await {
|
||||
println!("SHIET message {message:?}");
|
||||
|
||||
main_window
|
||||
.emit_all("new-message", json!({ "content" : message.content }))
|
||||
.unwrap();
|
||||
}
|
||||
});
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.manage(user_id)
|
||||
.manage(chat_client)
|
||||
.invoke_handler(tauri::generate_handler![send_message])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
||||
Ok(())
|
||||
}
|
66
client/src-tauri/tauri.conf.json
Normal file
|
@ -0,0 +1,66 @@
|
|||
{
|
||||
"$schema": "../node_modules/@tauri-apps/cli/schema.json",
|
||||
"build": {
|
||||
"beforeBuildCommand": "npm run build",
|
||||
"beforeDevCommand": "npm run dev",
|
||||
"devPath": "http://localhost:5173",
|
||||
"distDir": "../build"
|
||||
},
|
||||
"package": {
|
||||
"productName": "mraow",
|
||||
"version": "0.1.0"
|
||||
},
|
||||
"tauri": {
|
||||
"allowlist": {
|
||||
"all": false
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"category": "DeveloperTool",
|
||||
"copyright": "",
|
||||
"deb": {
|
||||
"depends": []
|
||||
},
|
||||
"externalBin": [],
|
||||
"icon": [
|
||||
"icons/32x32.png",
|
||||
"icons/128x128.png",
|
||||
"icons/128x128@2x.png",
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
],
|
||||
"identifier": "io.mzhang.mraow",
|
||||
"longDescription": "",
|
||||
"macOS": {
|
||||
"entitlements": null,
|
||||
"exceptionDomain": "",
|
||||
"frameworks": [],
|
||||
"providerShortName": null,
|
||||
"signingIdentity": null
|
||||
},
|
||||
"resources": [],
|
||||
"shortDescription": "",
|
||||
"targets": "all",
|
||||
"windows": {
|
||||
"certificateThumbprint": null,
|
||||
"digestAlgorithm": "sha256",
|
||||
"timestampUrl": ""
|
||||
}
|
||||
},
|
||||
"security": {
|
||||
"csp": null
|
||||
},
|
||||
"updater": {
|
||||
"active": false
|
||||
},
|
||||
"windows": [
|
||||
{
|
||||
"fullscreen": false,
|
||||
"height": 600,
|
||||
"resizable": true,
|
||||
"title": "mraow",
|
||||
"width": 800
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
1
client/src/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
*.scss.d.ts
|
9
client/src/App.module.scss
Normal file
|
@ -0,0 +1,9 @@
|
|||
body, html {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.app {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
18
client/src/App.tsx
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { Provider } from "react-redux";
|
||||
import { store, useAppDispatch } from "./store";
|
||||
|
||||
import styles from "./App.module.scss";
|
||||
import LeftSidebar from "./components/LeftSidebar";
|
||||
import CenterPanel from "./components/CenterPanel";
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<Provider store={store}>
|
||||
<div className={styles.app}>
|
||||
<LeftSidebar />
|
||||
|
||||
<CenterPanel />
|
||||
</div>
|
||||
</Provider>
|
||||
);
|
||||
}
|
20
client/src/components/CenterPanel.module.scss
Normal file
|
@ -0,0 +1,20 @@
|
|||
.centerPanel {
|
||||
flex-grow: 1;
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.middlePart {
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.form {
|
||||
margin-block-end: 0;
|
||||
}
|
||||
|
||||
.input {
|
||||
width: 100%;
|
||||
padding: 18px;
|
||||
outline: none;
|
||||
}
|
75
client/src/components/CenterPanel.tsx
Normal file
|
@ -0,0 +1,75 @@
|
|||
import { invoke } from "@tauri-apps/api/tauri";
|
||||
import styles from "./CenterPanel.module.scss";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useAppDispatch, useAppSelector } from "../store";
|
||||
import { messageSelectors, messageSlice } from "../store/messages";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { emit, listen } from "@tauri-apps/api/event";
|
||||
import { appWindow, WebviewWindow } from "@tauri-apps/api/window";
|
||||
|
||||
export default function CenterPanel() {
|
||||
const [currentMessage, setCurrentMessage] = useState("");
|
||||
const dispatch = useAppDispatch();
|
||||
const allMessages = useAppSelector((state) =>
|
||||
messageSelectors.selectAll(state)
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
let unlisten;
|
||||
|
||||
(async () => {
|
||||
unlisten = await appWindow.listen("new-message", (event) => {
|
||||
console.log("NEW EVENT", event);
|
||||
const id = "lol";
|
||||
const time = Date.now();
|
||||
const content = event.payload.content;
|
||||
dispatch(messageSlice.actions.addMessage({ id, time, content }));
|
||||
});
|
||||
|
||||
console.log("Listen handler active.");
|
||||
})();
|
||||
|
||||
return () => {
|
||||
if (unlisten) unlisten();
|
||||
};
|
||||
});
|
||||
|
||||
const onSubmit = (e) => {
|
||||
e.preventDefault();
|
||||
invoke("send_message", { message: currentMessage });
|
||||
|
||||
const id = uuidv4();
|
||||
const time = Date.now();
|
||||
dispatch(
|
||||
messageSlice.actions.addMessage({ id, time, content: currentMessage })
|
||||
);
|
||||
setCurrentMessage("");
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={styles.centerPanel}>
|
||||
<h1>mraow chat</h1>
|
||||
|
||||
<div className={styles.middlePart}>
|
||||
{allMessages.map((msg) => (
|
||||
<div key={msg.id}>
|
||||
<small>{new Date(msg.time).toISOString()}</small>
|
||||
|
||||
{msg.content}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<form onSubmit={onSubmit} className={styles.form}>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Send message..."
|
||||
value={currentMessage}
|
||||
className={styles.input}
|
||||
onChange={(e) => setCurrentMessage(e.currentTarget.value)}
|
||||
autoFocus
|
||||
/>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
4
client/src/components/LeftSidebar.module.scss
Normal file
|
@ -0,0 +1,4 @@
|
|||
.leftSidebar {
|
||||
width: var(--left-sidebar-width);
|
||||
background-color: var(--left-sidebar-background-color);
|
||||
}
|
5
client/src/components/LeftSidebar.tsx
Normal file
|
@ -0,0 +1,5 @@
|
|||
import styles from "./LeftSidebar.module.scss";
|
||||
|
||||
export default function LeftSidebar() {
|
||||
return <div className={styles.leftSidebar}>Rooms</div>;
|
||||
}
|
5
client/src/components/MessageContainer.tsx
Normal file
|
@ -0,0 +1,5 @@
|
|||
import { useSelector } from "react-redux";
|
||||
|
||||
export default function MessageContainer() {
|
||||
return <></>;
|
||||
}
|
9
client/src/main.tsx
Normal file
|
@ -0,0 +1,9 @@
|
|||
import { createRoot } from "react-dom/client";
|
||||
import App from "./App";
|
||||
import "./variables.scss";
|
||||
|
||||
// Render your React component instead
|
||||
const el = document.getElementById("app");
|
||||
if (!el) throw new Error("welp");
|
||||
const root = createRoot(el);
|
||||
root.render(<App />);
|
14
client/src/store/index.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { configureStore } from "@reduxjs/toolkit";
|
||||
import { messageSlice } from "./messages";
|
||||
import { TypedUseSelectorHook, useDispatch, useSelector } from "react-redux";
|
||||
|
||||
export const store = configureStore({
|
||||
reducer: {
|
||||
messages: messageSlice.reducer,
|
||||
},
|
||||
});
|
||||
|
||||
export type RootState = ReturnType<typeof store.getState>;
|
||||
export type AppDispatch = typeof store.dispatch;
|
||||
export const useAppDispatch: () => AppDispatch = useDispatch;
|
||||
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
|
24
client/src/store/messages.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import { createEntityAdapter, createSlice } from "@reduxjs/toolkit";
|
||||
import { RootState } from ".";
|
||||
|
||||
export type Message = {
|
||||
id: string;
|
||||
time: number;
|
||||
content: string;
|
||||
};
|
||||
|
||||
export const messageAdapter = createEntityAdapter<Message>({
|
||||
selectId: (item) => item.id,
|
||||
});
|
||||
|
||||
export const messageSelectors = messageAdapter.getSelectors<RootState>(
|
||||
(state) => state.messages
|
||||
);
|
||||
|
||||
export const messageSlice = createSlice({
|
||||
name: "messages",
|
||||
initialState: messageAdapter.getInitialState(),
|
||||
reducers: {
|
||||
addMessage: messageAdapter.addOne,
|
||||
},
|
||||
});
|
9
client/src/variables.scss
Normal file
|
@ -0,0 +1,9 @@
|
|||
:root {
|
||||
--left-sidebar-width: 288px;
|
||||
|
||||
--main-background-color: #eee;
|
||||
--left-sidebar-background-color: #ddd;
|
||||
|
||||
@mixin dark-mode() {
|
||||
}
|
||||
}
|
6
client/tsconfig.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"esModuleInterop": true,
|
||||
"jsx": "react-jsx"
|
||||
}
|
||||
}
|
28
client/vite.config.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
import { defineConfig } from "vite";
|
||||
import sassDts from "vite-plugin-sass-dts";
|
||||
|
||||
export default defineConfig({
|
||||
// prevent vite from obscuring rust errors
|
||||
clearScreen: false,
|
||||
|
||||
// Tauri expects a fixed port, fail if that port is not available
|
||||
server: {
|
||||
strictPort: false,
|
||||
},
|
||||
|
||||
// to make use of `TAURI_PLATFORM`, `TAURI_ARCH`, `TAURI_FAMILY`,
|
||||
// `TAURI_PLATFORM_VERSION`, `TAURI_PLATFORM_TYPE` and `TAURI_DEBUG`
|
||||
// env variables
|
||||
envPrefix: ["VITE_", "TAURI_"],
|
||||
|
||||
build: {
|
||||
// Tauri uses Chromium on Windows and WebKit on macOS and Linux
|
||||
target: process.env.TAURI_PLATFORM == "windows" ? "chrome105" : "safari13",
|
||||
// don't minify for debug builds
|
||||
minify: !process.env.TAURI_DEBUG ? "esbuild" : false,
|
||||
// produce sourcemaps for debug builds
|
||||
sourcemap: !!process.env.TAURI_DEBUG,
|
||||
},
|
||||
|
||||
plugins: [sassDts({ global: { generate: true } })],
|
||||
});
|
|
@ -1,14 +1,16 @@
|
|||
[package]
|
||||
name = "common"
|
||||
name = "mraow-common"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
server = []
|
||||
client = []
|
||||
|
||||
[dependencies]
|
||||
anyhow = { version = "1.0.76", features = ["backtrace"] }
|
||||
capnp = "0.18.10"
|
||||
chrono = { version = "0.4.31", features = ["serde"] }
|
||||
serde = { version = "1.0.193", features = ["derive"] }
|
||||
prost = "0.11.9"
|
||||
tonic = "0.9.2"
|
||||
|
||||
[build-dependencies]
|
||||
anyhow = { version = "1.0.76", features = ["backtrace"] }
|
||||
capnpc = "0.18.0"
|
||||
tonic-build = "0.9.2"
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
use anyhow::Result;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
capnpc::CompilerCommand::new()
|
||||
.file("./proto/clientserver.capnp")
|
||||
.import_path("./proto")
|
||||
.run()?;
|
||||
Ok(())
|
||||
fn main() {
|
||||
tonic_build::configure()
|
||||
.server_mod_attribute("attrs", "#[cfg(feature = \"server\")]")
|
||||
.client_mod_attribute("attrs", "#[cfg(feature = \"client\")]")
|
||||
.compile(&["../proto/chat.proto"], &["../proto"])
|
||||
.unwrap();
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
@0xdc2cdd8d84175827;
|
|
@ -1,21 +1,3 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde;
|
||||
|
||||
pub mod clientserver_capnp {
|
||||
include!(concat!(env!("OUT_DIR"), "/proto/clientserver_capnp.rs"));
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ClientMessage {
|
||||
pub author: String,
|
||||
pub body: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Message {
|
||||
#[serde(flatten)]
|
||||
pub inner: ClientMessage,
|
||||
pub server_timestamp: DateTime<Utc>,
|
||||
pub mod chat_proto {
|
||||
tonic::include_proto!("chat");
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
version: "3.1"
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
db:
|
||||
image: postgres
|
||||
ports: [5432:5432]
|
||||
environment:
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: postgres
|
||||
POSTGRES_DB: mraow
|
||||
database:
|
||||
image: cassandra
|
||||
volumes:
|
||||
- ./docker-data/cassandra:/var/lib/cassandra
|
||||
ports:
|
||||
- "7000:7000"
|
||||
|
|
111
flake.lock
Normal file
|
@ -0,0 +1,111 @@
|
|||
{
|
||||
"nodes": {
|
||||
"fenix": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs",
|
||||
"rust-analyzer-src": "rust-analyzer-src"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1683181309,
|
||||
"narHash": "sha256-+uTI+MzioDC01a/8STyaalCGtkeJTblamlwhaX6XoUM=",
|
||||
"owner": "nix-community",
|
||||
"repo": "fenix",
|
||||
"rev": "2e6694d1e079b6c62341a449af18646a288a8c82",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "fenix",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1681202837,
|
||||
"narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "cfacdce06f30d2b68473a46042957675eebb3401",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "flake-utils",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1683014792,
|
||||
"narHash": "sha256-6Va9iVtmmsw4raBc3QKvQT2KT/NGRWlvUlJj46zN8B8=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "1a411f23ba299db155a5b45d5e145b85a7aafc42",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1683231090,
|
||||
"narHash": "sha256-DxAuvlCQh6qpMNRSXIo/aCc0Zq/sXZYN0IDt4RANevE=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "9531d105edcc46d6163a81bda4e7db5a492d8343",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"fenix": "fenix",
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs_2"
|
||||
}
|
||||
},
|
||||
"rust-analyzer-src": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1683114408,
|
||||
"narHash": "sha256-MJo/tEm3edH9ydW8wdb1bTc7mwjzgCK69gLWwdu9BcE=",
|
||||
"owner": "rust-lang",
|
||||
"repo": "rust-analyzer",
|
||||
"rev": "60f4b3e26e8656bbe8b65530e237e3907c9565f3",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "rust-lang",
|
||||
"ref": "nightly",
|
||||
"repo": "rust-analyzer",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
69
flake.nix
Normal file
|
@ -0,0 +1,69 @@
|
|||
{
|
||||
inputs.nixpkgs.url = "github:nixos/nixpkgs";
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils, fenix }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [ fenix.overlays.default ];
|
||||
};
|
||||
|
||||
toolchain = pkgs.fenix.stable;
|
||||
|
||||
flakePkgs = rec {
|
||||
# client = pkgs.callPackage ./client { inherit toolchain; };
|
||||
NetAsyncHTTPServer =
|
||||
pkgs.perl536Packages.callPackage ./nix/NetAsyncHTTPServer.nix { };
|
||||
};
|
||||
in {
|
||||
packages = flake-utils.lib.flattenTree flakePkgs;
|
||||
|
||||
devShell = pkgs.mkShell {
|
||||
# inputsFrom = with flakePkgs; [ client ];
|
||||
|
||||
packages =
|
||||
(with pkgs; [ pkg-config perl openssl protobuf clang-tools ])
|
||||
++ (with toolchain; [
|
||||
rustc
|
||||
cargo
|
||||
|
||||
# Get the nightly version of rustfmt so we can wrap comments
|
||||
pkgs.fenix.default.rustfmt
|
||||
]);
|
||||
# ++ (with pkgs.perl536Packages; [
|
||||
# CPAN
|
||||
# EmailMIME
|
||||
# CryptEd25519
|
||||
# DigestSHA1
|
||||
# DigestHMAC
|
||||
# DataDump
|
||||
# EmailAddressXS
|
||||
# FileSlurper
|
||||
# Future
|
||||
# IOAsync
|
||||
# IOAsyncSSL
|
||||
# JSON
|
||||
# ListUtilsBy
|
||||
# ModulePluggable
|
||||
# NetAsyncHTTP
|
||||
# flakePkgs.NetAsyncHTTPServer
|
||||
|
||||
LIBRARY_PATH = pkgs.lib.concatStringsSep ":" [ "${pkgs.zlib}/lib" ];
|
||||
|
||||
PKG_CONFIG_PATH = pkgs.lib.concatStringsSep ":" [
|
||||
"${pkgs.gnome.libsoup.dev}/lib/pkgconfig"
|
||||
"${pkgs.webkitgtk.dev}/lib/pkgconfig"
|
||||
"${pkgs.gtk3.dev}/lib/pkgconfig"
|
||||
"${pkgs.gtk4.dev}/lib/pkgconfig"
|
||||
"${pkgs.glib.dev}/lib/pkgconfig"
|
||||
"${pkgs.cairo.dev}/lib/pkgconfig"
|
||||
"${pkgs.gdk-pixbuf.dev}/lib/pkgconfig"
|
||||
"${pkgs.pango.dev}/lib/pkgconfig"
|
||||
"${pkgs.harfbuzz.dev}/lib/pkgconfig"
|
||||
"${pkgs.at-spi2-atk.dev}/lib/pkgconfig"
|
||||
"${pkgs.zlib.dev}/lib/pkgconfig"
|
||||
];
|
||||
};
|
||||
});
|
||||
}
|
2
frontend/.gitignore
vendored
|
@ -1,2 +0,0 @@
|
|||
node_modules
|
||||
dist
|
3
frontend/.vscode/extensions.json
vendored
|
@ -1,3 +0,0 @@
|
|||
{
|
||||
"recommendations": ["tauri-apps.tauri-vscode", "rust-lang.rust-analyzer"]
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
# Tauri + Solid + Typescript
|
||||
|
||||
This template should help get you started developing with Tauri, Solid and Typescript in Vite.
|
||||
|
||||
## Recommended IDE Setup
|
||||
|
||||
- [VS Code](https://code.visualstudio.com/) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer)
|
|
@ -1,17 +0,0 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<link rel="icon" type="image/svg+xml" href="/src/assets/logo.svg" />
|
||||
<title>Tauri + Solid + Typescript App</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
|
||||
<script src="/src/index.tsx" type="module"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,24 +0,0 @@
|
|||
{
|
||||
"name": "frontend",
|
||||
"version": "0.0.0",
|
||||
"description": "",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "vite",
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"serve": "vite preview",
|
||||
"tauri": "tauri"
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"solid-js": "^1.7.8",
|
||||
"@tauri-apps/api": "^1.5.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.0.2",
|
||||
"vite": "^5.0.0",
|
||||
"vite-plugin-solid": "^2.8.0",
|
||||
"@tauri-apps/cli": "^1.5.8"
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
<svg width="206" height="231" viewBox="0 0 206 231" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M143.143 84C143.143 96.1503 133.293 106 121.143 106C108.992 106 99.1426 96.1503 99.1426 84C99.1426 71.8497 108.992 62 121.143 62C133.293 62 143.143 71.8497 143.143 84Z" fill="#FFC131"/>
|
||||
<ellipse cx="84.1426" cy="147" rx="22" ry="22" transform="rotate(180 84.1426 147)" fill="#24C8DB"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M166.738 154.548C157.86 160.286 148.023 164.269 137.757 166.341C139.858 160.282 141 153.774 141 147C141 144.543 140.85 142.121 140.558 139.743C144.975 138.204 149.215 136.139 153.183 133.575C162.73 127.404 170.292 118.608 174.961 108.244C179.63 97.8797 181.207 86.3876 179.502 75.1487C177.798 63.9098 172.884 53.4021 165.352 44.8883C157.82 36.3744 147.99 30.2165 137.042 27.1546C126.095 24.0926 114.496 24.2568 103.64 27.6274C92.7839 30.998 83.1319 37.4317 75.8437 46.1553C74.9102 47.2727 74.0206 48.4216 73.176 49.5993C61.9292 50.8488 51.0363 54.0318 40.9629 58.9556C44.2417 48.4586 49.5653 38.6591 56.679 30.1442C67.0505 17.7298 80.7861 8.57426 96.2354 3.77762C111.685 -1.01901 128.19 -1.25267 143.769 3.10474C159.348 7.46215 173.337 16.2252 184.056 28.3411C194.775 40.457 201.767 55.4101 204.193 71.404C206.619 87.3978 204.374 103.752 197.73 118.501C191.086 133.25 180.324 145.767 166.738 154.548ZM41.9631 74.275L62.5557 76.8042C63.0459 72.813 63.9401 68.9018 65.2138 65.1274C57.0465 67.0016 49.2088 70.087 41.9631 74.275Z" fill="#FFC131"/>
|
||||
<path fill-rule="evenodd" clip-rule="evenodd" d="M38.4045 76.4519C47.3493 70.6709 57.2677 66.6712 67.6171 64.6132C65.2774 70.9669 64 77.8343 64 85.0001C64 87.1434 64.1143 89.26 64.3371 91.3442C60.0093 92.8732 55.8533 94.9092 51.9599 97.4256C42.4128 103.596 34.8505 112.392 30.1816 122.756C25.5126 133.12 23.9357 144.612 25.6403 155.851C27.3449 167.09 32.2584 177.598 39.7906 186.112C47.3227 194.626 57.153 200.784 68.1003 203.846C79.0476 206.907 90.6462 206.743 101.502 203.373C112.359 200.002 122.011 193.568 129.299 184.845C130.237 183.722 131.131 182.567 131.979 181.383C143.235 180.114 154.132 176.91 164.205 171.962C160.929 182.49 155.596 192.319 148.464 200.856C138.092 213.27 124.357 222.426 108.907 227.222C93.458 232.019 76.9524 232.253 61.3736 227.895C45.7948 223.538 31.8055 214.775 21.0867 202.659C10.3679 190.543 3.37557 175.59 0.949823 159.596C-1.47592 143.602 0.768139 127.248 7.41237 112.499C14.0566 97.7497 24.8183 85.2327 38.4045 76.4519ZM163.062 156.711L163.062 156.711C162.954 156.773 162.846 156.835 162.738 156.897C162.846 156.835 162.954 156.773 163.062 156.711Z" fill="#24C8DB"/>
|
||||
</svg>
|
Before Width: | Height: | Size: 2.5 KiB |
|
@ -1 +0,0 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
Before Width: | Height: | Size: 1.5 KiB |
|
@ -1,31 +0,0 @@
|
|||
[package]
|
||||
name = "frontend"
|
||||
version = "0.0.0"
|
||||
description = "A Tauri App"
|
||||
authors = ["you"]
|
||||
license = ""
|
||||
repository = ""
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "1.5", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "1.5", features = ["shell-open"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0.108"
|
||||
|
||||
common = { path = "../../common" }
|
||||
tokio-tungstenite = { version = "0.21.0", features = ["rustls-tls-webpki-roots"] }
|
||||
tokio = { version = "1.35.1", features = ["full"] }
|
||||
reqwest = { version = "0.11.23", features = ["json"] }
|
||||
futures = "0.3.30"
|
||||
url = "2.5.0"
|
||||
chrono = { version = "0.4.31", features = ["serde"] }
|
||||
|
||||
[features]
|
||||
# this feature is used for production builds or when `devPath` points to the filesystem
|
||||
# DO NOT REMOVE!!
|
||||
custom-protocol = ["tauri/custom-protocol"]
|
|
@ -1 +0,0 @@
|
|||
fn main() { tauri_build::build() }
|
Before Width: | Height: | Size: 3.4 KiB |
Before Width: | Height: | Size: 6.8 KiB |
Before Width: | Height: | Size: 974 B |
Before Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 3.9 KiB |
Before Width: | Height: | Size: 7.6 KiB |
Before Width: | Height: | Size: 903 B |
Before Width: | Height: | Size: 8.4 KiB |
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 2 KiB |
Before Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 85 KiB |
Before Width: | Height: | Size: 14 KiB |
|
@ -1,120 +0,0 @@
|
|||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
use chrono::Utc;
|
||||
use common::{ClientMessage, Message};
|
||||
use futures::{stream::SplitSink, SinkExt, StreamExt};
|
||||
use tauri::{State, Window};
|
||||
use tokio::{net::TcpStream, sync::RwLock};
|
||||
use tokio_tungstenite::{
|
||||
tungstenite::Message as WsMessage, MaybeTlsStream, WebSocketStream,
|
||||
};
|
||||
use url::Url;
|
||||
|
||||
struct AppState {
|
||||
connection: RwLock<Connection>,
|
||||
}
|
||||
|
||||
enum Connection {
|
||||
Unconnected,
|
||||
Connected(ConnState),
|
||||
}
|
||||
|
||||
struct ConnState {
|
||||
server_address: String,
|
||||
username: String,
|
||||
socket_write:
|
||||
SplitSink<WebSocketStream<MaybeTlsStream<TcpStream>>, WsMessage>,
|
||||
}
|
||||
|
||||
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
|
||||
#[tauri::command]
|
||||
fn greet(name: &str) -> String {
|
||||
format!("Hello, {}! You've been greeted from Rust!", name)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn connect(
|
||||
server_address: String,
|
||||
username: String,
|
||||
state: State<'_, AppState>,
|
||||
window: Window,
|
||||
) -> Result<String, String> {
|
||||
let mut url = Url::parse(&server_address).unwrap();
|
||||
url.set_scheme("ws");
|
||||
url.set_path("/v1/events");
|
||||
url.set_query(Some(&format!("name={username}")));
|
||||
// &format!("/v1/events?name={username}"));
|
||||
|
||||
println!("connecting to {url}");
|
||||
let (socket, _response) =
|
||||
tokio_tungstenite::connect_async(url).await.unwrap();
|
||||
|
||||
let (socket_write, mut socket_read) = socket.split();
|
||||
|
||||
// Spawn reader
|
||||
tokio::spawn(async move {
|
||||
loop {
|
||||
let message = match socket_read.next().await {
|
||||
Some(v) => v.unwrap(),
|
||||
None => break,
|
||||
};
|
||||
|
||||
let message: Message = match message {
|
||||
WsMessage::Text(message) => serde_json::from_str(&message).unwrap(),
|
||||
_ => continue,
|
||||
};
|
||||
|
||||
window.emit("new_message", message).unwrap();
|
||||
}
|
||||
});
|
||||
|
||||
{
|
||||
let mut state_ref = state.connection.write().await;
|
||||
*state_ref = Connection::Connected(ConnState {
|
||||
server_address,
|
||||
username,
|
||||
socket_write,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(format!("connected"))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn send_message(
|
||||
state: State<'_, AppState>,
|
||||
content: String,
|
||||
) -> Result<String, String> {
|
||||
let state_ref = state.connection.read().await;
|
||||
match *state_ref {
|
||||
Connection::Unconnected => return Err(format!("L")),
|
||||
Connection::Connected(ref state) => {
|
||||
let message = ClientMessage {
|
||||
author: state.username.clone(),
|
||||
body: content,
|
||||
};
|
||||
// let payload = serde_json::to_string(&message).unwrap();
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
let url = format!("{}/v1/message", state.server_address);
|
||||
let res = client.post(url).json(&message).send().await.unwrap();
|
||||
// state.socket.send(WsMessage::Text(payload)).await.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
Ok(format!("done"))
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let state = AppState {
|
||||
connection: RwLock::new(Connection::Unconnected),
|
||||
};
|
||||
|
||||
tauri::Builder::default()
|
||||
.manage(state)
|
||||
.invoke_handler(tauri::generate_handler![greet, connect, send_message])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
{
|
||||
"build": {
|
||||
"beforeDevCommand": "pnpm dev",
|
||||
"beforeBuildCommand": "pnpm build",
|
||||
"devPath": "http://localhost:1420",
|
||||
"distDir": "../dist"
|
||||
},
|
||||
"package": {
|
||||
"productName": "frontend",
|
||||
"version": "0.0.0"
|
||||
},
|
||||
"tauri": {
|
||||
"allowlist": {
|
||||
"all": false,
|
||||
"shell": {
|
||||
"all": false,
|
||||
"open": true
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"targets": "all",
|
||||
"identifier": "com.tauri.dev",
|
||||
"icon": [
|
||||
"icons/32x32.png",
|
||||
"icons/128x128.png",
|
||||
"icons/128x128@2x.png",
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
]
|
||||
},
|
||||
"security": {
|
||||
"csp": null
|
||||
},
|
||||
"windows": [
|
||||
{
|
||||
"fullscreen": false,
|
||||
"resizable": true,
|
||||
"title": "frontend",
|
||||
"width": 800,
|
||||
"height": 600
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
import { createEffect, createSignal } from "solid-js";
|
||||
import { invoke } from "@tauri-apps/api/tauri";
|
||||
import "./App.css";
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import { createStore } from "solid-js/store";
|
||||
import { ServerMessage } from "./lib/interfaces";
|
||||
|
||||
const initialRandomNumber = Math.floor(Math.random() * 9000) + 1000;
|
||||
|
||||
function App() {
|
||||
const [serverAddress, setServerAddress] = createSignal(
|
||||
"http://localhost:1551"
|
||||
);
|
||||
const [username, setUsername] = createSignal(`meow${initialRandomNumber}`);
|
||||
const [connectionStatus, setConnectionStatus] = createSignal({
|
||||
status: "unconnected",
|
||||
});
|
||||
const [messageContent, setMessageContent] = createSignal("");
|
||||
const [messages, setMessages] = createStore<ServerMessage[]>([]);
|
||||
|
||||
// const [greetMsg, setGreetMsg] = createSignal("");
|
||||
// const [name, setName] = createSignal("");
|
||||
|
||||
// async function greet() {
|
||||
// // Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
|
||||
// setGreetMsg(await invoke("greet", { name: name() }));
|
||||
// }
|
||||
|
||||
const connect = async () => {
|
||||
setConnectionStatus({ status: "connecting" });
|
||||
const result = await invoke("connect", {
|
||||
serverAddress: serverAddress(),
|
||||
username: username(),
|
||||
});
|
||||
console.log("connection result", result);
|
||||
setConnectionStatus({ status: "connected" });
|
||||
};
|
||||
|
||||
const action = () => {
|
||||
switch (connectionStatus().status) {
|
||||
case "unconnected":
|
||||
return <button onClick={connect}>Connect</button>;
|
||||
case "connecting":
|
||||
return <>Connecting...</>;
|
||||
case "connected":
|
||||
return <>Connected!</>;
|
||||
}
|
||||
};
|
||||
const disabled = () => connectionStatus().status === "connecting";
|
||||
|
||||
createEffect(async () => {
|
||||
const unlisten = await listen<ServerMessage>("new_message", (event) => {
|
||||
console.log("new message", event);
|
||||
setMessages([...messages, event.payload]);
|
||||
});
|
||||
|
||||
return () => {
|
||||
unlisten();
|
||||
};
|
||||
});
|
||||
|
||||
return (
|
||||
<div class="container">
|
||||
<div>
|
||||
<input
|
||||
placeholder="Server address..."
|
||||
value={serverAddress()}
|
||||
onChange={(evt) => setServerAddress(evt.currentTarget.value)}
|
||||
disabled={disabled()}
|
||||
/>
|
||||
<input
|
||||
placeholder="Username..."
|
||||
value={username()}
|
||||
onChange={(evt) => setUsername(evt.currentTarget.value)}
|
||||
disabled={disabled()}
|
||||
/>
|
||||
|
||||
{action()}
|
||||
</div>
|
||||
|
||||
<div>{connectionStatus().status}</div>
|
||||
|
||||
<div>
|
||||
<ul>
|
||||
{messages.map((message) => (
|
||||
<li>{JSON.stringify(message)}</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<form
|
||||
onSubmit={async (evt) => {
|
||||
evt.preventDefault();
|
||||
await invoke("send_message", { content: messageContent() });
|
||||
setMessageContent("");
|
||||
console.log("SHIET");
|
||||
}}
|
||||
>
|
||||
<input
|
||||
placeholder="Send a message..."
|
||||
value={messageContent()}
|
||||
onChange={(evt) => setMessageContent(evt.currentTarget.value)}
|
||||
disabled={connectionStatus().status !== "connected"}
|
||||
/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
|
@ -1 +0,0 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 166 155.3"><path d="M163 35S110-4 69 5l-3 1c-6 2-11 5-14 9l-2 3-15 26 26 5c11 7 25 10 38 7l46 9 18-30z" fill="#76b3e1"/><linearGradient id="a" gradientUnits="userSpaceOnUse" x1="27.5" y1="3" x2="152" y2="63.5"><stop offset=".1" stop-color="#76b3e1"/><stop offset=".3" stop-color="#dcf2fd"/><stop offset="1" stop-color="#76b3e1"/></linearGradient><path d="M163 35S110-4 69 5l-3 1c-6 2-11 5-14 9l-2 3-15 26 26 5c11 7 25 10 38 7l46 9 18-30z" opacity=".3" fill="url(#a)"/><path d="M52 35l-4 1c-17 5-22 21-13 35 10 13 31 20 48 15l62-21S92 26 52 35z" fill="#518ac8"/><linearGradient id="b" gradientUnits="userSpaceOnUse" x1="95.8" y1="32.6" x2="74" y2="105.2"><stop offset="0" stop-color="#76b3e1"/><stop offset=".5" stop-color="#4377bb"/><stop offset="1" stop-color="#1f3b77"/></linearGradient><path d="M52 35l-4 1c-17 5-22 21-13 35 10 13 31 20 48 15l62-21S92 26 52 35z" opacity=".3" fill="url(#b)"/><linearGradient id="c" gradientUnits="userSpaceOnUse" x1="18.4" y1="64.2" x2="144.3" y2="149.8"><stop offset="0" stop-color="#315aa9"/><stop offset=".5" stop-color="#518ac8"/><stop offset="1" stop-color="#315aa9"/></linearGradient><path d="M134 80a45 45 0 00-48-15L24 85 4 120l112 19 20-36c4-7 3-15-2-23z" fill="url(#c)"/><linearGradient id="d" gradientUnits="userSpaceOnUse" x1="75.2" y1="74.5" x2="24.4" y2="260.8"><stop offset="0" stop-color="#4377bb"/><stop offset=".5" stop-color="#1a336b"/><stop offset="1" stop-color="#1a336b"/></linearGradient><path d="M114 115a45 45 0 00-48-15L4 120s53 40 94 30l3-1c17-5 23-21 13-34z" fill="url(#d)"/></svg>
|
Before Width: | Height: | Size: 1.6 KiB |
|
@ -1,7 +0,0 @@
|
|||
/* @refresh reload */
|
||||
import { render } from "solid-js/web";
|
||||
|
||||
import "./styles.css";
|
||||
import App from "./App";
|
||||
|
||||
render(() => <App />, document.getElementById("root") as HTMLElement);
|
|
@ -1,5 +0,0 @@
|
|||
export interface ServerMessage {
|
||||
author: string;
|
||||
body: string;
|
||||
server_timestamp: number;
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "preserve",
|
||||
"jsxImportSource": "solid-js",
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"include": ["src"],
|
||||
"references": [{ "path": "./tsconfig.node.json" }]
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"skipLibCheck": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
1
frontend/vite-env.d.ts
vendored
|
@ -1 +0,0 @@
|
|||
/// <reference types="vite/client" />
|
|
@ -1,21 +0,0 @@
|
|||
import { defineConfig } from "vite";
|
||||
import solid from "vite-plugin-solid";
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig(async () => ({
|
||||
plugins: [solid()],
|
||||
|
||||
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
|
||||
//
|
||||
// 1. prevent vite from obscuring rust errors
|
||||
clearScreen: false,
|
||||
// 2. tauri expects a fixed port, fail if that port is not available
|
||||
server: {
|
||||
port: 1420,
|
||||
strictPort: true,
|
||||
watch: {
|
||||
// 3. tell vite to ignore watching `src-tauri`
|
||||
ignored: ["**/src-tauri/**"],
|
||||
},
|
||||
},
|
||||
}));
|
15
nix/NetAsyncHTTPServer.nix
Normal file
|
@ -0,0 +1,15 @@
|
|||
{ buildPerlModule, lib, fetchurl, IOAsync, TestMetricsAny, HTTPMessage
|
||||
, TestIdentity, TestRefcount }:
|
||||
|
||||
buildPerlModule {
|
||||
pname = "Net-Async-HTTP";
|
||||
version = "0.48";
|
||||
src = fetchurl {
|
||||
url =
|
||||
"mirror://cpan/authors/id/P/PE/PEVANS/Net-Async-HTTP-Server-0.13.tar.gz";
|
||||
sha256 = "sha256-yk3kcfIieNI5PIqy7G56xO8hfbRjXS3Mi6KoynIhFO4=";
|
||||
};
|
||||
|
||||
buildInputs = [ TestMetricsAny TestIdentity TestRefcount ];
|
||||
propagatedBuildInputs = [ IOAsync HTTPMessage ];
|
||||
}
|