mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Refactoring
This commit is contained in:
@@ -30,7 +30,6 @@ function openBrowserSWPreviewDB() {
|
||||
|
||||
request.onsuccess = () => {
|
||||
const db = request.result;
|
||||
console.log('[ServiceWorker] Preview database opened successfully');
|
||||
resolve(db);
|
||||
};
|
||||
|
||||
|
@@ -10,6 +10,7 @@ import './UI/icomoon-font.css'; // Styles for Icomoon font.
|
||||
import browserResourceSources from './ResourcesList/BrowserResourceSources';
|
||||
import browserResourceExternalEditors from './ResourcesList/BrowserResourceExternalEditors';
|
||||
import BrowserSWPreviewLauncher from './ExportAndShare/BrowserExporters/BrowserSWPreviewLauncher';
|
||||
import BrowserS3PreviewLauncher from './ExportAndShare/BrowserExporters/BrowserS3PreviewLauncher';
|
||||
import {
|
||||
browserAutomatedExporters,
|
||||
browserManualExporters,
|
||||
@@ -19,6 +20,7 @@ import makeExtensionsLoader from './JsExtensionsLoader/BrowserJsExtensionsLoader
|
||||
import ObjectsEditorService from './ObjectEditor/ObjectsEditorService';
|
||||
import ObjectsRenderingService from './ObjectsRendering/ObjectsRenderingService';
|
||||
import { makeBrowserSWEventsFunctionCodeWriter } from './EventsFunctionsExtensionsLoader/CodeWriters/BrowserSWEventsFunctionCodeWriter';
|
||||
import { makeBrowserS3EventsFunctionCodeWriter } from './EventsFunctionsExtensionsLoader/CodeWriters/BrowserS3EventsFunctionCodeWriter';
|
||||
import Providers from './MainFrame/Providers';
|
||||
import ProjectStorageProviders from './ProjectsStorage/ProjectStorageProviders';
|
||||
import UrlStorageProvider from './ProjectsStorage/UrlStorageProvider';
|
||||
@@ -30,6 +32,7 @@ import BrowserResourceFetcher from './ProjectsStorage/ResourceFetcher/BrowserRes
|
||||
import BrowserEventsFunctionsExtensionOpener from './EventsFunctionsExtensionsLoader/Storage/BrowserEventsFunctionsExtensionOpener';
|
||||
import BrowserEventsFunctionsExtensionWriter from './EventsFunctionsExtensionsLoader/Storage/BrowserEventsFunctionsExtensionWriter';
|
||||
import BrowserLoginProvider from './LoginProvider/BrowserLoginProvider';
|
||||
import { isServiceWorkerSupported } from './ServiceWorkerSetup';
|
||||
|
||||
export const create = (authentication: Authentication) => {
|
||||
Window.setUpContextMenu();
|
||||
@@ -38,12 +41,17 @@ export const create = (authentication: Authentication) => {
|
||||
|
||||
let app = null;
|
||||
const appArguments = Window.getArguments();
|
||||
const canUseBrowserSW = isServiceWorkerSupported();
|
||||
|
||||
app = (
|
||||
<Providers
|
||||
authentication={authentication}
|
||||
disableCheckForUpdates={!!appArguments['disable-update-check']}
|
||||
makeEventsFunctionCodeWriter={makeBrowserSWEventsFunctionCodeWriter}
|
||||
makeEventsFunctionCodeWriter={
|
||||
canUseBrowserSW
|
||||
? makeBrowserSWEventsFunctionCodeWriter
|
||||
: makeBrowserS3EventsFunctionCodeWriter
|
||||
}
|
||||
eventsFunctionsExtensionWriter={BrowserEventsFunctionsExtensionWriter}
|
||||
eventsFunctionsExtensionOpener={BrowserEventsFunctionsExtensionOpener}
|
||||
>
|
||||
@@ -67,9 +75,13 @@ export const create = (authentication: Authentication) => {
|
||||
}) => (
|
||||
<MainFrame
|
||||
i18n={i18n}
|
||||
renderPreviewLauncher={(props, ref) => (
|
||||
<BrowserSWPreviewLauncher {...props} ref={ref} />
|
||||
)}
|
||||
renderPreviewLauncher={(props, ref) =>
|
||||
canUseBrowserSW ? (
|
||||
<BrowserSWPreviewLauncher {...props} ref={ref} />
|
||||
) : (
|
||||
<BrowserS3PreviewLauncher {...props} ref={ref} />
|
||||
)
|
||||
}
|
||||
renderShareDialog={props => (
|
||||
<ShareDialog
|
||||
project={props.project}
|
||||
@@ -104,7 +116,9 @@ export const create = (authentication: Authentication) => {
|
||||
filterExamples: !Window.isDev(),
|
||||
})}
|
||||
initialFileMetadataToOpen={initialFileMetadataToOpen}
|
||||
initialExampleSlugToOpen={appArguments['create-from-example'] || null}
|
||||
initialExampleSlugToOpen={
|
||||
appArguments['create-from-example'] || null
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</ProjectStorageProviders>
|
||||
|
@@ -23,8 +23,7 @@ const flushBatchedWrites = debounce(async () => {
|
||||
console.info(
|
||||
`[BrowserSWEventsFunctionCodeWriter] Storing a batch of ${
|
||||
writes.length
|
||||
} extension generated files in IndexedDB...`,
|
||||
writes.map(w => w.path)
|
||||
} extension generated files in IndexedDB...`
|
||||
);
|
||||
|
||||
batchedWrites = [];
|
||||
|
@@ -3,7 +3,7 @@ import {
|
||||
type PreviewDebuggerServerCallbacks,
|
||||
type PreviewDebuggerServer,
|
||||
type DebuggerId,
|
||||
} from '../../PreviewLauncher.flow';
|
||||
} from '../PreviewLauncher.flow';
|
||||
|
||||
let debuggerServerState: 'started' | 'stopped' = 'stopped';
|
||||
const callbacksList: Array<PreviewDebuggerServerCallbacks> = [];
|
@@ -2,10 +2,10 @@
|
||||
import { Trans } from '@lingui/macro';
|
||||
import { I18n } from '@lingui/react';
|
||||
import React, { Component } from 'react';
|
||||
import Dialog from '../../../UI/Dialog';
|
||||
import FlatButton from '../../../UI/FlatButton';
|
||||
import { Column, Line } from '../../../UI/Grid';
|
||||
import Text from '../../../UI/Text';
|
||||
import Dialog from '../../UI/Dialog';
|
||||
import FlatButton from '../../UI/FlatButton';
|
||||
import { Column, Line } from '../../UI/Grid';
|
||||
import Text from '../../UI/Text';
|
||||
|
||||
type Props = {|
|
||||
error: Error,
|
@@ -1,6 +1,6 @@
|
||||
// @flow
|
||||
import * as React from 'react';
|
||||
import BrowserPreviewErrorDialog from './BrowserPreviewErrorDialog';
|
||||
import BrowserPreviewErrorDialog from '../BrowserPreviewErrorDialog';
|
||||
import BrowserS3FileSystem from '../BrowserS3FileSystem';
|
||||
import { findGDJS } from '../../../GameEngineFinder/BrowserS3GDJSFinder';
|
||||
import assignIn from 'lodash/assignIn';
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
browserPreviewDebuggerServer,
|
||||
getExistingPreviewWindowForDebuggerId,
|
||||
registerNewPreviewWindow,
|
||||
} from './BrowserPreviewDebuggerServer';
|
||||
} from '../BrowserPreviewDebuggerServer';
|
||||
import Window from '../../../Utils/Window';
|
||||
import { displayBlackLoadingScreenOrThrow } from '../../../Utils/BrowserExternalWindowUtils';
|
||||
import { getGDevelopResourceJwtToken } from '../../../Utils/GDevelopServices/Project';
|
||||
|
@@ -1,6 +1,6 @@
|
||||
// @flow
|
||||
import * as React from 'react';
|
||||
import BrowserPreviewErrorDialog from '../BrowserS3PreviewLauncher/BrowserPreviewErrorDialog';
|
||||
import BrowserPreviewErrorDialog from '../BrowserPreviewErrorDialog';
|
||||
import BrowserSWFileSystem from '../BrowserSWFileSystem';
|
||||
import { findGDJS } from '../../../GameEngineFinder/BrowserS3GDJSFinder';
|
||||
import assignIn from 'lodash/assignIn';
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
import {
|
||||
browserPreviewDebuggerServer,
|
||||
registerNewPreviewWindow,
|
||||
} from '../BrowserS3PreviewLauncher/BrowserPreviewDebuggerServer';
|
||||
} from '../BrowserPreviewDebuggerServer';
|
||||
import Window from '../../../Utils/Window';
|
||||
import { displayBlackLoadingScreenOrThrow } from '../../../Utils/BrowserExternalWindowUtils';
|
||||
import { getGDevelopResourceJwtToken } from '../../../Utils/GDevelopServices/Project';
|
||||
|
@@ -1,60 +1,73 @@
|
||||
// @flow
|
||||
import optionalRequire from './Utils/OptionalRequire';
|
||||
import { isNativeMobileApp } from './Utils/Platform';
|
||||
|
||||
const PUBLIC_URL: string = process.env.PUBLIC_URL || '';
|
||||
const isDev = process.env.NODE_ENV !== 'production';
|
||||
|
||||
export function registerServiceWorker() {
|
||||
const enabled = true;
|
||||
const serviceWorker = navigator.serviceWorker;
|
||||
const electron = optionalRequire('electron');
|
||||
const serviceWorker = navigator.serviceWorker;
|
||||
|
||||
if (enabled && serviceWorker) {
|
||||
window.addEventListener('load', () => {
|
||||
// Use a cache-buster for development so that the service worker is
|
||||
// always reloaded when the app is reloaded.
|
||||
const swUrl = isDev
|
||||
? `${PUBLIC_URL}/service-worker.js?dev=${Date.now()}`
|
||||
: `${PUBLIC_URL}/service-worker.js`;
|
||||
|
||||
serviceWorker
|
||||
.register(swUrl)
|
||||
.then(registration => {
|
||||
registration.onupdatefound = () => {
|
||||
const installingWorker = registration.installing;
|
||||
if (installingWorker == null) {
|
||||
return;
|
||||
}
|
||||
installingWorker.onstatechange = () => {
|
||||
if (installingWorker.state === 'installed') {
|
||||
const alreadyHasAServiceWorker = !!serviceWorker.controller;
|
||||
if (alreadyHasAServiceWorker) {
|
||||
// At this point, the updated precached content has been fetched,
|
||||
// but the previous service worker will still serve the older
|
||||
// content until all client tabs are closed.
|
||||
console.log(
|
||||
'New content is available and will be used when all tabs for this page are closed.'
|
||||
);
|
||||
} else {
|
||||
// Service worker has been installed for the first time.
|
||||
console.log('Content is cached for offline use.');
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error during service worker registration:', error);
|
||||
});
|
||||
|
||||
if (isDev) {
|
||||
serviceWorker.ready.then(registration => {
|
||||
// Forces a check right now for a newer service worker script in development.
|
||||
// If there is one, it will be installed (see the service worker script to verify how in development
|
||||
// a new service worker script does a `self.skipWaiting()` and `self.clients.claim()`).
|
||||
registration.update();
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log('Service Worker disabled - TODO: fallback to S3?');
|
||||
}
|
||||
export function isServiceWorkerSupported() {
|
||||
return !!serviceWorker;
|
||||
}
|
||||
|
||||
export function registerServiceWorker() {
|
||||
if (isNativeMobileApp() || !!electron) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!serviceWorker) {
|
||||
console.warn(
|
||||
'Service Worker not supported on this deployment (probably: not HTTPS and not localhost).'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
// Use a cache-buster for development so that the service worker is
|
||||
// always reloaded when the app is reloaded.
|
||||
const swUrl = isDev
|
||||
? `${PUBLIC_URL}/service-worker.js?dev=${Date.now()}`
|
||||
: `${PUBLIC_URL}/service-worker.js`;
|
||||
|
||||
serviceWorker
|
||||
.register(swUrl)
|
||||
.then(registration => {
|
||||
registration.onupdatefound = () => {
|
||||
const installingWorker = registration.installing;
|
||||
if (installingWorker == null) {
|
||||
return;
|
||||
}
|
||||
installingWorker.onstatechange = () => {
|
||||
if (installingWorker.state === 'installed') {
|
||||
const alreadyHasAServiceWorker = !!serviceWorker.controller;
|
||||
if (alreadyHasAServiceWorker) {
|
||||
// At this point, the updated precached content has been fetched,
|
||||
// but the previous service worker will still serve the older
|
||||
// content until all client tabs are closed.
|
||||
console.log(
|
||||
'New content is available and will be used when all tabs for this page are closed.'
|
||||
);
|
||||
} else {
|
||||
// Service worker has been installed for the first time.
|
||||
console.log('Content is cached for offline use.');
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error during service worker registration:', error);
|
||||
});
|
||||
|
||||
if (isDev) {
|
||||
serviceWorker.ready.then(registration => {
|
||||
// Forces a check right now for a newer service worker script in development.
|
||||
// If there is one, it will be installed (see the service worker script to verify how in development
|
||||
// a new service worker script does a `self.skipWaiting()` and `self.clients.claim()`).
|
||||
registration.update();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@@ -79,7 +79,7 @@ import EditorMosaicPlayground from './EditorMosaicPlayground';
|
||||
import EditorNavigator from '../UI/EditorMosaic/EditorNavigator';
|
||||
import PropertiesEditor from '../PropertiesEditor';
|
||||
import { OpenConfirmDialog } from '../ProjectsStorage/OpenConfirmDialog';
|
||||
import BrowserPreviewErrorDialog from '../ExportAndShare/BrowserExporters/BrowserS3PreviewLauncher/BrowserPreviewErrorDialog';
|
||||
import BrowserPreviewErrorDialog from '../ExportAndShare/BrowserExporters/BrowserPreviewErrorDialog';
|
||||
import RaisedButton from '../UI/RaisedButton';
|
||||
import Text from '../UI/Text';
|
||||
import IconButton from '../UI/IconButton';
|
||||
|
Reference in New Issue
Block a user