MCPcopy
hub / github.com/compiler-explorer/compiler-explorer / findConfig

Function findConfig

static/main.ts:311–389  ·  view source on GitHub ↗
(
    defaultConfig: GoldenLayoutConfig,
    options: CompilerExplorerOptions,
    defaultLangId: string,
)

Source from the content-addressed store, hash-verified

309}
310
311function findConfig(
312 defaultConfig: GoldenLayoutConfig,
313 options: CompilerExplorerOptions,
314 defaultLangId: string,
315): GoldenLayoutConfig {
316 let config: any;
317 if (!options.embedded) {
318 if (options.slides) {
319 const presentation = new Presentation(unwrap(window.compilerExplorerOptions.slides).length);
320 const currentSlide = presentation.currentSlide;
321 if (currentSlide < options.slides.length) {
322 config = options.slides[currentSlide];
323 } else {
324 presentation.currentSlide = 0;
325 config = options.slides[0];
326 }
327 if (
328 isMobileViewer() &&
329 window.compilerExplorerOptions.slides &&
330 window.compilerExplorerOptions.slides.length > 1
331 ) {
332 $('#share').remove();
333 $('.ui-presentation-control').removeClass('d-none');
334 $('.ui-presentation-first').on('click', presentation.first.bind(presentation));
335 $('.ui-presentation-prev').on('click', presentation.previous.bind(presentation));
336 $('.ui-presentation-next').on('click', presentation.next.bind(presentation));
337 }
338 } else {
339 if (options.config) {
340 config = options.config;
341 } else {
342 try {
343 config = deserialiseState(window.location.hash.substring(1));
344 } catch {
345 // #3518 Alert the user that the url is invalid
346 const alertSystem = new Alert();
347 alertSystem.alert(
348 'Decode Error',
349 'An error was encountered while decoding the URL, the last locally saved configuration will ' +
350 "be used if present.<br/><br/>Make sure the URL you're using hasn't been truncated, " +
351 'otherwise if you believe your URL is valid please let us know on ' +
352 '<a href="https://github.com/compiler-explorer/compiler-explorer/issues">our github</a>.',
353 {isError: true},
354 );
355 }
356 }
357
358 if (config) {
359 // replace anything in the default config with that from the hash
360 config = _.extend(defaultConfig, config);
361 }
362 if (!config) {
363 const savedState = sessionThenLocalStorage.get('gl', null);
364 if (savedState) config = JSON.parse(savedState);
365 }
366 if (!config?.content || config.content?.length === 0) {
367 config = defaultConfig;
368 }

Callers 1

startFunction · 0.85

Calls 11

alertMethod · 0.95
configFromEmbeddedFunction · 0.85
fixBugsInConfigFunction · 0.85
isMobileViewerFunction · 0.70
deserialiseStateFunction · 0.70
removeMethod · 0.65
getMethod · 0.65
unwrapFunction · 0.50
onMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected