Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions openless-all/app/src-tauri/src/coordinator/dictation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,8 @@ pub(super) async fn end_session(inner: &Arc<Inner>) -> Result<(), String> {
return Ok(());
}

emit_capsule(inner, CapsuleState::Inserting, 0.0, elapsed, None, None);

let focus_target = inner.state.lock().focus_target;
let focus_ready_for_paste = restore_focus_target_if_possible(focus_target);
let prefs = inner.prefs.get();
Expand Down Expand Up @@ -1142,15 +1144,15 @@ pub(super) async fn end_session(inner: &Arc<Inner>) -> Result<(), String> {
Some("TSF 未上屏,已禁止非 TSF 兜底".to_string())
} else if polish_error.is_some() {
// polish 失败优先告知用户,即使 insert 成功也要让用户知道这版是原文
Some("润色失败,已插入原文".to_string())
Some(format!("润色失败,已插入识别文本 {inserted_chars} 字"))
} else {
match status {
InsertStatus::Inserted => None,
InsertStatus::PasteSent => Some("已尝试粘贴".to_string()),
InsertStatus::Inserted => Some(format!("已润色并插入 {inserted_chars} 字")),
InsertStatus::PasteSent => Some(format!("已润色,尝试插入 {inserted_chars} 字")),
InsertStatus::CopiedFallback => Some(if cfg!(target_os = "windows") {
"已复制,请 Ctrl+V".to_string()
format!("已润色并复制 {inserted_chars} 字,请 Ctrl+V")
} else {
"已复制,请粘贴".to_string()
format!("已润色并复制 {inserted_chars} 字,请粘贴")
}),
InsertStatus::Failed => Some("插入失败".to_string()),
}
Expand Down
1 change: 1 addition & 0 deletions openless-all/app/src-tauri/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,7 @@ pub enum CapsuleState {
Recording,
Transcribing,
Polishing,
Inserting,
Done,
Cancelled,
Error,
Expand Down
50 changes: 47 additions & 3 deletions openless-all/app/src/components/Capsule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ function ProcessingDots() {
);
}

function formatElapsed(ms: number) {
const totalSeconds = Math.max(0, Math.floor(ms / 1000));
const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds % 60;
return `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
}

interface CenterTextProps {
os: OS;
kind: 'default' | 'processing' | 'error';
Expand Down Expand Up @@ -164,13 +171,14 @@ interface PillProps {
os: OS;
state: CapsuleState;
level: number;
elapsedMs: number;
insertedChars: number;
message?: string;
onCancel: () => void;
onConfirm: () => void;
}

function Pill({ os, state, level, insertedChars, message, onCancel, onConfirm }: PillProps) {
function Pill({ os, state, level, elapsedMs, insertedChars, message, onCancel, onConfirm }: PillProps) {
const { t } = useTranslation();
const metrics = getCapsulePillMetrics(os);
const processingLayout = getCapsuleMessageLayout(os, 'processing');
Expand All @@ -179,10 +187,42 @@ function Pill({ os, state, level, insertedChars, message, onCancel, onConfirm }:
let center: JSX.Element;
switch (state) {
case 'recording':
center = <AudioBars level={level} />;
center = (
<div
style={{
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
gap: 7,
width: '100%',
maxWidth: metrics.textWidth,
minWidth: 0,
}}
>
<AudioBars level={level} />
<span
style={{
fontSize: 10.5,
fontWeight: 600,
color: 'var(--ol-ink-2)',
whiteSpace: 'nowrap',
fontVariantNumeric: 'tabular-nums',
}}
>
{t('capsule.recordingElapsed', { time: formatElapsed(elapsedMs) })}
</span>
</div>
);
break;
case 'transcribing':
case 'polishing':
case 'inserting': {
const processingText =
state === 'transcribing'
? t('capsule.transcribing')
: state === 'polishing'
? t('capsule.polishing')
: t('capsule.inserting');
center = (
<div
style={{
Expand Down Expand Up @@ -213,11 +253,12 @@ function Pill({ os, state, level, insertedChars, message, onCancel, onConfirm }:
WebkitLineClamp: processingLayout.lineClamp,
}}
>
{t('capsule.thinking')}
{processingText}
</span>
</div>
);
break;
}
case 'done':
center = <CenterText os={os} kind="default" text={message || t('capsule.inserted', { count: insertedChars })} />;
break;
Expand Down Expand Up @@ -278,6 +319,7 @@ export function Capsule() {
const metrics = getCapsulePillMetrics(os);
const [state, setState] = useState<CapsuleState>(isTauri ? 'idle' : 'recording');
const [level, setLevel] = useState<number>(isTauri ? 0 : 0.6);
const [elapsedMs, setElapsedMs] = useState<number>(0);
const [insertedChars, setInsertedChars] = useState<number>(0);
const [message, setMessage] = useState<string | undefined>();
const [translation, setTranslation] = useState<boolean>(false);
Expand All @@ -294,6 +336,7 @@ export function Capsule() {
const p = event.payload;
setState(p.state);
setLevel(p.level ?? 0);
setElapsedMs(p.elapsedMs ?? 0);
setMessage(p.message ?? undefined);
if (p.insertedChars != null) setInsertedChars(p.insertedChars);
setTranslation(p.translation === true);
Expand Down Expand Up @@ -390,6 +433,7 @@ export function Capsule() {
os={os}
state={state}
level={level}
elapsedMs={elapsedMs}
insertedChars={insertedChars}
message={message}
onCancel={onCancel}
Expand Down
6 changes: 5 additions & 1 deletion openless-all/app/src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ export const en: typeof zhCN = {
},
capsule: {
thinking: 'Thinking…',
recordingElapsed: 'Recording {{time}}',
transcribing: 'Transcribing…',
polishing: 'Polishing…',
inserting: 'Inserting…',
cancelled: 'Cancelled',
error: 'Something went wrong',
inserted: 'Inserted {{count}}',
inserted: 'Inserted {{count}} chars',
translating: 'Translating',
},
qa: {
Expand Down
4 changes: 4 additions & 0 deletions openless-all/app/src/i18n/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export const ja: typeof zhCN = {
},
capsule: {
thinking: '考えています',
recordingElapsed: '録音中 {{time}}',
transcribing: '文字起こし中…',
polishing: '整えています…',
inserting: '入力中…',
cancelled: 'キャンセルしました',
error: 'エラーが発生しました',
inserted: '{{count}} 文字を入力しました',
Expand Down
4 changes: 4 additions & 0 deletions openless-all/app/src/i18n/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export const ko: typeof zhCN = {
},
capsule: {
thinking: '생각 중',
recordingElapsed: '녹음 중 {{time}}',
transcribing: '인식 중…',
polishing: '다듬는 중…',
inserting: '입력 중…',
cancelled: '취소됨',
error: '오류 발생',
inserted: '{{count}}자 입력됨',
Expand Down
6 changes: 5 additions & 1 deletion openless-all/app/src/i18n/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ export const zhCN = {
},
capsule: {
thinking: '正在思考中',
recordingElapsed: '录音中 {{time}}',
transcribing: '正在识别…',
polishing: '正在润色…',
inserting: '正在插入…',
cancelled: '已取消',
error: '出错了',
inserted: '已插入 {{count}}',
inserted: '已插入 {{count}}',
translating: '正在翻译',
},
qa: {
Expand Down
6 changes: 5 additions & 1 deletion openless-all/app/src/i18n/zh-TW.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ export const zhTW: typeof zhCN = {
},
capsule: {
thinking: '正在思考中',
recordingElapsed: '錄音中 {{time}}',
transcribing: '正在識別…',
polishing: '正在潤色…',
inserting: '正在插入…',
cancelled: '已取消',
error: '出錯了',
inserted: '已插入 {{count}}',
inserted: '已插入 {{count}}',
translating: '正在翻譯',
},
qa: {
Expand Down
1 change: 1 addition & 0 deletions openless-all/app/src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ export type CapsuleState =
| 'recording'
| 'transcribing'
| 'polishing'
| 'inserting'
| 'done'
| 'cancelled'
| 'error';
Expand Down
Loading