forked from phcode-dev/staging.phcode.dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug-overrides.js
More file actions
1 lines (1 loc) · 2.23 KB
/
Copy pathdebug-overrides.js
File metadata and controls
1 lines (1 loc) · 2.23 KB
1
define(function(require,exports,module){if(!window.AppConfig||"dev"!==AppConfig.config.environment)return;const CommandManager=require("command/CommandManager"),Commands=require("command/Commands"),Dialogs=require("widgets/Dialogs"),Mustache=require("thirdparty/mustache/mustache"),OverridesTpl=require("text!./debug-overrides-dialog.html"),COMMAND_ID="debug.debugOverrides",STORAGE_KEY="LOCAL_OVERIDES_FOR_PHOIENXI_DEBUG";function _readOverrides(){try{const raw=localStorage.getItem(STORAGE_KEY);if(!raw)return{};const parsed=JSON.parse(raw);return parsed&&"object"==typeof parsed?parsed:{}}catch(e){return{}}}function _writeOverrides(obj){try{localStorage.setItem(STORAGE_KEY,JSON.stringify(obj||{}))}catch(e){console.warn("[Debug Overrides] Failed to persist:",e)}}function _handleDebugOverrides(){const overrides=_readOverrides(),persistedAiOverride=!!overrides.AI_PANEL_LOCAL_OVERRIDE,persistedAccountsOverride=overrides.ACCOUNTS_SERVER_OVERRIDE||"";let aiPanelLocalOverride=persistedAiOverride,accountsServerOverride=persistedAccountsOverride,needsReload=!1;const html=Mustache.render(OverridesTpl,{aiPanelLocalOverride:aiPanelLocalOverride,accountsStaging:"staging"===accountsServerOverride,accountsDev:"dev"===accountsServerOverride});Dialogs.showModalDialogUsingTemplate(html).done(function(id){if(id!==Dialogs.DIALOG_BTN_OK)return;const next=_readOverrides();next.AI_PANEL_LOCAL_OVERRIDE=aiPanelLocalOverride,accountsServerOverride?next.ACCOUNTS_SERVER_OVERRIDE=accountsServerOverride:delete next.ACCOUNTS_SERVER_OVERRIDE,_writeOverrides(next),needsReload&&CommandManager.execute(Commands.APP_RELOAD)});const $dialog=$(".phoenix-debug-overrides.instance");function _updateSaveButton(){needsReload=aiPanelLocalOverride!==persistedAiOverride||accountsServerOverride!==persistedAccountsOverride,$dialog.find(".debug-overrides-save-btn").text(needsReload?"Save & Reload":"Save")}$dialog.find(".ai-panel-local-override").on("change",function(){aiPanelLocalOverride=$(this).is(":checked"),_updateSaveButton()}),$dialog.find(".accounts-server-override").on("change",function(){accountsServerOverride=$(this).val()||"",_updateSaveButton()})}CommandManager.register("Debug Overrides…",COMMAND_ID,_handleDebugOverrides),exports.COMMAND_ID=COMMAND_ID,exports.STORAGE_KEY=STORAGE_KEY});