initial
24
.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
3
.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"recommendations": ["tauri-apps.tauri-vscode", "rust-lang.rust-analyzer"]
|
||||
}
|
||||
7
README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Tauri + Vanilla
|
||||
|
||||
This template should help get you started developing with Tauri in vanilla HTML, CSS and Javascript.
|
||||
|
||||
## 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)
|
||||
7
src-tauri/.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/target/
|
||||
|
||||
# Generated by Tauri
|
||||
# will have schema files for capabilities auto-completion
|
||||
/gen/schemas
|
||||
5523
src-tauri/Cargo.lock
generated
Normal file
28
src-tauri/Cargo.toml
Normal file
@@ -0,0 +1,28 @@
|
||||
[package]
|
||||
name = "ircd"
|
||||
version = "0.1.0"
|
||||
description = "A Tauri App"
|
||||
authors = ["you"]
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[lib]
|
||||
# The `_lib` suffix may seem redundant but it is necessary
|
||||
# to make the lib name unique and wouldn't conflict with the bin name.
|
||||
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
|
||||
name = "ircd_lib"
|
||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "2", features = [] }
|
||||
tauri-plugin-opener = "2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
irc = "1.1.0"
|
||||
tokio = "1.48.0"
|
||||
futures = "0.3.31"
|
||||
|
||||
3
src-tauri/build.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
||||
10
src-tauri/capabilities/default.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"$schema": "../gen/schemas/desktop-schema.json",
|
||||
"identifier": "default",
|
||||
"description": "Capability for the main window",
|
||||
"windows": ["main"],
|
||||
"permissions": [
|
||||
"core:default",
|
||||
"opener:default"
|
||||
]
|
||||
}
|
||||
BIN
src-tauri/icons/128x128.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
BIN
src-tauri/icons/128x128@2x.png
Normal file
|
After Width: | Height: | Size: 6.8 KiB |
BIN
src-tauri/icons/32x32.png
Normal file
|
After Width: | Height: | Size: 974 B |
BIN
src-tauri/icons/Square107x107Logo.png
Normal file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
src-tauri/icons/Square142x142Logo.png
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
src-tauri/icons/Square150x150Logo.png
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
BIN
src-tauri/icons/Square284x284Logo.png
Normal file
|
After Width: | Height: | Size: 7.6 KiB |
BIN
src-tauri/icons/Square30x30Logo.png
Normal file
|
After Width: | Height: | Size: 903 B |
BIN
src-tauri/icons/Square310x310Logo.png
Normal file
|
After Width: | Height: | Size: 8.4 KiB |
BIN
src-tauri/icons/Square44x44Logo.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
src-tauri/icons/Square71x71Logo.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
src-tauri/icons/Square89x89Logo.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
src-tauri/icons/StoreLogo.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
src-tauri/icons/icon.icns
Normal file
BIN
src-tauri/icons/icon.ico
Normal file
|
After Width: | Height: | Size: 85 KiB |
BIN
src-tauri/icons/icon.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
71
src-tauri/src/command.rs
Normal file
@@ -0,0 +1,71 @@
|
||||
use crate::connection_manager::ConnectionManager;
|
||||
use tauri::State;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
/// Connect to an IRC server
|
||||
#[tauri::command]
|
||||
pub async fn connect(
|
||||
state: State<'_, Mutex<ConnectionManager>>,
|
||||
server: String,
|
||||
port: u16,
|
||||
nickname: String,
|
||||
use_tls: bool,
|
||||
app_handle: tauri::AppHandle,
|
||||
) -> Result<(), String> {
|
||||
// Await the connect future while holding the lock
|
||||
println!("Connecting to {}:{} as {}", server, port, nickname);
|
||||
let mut manager = state.lock().await; // <-- .await for Tokio Mutex
|
||||
manager.connect(server, port, nickname, app_handle, use_tls).await
|
||||
}
|
||||
|
||||
/// Disconnect from IRC
|
||||
#[tauri::command]
|
||||
pub fn disconnect(state: State<'_, Mutex<ConnectionManager>>) -> Result<(), String> {
|
||||
let mut manager = futures::executor::block_on(state.lock()); // <-- block_on for sync fn
|
||||
manager.disconnect()
|
||||
}
|
||||
|
||||
/// Join a channel
|
||||
#[tauri::command]
|
||||
pub fn join_channel(
|
||||
state: State<'_, Mutex<ConnectionManager>>,
|
||||
channel: String
|
||||
) -> Result<(), String> {
|
||||
let mut manager = futures::executor::block_on(state.lock());
|
||||
manager.join_channel(&channel)
|
||||
}
|
||||
|
||||
/// Leave a channel
|
||||
#[tauri::command]
|
||||
pub fn part_channel(
|
||||
state: State<'_, Mutex<ConnectionManager>>,
|
||||
channel: String
|
||||
) -> Result<(), String> {
|
||||
let mut manager = futures::executor::block_on(state.lock());
|
||||
manager.part_channel(&channel)
|
||||
}
|
||||
|
||||
/// Send a message
|
||||
#[tauri::command]
|
||||
pub fn send_message(
|
||||
state: State<'_, Mutex<ConnectionManager>>,
|
||||
target: String,
|
||||
message: String
|
||||
) -> Result<(), String> {
|
||||
let manager = futures::executor::block_on(state.lock());
|
||||
manager.send_message(&target, &message)
|
||||
}
|
||||
|
||||
/// List joined channels
|
||||
#[tauri::command]
|
||||
pub fn list_channels(state: State<'_, Mutex<ConnectionManager>>) -> Vec<String> {
|
||||
let manager = futures::executor::block_on(state.lock());
|
||||
manager.list_channels()
|
||||
}
|
||||
|
||||
/// Check if connected
|
||||
#[tauri::command]
|
||||
pub fn is_connected(state: State<'_, Mutex<ConnectionManager>>) -> bool {
|
||||
let manager = futures::executor::block_on(state.lock());
|
||||
manager.is_connected()
|
||||
}
|
||||
120
src-tauri/src/connection_manager.rs
Normal file
@@ -0,0 +1,120 @@
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::Mutex;
|
||||
use tauri::{AppHandle, Emitter};
|
||||
use irc::client::prelude::*;
|
||||
use futures::stream::StreamExt;
|
||||
|
||||
pub struct ConnectionManager {
|
||||
pub client: Option<Arc<Mutex<Client>>>,
|
||||
pub channels: HashSet<String>,
|
||||
pub connected: bool,
|
||||
}
|
||||
|
||||
impl ConnectionManager {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
client: None,
|
||||
channels: HashSet::new(),
|
||||
connected: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Connect to an IRC server
|
||||
pub async fn connect(
|
||||
&mut self,
|
||||
server: String,
|
||||
port: u16,
|
||||
nickname: String,
|
||||
app_handle: AppHandle,
|
||||
use_tls: bool,
|
||||
) -> Result<(), String> {
|
||||
if self.connected {
|
||||
return Err("Already connected".into());
|
||||
}
|
||||
|
||||
let config = Config {
|
||||
nickname: Some(nickname.clone()),
|
||||
server: Some(server.clone()),
|
||||
port: Some(port),
|
||||
use_tls: Some(use_tls),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let client = Client::from_config(config)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
client.identify().map_err(|e| e.to_string())?;
|
||||
|
||||
let arc_client = Arc::new(Mutex::new(client));
|
||||
self.client = Some(arc_client.clone());
|
||||
self.connected = true;
|
||||
|
||||
// Spawn a listener for messages
|
||||
tokio::spawn({
|
||||
let arc_client = arc_client.clone();
|
||||
let app_handle = app_handle.clone();
|
||||
async move {
|
||||
let mut stream = arc_client.lock().await.stream().unwrap(); // <-- .await for Tokio Mutex
|
||||
while let Some(message) = stream.next().await.transpose().unwrap() {
|
||||
let msg_str = format!("{:?}", message);
|
||||
let _ = app_handle.emit("irc-message", msg_str);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Disconnect from IRC server
|
||||
pub fn disconnect(&mut self) -> Result<(), String> {
|
||||
if let Some(client) = &self.client {
|
||||
futures::executor::block_on(client.lock()).send_quit("Bye").ok();
|
||||
}
|
||||
self.client = None;
|
||||
self.channels.clear();
|
||||
self.connected = false;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Join a channel
|
||||
pub fn join_channel(&mut self, channel: &str) -> Result<(), String> {
|
||||
if let Some(client) = &self.client {
|
||||
futures::executor::block_on(client.lock()).send_join(channel).map_err(|e| e.to_string())?;
|
||||
self.channels.insert(channel.to_string());
|
||||
Ok(())
|
||||
} else {
|
||||
Err("Not connected".into())
|
||||
}
|
||||
}
|
||||
|
||||
/// Leave a channel
|
||||
pub fn part_channel(&mut self, channel: &str) -> Result<(), String> {
|
||||
if let Some(client) = &self.client {
|
||||
futures::executor::block_on(client.lock()).send_part(channel).map_err(|e| e.to_string())?;
|
||||
self.channels.remove(channel);
|
||||
Ok(())
|
||||
} else {
|
||||
Err("Not connected".into())
|
||||
}
|
||||
}
|
||||
|
||||
/// Send a message to a channel or user
|
||||
pub fn send_message(&self, target: &str, message: &str) -> Result<(), String> {
|
||||
if let Some(client) = &self.client {
|
||||
futures::executor::block_on(client.lock()).send_privmsg(target, message).map_err(|e| e.to_string())
|
||||
} else {
|
||||
Err("Not connected".into())
|
||||
}
|
||||
}
|
||||
|
||||
/// Get list of joined channels
|
||||
pub fn list_channels(&self) -> Vec<String> {
|
||||
self.channels.iter().cloned().collect()
|
||||
}
|
||||
|
||||
/// Check connection state
|
||||
pub fn is_connected(&self) -> bool {
|
||||
self.connected
|
||||
}
|
||||
}
|
||||
28
src-tauri/src/lib.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
mod connection_manager;
|
||||
mod command; // now it exists
|
||||
|
||||
use connection_manager::ConnectionManager;
|
||||
use command::{
|
||||
connect, disconnect, join_channel, part_channel, send_message,
|
||||
list_channels, is_connected
|
||||
};
|
||||
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.manage(Mutex::new(ConnectionManager::new()))
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
connect,
|
||||
disconnect,
|
||||
join_channel,
|
||||
part_channel,
|
||||
send_message,
|
||||
list_channels,
|
||||
is_connected
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
||||
11
src-tauri/src/linux_disable_dmabuf.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
/// Disable the DMA Buffer which WebView uses for rendering, this is neccessary for a
|
||||
/// NVIDIA Linux System
|
||||
pub fn disable_dmabuf() {
|
||||
if std::env::var("XDG_SESSION_TYPE").unwrap_or_default() == "wayland" {
|
||||
if let Ok(vendor) = std::fs::read_to_string("/proc/driver/nvidia/version") {
|
||||
if vendor.contains("NVIDIA") {
|
||||
std::env::set_var("WEBKIT_DISABLE_DMABUF_RENDERER", "1")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
src-tauri/src/main.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
mod linux_disable_dmabuf;
|
||||
use linux_disable_dmabuf::disable_dmabuf;
|
||||
|
||||
fn main() {
|
||||
disable_dmabuf();
|
||||
ircd_lib::run()
|
||||
}
|
||||
33
src-tauri/tauri.conf.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "ircd",
|
||||
"version": "0.1.0",
|
||||
"identifier": "com.rattatwinko.ircd",
|
||||
"build": {
|
||||
"frontendDist": "../src"
|
||||
},
|
||||
"app": {
|
||||
"withGlobalTauri": true,
|
||||
"windows": [
|
||||
{
|
||||
"title": "ircd",
|
||||
"width": 800,
|
||||
"height": 600
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": null
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"targets": "all",
|
||||
"icon": [
|
||||
"icons/32x32.png",
|
||||
"icons/128x128.png",
|
||||
"icons/128x128@2x.png",
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
]
|
||||
}
|
||||
}
|
||||
1
src/assets/javascript.svg
Normal file
@@ -0,0 +1 @@
|
||||
<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="32" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path fill="#F7DF1E" d="M0 0h256v256H0V0Z"></path><path d="m67.312 213.932l19.59-11.856c3.78 6.701 7.218 12.371 15.465 12.371c7.905 0 12.89-3.092 12.89-15.12v-81.798h24.057v82.138c0 24.917-14.606 36.259-35.916 36.259c-19.245 0-30.416-9.967-36.087-21.996m85.07-2.576l19.588-11.341c5.157 8.421 11.859 14.607 23.715 14.607c9.969 0 16.325-4.984 16.325-11.858c0-8.248-6.53-11.17-17.528-15.98l-6.013-2.58c-17.357-7.387-28.87-16.667-28.87-36.257c0-18.044 13.747-31.792 35.228-31.792c15.294 0 26.292 5.328 34.196 19.247l-18.732 12.03c-4.125-7.389-8.591-10.31-15.465-10.31c-7.046 0-11.514 4.468-11.514 10.31c0 7.217 4.468 10.14 14.778 14.608l6.014 2.577c20.45 8.765 31.963 17.7 31.963 37.804c0 21.654-17.012 33.51-39.867 33.51c-22.339 0-36.774-10.654-43.819-24.574"></path></svg>
|
||||
|
After Width: | Height: | Size: 995 B |
6
src/assets/tauri.svg
Normal file
@@ -0,0 +1,6 @@
|
||||
<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>
|
||||
|
After Width: | Height: | Size: 2.5 KiB |
42
src/formatIRC.js
Normal file
@@ -0,0 +1,42 @@
|
||||
function formatIRCMessage(msg) {
|
||||
// Tauri gives us the message as a stringified Rust Debug object
|
||||
// e.g. Message { tags: None, prefix: Some(Nickname("Nick", "", "")), command: PRIVMSG("#chan", "Hello") }
|
||||
// We'll try to parse key info using regex
|
||||
|
||||
try {
|
||||
// Extract the prefix (who sent it)
|
||||
const prefixMatch = msg.match(/prefix: Some\(([^)]+)\)/);
|
||||
let sender = prefixMatch ? prefixMatch[1] : "Unknown";
|
||||
|
||||
// Extract the command and arguments
|
||||
const cmdMatch = msg.match(/command: (\w+)\((.*)\)/);
|
||||
if (!cmdMatch) return msg;
|
||||
|
||||
const command = cmdMatch[1];
|
||||
const argsRaw = cmdMatch[2];
|
||||
|
||||
// Simple handler for common IRC commands
|
||||
switch(command) {
|
||||
case 'PRIVMSG': {
|
||||
const args = argsRaw.split(/,(.+)/); // split first comma
|
||||
const target = args[0].replace(/^"|"$/g, '');
|
||||
const message = args[1].replace(/^"|"$/g, '');
|
||||
return `[${target}] <${sender}> ${message}`;
|
||||
}
|
||||
case 'NOTICE': {
|
||||
const args = argsRaw.split(/,(.+)/);
|
||||
const target = args[0].replace(/^"|"$/g, '');
|
||||
const message = args[1].replace(/^"|"$/g, '');
|
||||
return `[NOTICE ${target}] ${message}`;
|
||||
}
|
||||
case 'Response':
|
||||
case 'Raw':
|
||||
case 'UserMODE':
|
||||
return `[${command}] ${argsRaw}`;
|
||||
default:
|
||||
return msg; // fallback for unknown messages
|
||||
}
|
||||
} catch(e) {
|
||||
return msg; // fallback if parsing fails
|
||||
}
|
||||
}
|
||||
49
src/index.html
Normal file
@@ -0,0 +1,49 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Tauri IRC Client</title>
|
||||
<style>
|
||||
body { font-family: sans-serif; margin:0; display:flex; flex-direction:column; height:100vh; }
|
||||
header { background:#222; color:#fff; padding:10px; display:flex; gap:10px; align-items:center; }
|
||||
main { flex:1; display:flex; overflow:hidden; }
|
||||
#channels { width:200px; background:#f0f0f0; padding:10px; overflow-y:auto; }
|
||||
#chat { flex:1; display:flex; flex-direction:column; padding:10px; }
|
||||
#messages { flex:1; overflow-y:auto; border:1px solid #ccc; padding:5px; margin-bottom:5px; background:#fff; }
|
||||
#input { display:flex; gap:5px; }
|
||||
input, button { padding:5px; }
|
||||
button { cursor:pointer; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header>
|
||||
<input id="server" placeholder="Server" value="irc.libera.chat">
|
||||
<input id="port" type="number" placeholder="Port" value="6667">
|
||||
<input id="nickname" placeholder="Nickname" value="TauriUser">
|
||||
<button id="connectBtn">Connect</button>
|
||||
<button id="disconnectBtn" disabled>Disconnect</button>
|
||||
<span id="status">Disconnected</span>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<div id="channels">
|
||||
<h4>Channels</h4>
|
||||
<ul id="channelList"></ul>
|
||||
<input id="newChannel" placeholder="#channel">
|
||||
<button id="joinBtn">Join</button>
|
||||
<button id="partBtn">Part</button>
|
||||
</div>
|
||||
<div id="chat">
|
||||
<div id="messages"></div>
|
||||
<div id="input">
|
||||
<input id="messageInput" placeholder="Type message...">
|
||||
<button id="sendBtn">Send</button>
|
||||
</div>
|
||||
</div>
|
||||
<script src="main.js"></script>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
148
src/main.js
Normal file
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
// this is needed for Tauri to work properly!
|
||||
const { invoke } = window.__TAURI__.core;
|
||||
//
|
||||
|
||||
let greetInputEl;
|
||||
let greetMsgEl;
|
||||
|
||||
async function greet() {
|
||||
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
||||
greetMsgEl.textContent = await invoke("greet", { name: greetInputEl.value });
|
||||
}
|
||||
|
||||
window.addEventListener("DOMContentLoaded", () => {
|
||||
greetInputEl = document.querySelector("#greet-input");
|
||||
greetMsgEl = document.querySelector("#greet-msg");
|
||||
document.querySelector("#greet-form").addEventListener("submit", (e) => {
|
||||
e.preventDefault();
|
||||
greet();
|
||||
});
|
||||
});
|
||||
*/
|
||||
const { invoke } = window.__TAURI__.core;
|
||||
const { listen } = window.__TAURI__.event;
|
||||
|
||||
const serverEl = document.getElementById('server');
|
||||
const portEl = document.getElementById('port');
|
||||
const nicknameEl = document.getElementById('nickname');
|
||||
const connectBtn = document.getElementById('connectBtn');
|
||||
const disconnectBtn = document.getElementById('disconnectBtn');
|
||||
const statusEl = document.getElementById('status');
|
||||
|
||||
const channelListEl = document.getElementById('channelList');
|
||||
const newChannelEl = document.getElementById('newChannel');
|
||||
const joinBtn = document.getElementById('joinBtn');
|
||||
const partBtn = document.getElementById('partBtn');
|
||||
|
||||
const messagesEl = document.getElementById('messages');
|
||||
const messageInputEl = document.getElementById('messageInput');
|
||||
const sendBtn = document.getElementById('sendBtn');
|
||||
|
||||
function addMessage(msg) {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = msg;
|
||||
messagesEl.appendChild(div);
|
||||
messagesEl.scrollTop = messagesEl.scrollHeight;
|
||||
}
|
||||
|
||||
async function refreshChannels() {
|
||||
try {
|
||||
const channels = await invoke("list_channels");
|
||||
channelListEl.innerHTML = '';
|
||||
channels.forEach(ch => {
|
||||
const li = document.createElement('li');
|
||||
li.textContent = ch;
|
||||
li.dataset.channel = ch;
|
||||
li.onclick = () => { newChannelEl.value = ch; };
|
||||
channelListEl.appendChild(li);
|
||||
});
|
||||
} catch (e) {
|
||||
addMessage("Failed to refresh channels: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
connectBtn.onclick = async () => {
|
||||
const server = serverEl.value.trim();
|
||||
const port = Number(portEl.value);
|
||||
const nickname = nicknameEl.value.trim();
|
||||
|
||||
if (!server || !port || !nickname) {
|
||||
addMessage('Please fill in server, port, and nickname.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await invoke('connect', {
|
||||
server: serverEl.value.trim(),
|
||||
port: Number(portEl.value),
|
||||
nickname: nicknameEl.value.trim(),
|
||||
useTls: false // must match Rust parameter exactly
|
||||
});
|
||||
|
||||
|
||||
statusEl.textContent = 'Connected';
|
||||
connectBtn.disabled = true;
|
||||
disconnectBtn.disabled = false;
|
||||
addMessage('Connected to ' + server);
|
||||
refreshChannels();
|
||||
} catch(e) {
|
||||
addMessage('Connection failed: ' + e);
|
||||
}
|
||||
};
|
||||
|
||||
disconnectBtn.onclick = async () => {
|
||||
try {
|
||||
await invoke('disconnect');
|
||||
statusEl.textContent = 'Disconnected';
|
||||
connectBtn.disabled = false;
|
||||
disconnectBtn.disabled = true;
|
||||
channelListEl.innerHTML = '';
|
||||
addMessage('Disconnected');
|
||||
} catch(e) {
|
||||
addMessage('Disconnect failed: ' + e);
|
||||
}
|
||||
};
|
||||
|
||||
joinBtn.onclick = async () => {
|
||||
const channel = newChannelEl.value.trim();
|
||||
if (!channel) return;
|
||||
try {
|
||||
await invoke('join_channel', { channel });
|
||||
addMessage(`Joined ${channel}`);
|
||||
refreshChannels();
|
||||
} catch(e) {
|
||||
addMessage(`Failed to join ${channel}: ${e}`);
|
||||
}
|
||||
};
|
||||
|
||||
partBtn.onclick = async () => {
|
||||
const channel = newChannelEl.value.trim();
|
||||
if (!channel) return;
|
||||
try {
|
||||
await invoke('part_channel', { channel });
|
||||
addMessage(`Left ${channel}`);
|
||||
refreshChannels();
|
||||
} catch(e) {
|
||||
addMessage(`Failed to leave ${channel}: ${e}`);
|
||||
}
|
||||
};
|
||||
|
||||
sendBtn.onclick = async () => {
|
||||
const target = newChannelEl.value.trim();
|
||||
const message = messageInputEl.value.trim();
|
||||
if (!target || !message) return;
|
||||
try {
|
||||
await invoke('send_message', { target, message });
|
||||
addMessage(`<You> ${message}`);
|
||||
messageInputEl.value = '';
|
||||
} catch(e) {
|
||||
addMessage(`Failed to send message: ${e}`);
|
||||
}
|
||||
};
|
||||
|
||||
// Listen to backend IRC messages
|
||||
listen('irc-message', event => {
|
||||
const formatted = formatIRCMessage(event.payload);
|
||||
});
|
||||
|
||||
112
src/styles.css
Normal file
@@ -0,0 +1,112 @@
|
||||
.logo.vanilla:hover {
|
||||
filter: drop-shadow(0 0 2em #ffe21c);
|
||||
}
|
||||
:root {
|
||||
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
font-weight: 400;
|
||||
|
||||
color: #0f0f0f;
|
||||
background-color: #f6f6f6;
|
||||
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
}
|
||||
|
||||
.container {
|
||||
margin: 0;
|
||||
padding-top: 10vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 6em;
|
||||
padding: 1.5em;
|
||||
will-change: filter;
|
||||
transition: 0.75s;
|
||||
}
|
||||
|
||||
.logo.tauri:hover {
|
||||
filter: drop-shadow(0 0 2em #24c8db);
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: 500;
|
||||
color: #646cff;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #535bf2;
|
||||
}
|
||||
|
||||
h1 {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
input,
|
||||
button {
|
||||
border-radius: 8px;
|
||||
border: 1px solid transparent;
|
||||
padding: 0.6em 1.2em;
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
font-family: inherit;
|
||||
color: #0f0f0f;
|
||||
background-color: #ffffff;
|
||||
transition: border-color 0.25s;
|
||||
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
button {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
border-color: #396cd8;
|
||||
}
|
||||
button:active {
|
||||
border-color: #396cd8;
|
||||
background-color: #e8e8e8;
|
||||
}
|
||||
|
||||
input,
|
||||
button {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
#greet-input {
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
color: #f6f6f6;
|
||||
background-color: #2f2f2f;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #24c8db;
|
||||
}
|
||||
|
||||
input,
|
||||
button {
|
||||
color: #ffffff;
|
||||
background-color: #0f0f0f98;
|
||||
}
|
||||
button:active {
|
||||
background-color: #0f0f0f69;
|
||||
}
|
||||
}
|
||||