feat: add reset button to Global script

This commit is contained in:
wonfen
2026-06-18 15:13:38 +08:00
parent 57b891215e
commit 7e233efd10
3 changed files with 29 additions and 0 deletions
+1
View File
@@ -15,6 +15,7 @@
<summary><strong> ✨ 新增功能 </strong></summary>
- 增加 TrustTunnel, OpenVPN, Tailscale, GostRelay 节点显示支持
- 全局扩展脚本增加恢复默认按钮、
</details>
+14
View File
@@ -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<void>
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 = ({
</DialogContent>
<DialogActions>
{!readOnly && onResetToDefault && (
<Button
onClick={onResetToDefault}
variant="outlined"
color="warning"
startIcon={<RestartAltRounded />}
disabled={loading}
>
{t('shared.actions.resetToDefault')}
</Button>
)}
<Button onClick={handleClose} variant="outlined">
{t(readOnly ? 'shared.actions.close' : 'shared.actions.cancel')}
</Button>
+14
View File
@@ -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 (
<>
<ProfileBox
@@ -207,6 +220,7 @@ export const ProfileMore = (props: Props) => {
dirty={document.dirty}
onChange={document.setValue}
onSave={handleSave}
onResetToDefault={id === 'Script' ? handleResetToDefault : undefined}
onClose={() => setFileOpen(false)}
/>
)}