@@ -87,25 +87,9 @@ define(function (require, exports, module) {
8787 const PREVIEW_TRUSTED_PROJECT_KEY = "preview_trusted" ;
8888 const PREVIEW_PROJECT_README_KEY = "preview_readme" ;
8989
90- // live preview mode pref
91- const PREFERENCE_LIVE_PREVIEW_MODE = "livePreviewMode" ;
92-
9390 // holds the dropdown instance
9491 let $dropdown = null ;
95-
96- /**
97- * Get the appropriate default mode based on whether edit features are active
98- * @returns {string } "highlight" if edit features inactive, "edit" if active
99- */
100- function _getDefaultMode ( ) {
101- return LiveDevelopment . isProUser ? "edit" : "highlight" ;
102- }
103-
104- // define the live preview mode preference
105- PreferencesManager . definePreference ( PREFERENCE_LIVE_PREVIEW_MODE , "string" , _getDefaultMode ( ) , {
106- description : StringUtils . format ( Strings . LIVE_PREVIEW_MODE_PREFERENCE , "'preview'" , "'highlight'" , "'edit'" ) ,
107- values : [ "preview" , "highlight" , "edit" ]
108- } ) ;
92+ const PREFERENCE_LIVE_PREVIEW_MODE = "livePreviewMode" ;
10993
11094 // live preview element highlights preference (whether on hover or click)
11195 const PREFERENCE_PROJECT_ELEMENT_HIGHLIGHT = "livePreviewElementHighlights" ;
@@ -372,43 +356,21 @@ define(function (require, exports, module) {
372356 }
373357 }
374358
375- /**
376- * init live preview mode from saved preferences
377- */
378359 function _initializeMode ( ) {
379- // when user is on free trial we just push the edit mode to them every time they open/reload Phoenix
380- if ( LiveDevelopment . isFreeTrialUser ) {
381- PreferencesManager . set ( PREFERENCE_LIVE_PREVIEW_MODE , "edit" ) ;
382- _LPEditMode ( ) ;
383- $previewBtn . removeClass ( 'selected' ) ;
384- _updateModeButton ( "edit" ) ;
385- return ;
386- }
387-
388- const savedMode = PreferencesManager . get ( PREFERENCE_LIVE_PREVIEW_MODE ) || _getDefaultMode ( ) ;
389- const isEditFeaturesActive = LiveDevelopment . isProUser ;
360+ const currentMode = LiveDevelopment . getCurrentMode ( ) ;
390361
391- // If user has edit mode saved but edit features are not active, default to highlight
392- let effectiveMode = savedMode ;
393- if ( savedMode === "edit" && ! isEditFeaturesActive ) {
394- effectiveMode = "highlight" ;
395- // Update the preference to reflect the actual mode being used
396- PreferencesManager . set ( PREFERENCE_LIVE_PREVIEW_MODE , "highlight" ) ;
397- }
398-
399- // apply the effective mode
400- if ( effectiveMode === "highlight" ) {
362+ if ( currentMode === "highlight" ) {
401363 _LPHighlightMode ( ) ;
402364 $previewBtn . removeClass ( 'selected' ) ;
403- } else if ( effectiveMode === "edit" && isEditFeaturesActive ) {
365+ } else if ( currentMode === "edit" ) {
404366 _LPEditMode ( ) ;
405367 $previewBtn . removeClass ( 'selected' ) ;
406368 } else {
407369 _LPPreviewMode ( ) ;
408370 $previewBtn . addClass ( 'selected' ) ;
409371 }
410372
411- _updateModeButton ( effectiveMode ) ;
373+ _updateModeButton ( currentMode ) ;
412374 }
413375
414376 function _showModeSelectionDropdown ( event ) {
@@ -425,9 +387,7 @@ define(function (require, exports, module) {
425387 items . push ( Strings . LIVE_PREVIEW_EDIT_HIGHLIGHT_ON ) ;
426388 }
427389
428- const rawMode = PreferencesManager . get ( PREFERENCE_LIVE_PREVIEW_MODE ) || _getDefaultMode ( ) ;
429- // this is to take care of invalid values in the pref file
430- const currentMode = [ "preview" , "highlight" , "edit" ] . includes ( rawMode ) ? rawMode : _getDefaultMode ( ) ;
390+ const currentMode = LiveDevelopment . getCurrentMode ( ) ;
431391
432392 $dropdown = new DropdownButton . DropdownButton ( "" , items , function ( item , index ) {
433393 if ( item === Strings . LIVE_PREVIEW_MODE_PREVIEW ) {
@@ -472,28 +432,22 @@ define(function (require, exports, module) {
472432
473433 // handle the option selection
474434 $dropdown . on ( "select" , function ( e , item , index ) {
475- // here we just set the preference
476- // as the preferences listener will automatically handle the required changes
477435 if ( index === 0 ) {
478- PreferencesManager . set ( PREFERENCE_LIVE_PREVIEW_MODE , "preview" ) ;
436+ LiveDevelopment . setMode ( "preview" ) ;
479437 } else if ( index === 1 ) {
480- PreferencesManager . set ( PREFERENCE_LIVE_PREVIEW_MODE , "highlight" ) ;
438+ LiveDevelopment . setMode ( "highlight" ) ;
481439 } else if ( index === 2 ) {
482- if ( ! isEditFeaturesActive ) {
483- // when the feature is not active we need to show a dialog to the user asking
484- // them to subscribe to pro
440+ if ( ! LiveDevelopment . setMode ( "edit" ) ) {
485441 _showProFeatureDialog ( ) ;
486- } else {
487- PreferencesManager . set ( PREFERENCE_LIVE_PREVIEW_MODE , "edit" ) ;
488442 }
489443 } else if ( item === Strings . LIVE_PREVIEW_EDIT_HIGHLIGHT_ON ) {
490444 // Don't allow edit highlight toggle if edit features are not active
491445 if ( ! isEditFeaturesActive ) {
492446 return ;
493447 }
494448 // Toggle between hover and click
495- const currentMode = PreferencesManager . get ( PREFERENCE_PROJECT_ELEMENT_HIGHLIGHT ) ;
496- const newMode = currentMode !== "click" ? "click" : "hover" ;
449+ const currMode = PreferencesManager . get ( PREFERENCE_PROJECT_ELEMENT_HIGHLIGHT ) ;
450+ const newMode = currMode !== "click" ? "click" : "hover" ;
497451 PreferencesManager . set ( PREFERENCE_PROJECT_ELEMENT_HIGHLIGHT , newMode ) ;
498452 return ; // Don't dismiss highlights for this option
499453 }
@@ -1268,32 +1222,8 @@ define(function (require, exports, module) {
12681222 // init live preview mode from saved preferences
12691223 _initializeMode ( ) ;
12701224 // listen for pref changes
1271- PreferencesManager . on ( "change" , PREFERENCE_LIVE_PREVIEW_MODE , function ( ) {
1272- // Get the current preference value directly
1273- const newMode = PreferencesManager . get ( PREFERENCE_LIVE_PREVIEW_MODE ) ;
1274- const isEditFeaturesActive = LiveDevelopment . isProUser ;
1275-
1276- // If user tries to set edit mode but edit features are not active, default to highlight
1277- let effectiveMode = newMode ;
1278- if ( newMode === "edit" && ! isEditFeaturesActive ) {
1279- effectiveMode = "highlight" ;
1280- // Update the preference to reflect the actual mode being used
1281- PreferencesManager . set ( PREFERENCE_LIVE_PREVIEW_MODE , "highlight" ) ;
1282- return ; // Return to avoid infinite loop
1283- }
1284-
1285- if ( effectiveMode === "highlight" ) {
1286- _LPHighlightMode ( ) ;
1287- $previewBtn . removeClass ( 'selected' ) ;
1288- } else if ( effectiveMode === "edit" && isEditFeaturesActive ) {
1289- _LPEditMode ( ) ;
1290- $previewBtn . removeClass ( 'selected' ) ;
1291- } else {
1292- _LPPreviewMode ( ) ;
1293- $previewBtn . addClass ( 'selected' ) ;
1294- }
1295-
1296- _updateModeButton ( effectiveMode ) ;
1225+ PreferencesManager . on ( "change" , "livePreviewMode" , function ( ) {
1226+ _initializeMode ( ) ;
12971227 } ) ;
12981228
12991229 // Handle element highlight preference changes from this extension
0 commit comments