diff --git a/Changelog.md b/Changelog.md index 99e39fe0e..6aeff12fc 100644 --- a/Changelog.md +++ b/Changelog.md @@ -15,6 +15,7 @@ ✨ 新增功能 - 增加 TrustTunnel, OpenVPN, Tailscale, GostRelay 节点显示支持 +- 全局扩展脚本增加恢复默认按钮、 diff --git a/src/components/profile/editor-viewer.tsx b/src/components/profile/editor-viewer.tsx index f8d115dde..2b6d61f9b 100644 --- a/src/components/profile/editor-viewer.tsx +++ b/src/components/profile/editor-viewer.tsx @@ -3,6 +3,7 @@ import { ContentPasteRounded, FormatPaintRounded, OpenInFullRounded, + RestartAltRounded, } from '@mui/icons-material' import { Button, @@ -41,6 +42,7 @@ export interface EditorViewerProps { saveDisabled?: boolean onChange?: (value: string) => void onSave?: () => void | Promise + onResetToDefault?: () => void onClose: () => void onValidate?: (markers: MonacoMarker[]) => void } @@ -57,6 +59,7 @@ export const EditorViewer = ({ saveDisabled = false, onChange, onSave, + onResetToDefault, onClose, onValidate, }: EditorViewerProps) => { @@ -298,6 +301,17 @@ export const EditorViewer = ({ + {!readOnly && onResetToDefault && ( + + )} diff --git a/src/components/profile/profile-more.tsx b/src/components/profile/profile-more.tsx index e08a8a875..9bdef3ce7 100644 --- a/src/components/profile/profile-more.tsx +++ b/src/components/profile/profile-more.tsx @@ -28,6 +28,15 @@ interface Props { const EMPTY_LOG_INFO: [string, string][] = [] +// Default global extend script content (mirrors `ITEM_SCRIPT` in +// src-tauri/src/utils/tmpl.rs). +const DEFAULT_SCRIPT = `// Define main function (script entry) + +function main(config, profileName) { + return config; +} +` + // profile enhanced item export const ProfileMore = (props: Props) => { const { id, logInfo, onSave } = props @@ -94,6 +103,10 @@ export const ProfileMore = (props: Props) => { document.markSaved(currentValue) }) + const handleResetToDefault = useCallback(() => { + document.setValue(DEFAULT_SCRIPT) + }, [document]) + return ( <> { dirty={document.dirty} onChange={document.setValue} onSave={handleSave} + onResetToDefault={id === 'Script' ? handleResetToDefault : undefined} onClose={() => setFileOpen(false)} /> )}