mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-10-22 19:52:14 +08:00
feat: add reset button to Global script
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
<summary><strong> ✨ 新增功能 </strong></summary>
|
||||
|
||||
- 增加 TrustTunnel, OpenVPN, Tailscale, GostRelay 节点显示支持
|
||||
- 全局扩展脚本增加恢复默认按钮、
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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)}
|
||||
/>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user