initial
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"
|
||||
]
|
||||
}
|
||||
}
|
||||