Skip to content

Commit 615e5e2

Browse files
committed
fix: Update ext contribs when state changes
refactor: Remove outdated devScripts contribs
1 parent c084b5d commit 615e5e2

11 files changed

Lines changed: 52 additions & 61 deletions

File tree

extensions/core-manager/src/components/ExtensionSubsection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export function ExtensionSubsection() {
6161
<ExtensionRow
6262
ext={ext}
6363
index={index}
64-
disabled={!disabledExtensions.includes(ext.id)}/>
64+
disabled={disabledExtensions.includes(ext.id)}/>
6565
);
6666
}) : <div>Loading...</div>}
6767
</div>

src/back/extensions/ApiImplementation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ export function createApiFactory(extId: string, extManifest: IExtensionManifest,
468468
return [...state.loadedCurations];
469469
},
470470
async getCurationTemplates(): Promise<CurationTemplate[]> {
471-
const contribs = await state.extensionsService.getContributions('curationTemplates');
471+
const contribs = await state.extensionsService.getEnabledContributions('curationTemplates', state.preferences.disabledExtensions);
472472
return contribs.reduce<CurationTemplate[]>((prev, cur) => prev.concat(cur.value), []);
473473
},
474474
getCuration: (folder: string) => {

src/back/extensions/ExtensionService.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ export class ExtensionService {
9797
});
9898
}
9999

100+
/**
101+
* Returns a list of all extension contributions of a particular type filtered for enabled extensions
102+
*
103+
* @param key Type of contribution to get
104+
* @param disabledExts Array of disabled extension IDs
105+
* @returns All of this contribution type from all enabled and loaded extensions
106+
*/
107+
getEnabledContributions<T extends keyof Contributions>(key: T, disabled: string[]): Promise<ExtensionContribution<T>[]> {
108+
return this.getContributions(key)
109+
.then((contribs) => {
110+
return contribs.filter(c => !disabled.includes(c.extId));
111+
});
112+
}
113+
100114
/** Build a search tree mapping extensions and their paths */
101115
public async getExtensionPathIndex(): Promise<TernarySearchTree<string, IExtension>> {
102116
return this.installedExtensionsReady.wait().then(() => {

src/back/extensions/ExtensionsScanner.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { EditCurationMeta } from '@shared/curate/OLD_types';
2+
import { ExtensionType, IExtension } from '@shared/extensions/interfaces';
23
import { readJsonFile } from '@shared/Util';
34
import * as Coerce from '@shared/utils/Coerce';
45
import { IObjectParserProp, ObjectParser } from '@shared/utils/ObjectParser';
6+
import { AppConfigData, Application, ButtonContext, ContextButton, Contributions, CurationTemplate, ExtConfiguration, ExtConfigurationProp, ExtTheme, IExtensionManifest, ILogoSet, ModuleContribution } from 'flashpoint-launcher';
57
import * as fs from 'node:fs';
68
import * as path from 'node:path';
7-
import { ExtensionType, IExtension } from '@shared/extensions/interfaces';
8-
import { AppConfigData, Application, ButtonContext, ContextButton, Contributions, CurationTemplate, DevScript, ExtConfiguration, ExtConfigurationProp, ExtTheme, IExtensionManifest, ILogoSet, ModuleContribution } from 'flashpoint-launcher';
99

1010
const { str, num } = Coerce;
1111
const fsPromises = fs.promises;
@@ -179,7 +179,6 @@ function parseContributions(parser: IObjectParserProp<Contributions>): Contribut
179179
const contributes: Contributions = {
180180
logoSets: [],
181181
themes: [],
182-
devScripts: [],
183182
contextButtons: [],
184183
applications: [],
185184
configuration: [],
@@ -189,7 +188,6 @@ function parseContributions(parser: IObjectParserProp<Contributions>): Contribut
189188
};
190189
parser.prop('logoSets', true).array(item => contributes.logoSets.push(parseLogoSet(item)));
191190
parser.prop('themes', true).array(item => contributes.themes.push(parseTheme(item)));
192-
parser.prop('devScripts', true).array(item => contributes.devScripts.push(parseDevScript(item)));
193191
parser.prop('contextButtons', true).array(item => contributes.contextButtons.push(parseContextButton(item)));
194192
parser.prop('applications', true).array(item => contributes.applications.push(parseApplication(item)));
195193
parser.prop('configuration', true).array(item => contributes.configuration.push(parseConfiguration(item)));
@@ -222,18 +220,6 @@ function parseTheme(parser: IObjectParserProp<ExtTheme>): ExtTheme {
222220
return theme;
223221
}
224222

225-
function parseDevScript(parser: IObjectParserProp<DevScript>): DevScript {
226-
const devScript: DevScript = {
227-
name: '',
228-
description: '',
229-
command: ''
230-
};
231-
parser.prop('name', v => devScript.name = str(v));
232-
parser.prop('description', v => devScript.description = str(v));
233-
parser.prop('command', v => devScript.command = str(v));
234-
return devScript;
235-
}
236-
237223
function parseContextButton(parser: IObjectParserProp<ContextButton>): ContextButton {
238224
const contextButton: ContextButton = {
239225
context: 'game',

src/back/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ async function prepForInit(initConfig: BackInitArgs): Promise<void> {
683683
} catch (error: any) {
684684
log.error('Launcher', `Error loading default Themes folder\n${error.message}`);
685685
}
686-
const themeContributions = await state.extensionsService.getContributions('themes');
686+
const themeContributions = await state.extensionsService.getEnabledContributions('themes', state.preferences.disabledExtensions);
687687
for (const c of themeContributions) {
688688
for (const theme of c.value) {
689689
const ext = await state.extensionsService.getExtension(c.extId);
@@ -1126,7 +1126,7 @@ async function initialize() {
11261126
await state.extensionsService.getExtensions()
11271127
.then(async (exts) => {
11281128
// Set any ext config defaults
1129-
for (const contrib of (await state.extensionsService.getContributions('configuration'))) {
1129+
for (const contrib of (await state.extensionsService.getEnabledContributions('configuration', state.preferences.disabledExtensions))) {
11301130
for (const extConfig of contrib.value) {
11311131
for (const key in extConfig.properties) {
11321132
// Value not set, use default
@@ -1185,7 +1185,7 @@ async function initialize() {
11851185
}
11861186

11871187
// Init Ext Logo Sets
1188-
await state.extensionsService.getContributions('logoSets')
1188+
await state.extensionsService.getEnabledContributions('logoSets', state.preferences.disabledExtensions)
11891189
.then(async (logoSetContributions) => {
11901190
for (const c of logoSetContributions) {
11911191
for (const logoSet of c.value) {

src/back/responses.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,9 @@ export function registerRequestCallbacks(state: BackState, init: () => Promise<v
188188

189189
state.socketServer.register(BackIn.GET_RENDERER_EXTENSION_INFO, async () => {
190190
return {
191-
devScripts: await state.extensionsService.getContributions('devScripts'),
192-
contextButtons: await state.extensionsService.getContributions('contextButtons'),
193-
curationTemplates: await state.extensionsService.getContributions('curationTemplates'),
194-
extConfigs: await state.extensionsService.getContributions('configuration'),
191+
contextButtons: await state.extensionsService.getEnabledContributions('contextButtons', state.preferences.disabledExtensions),
192+
curationTemplates: await state.extensionsService.getEnabledContributions('curationTemplates', state.preferences.disabledExtensions),
193+
extConfigs: await state.extensionsService.getEnabledContributions('configuration', state.preferences.disabledExtensions),
195194
extConfig: state.extConfig,
196195
extensions: (await state.extensionsService.getExtensions()).map(e => {
197196
return {
@@ -1439,23 +1438,24 @@ export function registerRequestCallbacks(state: BackState, init: () => Promise<v
14391438
catch (error: any) { log.error('Launcher', error); }
14401439
});
14411440

1442-
state.socketServer.register(BackIn.SET_EXTENSION_ENABLED, async (event, extId, newState) => {
1441+
state.socketServer.register(BackIn.SET_EXTENSION_ENABLED, async (event, extId, enable) => {
14431442
const isEnabled = !state.preferences.disabledExtensions.includes(extId);
1444-
if (newState !== isEnabled) {
1445-
if (newState) {
1446-
// Enable ext
1447-
state.preferences.disabledExtensions = state.preferences.disabledExtensions.filter(c => c !== extId);
1448-
await state.extensionsService.loadExtension(extId);
1449-
} else {
1450-
// Disable ext
1451-
state.preferences.disabledExtensions.push(extId);
1452-
await state.extensionsService.unloadExtension(extId);
1453-
}
1443+
if (enable !== isEnabled && enable) {
1444+
// Enable ext
1445+
state.preferences.disabledExtensions = state.preferences.disabledExtensions.filter(c => c !== extId);
1446+
await state.extensionsService.loadExtension(extId);
1447+
state.prefsQueue.push(() => {
1448+
PreferencesFile.saveFile(path.join(state.config.flashpointPath, PREFERENCES_FILENAME), state.preferences, state);
1449+
});
1450+
} else if (enable !== isEnabled && !enable) {
1451+
// Disable ext
1452+
state.preferences.disabledExtensions.push(extId);
1453+
await state.extensionsService.unloadExtension(extId);
14541454
state.prefsQueue.push(() => {
14551455
PreferencesFile.saveFile(path.join(state.config.flashpointPath, PREFERENCES_FILENAME), state.preferences, state);
14561456
});
14571457
}
1458-
state.socketServer.broadcast(BackOut.UPDATE_EXTENSION_STATE, extId, newState);
1458+
state.socketServer.broadcast(BackOut.UPDATE_EXTENSION_STATE, extId, enable);
14591459
});
14601460

14611461
state.socketServer.register(BackIn.UPDATE_PREFERENCES, async (event, data) => {
@@ -2731,7 +2731,7 @@ async function runCommand(state: BackState, command: string, args: any[] = []):
27312731
* @param state Current back state
27322732
*/
27332733
export async function getProviders(state: BackState): Promise<AppProvider[]> {
2734-
return state.extensionsService.getContributions('applications')
2734+
return state.extensionsService.getEnabledContributions('applications', state.preferences.disabledExtensions)
27352735
.then(contributions => {
27362736
return contributions.map(c => {
27372737
const apps = c.value;

src/renderer/components/pages/ConfigPage.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -517,13 +517,6 @@ export function ConfigPage() {
517517

518518
const shortContribs = [];
519519
if (ext.contributes) {
520-
if (ext.contributes.devScripts && ext.contributes.devScripts.length > 0) {
521-
shortContribs.push(
522-
<div key='devScripts'>
523-
{`${ext.contributes.devScripts.length} ${strings.extDevScripts}`}
524-
</div>
525-
);
526-
}
527520
if (ext.contributes.themes && ext.contributes.themes.length > 0) {
528521
shortContribs.push(
529522
<div key='themes'>

src/renderer/store/main/slice.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ export type MainState = {
8484
metaEditExporterOpen: boolean;
8585
/** ID of the game used in the "Meta Edit Popup". */
8686
metaEditExporterGameId: string;
87-
/** Scripts for the Developer Page */
88-
devScripts: ExtensionContribution<'devScripts'>[];
8987
/** Context buttons added by extensions */
9088
contextButtons: ExtensionContribution<'contextButtons'>[];
9189
/** Curation Templates added by extensions */
@@ -242,7 +240,6 @@ const initialState: MainState = {
242240
extensions: [],
243241
extConfig: {},
244242
extConfigs: [],
245-
devScripts: [],
246243
contextButtons: [],
247244
curationTemplates: [],
248245
services: [],

src/renderer/store/preferences/middleware.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { isAnyOf, PayloadAction } from '@reduxjs/toolkit';
22
import { BackIn } from '@shared/back/types';
33
import { debounce } from '@shared/utils/debounce';
44
import { startAppListening } from '../listenerMiddleware';
5-
import store from '../store';
6-
import { newAppPathOverride, newTagFilterGroup, removeAppPathOverride, removeTagFilterGroup, setHomePageBoxOpen, setLogoSet, setUseCustomViews, setUseStoredViews, toggleExcludedLibrary, toggleNativePlatform, updateAppPathOverride, updatePreferences, updateTagFilterGroup } from './slice';
5+
import { incrementLogoVersion, setMainState } from '../main/slice';
76
import { createViews } from '../search/slice';
8-
import { incrementLogoVersion } from '../main/slice';
7+
import store from '../store';
8+
import { newAppPathOverride, newTagFilterGroup, removeAppPathOverride, removeTagFilterGroup, setExtState, setHomePageBoxOpen, setLogoSet, setUseCustomViews, setUseStoredViews, toggleExcludedLibrary, toggleNativePlatform, updateAppPathOverride, updatePreferences, updateTagFilterGroup } from './slice';
99

1010
export function addPreferencesMiddleware() {
1111
startAppListening({
@@ -15,6 +15,17 @@ export function addPreferencesMiddleware() {
1515
}
1616
});
1717

18+
startAppListening({
19+
matcher: isAnyOf(setExtState),
20+
effect: async () => {
21+
// Refetch extension contributions
22+
window.Shared.back.request(BackIn.GET_RENDERER_EXTENSION_INFO)
23+
.then((data) => {
24+
store.dispatch(setMainState(data));
25+
});
26+
}
27+
});
28+
1829
startAppListening({
1930
matcher: isAnyOf(setUseCustomViews),
2031
effect: async (action: PayloadAction<boolean>, listenerApi) => {

src/shared/back/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,6 @@ export type GetLoggerInitDataResponse = {
645645

646646
export type GetRendererExtDataResponse = {
647647
extensions: IExtensionDescription[];
648-
devScripts: ExtensionContribution<'devScripts'>[];
649648
contextButtons: ExtensionContribution<'contextButtons'>[];
650649
curationTemplates: ExtensionContribution<'curationTemplates'>[];
651650
extConfigs: ExtensionContribution<'configuration'>[];

0 commit comments

Comments
 (0)