From 400051ddb4b2eddf1e74120a552de43d0e1d6e77 Mon Sep 17 00:00:00 2001 From: Tyler Date: Fri, 2 Aug 2024 18:27:18 +0100 Subject: [PATCH] Implemented a SpOnGeBoB mOcKiNg text mode. --- src-tauri/Cargo.lock | 9 +++-- src/constants/SystemEventMap.ts | 13 +++++++ src/types.d.ts | 1 + wooting-macro-backend/Cargo.lock | 9 +++-- wooting-macro-backend/Cargo.toml | 1 + .../src/plugin/system_event.rs | 38 +++++++++++++++++++ 6 files changed, 63 insertions(+), 8 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index ac531ddf..0eea3682 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -5121,9 +5121,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.34" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa 1.0.10", @@ -5144,9 +5144,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" dependencies = [ "num-conv", "time-core", @@ -6367,6 +6367,7 @@ dependencies = [ "serde_json", "serde_repr", "tauri", + "time", "tokio", "tokio-serde", "url", diff --git a/src/constants/SystemEventMap.ts b/src/constants/SystemEventMap.ts index 78e82b21..0ef1e788 100644 --- a/src/constants/SystemEventMap.ts +++ b/src/constants/SystemEventMap.ts @@ -61,6 +61,18 @@ export class SystemEvent { description: "Randomly capitalizes some letters in the currently highlighted text." } } + static get Spongebob(): SystemEventInfo { + return { + type: 'Clipboard', + subtype: 'Spongebob', + displayString: 'SpOnGeBoB tExT', + defaultData: { + type: 'Clipboard', + action: { type: 'Spongebob' } + }, + description: "Alternating capitalization of letters in the currently highlighted text." + } + } static get IncreaseVolume(): SystemEventInfo { return { type: 'Volume', @@ -95,6 +107,7 @@ export class SystemEvent { SystemEvent.OpenWebsite, SystemEvent.Clipboard, SystemEvent.Sarcasm, + SystemEvent.Spongebob, SystemEvent.IncreaseVolume, SystemEvent.DecreaseVolume, SystemEvent.ToggleMuteVolume, diff --git a/src/types.d.ts b/src/types.d.ts index ee4f3342..c7087732 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -180,6 +180,7 @@ export type ClipboardAction = | { type: 'Paste' } | { type: 'PasteUserDefinedString'; data: string } | { type: 'Sarcasm' } + | { type: 'Spongebob' } export type VolumeAction = | { type: 'LowerVolume' } diff --git a/wooting-macro-backend/Cargo.lock b/wooting-macro-backend/Cargo.lock index c535c4f6..7aa82d2d 100644 --- a/wooting-macro-backend/Cargo.lock +++ b/wooting-macro-backend/Cargo.lock @@ -4744,9 +4744,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.34" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa 1.0.10", @@ -4765,9 +4765,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" dependencies = [ "num-conv", "time-core", @@ -5912,6 +5912,7 @@ dependencies = [ "serde_json", "serde_repr", "tauri", + "time", "tokio", "tokio-serde", "url", diff --git a/wooting-macro-backend/Cargo.toml b/wooting-macro-backend/Cargo.toml index c044938b..02a7e028 100644 --- a/wooting-macro-backend/Cargo.toml +++ b/wooting-macro-backend/Cargo.toml @@ -31,6 +31,7 @@ log = "0.4" env_logger = "0.11" rayon = "1.8" url = "2.5" +time = "0.3.36" [profile.release] lto = true diff --git a/wooting-macro-backend/src/plugin/system_event.rs b/wooting-macro-backend/src/plugin/system_event.rs index 7129b51c..2e3f2706 100644 --- a/wooting-macro-backend/src/plugin/system_event.rs +++ b/wooting-macro-backend/src/plugin/system_event.rs @@ -106,6 +106,29 @@ impl SystemAction { // Paste the text again util::direct_send_hotkey(&send_channel, PASTE_HOTKEY.to_vec()).await?; } + + ClipboardAction::Spongebob => { + let mut ctx = ClipboardContext::new() + .map_err(|err| anyhow::Error::msg(err.to_string()))?; + + // Copy the text + util::direct_send_hotkey(&send_channel, COPY_HOTKEY.to_vec()).await?; + + // Delay is required to make Discord, and some other apps cooperate properly. + tokio::time::sleep(time::Duration::from_millis(10)).await; + + // Transform the text + let content = spongebob_text_transform( + ctx.get_contents() + .map_err(|err| anyhow::Error::msg(err.to_string()))?, + ); + + ctx.set_contents(content) + .map_err(|err| anyhow::Error::msg(err.to_string()))?; + + // Paste the text again + util::direct_send_hotkey(&send_channel, PASTE_HOTKEY.to_vec()).await?; + } }, } Ok(()) @@ -129,6 +152,20 @@ fn transform_text(text: String) -> String { .collect() } +// Spongebob text transformation +fn spongebob_text_transform(text: String) -> String { + text.chars() + .enumerate() + .map(|(i, c)| { + if i % 2 == 0 { + c.to_ascii_uppercase() + } else { + c.to_ascii_lowercase() + } + }) + .collect() +} + #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Hash, Eq)] #[serde(tag = "type")] /// The type of action to perform. This is used to determine which action to perform. @@ -139,6 +176,7 @@ pub enum ClipboardAction { Paste, PasteUserDefinedString { data: String }, Sarcasm, + Spongebob, } #[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Hash, Eq)]