Skip to content

Commit e4deaef

Browse files
committed
fix: improve manual report export and linux appimage build
1 parent d029df5 commit e4deaef

4 files changed

Lines changed: 50 additions & 6 deletions

File tree

.github/workflows/release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ jobs:
5151
libgtk-3-dev \
5252
libayatana-appindicator3-dev \
5353
librsvg2-dev \
54-
patchelf
54+
patchelf \
55+
libfuse2
5556
5657
- name: Install frontend dependencies
5758
run: npm install

src-tauri/src/commands.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,15 +2495,26 @@ pub async fn get_saved_report(
24952495
pub async fn export_report_markdown(
24962496
date: String,
24972497
content: Option<String>,
2498+
export_dir: Option<String>,
24982499
state: State<'_, Arc<Mutex<AppState>>>,
24992500
) -> Result<String, AppError> {
25002501
let (export_dir, saved_content) = {
25012502
let state = state.lock().map_err(|e| AppError::Unknown(e.to_string()))?;
2502-
let export_dir = state
2503+
let requested_export_dir = export_dir
2504+
.as_deref()
2505+
.map(str::trim)
2506+
.filter(|dir| !dir.is_empty())
2507+
.map(|dir| dir.to_string());
2508+
let configured_export_dir = state
25032509
.config
25042510
.daily_report_export_dir
2505-
.clone()
2506-
.ok_or_else(|| AppError::Config("请先在设置中配置日报 Markdown 导出目录".to_string()))?;
2511+
.as_deref()
2512+
.map(str::trim)
2513+
.filter(|dir| !dir.is_empty())
2514+
.map(|dir| dir.to_string());
2515+
let export_dir = requested_export_dir.or(configured_export_dir).ok_or_else(|| {
2516+
AppError::Config("请先选择导出目录,或在设置中配置日报 Markdown 导出目录".to_string())
2517+
})?;
25072518
let saved_content = if let Some(content) = content {
25082519
content
25092520
} else {

src/routes/report/Report.svelte

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script>
22
import { onMount } from 'svelte';
33
import { invoke } from '@tauri-apps/api/core';
4+
import { open as openDialog } from '@tauri-apps/plugin-dialog';
45
import { open } from '@tauri-apps/plugin-shell';
56
import { marked } from 'marked';
67
import { showToast } from '../../lib/stores/toast.js';
@@ -185,9 +186,24 @@
185186
186187
exportInProgress = true;
187188
try {
189+
let exportDir = config?.daily_report_export_dir || null;
190+
if (!exportDir) {
191+
const selected = await openDialog({
192+
directory: true,
193+
multiple: false,
194+
});
195+
196+
if (!selected || Array.isArray(selected)) {
197+
return;
198+
}
199+
200+
exportDir = selected;
201+
}
202+
188203
const exportPath = await invoke('export_report_markdown', {
189204
date: report.date || selectedDate,
190205
content: report.content,
206+
exportDir,
191207
});
192208
showToast(`日报已导出到 ${exportPath}`, 'success');
193209
} catch (e) {
@@ -305,8 +321,8 @@
305321
<button
306322
class="page-action-secondary min-h-10 px-4 py-2"
307323
on:click={exportReportMarkdown}
308-
disabled={exportInProgress || !config?.daily_report_export_dir}
309-
title={config?.daily_report_export_dir ? '' : '请先在设置中配置日报 Markdown 导出目录'}
324+
disabled={exportInProgress}
325+
title={config?.daily_report_export_dir ? '' : '未设置默认目录时,点击后会先让你选择导出位置'}
310326
>
311327
{#if exportInProgress}
312328
<div class="animate-spin rounded-full h-4 w-4 border-2 border-current border-t-transparent"></div>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import test from 'node:test';
2+
import assert from 'node:assert/strict';
3+
import { readFile } from 'node:fs/promises';
4+
5+
test('日报手动导出在未设置默认目录时应允许临时选择目录', async () => {
6+
const source = await readFile(
7+
new URL('./Report.svelte', import.meta.url),
8+
'utf8'
9+
);
10+
11+
assert.match(source, /import \{ open as openDialog \} from '@tauri-apps\/plugin-dialog';/);
12+
assert.match(source, /const selected = await openDialog\(\{\s*directory: true,\s*multiple: false,/s);
13+
assert.match(source, /exportDir = selected;/);
14+
assert.match(source, /invoke\('export_report_markdown', \{\s*date: report\.date \|\| selectedDate,\s*content: report\.content,\s*exportDir,/s);
15+
assert.doesNotMatch(source, /disabled=\{exportInProgress \|\| !config\?\.daily_report_export_dir\}/);
16+
});

0 commit comments

Comments
 (0)