MCPcopy Create free account
hub / github.com/FlashpointProject/launcher / createApiFactory

Function createApiFactory

src/back/extensions/ApiImplementation.ts:57–697  ·  view source on GitHub ↗
(extId: string, extManifest: IExtensionManifest, addExtLog: (log: ILogEntry) => void, version: string, state: BackState, extPath?: string)

Source from the content-addressed store, hash-verified

55 * @returns API Implementation specific to the caller
56 */
57export function createApiFactory(extId: string, extManifest: IExtensionManifest, addExtLog: (log: ILogEntry) => void, version: string, state: BackState, extPath?: string): typeof flashpoint {
58 const { registry, apiEmitters } = state;
59
60 const getPreferences = () => state.preferences;
61 const extOverwritePreferenceData = async (
62 data: flashpoint.DeepPartial<flashpoint.AppPreferencesData>,
63 onError?: (error: string) => void
64 ) => {
65 overwritePreferenceData(state.preferences, data, onError);
66 await PreferencesFile.saveFile(path.join(state.configFolder, PREFERENCES_FILENAME), state.preferences, state);
67 state.socketServer.broadcast(BackOut.UPDATE_PREFERENCES_RESPONSE, state.preferences);
68 return state.preferences;
69 };
70
71 const unloadExtension = () => state.extensionsService.unloadExtension(extId);
72
73 const reloadExtension = () => {
74 setTimeout(() => {
75 state.extensionsService.unloadExtension(extId).then(() => {
76 console.log(`Back - attempting reload for ${extId}`);
77 state.extensionsService.loadExtension(extId);
78 });
79 }, 10);
80 };
81
82 const getExtensionFileURL = (filePath: string): string => {
83 return `http://localhost:${state.fileServerPort}/extdata/${extId}/${filePath}`;
84 };
85
86 const unzipFile = (filePath: string, outDir: string, opts?: flashpoint.ZipExtractOptions): Promise<void> => {
87 return new Promise<void>((resolve, reject) => {
88 const { onProgress, onData } = opts || {};
89 const readable = extractFull(filePath, outDir, { $bin: pathTo7zBack(state.isDev, state.exePath), $progress: onProgress !== undefined });
90 readable.on('end', () => {
91 resolve();
92 });
93 if (onProgress) { readable.on('progress', onProgress); }
94 if (onData) { readable.on('data', onData); }
95 readable.on('error', (err) => {
96 reject(err);
97 });
98 });
99 };
100
101 const getExtConfigValue = (key: string): any => {
102 return state.extConfig[key];
103 };
104
105 const setExtConfigValue = async (key: string, value: any): Promise<void> => {
106 state.extConfig[key] = value;
107 await ExtConfigFile.saveFile(path.join(state.config.flashpointPath, EXT_CONFIG_FILENAME), state.extConfig);
108 state.socketServer.broadcast(BackOut.UPDATE_EXT_CONFIG_DATA, state.extConfig);
109 };
110
111 const focusWindow = () => {
112 state.socketServer.broadcast(BackOut.FOCUS_WINDOW);
113 };
114

Callers

nothing calls this directly

Calls 15

newExtLogFunction · 0.90
newDisposableFunction · 0.90
findPlaylistFunction · 0.90
findPlaylistByNameFunction · 0.90
filterPlaylistsFunction · 0.90
updatePlaylistFunction · 0.90
deletePlaylistFunction · 0.90
addPlaylistGameFunction · 0.90
getPlaylistGameFunction · 0.90
deletePlaylistGameFunction · 0.90
savePlaylistGameFunction · 0.90
downloadGameDataFunction · 0.90

Tested by

no test coverage detected