this repo has no description

moonbase: Process config changes from other extensions

+29 -13
+2 -2
packages/core-extensions/src/moonbase/webpackModules/crashScreen.tsx
··· 84 84 } 85 85 86 86 function ExtensionDisableCard({ ext }: { ext: DetectedExtension }) { 87 - function disableWithDependents() { 87 + async function disableWithDependents() { 88 88 const disable = new Set<string>(); 89 89 disable.add(ext.id); 90 90 for (const [id, dependencies] of moonlightNode.processedExtensions.dependencyGraph) { ··· 105 105 msg += "?"; 106 106 107 107 if (confirm(msg)) { 108 - moonlightNode.writeConfig(config); 108 + await moonlightNode.writeConfig(config); 109 109 window.location.reload(); 110 110 } 111 111 }
+2 -2
packages/core-extensions/src/moonbase/webpackModules/settings.tsx
··· 19 19 onReset={() => { 20 20 MoonbaseSettingsStore.reset(); 21 21 }} 22 - onSave={() => { 23 - MoonbaseSettingsStore.writeConfig(); 22 + onSave={async () => { 23 + await MoonbaseSettingsStore.writeConfig(); 24 24 }} 25 25 /> 26 26 );
+25 -9
packages/core-extensions/src/moonbase/webpackModules/stores.ts
··· 13 13 import { mainRepo } from "@moonlight-mod/types/constants"; 14 14 import { checkExtensionCompat, ExtensionCompat } from "@moonlight-mod/core/extension/loader"; 15 15 import { CustomComponent } from "@moonlight-mod/types/coreExtensions/moonbase"; 16 + import { NodeEventType } from "@moonlight-mod/types/core/event"; 16 17 import { getConfigOption, setConfigOption } from "@moonlight-mod/core/util/config"; 17 18 import diff from "microdiff"; 18 19 ··· 78 79 }; 79 80 } 80 81 82 + // This is async but we're calling it without 81 83 this.checkUpdates(); 84 + 85 + // Update our state if another extension edited the config programatically 86 + moonlightNode.events.addEventListener(NodeEventType.ConfigSaved, async (config) => { 87 + if (!this.submitting) { 88 + this.config = this.clone(config); 89 + await this.processConfigChanged(); 90 + this.emitChange(); 91 + } 92 + }); 82 93 } 83 94 84 95 async checkUpdates() { ··· 499 510 return returnedAdvice; 500 511 } 501 512 502 - writeConfig() { 503 - this.submitting = true; 504 - this.restartAdvice = this.#computeRestartAdvice(); 505 - const modifiedRepos = diff(this.savedConfig.repositories, this.config.repositories); 513 + async writeConfig() { 514 + try { 515 + this.submitting = true; 516 + await moonlightNode.writeConfig(this.config); 517 + await this.processConfigChanged(); 518 + } finally { 519 + this.submitting = false; 520 + this.emitChange(); 521 + } 522 + } 506 523 507 - moonlightNode.writeConfig(this.config); 524 + private async processConfigChanged() { 508 525 this.savedConfig = this.clone(this.config); 509 - 510 - this.submitting = false; 526 + this.restartAdvice = this.#computeRestartAdvice(); 511 527 this.modified = false; 512 - this.emitChange(); 513 528 514 - if (modifiedRepos.length !== 0) this.checkUpdates(); 529 + const modifiedRepos = diff(this.savedConfig.repositories, this.config.repositories); 530 + if (modifiedRepos.length !== 0) await this.checkUpdates(); 515 531 } 516 532 517 533 reset() {