Skip to content

Commit

Permalink
fix: 修复独立窗口也会获取文本的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Pylogmon committed Mar 9, 2023
1 parent 87cc8ce commit 3642369
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/windows/translator/components/SourceArea/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react'
import { Card, Box, InputBase, IconButton, Button as MuiButton } from '@mui/material';
import ContentCopyIcon from '@mui/icons-material/ContentCopy';
import { writeText } from '@tauri-apps/api/clipboard';
import { appWindow } from '@tauri-apps/api/window'
import { invoke } from '@tauri-apps/api/tauri';
import PubSub from 'pubsub-js';
import './style.css'
Expand All @@ -10,15 +11,17 @@ export default function SourceArea() {
const [sourceText, setSourceText] = useState('');

useEffect(() => {
// 获取选中文本
invoke('get_selection_text').then(
text => {
if (text != "") {
setSourceText(text.trim());
PubSub.publish('SourceText', text);
if (appWindow.label == "translator") {
// 获取选中文本
invoke('get_selection_text').then(
text => {
if (text != "") {
setSourceText(text.trim());
PubSub.publish('SourceText', text);
}
}
}
)
)
}
}, [])

// 按键回调
Expand Down

0 comments on commit 3642369

Please sign in to comment.