Skip to content

Commit

Permalink
GH-1 GH-13: Add Gif Search and improve Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
SetZero committed Feb 4, 2024
1 parent d02b9a8 commit 25a54fd
Show file tree
Hide file tree
Showing 44 changed files with 2,291 additions and 1,131 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@reduxjs/toolkit": "^1.9.5",
"@tauri-apps/api": "^1.2.0",
"@types/dompurify": "^3.0.1",
"@types/lodash": "^4.14.202",
"@types/marked": "^5.0.0",
"@types/quill": "^2.0.10",
"@types/react-color": "^3.0.6",
Expand All @@ -34,6 +35,7 @@
"marked": "^5.0.2",
"marked-highlight": "^2.0.0",
"quill": "^1.3.7",
"quill-delta": "^5.1.0",
"react": "^18.2.0",
"react-color": "^2.19.3",
"react-dom": "^18.2.0",
Expand All @@ -43,6 +45,7 @@
"react-router-dom": "^6.10.0",
"socket.io": "^4.7.4",
"socket.io-client": "^4.7.4",
"tauri-plugin-store-api": "https://github.com/tauri-apps/tauri-plugin-store#v1",
"tinycolor2": "^1.6.0"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion public/locales/de/appearance.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"Primary": "Primär",
"Accent": "Akzent",
"Disable Auto-Scroll": "Automatisches Scrollen deaktivieren",
"Always auto-scroll, even if scrolled up": "Immer automatisch scrollen, auch wenn nach oben gescrollt wurde"
"Always auto-scroll, even if scrolled up": "Immer automatisch scrollen, auch wenn nach oben gescrollt wurde",
"Enable WYSIWYG Editor": "WYSIWYG-Editor aktivieren"
}
4 changes: 3 additions & 1 deletion public/locales/de/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@
"Description": "Beschreibung",
"Server": "Server",
"Port": "Port",
"Username": "Benutzername"
"Username": "Benutzername",
"Advanced Settings": "Erweiterte Einstellungen",
"Beta": "Beta"
}
3 changes: 2 additions & 1 deletion public/locales/dev/appearance.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"Primary": "---",
"Accent": "---",
"Disable Auto-Scroll": "---",
"Always auto-scroll, even if scrolled up": "---"
"Always auto-scroll, even if scrolled up": "---",
"Enable WYSIWYG Editor": "---"
}
4 changes: 3 additions & 1 deletion public/locales/dev/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@
"Description": "---",
"Server": "---",
"Port": "---",
"Username": "---"
"Username": "---",
"Advanced Settings": "---",
"Beta": "---"
}
3 changes: 2 additions & 1 deletion public/locales/en/appearance.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"Primary": "Primary",
"Accent": "Accent",
"Disable Auto-Scroll": "Disable Auto-Scroll",
"Always auto-scroll, even if scrolled up": "Always auto-scroll, even if scrolled up"
"Always auto-scroll, even if scrolled up": "Always auto-scroll, even if scrolled up",
"Enable WYSIWYG Editor": "Enable WYSIWYG Editor"
}
4 changes: 3 additions & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@
"Server": "Server",
"Port": "Port",
"Username": "Username",
"Client Certitcate": "Client Certitcate"
"Client Certitcate": "Client Certitcate",
"Advanced Settings": "Advanced Settings",
"Beta": "Beta"
}
11 changes: 11 additions & 0 deletions public/locales/es/appearance.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Appearance": "Apariencia",
"Colors": "Colores",
"Background Image": "Imagen de Fondo",
"Profile Image": "Imagen de Perfil",
"Primary": "Principal",
"Accent": "Acento",
"Disable Auto-Scroll": "Desactivar Auto-Scroll",
"Always auto-scroll, even if scrolled up": "Siempre auto-scroll, incluso si se desplaza hacia arriba",
"Enable WYSIWYG Editor": "Habilitar Editor WYSIWYG"
}
19 changes: 19 additions & 0 deletions public/locales/es/audio.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"Audio": "Audio",
"Input Device": "Dispositivo de entrada",
"Microphone": "Micrófono",
"Voice Activation": "Activación de voz",
"Push To Talk": "Pulsar para hablar",
"Automatically detect Microphone sensitivity": "Detectar automáticamente la sensibilidad del micrófono",
"Hold Activation for": "Mantener activación durante {{duration}}",
"Fade-out Audio after activation for": "Desvanecer audio después de la activación durante {{duration}}",
"Audio activation at": "Activación de audio en {{threshold}}",
"Audio deactivation at": "Desactivación de audio en {{threshold}}",
"Amplification dB": "Amplificación +{{amplification}}dB",
"Echo Cancelation": "Cancelación de eco",
"Noise Suppression": "Supresión de ruido",
"Compressor Threshold": "Umbral del compresor {{threshold}}dB",
"Compressor Ratio": "Relación del compresor {{ratio}}:1",
"Attack Time": "Tiempo de ataque {{duration}}",
"Release Time": "Tiempo de liberación {{duration}}"
}
34 changes: 34 additions & 0 deletions public/locales/es/common.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"User Profiles": "Perfiles de usuario",
"Profile": "Perfil",
"Add New Server": "Agregar nuevo servidor",
"Fancy Mumble Title": "Título elegante de Mumble",
"Unknown User": "Usuario desconocido",
"Search": "Buscar",
"Search Channel": "Buscar canal",
"Search Tenor": "Buscar Tenor para GIFs",
"Open In Browser": "Abrir en el navegador",
"Muted": "Silenciado",
"Deafened": "Sordo",
"Joined": "Unido",
"User ID": "ID de usuario",
"Settings": "Configuración",
"None": "Ninguno",
"Image too large": "[[ Imagen demasiado grande ({{size}} de {{maximum}}) ]]",
"write something": "Escribe algo :)",
"Feature Not Implemented": "{{feature}} (No implementado)",
"About Me": "Acerca de mí",
"Tell us about yourself": "Cuéntanos sobre ti",
"Edit Image": "Editar imagen",
"Link Preview": "Vista previa del enlace",
"Additional Features": "Funciones adicionales",
"Advanced": "Avanzado",
"Images": "Imágenes",
"Description": "Descripción",
"Server": "Servidor",
"Port": "Puerto",
"Username": "Nombre de usuario",
"Client Certitcate": "Certificado de cliente",
"Advanced Settings": "Configuración avanzada",
"Beta": "Beta"
}
13 changes: 13 additions & 0 deletions public/locales/es/language.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"Language": "Idioma",
"en": "English",
"en native": "Inglés",
"de": "Deutsch",
"de native": "Alemán",
"fr": "Français",
"fr native": "Francés",
"es": "Español",
"es native": "Español",
"dev": "Development",
"dev native": "Desarrollo"
}
4 changes: 4 additions & 0 deletions public/locales/es/notifications.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"Notifications": "Notifications",
"Hotkeys": "Hotkeys"
}
7 changes: 7 additions & 0 deletions public/locales/es/privacy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"Privacy": "Privacidad",
"Allow URLs from all sources": "Permitir URLs de todas las fuentes",
"Allowed Link Preview Urls": "URLs permitidas para vista previa de enlaces",
"Enable Link Preview": "Habilitar vista previa de enlaces",
"Tenor API Key": "Clave de API de Tenor"
}
8 changes: 8 additions & 0 deletions public/locales/es/time.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Timestamp": "Marca de tiempo",
"day short": "d",
"hour short": "h",
"minute short": "m",
"second short": "s",
"millisecond short": "ms"
}
18 changes: 18 additions & 0 deletions public/locales/es/user_interaction.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"Are you sure you want to delete all messages?": "¿Estás seguro de que quieres eliminar todos los mensajes?",
"Yes": "",
"No": "No",
"Skip": "Saltar",
"Cancel": "Cancelar",
"Like": "Me gusta",
"Message": "Mensaje",
"Go Back": "Volver",
"Save": "Guardar",
"Connect": "Conectar",
"Apply": "Aplicar",
"Discard": "Descartar",
"write user a message": "escribe un mensaje a {{user}}...",
"Delete all messages": "Eliminar todos los mensajes",
"Send Message to Channel": "Enviar mensaje a {{channel}}",
"User Joined the Server": "{{user}} se unió al servidor"
}
3 changes: 2 additions & 1 deletion public/locales/fr/appearance.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"Primary": "Primaire",
"Accent": "Accent",
"Disable Auto-Scroll": "Désactiver le défilement automatique",
"Always auto-scroll, even if scrolled up": "Toujours défilement automatique, même si défilé vers le haut"
"Always auto-scroll, even if scrolled up": "Toujours défilement automatique, même si défilé vers le haut",
"Enable WYSIWYG Editor": "Activer l'éditeur WYSIWYG"
}
4 changes: 3 additions & 1 deletion public/locales/fr/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@
"Description": "Description",
"Server": "Serveur",
"Port": "Port",
"Username": "Nom d'utilisateur"
"Username": "Nom d'utilisateur",
"Advanced Settings": "Paramètres avancés",
"Beta": "Bêta"
}
3 changes: 2 additions & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ patch = "0.7.0"
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.4.0", features = ["dialog-open", "global-shortcut-all", "shell-open", "updater", "window-close", "window-hide", "window-maximize", "window-minimize", "window-start-dragging", "window-unmaximize", "window-unminimize"] }
tauri = { version = "1.5.4", features = [ "path-all", "dialog-open", "global-shortcut-all", "shell-open", "updater", "window-close", "window-hide", "window-maximize", "window-minimize", "window-start-dragging", "window-unmaximize", "window-unminimize"] }
futures = "0.3.4"
tokio = { version = "1", features = ["full"] }
tokio-native-tls = "0.3.1"
Expand All @@ -44,6 +44,7 @@ webbrowser = "0.8.10"
reqwest = "0.11"
scraper = "0.18.1"
tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
symphonia = "0.5.3"
mime_guess = "2.0.4"
uuid = "1.7.0"
Expand Down
1 change: 1 addition & 0 deletions src-tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ fn main() -> io::Result<()> {

prost_build::compile_protos(&["src/proto/Mumble.proto"], &["src/"])?;
prost_build::compile_protos(&["src/proto/MumbleUDP.proto"], &["src/"])?;
prost_build::compile_protos(&["src/proto/Fancy.proto"], &["src/"])?;
tauri_build::build();

Ok(())
Expand Down
73 changes: 1 addition & 72 deletions src-tauri/src/commands/settings_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
use std::{
fs,
io::{Read, Seek, SeekFrom, Write},
sync::RwLock,
io::{Seek, SeekFrom, Write},
};

use tauri::State;
use tracing::{info, trace};

use crate::{
errors::certificate_error::CertificateError,
utils::{constants::get_project_dirs, server::Server},
};

use super::utils::settings::FrontendSettings;

const SERVER_SETTINS_FILE: &str = "server.json";
const FRONTEND_SETTINS_FILE: &str = "frontend_settings.json";

pub fn get_settings_file(file_name: &str) -> Result<std::fs::File, String> {
let project_dirs = get_project_dirs().ok_or("Unable to load project dir")?;
Expand All @@ -30,18 +25,6 @@ pub fn get_settings_file(file_name: &str) -> Result<std::fs::File, String> {
Ok(settings_file)
}

pub fn get_settings_file_location(file_name: &str) -> Result<String, String> {
let project_dirs = get_project_dirs().ok_or("Unable to load project dir")?;
let data_dir = project_dirs.config_dir();
std::fs::create_dir_all(data_dir).map_err(|e| format!("{e:?}"))?;

Ok(data_dir
.join(file_name)
.to_str()
.ok_or_else(|| "Unable to get file location".to_string())?
.to_string())
}

#[tauri::command]
pub fn save_server(
description: &str,
Expand Down Expand Up @@ -116,60 +99,6 @@ pub fn get_server_list() -> Result<Vec<Server>, String> {
Ok(server_list)
}

pub struct FrontendSettingsState {
pub state: RwLock<bool>,
}

#[allow(clippy::needless_pass_by_value)] // LinkPreview needs to be deserialized
#[allow(clippy::significant_drop_tightening)] // we need this to prevent simultaneous writes
#[tauri::command]
pub fn save_frontend_settings(
state: State<'_, FrontendSettingsState>,
settings_name: &str,
data: FrontendSettings,
) -> Result<(), String> {
trace!("Saving frontend settings: {settings_name}");

trace!("Settings data: {:#?}", data);
let lock = state.state.write();
if let Err(e) = lock {
return Err(format!("Error locking write state: {}", e.get_ref()));
}
let data = serde_json::to_string_pretty(&data).map_err(|e| format!("{e:?}"))?;

fs::write(
get_settings_file_location(&format!("{settings_name}_{FRONTEND_SETTINS_FILE}"))?,
data,
)
.map_err(|e| format!("{e:?}"))?;

Ok(())
}

// State is passed by value by tauri
#[allow(clippy::needless_pass_by_value)]
#[tauri::command]
pub fn get_frontend_settings(
state: State<'_, FrontendSettingsState>,
settings_name: &str,
) -> Result<String, String> {
info!("Getting frontend settings: {settings_name}");
let mut settings_file = get_settings_file(&format!("{settings_name}_{FRONTEND_SETTINS_FILE}"))?;

if let Err(e) = state.state.read() {
return Err(format!("Error locking write state: {}", e.get_ref()));
}

let mut settings_data = String::new();
settings_file
.read_to_string(&mut settings_data)
.map_err(|e| format!("{e:?}"))?;

trace!("Settings data: {:#?}", settings_data);

Ok(settings_data)
}

#[tauri::command]
pub fn get_identity_certs() -> Result<Vec<String>, String> {
let project_dirs = get_project_dirs()
Expand Down
30 changes: 30 additions & 0 deletions src-tauri/src/commands/web_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,33 @@ pub async fn get_open_graph_data_from_website(

Ok(result.to_string())
}

#[tauri::command]
pub async fn get_tenor_search_results(
api_key: &str,
query: &str,
limit: u32,
pos: u32,
) -> Result<String, String> {
let params = format!("&q={query}&limit={limit}&pos={pos}");

get_tenor_results(api_key, "search", params).await
}

#[tauri::command]
pub async fn get_tenor_trending_results(api_key: &str) -> Result<String, String> {
get_tenor_results(api_key, "trending", String::new()).await
}

async fn get_tenor_results(api_key: &str, api: &str, params: String) -> Result<String, String> {
let url = format!("https://api.tenor.com/v1/{api}?key={api_key}{params}");

let response = reqwest::get(&url)
.await
.map_err(|e| format!("{e:?}"))?
.text()
.await
.map_err(|e| format!("{e:?}"))?;

Ok(response)
}
Loading

0 comments on commit 25a54fd

Please sign in to comment.