From 32482d87dc6a8e121df84c4bb2a72dc1607d580e Mon Sep 17 00:00:00 2001 From: Vitaly Date: Mon, 4 Sep 2023 10:47:15 +0300 Subject: [PATCH] add a way to disable prompts on load --- src/browserfs.js | 5 +++-- src/index.js | 1 - src/loadSave.ts | 6 ++++-- src/optionsStorage.js | 2 ++ 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/browserfs.js b/src/browserfs.js index 44c29142..5ea250a1 100644 --- a/src/browserfs.js +++ b/src/browserfs.js @@ -3,6 +3,7 @@ import { fsState, loadSave } from './loadSave' import { oneOf } from '@zardoy/utils' import JSZip from 'jszip' import { join } from 'path' +import { options } from './optionsStorage' const { promisify } = require('util') const browserfs = require('browserfs') @@ -124,10 +125,10 @@ export const openWorldDirectory = async (/** @type {FileSystemDirectoryHandle?} } const directoryHandle = _directoryHandle - const requestResult = SUPPORT_WRITE ? await directoryHandle.requestPermission?.({ mode: 'readwrite' }) : undefined + const requestResult = SUPPORT_WRITE && !options.preferLoadReadonly ? await directoryHandle.requestPermission?.({ mode: 'readwrite' }) : undefined const writeAccess = requestResult === 'granted' - const doContinue = writeAccess || !SUPPORT_WRITE || confirm('Continue in readonly mode?') + const doContinue = writeAccess || !SUPPORT_WRITE || options.disableLoadPrompts || confirm('Continue in readonly mode?') if (!doContinue) return await new Promise(resolve => { browserfs.configure({ diff --git a/src/index.js b/src/index.js index 1bd991b0..550b60d7 100644 --- a/src/index.js +++ b/src/index.js @@ -384,7 +384,6 @@ async function connect (connectOptions) { setLoadingScreenStatus('Starting local server') window.serverDataChannel ??= {} - window.worldLoaded = false localServer = window.localServer = startLocalServer() // todo need just to call quit if started // loadingScreen.maybeRecoverable = false diff --git a/src/loadSave.ts b/src/loadSave.ts index 3563328d..5ed8b967 100644 --- a/src/loadSave.ts +++ b/src/loadSave.ts @@ -19,6 +19,8 @@ export const fsState = proxy({ const PROPOSE_BACKUP = true export const loadSave = async (root = '/world') => { + const disablePrompts = options.disableLoadPrompts + // todo do it in singleplayer as well for (const key in forceCachedDataPaths) { delete forceCachedDataPaths[key] @@ -50,7 +52,7 @@ export const loadSave = async (root = '/world') => { const qs = new URLSearchParams(window.location.search) version = levelDat.Version?.Name ?? qs.get('version') if (!version) { - const newVersion = prompt(`In 1.8 and before world save doesn\'t contain version info, please enter version you want to use to load the world.\nSupported versions ${supportedVersions.join(', ')}`, '1.8.8') + const newVersion = disablePrompts ? '1.8.8' : prompt(`In 1.8 and before world save doesn\'t contain version info, please enter version you want to use to load the world.\nSupported versions ${supportedVersions.join(', ')}`, '1.8.8') if (!newVersion) return version = newVersion } @@ -89,7 +91,7 @@ export const loadSave = async (root = '/world') => { } - if (warnings.length) { + if (warnings.length && !disablePrompts) { const doContinue = confirm(`Continue with following warnings?\n${warnings.join('\n')}`) if (!doContinue) return } diff --git a/src/optionsStorage.js b/src/optionsStorage.js index 3632c54d..8165140a 100644 --- a/src/optionsStorage.js +++ b/src/optionsStorage.js @@ -20,6 +20,8 @@ const defaultOptions = { numWorkers: 4, localServerOptions: {}, localUsername: 'wanderer', + preferLoadReadonly: false, + disableLoadPrompts: false } export const options = proxy(