forked from PrismarineJS/prismarine-web-client
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config-json): Only either bundle or load from remote (#291)
- Loading branch information
Showing
15 changed files
with
127 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { disabledSettings, options, qsOptions } from './optionsStorage' | ||
import { miscUiState } from './globalState' | ||
import { setLoadingScreenStatus } from './appStatus' | ||
|
||
export type AppConfig = { | ||
// defaultHost?: string | ||
// defaultHostSave?: string | ||
defaultProxy?: string | ||
// defaultProxySave?: string | ||
// defaultVersion?: string | ||
peerJsServer?: string | ||
peerJsServerFallback?: string | ||
promoteServers?: Array<{ ip, description, version? }> | ||
mapsProvider?: string | ||
|
||
appParams?: Record<string, any> // query string params | ||
|
||
defaultSettings?: Record<string, any> | ||
forceSettings?: Record<string, boolean> | ||
// hideSettings?: Record<string, boolean> | ||
allowAutoConnect?: boolean | ||
pauseLinks?: Array<Array<Record<string, any>>> | ||
} | ||
|
||
export const loadAppConfig = (appConfig: AppConfig) => { | ||
if (miscUiState.appConfig) { | ||
Object.assign(miscUiState.appConfig, appConfig) | ||
} else { | ||
miscUiState.appConfig = appConfig | ||
} | ||
|
||
if (appConfig.forceSettings) { | ||
for (const [key, value] of Object.entries(appConfig.forceSettings)) { | ||
if (value) { | ||
disabledSettings.value.add(key) | ||
// since the setting is forced, we need to set it to that value | ||
if (appConfig.defaultSettings?.[key] && !qsOptions[key]) { | ||
options[key] = appConfig.defaultSettings[key] | ||
} | ||
} else { | ||
disabledSettings.value.delete(key) | ||
} | ||
} | ||
} | ||
} | ||
|
||
export const isBundledConfigUsed = !!process.env.INLINED_APP_CONFIG | ||
|
||
if (isBundledConfigUsed) { | ||
loadAppConfig(process.env.INLINED_APP_CONFIG as AppConfig ?? {}) | ||
} else { | ||
void window.fetch('config.json').then(async res => res.json()).then(c => c, (error) => { | ||
// console.warn('Failed to load optional app config.json', error) | ||
// return {} | ||
setLoadingScreenStatus('Failed to load app config.json', true) | ||
}).then((config: AppConfig) => { | ||
loadAppConfig(config) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.