Skip to content

Commit 3e2188b

Browse files
feat(standalone): support page zoom (#70)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: typed-sigterm <[email protected]> Co-authored-by: Typed SIGTERM <[email protected]>
1 parent 2224192 commit 3e2188b

File tree

5 files changed

+41
-4
lines changed

5 files changed

+41
-4
lines changed

src-tauri/src/main.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,18 @@ fn write_file(path: String, content: String) -> Result<(), String> {
3030
Ok(())
3131
}
3232

33+
#[command]
34+
fn set_zoom(app: tauri::AppHandle, factor: f64) -> Result<(), String> {
35+
let window = app.get_webview_window("main").ok_or("Failed to get main window")?;
36+
window.set_zoom(factor).map_err(|e| e.to_string())
37+
}
38+
3339
fn main() {
3440
tauri::Builder::default()
3541
.plugin(tauri_plugin_dialog::init())
3642
.plugin(tauri_plugin_fs::init())
3743
.plugin(tauri_plugin_opener::init())
38-
.invoke_handler(tauri::generate_handler![read_file, write_file])
44+
.invoke_handler(tauri::generate_handler![read_file, write_file, set_zoom])
3945
.setup(|app| {
4046
let quit_item = MenuItem::with_id(app, "quit", "退出", true, None::<&str>).unwrap();
4147
let menu = Menu::with_items(app, &[&quit_item]).unwrap();
@@ -67,3 +73,5 @@ fn main() {
6773
.run(tauri::generate_context!())
6874
.expect("error while running tauri application");
6975
}
76+
77+

src/components/settings/ui.vue

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<script lang="ts" setup>
2+
import { invoke } from '@tauri-apps/api/core';
23
import { ref } from 'vue';
34
import { useI18n } from 'vue-i18n';
45
import { useConfigStore } from '@/stores/config';
5-
import { MAX_INTERVAL, MIN_INTERVAL } from '@/utils/config';
6+
import { __APP__ } from '@/utils/app';
7+
import { MAX_INTERVAL, MAX_ZOOM, MIN_INTERVAL, MIN_ZOOM, ZOOM_STEP } from '@/utils/config';
68
79
const { t } = useI18n();
810
@@ -15,6 +17,15 @@ config.$subscribe(() => {
1517
function handleInputIntervalDone() {
1618
config.interval = inputInterval.value;
1719
}
20+
21+
function handleZoomChange(factor: number | null) {
22+
if (!__APP__ || factor == null)
23+
return;
24+
invoke('set_zoom', { factor });
25+
}
26+
27+
if (__APP__)
28+
invoke('set_zoom', { factor: config.zoom });
1829
</script>
1930

2031
<template>
@@ -33,5 +44,16 @@ function handleInputIntervalDone() {
3344
<NFormItem :label="t('settings.ui.confetti')">
3445
<NSwitch v-model:value="config.confetti" />
3546
</NFormItem>
47+
48+
<NFormItem v-if="__APP__" :label="t('settings.ui.zoom')">
49+
<NInputNumber
50+
v-model:value="config.zoom"
51+
:format="x => `${Math.round((x ?? 1) * 100)}%`"
52+
:max="MAX_ZOOM"
53+
:min="MIN_ZOOM"
54+
:step="ZOOM_STEP"
55+
@update:value="handleZoomChange"
56+
/>
57+
</NFormItem>
3658
</NForm>
3759
</template>

src/locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@
196196
"ui": {
197197
"interval": "Interval",
198198
"confetti": "Confetti Effect",
199-
"second": "s"
199+
"second": "s",
200+
"zoom": "Page Zoom"
200201
}
201202
},
202203
"updater": {

src/locales/zh-CN.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@
196196
"ui": {
197197
"interval": "过号时间",
198198
"confetti": "彩带效果",
199-
"second": ""
199+
"second": "",
200+
"zoom": "页面缩放"
200201
}
201202
},
202203
"updater": {

src/utils/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export const UserConfigSchema = z.object({
1212
interval: z.number().default(100),
1313
/** 抽取完成后是否显示彩带效果 */
1414
confetti: z.boolean().default(true),
15+
/** 页面缩放级别 (0.25-5.0, 1.0 为 100%) */
16+
zoom: z.number().default(1.0),
1517
/** 计划设置 */
1618
plan: z.object({
1719
/** 是否启用计划队列 */
@@ -41,6 +43,9 @@ export const MAX_GROUP_MEMBER_LENGTH = 100;
4143
export const MAX_INTERVAL = 1000;
4244
export const MIN_INTERVAL = 20;
4345
export const MAX_PLAN_QUEUE_SIZE = 10000;
46+
export const MIN_ZOOM = 0.25;
47+
export const MAX_ZOOM = 5.0;
48+
export const ZOOM_STEP = 0.1;
4449

4550
export const DEFAULT_NAMELIST_OPTIONS: RollCallOption[] = [
4651
'Geopedia',

0 commit comments

Comments
 (0)