add auto skip when outside of VRChat

This commit is contained in:
mii443
2024-09-27 21:13:38 +09:00
parent 8397c29187
commit 4e07a1ebf0
9 changed files with 48 additions and 21 deletions

View File

@ -1,7 +1,7 @@
{
"name": "vrclipboard-ime-gui",
"private": true,
"version": "1.8.0",
"version": "1.9.0",
"type": "module",
"scripts": {
"dev": "vite",

View File

@ -1,5 +1,5 @@
{
"url": "https://r2-vrime.mii.dev/releases/vrclipboard-ime-gui_1.8.0_x64_ja-JP.msi.zip",
"url": "https://r2-vrime.mii.dev/releases/vrclipboard-ime-gui_1.9.0_x64_ja-JP.msi.zip",
"version": "1.8.0",
"notes": "ログの出力を改善",
"pub_date": "2024-09-25T14:51:05+00:00",

2
src-tauri/Cargo.lock generated
View File

@ -3903,7 +3903,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "vrclipboard-ime-gui"
version = "1.8.0"
version = "1.9.0"
dependencies = [
"anyhow",
"calc",

View File

@ -1,6 +1,6 @@
[package]
name = "vrclipboard-ime-gui"
version = "1.8.0"
version = "1.9.0"
description = "VRClipboard IME"
authors = ["mii"]
edition = "2021"
@ -41,6 +41,7 @@ features = [
"Win32_UI_Input_Ime",
"Win32_UI_TextServices",
"Win32_UI_Input_KeyboardAndMouse",
"Win32_System_DataExchange",
"Win32_UI_WindowsAndMessaging"
]

View File

@ -24,7 +24,9 @@ pub struct Config {
#[serde(default = "bool_true")]
pub skip_url: bool,
#[serde(default = "bool_false")]
pub use_tsf_reconvert: bool
pub use_tsf_reconvert: bool,
#[serde(default = "bool_true")]
pub skip_on_out_of_vrc: bool,
}
impl Default for Config {
@ -36,7 +38,8 @@ impl Default for Config {
ignore_prefix: true,
on_copy_mode: OnCopyMode::ReturnToChatbox,
skip_url: true,
use_tsf_reconvert: false
use_tsf_reconvert: false,
skip_on_out_of_vrc: true,
}
}
}

View File

@ -6,6 +6,7 @@ use clipboard_master::{ClipboardHandler, CallbackResult};
use regex::Regex;
use rosc::{encoder, OscMessage, OscPacket, OscType};
use tauri::{AppHandle, Manager};
use windows::Win32::System::DataExchange::GetClipboardOwner;
use crate::{config::{Config, OnCopyMode}, conversion::Conversion, tsf_conversion::TsfConversion, Log, STATE};
use anyhow::Result;
use tracing::{info, warn, error};
@ -34,6 +35,10 @@ impl ConversionHandler {
}
impl ConversionHandler {
fn clipboard_has_owner(&mut self) -> bool {
unsafe { GetClipboardOwner() }.is_ok()
}
fn tsf_conversion(&mut self, contents: &str, config: &Config) -> Result<()> {
if contents.chars().count() > 140 {
info!("Content exceeds 140 characters, skipping TSF conversion");
@ -126,6 +131,11 @@ impl ConversionHandler {
impl ClipboardHandler for ConversionHandler {
fn on_clipboard_change(&mut self) -> CallbackResult {
let config = self.get_config();
if config.skip_on_out_of_vrc && self.clipboard_has_owner() {
info!("Clipboard has owner (maybe from outside of VRChat), skipping conversion");
return CallbackResult::Next;
}
if let Ok(mut contents) = self.clipboard_ctx.get_contents() {
if config.use_tsf_reconvert {
if let Err(e) = self.tsf_conversion(&contents, &config) {

View File

@ -7,7 +7,7 @@
},
"package": {
"productName": "vrclipboard-ime-gui",
"version": "1.8.0"
"version": "1.9.0"
},
"tauri": {
"updater": {

View File

@ -10,6 +10,7 @@ interface Config {
on_copy_mode: OnCopyMode;
skip_url: boolean;
use_tsf_reconvert: boolean;
skip_on_out_of_vrc: boolean;
}
enum OnCopyMode {
@ -26,7 +27,8 @@ const SettingsComponent = () => {
ignore_prefix: false,
on_copy_mode: OnCopyMode.ReturnToChatbox,
skip_url: true,
use_tsf_reconvert: false
use_tsf_reconvert: false,
skip_on_out_of_vrc: true,
});
const [isOpen, setIsOpen] = useState(false);
const dropdownRef = useRef<HTMLDivElement>(null);
@ -48,9 +50,9 @@ const SettingsComponent = () => {
}
};
const saveSettings = async () => {
const saveSettings = async (newSettings: Config) => {
try {
await invoke('save_settings', { config: settings });
await invoke('save_settings', { config: newSettings });
alert('設定が正常に保存されました。');
} catch (error) {
console.error('Failed to save settings:', error);
@ -60,15 +62,19 @@ const SettingsComponent = () => {
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { name, value, type, checked } = e.target;
setSettings(prev => ({
...prev,
const newSettings = {
...settings,
[name]: type === 'checkbox' ? checked : value
}));
};
setSettings(newSettings);
saveSettings(newSettings);
};
const handleSelectChange = (value: OnCopyMode) => {
setSettings(prev => ({ ...prev, on_copy_mode: value }));
const newSettings = { ...settings, on_copy_mode: value };
setSettings(newSettings);
setIsOpen(false);
saveSettings(newSettings);
};
const handleClickOutside = (event: MouseEvent) => {
@ -195,12 +201,19 @@ const SettingsComponent = () => {
Windows10または11を使用している場合は Microsoft IME 使
</label>
</div>
<button
onClick={saveSettings}
className="bg-blue-500 text-white px-4 py-2 rounded-md hover:bg-blue-600 transition-colors"
>
</button>
<div className="flex items-center">
<input
type="checkbox"
id="skip_on_out_of_vrc"
name="skip_on_out_of_vrc"
checked={settings.skip_on_out_of_vrc}
onChange={handleChange}
className="mr-2"
/>
<label htmlFor="skip_on_out_of_vrc" className="text-sm font-medium text-gray-700">
VRChat以外からのコピーをスキップ
</label>
</div>
</div>
</div>
</div>

View File

@ -10,7 +10,7 @@ const TitleBar = () => {
<div className="flex justify-between items-center bg-gray-800 text-white h-8 px-2" data-tauri-drag-region>
<div className="flex items-center">
<span className="text-sm font-semibold">VRClipboard-IME</span>
<span className="text-xs font-semibold ml-2">v1.7.0</span>
<span className="text-xs font-semibold ml-2">v1.9.0</span>
</div>
<div className="flex">
<button onClick={handleMinimize} className="p-1 hover:bg-gray-700 focus:outline-none">