this repo has no description

Merge pull request #239 from moonlight-mod/notnite/moonbase-config-fixes

Moonbase config fixes

Changed files
+34 -14
packages
core-extensions
src
moonbase
+2 -2
packages/core-extensions/src/moonbase/webpackModules/crashScreen.tsx
···
}
function ExtensionDisableCard({ ext }: { ext: DetectedExtension }) {
-
function disableWithDependents() {
+
async function disableWithDependents() {
const disable = new Set<string>();
disable.add(ext.id);
for (const [id, dependencies] of moonlightNode.processedExtensions.dependencyGraph) {
···
msg += "?";
if (confirm(msg)) {
-
moonlightNode.writeConfig(config);
+
await moonlightNode.writeConfig(config);
window.location.reload();
}
}
+2 -2
packages/core-extensions/src/moonbase/webpackModules/settings.tsx
···
onReset={() => {
MoonbaseSettingsStore.reset();
}}
-
onSave={() => {
-
MoonbaseSettingsStore.writeConfig();
+
onSave={async () => {
+
await MoonbaseSettingsStore.writeConfig();
}}
/>
);
+30 -10
packages/core-extensions/src/moonbase/webpackModules/stores.ts
···
import { mainRepo } from "@moonlight-mod/types/constants";
import { checkExtensionCompat, ExtensionCompat } from "@moonlight-mod/core/extension/loader";
import { CustomComponent } from "@moonlight-mod/types/coreExtensions/moonbase";
+
import { NodeEventType } from "@moonlight-mod/types/core/event";
import { getConfigOption, setConfigOption } from "@moonlight-mod/core/util/config";
import diff from "microdiff";
···
};
}
+
// This is async but we're calling it without
this.checkUpdates();
+
+
// Update our state if another extension edited the config programatically
+
moonlightNode.events.addEventListener(NodeEventType.ConfigSaved, (config) => {
+
if (!this.submitting) {
+
this.config = this.clone(config);
+
// NOTE: This is also async but we're calling it without
+
this.processConfigChanged();
+
}
+
});
}
async checkUpdates() {
···
let val = this.config.extensions[ext.id];
if (val == null) {
-
this.config.extensions[ext.id] = { enabled };
+
this.config.extensions[ext.id] = enabled;
this.modified = this.isModified();
this.emitChange();
return;
···
return returnedAdvice;
}
-
writeConfig() {
-
this.submitting = true;
-
this.restartAdvice = this.#computeRestartAdvice();
-
const modifiedRepos = diff(this.savedConfig.repositories, this.config.repositories);
+
async writeConfig() {
+
try {
+
this.submitting = true;
+
this.emitChange();
-
moonlightNode.writeConfig(this.config);
-
this.savedConfig = this.clone(this.config);
+
await moonlightNode.writeConfig(this.config);
+
await this.processConfigChanged();
+
} finally {
+
this.submitting = false;
+
this.emitChange();
+
}
+
}
-
this.submitting = false;
+
private async processConfigChanged() {
+
this.savedConfig = this.clone(this.config);
+
this.restartAdvice = this.#computeRestartAdvice();
this.modified = false;
-
this.emitChange();
-
if (modifiedRepos.length !== 0) this.checkUpdates();
+
const modifiedRepos = diff(this.savedConfig.repositories, this.config.repositories);
+
if (modifiedRepos.length !== 0) await this.checkUpdates();
+
+
this.emitChange();
}
reset() {