Skip to content

Commit ff68b58

Browse files
committed
feat: 在隐私保护模式中增加凯撒移位模式
1 parent 9c84995 commit ff68b58

File tree

7 files changed

+58
-11
lines changed

7 files changed

+58
-11
lines changed

app/src/core/service/Settings.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const settingsSchema = z.object({
2525
entityDetailsWidthLimit: z.number().min(200).max(2000).int().default(200),
2626
showDebug: z.boolean().default(false),
2727
protectingPrivacy: z.boolean().default(false),
28+
protectingPrivacyMode: z.union([z.literal("secretWord"), z.literal("caesar")]).default("secretWord"),
2829
windowCollapsingWidth: z.number().min(50).max(2000).int().default(300),
2930
windowCollapsingHeight: z.number().min(25).max(2000).int().default(300),
3031
limitCameraInCycleSpace: z.boolean().default(false),

app/src/core/service/SettingsIcons.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export const settingsIcons = {
145145
entityDetailsWidthLimit: Space,
146146
showDebug: Bug,
147147
protectingPrivacy: VenetianMask,
148+
protectingPrivacyMode: VenetianMask,
148149
windowCollapsingWidth: MoveHorizontal,
149150
windowCollapsingHeight: MoveVertical,
150151
limitCameraInCycleSpace: Ratio,

app/src/core/service/controlService/shortcutKeysEngine/shortcutKeysRegister.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -544,11 +544,6 @@ export const allKeyBinds: KeyBindItem[] = [
544544
id: "checkoutProtectPrivacy",
545545
defaultKey: "C-2",
546546
onPress: async () => {
547-
if (Settings.protectingPrivacy) {
548-
toast.info("您已退出隐私模式,再次按下此快捷键、或在设置中开启,可进入隐私模式");
549-
} else {
550-
toast.info("您已通过快捷键进入隐私模式,再次按下此快捷键、或在设置中关闭,可退出隐私模式");
551-
}
552547
Settings.protectingPrivacy = !Settings.protectingPrivacy;
553548
},
554549
isUI: true,

app/src/locales/en.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,16 @@ settings:
197197
protectingPrivacy:
198198
title: Privacy Protection
199199
description: |
200-
When enabled for screenshot feedback, all Chinese characters will be replaced with 《㊙》 to protect privacy.
200+
When enabled for screenshot feedback, text will be replaced according to the selected mode to protect privacy.
201201
This is only a display-level replacement and does not affect the actual data.
202202
You can disable it after feedback to restore the original view.
203+
protectingPrivacyMode:
204+
title: Privacy Protection Mode
205+
description: |
206+
Select the text replacement method for privacy protection
207+
options:
208+
secretWord: Uniform Replacement (Chinese→㊙, Letters→a/A, Numbers→6)
209+
caesar: Caesar Shift (all characters shifted one position back)
203210
entityDetailsFontSize:
204211
title: Entity Details Font Size
205212
description: |

app/src/locales/zh_CN.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,16 @@ settings:
259259
protectingPrivacy:
260260
title: 隐私保护
261261
description: |
262-
用于反馈问题截图时,开启此项之后将汉字全部替换成《㊙》,以保护隐私。
262+
用于反馈问题截图时,开启此项之后将根据所选模式替换文字,以保护隐私。
263263
仅作显示层面的替换,不会影响真实数据
264264
反馈完毕后可再关闭,复原
265+
protectingPrivacyMode:
266+
title: 隐私保护模式
267+
description: |
268+
选择隐私保护时的文字替换方式
269+
options:
270+
secretWord: 统一替换(汉字→㊙,字母→a/A,数字→6)
271+
caesar: 凯撒移位(所有字符往后移动一位)
265272
entityDetailsFontSize:
266273
title: 实体详细信息字体大小
267274
description: |

app/src/sub/SettingsWindow/settings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ const categories = {
224224
"entityDetailsLinesLimit",
225225
"entityDetailsWidthLimit",
226226
],
227-
debug: ["showDebug", "protectingPrivacy"],
227+
debug: ["showDebug", "protectingPrivacy", "protectingPrivacyMode"],
228228
miniWindow: ["windowCollapsingWidth", "windowCollapsingHeight"],
229229
experimental: ["limitCameraInCycleSpace", "cameraCycleSpaceSizeX", "cameraCycleSpaceSizeY"],
230230
},

app/src/utils/font.tsx

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { isMac } from "@/utils/platform";
22
import { MaxSizeCache, Vector } from "@graphif/data-structures";
3+
import { Settings } from "@/core/service/Settings";
34

45
const _canvas = document.createElement("canvas");
56
const _context = _canvas.getContext("2d");
@@ -65,12 +66,47 @@ export function getMultiLineTextSize(text: string, fontSize: number, lineHeight:
6566
}
6667

6768
/**
68-
* 所有的汉字替换成“㊙”
69-
* 所有小写字母替换成 a,大写字母替换成 A
70-
* 所有数字全部替换成 6
69+
* 隐私保护文本替换
70+
* 根据设置的保护模式进行不同的替换
7171
* @param text
7272
*/
7373
export function replaceTextWhenProtect(text: string) {
74+
// 检查是否设置了保护模式,如果没有,默认为secretWord
75+
const mode = Settings.protectingPrivacyMode || "secretWord";
76+
77+
if (mode === "caesar") {
78+
// 凯撒移位加密:所有字符往后移动一位
79+
return text
80+
.split("")
81+
.map((char) => {
82+
const code = char.charCodeAt(0);
83+
84+
// 对于可打印ASCII字符进行移位
85+
if (code >= 32 && code <= 126) {
86+
// 特殊处理:'z' 移到 'a','Z' 移到 'A','9' 移到 '0'
87+
if (char === "z") return "a";
88+
if (char === "Z") return "A";
89+
if (char === "9") return "0";
90+
// 其他字符直接 +1
91+
return String.fromCharCode(code + 1);
92+
}
93+
94+
// 对于中文字符,进行移位加密
95+
if (code >= 0x4e00 && code <= 0x9fa5) {
96+
// 中文字符在Unicode范围内循环移位
97+
// 0x4e00是汉字起始,0x9fa5是汉字结束,总共约20902个汉字
98+
const shiftedCode = code + 1;
99+
// 如果超过汉字范围,则回到起始位置
100+
return String.fromCharCode(shiftedCode <= 0x9fa5 ? shiftedCode : 0x4e00);
101+
}
102+
103+
// 其他字符保持不变
104+
return char;
105+
})
106+
.join("");
107+
}
108+
109+
// 默认的secretWord模式
74110
return text
75111
.replace(/[\u4e00-\u9fa5]/g, "㊙")
76112
.replace(/[a-z]/g, "a")

0 commit comments

Comments
 (0)