11import { runLatestOnlyQueue } from '../logic.mjs' ;
2+ import { normalizeConfigTemplateDiffConfirmEnabled } from './config-template-confirm-pref.mjs' ;
23
34function hasResponseError ( response ) {
45 if ( ! response || typeof response !== 'object' ) {
@@ -736,6 +737,40 @@ export function createCodexConfigMethods(options = {}) {
736737 return ;
737738 }
738739
740+ // Default to two-step confirmation when the setting is unset.
741+ // (The normalize helper lives in session-actions; keep a safe fallback here.)
742+ const shouldUseTwoStepConfirm = normalizeConfigTemplateDiffConfirmEnabled ( this . configTemplateDiffConfirmEnabled ) ;
743+
744+ const performApply = async ( ) => {
745+ this . configTemplateApplying = true ;
746+ try {
747+ const res = await api ( 'apply-config-template' , {
748+ template : this . configTemplateContent
749+ } ) ;
750+ if ( res . error ) {
751+ this . showMessage ( res . error , 'error' ) ;
752+ return ;
753+ }
754+ this . showMessage ( '模板已应用' , 'success' ) ;
755+ this . closeConfigTemplateModal ( { force : true } ) ;
756+ try {
757+ await this . loadAll ( ) ;
758+ } catch ( _ ) {
759+ this . showMessage ( '模板已应用,但界面刷新失败,请手动刷新' , 'error' ) ;
760+ }
761+ } catch ( e ) {
762+ this . showMessage ( '应用模板失败' , 'error' ) ;
763+ } finally {
764+ this . configTemplateApplying = false ;
765+ }
766+ } ;
767+
768+ // One-step mode: apply immediately unless user explicitly entered the diff preview state.
769+ if ( ! shouldUseTwoStepConfirm && ! this . configTemplateDiffVisible ) {
770+ await performApply ( ) ;
771+ return ;
772+ }
773+
739774 if ( ! this . configTemplateDiffVisible ) {
740775 await this . prepareConfigTemplateDiff ( ) ;
741776 return ;
@@ -757,27 +792,7 @@ export function createCodexConfigMethods(options = {}) {
757792 return ;
758793 }
759794
760- this . configTemplateApplying = true ;
761- try {
762- const res = await api ( 'apply-config-template' , {
763- template : this . configTemplateContent
764- } ) ;
765- if ( res . error ) {
766- this . showMessage ( res . error , 'error' ) ;
767- return ;
768- }
769- this . showMessage ( '模板已应用' , 'success' ) ;
770- this . closeConfigTemplateModal ( { force : true } ) ;
771- try {
772- await this . loadAll ( ) ;
773- } catch ( _ ) {
774- this . showMessage ( '模板已应用,但界面刷新失败,请手动刷新' , 'error' ) ;
775- }
776- } catch ( e ) {
777- this . showMessage ( '应用模板失败' , 'error' ) ;
778- } finally {
779- this . configTemplateApplying = false ;
780- }
795+ await performApply ( ) ;
781796 }
782797 } ;
783798}
0 commit comments