mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Add support for opening a file from command line option or from url "project" option
This commit is contained in:
@@ -50,6 +50,7 @@
|
||||
"react-virtualized": "9.14.1",
|
||||
"slugs": "0.1.3",
|
||||
"source-map-explorer": "^1.4.0",
|
||||
"url-search-params": "^1.0.2",
|
||||
"wait-promise": "0.4.1",
|
||||
"why-did-you-update": "^0.1.1"
|
||||
},
|
||||
|
@@ -121,6 +121,7 @@ type Props = {
|
||||
createDialog?: React.Element<*>,
|
||||
authentification: Authentification,
|
||||
extensionsLoader?: JsExtensionsLoader,
|
||||
initialPathsOrURLsToOpen: ?Array<string>,
|
||||
};
|
||||
|
||||
export default class MainFrame extends React.Component<Props, State> {
|
||||
@@ -159,7 +160,14 @@ export default class MainFrame extends React.Component<Props, State> {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { initialPathsOrURLsToOpen } = this.props;
|
||||
|
||||
this.loadExtensions();
|
||||
if (initialPathsOrURLsToOpen && initialPathsOrURLsToOpen[0]) {
|
||||
this.openFromPathOrURL(initialPathsOrURLsToOpen[0], () =>
|
||||
this.openSceneOrProjectManager()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
loadExtensions = () => {
|
||||
@@ -253,7 +261,7 @@ export default class MainFrame extends React.Component<Props, State> {
|
||||
},
|
||||
err => {
|
||||
showErrorBox(
|
||||
'Unable to read this project. Please try again later or with another save of the project.',
|
||||
'Unable to open this project. Check that the path/URL is correct, that you selected a file that is a game file created with GDevelop and that is was not removed.',
|
||||
err
|
||||
);
|
||||
return;
|
||||
|
@@ -115,7 +115,7 @@ I confirm that any assets can be used freely by anybody, including for commercia
|
||||
primaryText={formatExampleName(exampleName)}
|
||||
onClick={() => {
|
||||
sendNewGameCreated(exampleName);
|
||||
this.props.onOpen(`internal://${exampleName}`);
|
||||
this.props.onOpen(`example://${exampleName}`);
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
|
@@ -27,7 +27,7 @@ export default class BrowserStarters extends Component {
|
||||
secondaryTextLines={2}
|
||||
onClick={() => {
|
||||
sendNewGameCreated('platformer');
|
||||
this.props.onOpen('internal://platformer');
|
||||
this.props.onOpen('example://platformer');
|
||||
}}
|
||||
/>
|
||||
<ListItem
|
||||
@@ -41,7 +41,7 @@ export default class BrowserStarters extends Component {
|
||||
secondaryTextLines={2}
|
||||
onClick={() => {
|
||||
sendNewGameCreated('space-shooter');
|
||||
this.props.onOpen('internal://space-shooter');
|
||||
this.props.onOpen('example://space-shooter');
|
||||
}}
|
||||
/>
|
||||
<ListItem
|
||||
@@ -54,7 +54,7 @@ export default class BrowserStarters extends Component {
|
||||
secondaryTextLines={2}
|
||||
onClick={() => {
|
||||
sendNewGameCreated('isometric-game');
|
||||
this.props.onOpen('internal://isometric-game');
|
||||
this.props.onOpen('example://isometric-game');
|
||||
}}
|
||||
/>
|
||||
</List>
|
||||
|
@@ -64,131 +64,131 @@ import zombieLaser from '../fixtures/zombie-laser/zombie-laser.json';
|
||||
|
||||
export default class BrowserProjectOpener {
|
||||
static readInternalFile(url) {
|
||||
if (url === 'internal://advanced-shape-based-painter') {
|
||||
if (url === 'example://advanced-shape-based-painter') {
|
||||
return Promise.resolve(advancedShapeBasedPainter);
|
||||
} else if (url === 'internal://animation-speed-scale') {
|
||||
} else if (url === 'example://animation-speed-scale') {
|
||||
return Promise.resolve(animationSpeedScale);
|
||||
} else if (url === 'internal://asteroids') {
|
||||
} else if (url === 'example://asteroids') {
|
||||
return Promise.resolve(asteroids);
|
||||
} else if (url === 'internal://basic-ai-with-pathfinding') {
|
||||
} else if (url === 'example://basic-ai-with-pathfinding') {
|
||||
return Promise.resolve(basicAiWithPathfinding);
|
||||
} else if (url === 'internal://basic-artificial-intelligence') {
|
||||
} else if (url === 'example://basic-artificial-intelligence') {
|
||||
return Promise.resolve(basicArtificialIntelligence);
|
||||
} else if (url === 'internal://basic-topdown-car-driving') {
|
||||
} else if (url === 'example://basic-topdown-car-driving') {
|
||||
return Promise.resolve(basicTopdownCarDriving);
|
||||
} else if (url === 'internal://brakeout') {
|
||||
} else if (url === 'example://brakeout') {
|
||||
return Promise.resolve(brakeout);
|
||||
} else if (url === 'internal://buttons') {
|
||||
} else if (url === 'example://buttons') {
|
||||
return Promise.resolve(buttons);
|
||||
} else if (url === 'internal://car-physics') {
|
||||
} else if (url === 'example://car-physics') {
|
||||
return Promise.resolve(carPhysics);
|
||||
} else if (url === 'internal://center-object-within-another') {
|
||||
} else if (url === 'example://center-object-within-another') {
|
||||
return Promise.resolve(centerObjectWithinAnother);
|
||||
} else if (url === 'internal://change-position-of-object') {
|
||||
} else if (url === 'example://change-position-of-object') {
|
||||
return Promise.resolve(changePositionOfObject);
|
||||
} else if (url === 'internal://change-scale-of-sprites') {
|
||||
} else if (url === 'example://change-scale-of-sprites') {
|
||||
return Promise.resolve(changeScaleOfSprites);
|
||||
} else if (url === 'internal://change-sprite-animation') {
|
||||
} else if (url === 'example://change-sprite-animation') {
|
||||
return Promise.resolve(changeSpriteAnimation);
|
||||
} else if (url === 'internal://change-sprite-color') {
|
||||
} else if (url === 'example://change-sprite-color') {
|
||||
return Promise.resolve(changeSpriteColor);
|
||||
} else if (url === 'internal://create-object-with-mouseclick') {
|
||||
} else if (url === 'example://create-object-with-mouseclick') {
|
||||
return Promise.resolve(createObjectWithMouseclick);
|
||||
} else if (url === 'internal://customize-keys-with-lastpressedkey') {
|
||||
} else if (url === 'example://customize-keys-with-lastpressedkey') {
|
||||
return Promise.resolve(customizeKeysWithLastpressedkey);
|
||||
} else if (url === 'internal://drag-camera-with-mouse') {
|
||||
} else if (url === 'example://drag-camera-with-mouse') {
|
||||
return Promise.resolve(dragCameraWithMouse);
|
||||
} else if (url === 'internal://find-diagonals') {
|
||||
} else if (url === 'example://find-diagonals') {
|
||||
return Promise.resolve(findDiagonals);
|
||||
} else if (url === 'internal://infinite-scrolling-background') {
|
||||
} else if (url === 'example://infinite-scrolling-background') {
|
||||
return Promise.resolve(infiniteScrollingBackground);
|
||||
} else if (url === 'internal://instance-timer') {
|
||||
} else if (url === 'example://instance-timer') {
|
||||
return Promise.resolve(instanceTimer);
|
||||
} else if (url === 'internal://inventory-system') {
|
||||
} else if (url === 'example://inventory-system') {
|
||||
return Promise.resolve(inventorySystem);
|
||||
} else if (url === 'internal://isometric-game') {
|
||||
} else if (url === 'example://isometric-game') {
|
||||
return Promise.resolve(isometricGame);
|
||||
} else if (url === 'internal://keyboard-practice') {
|
||||
} else if (url === 'example://keyboard-practice') {
|
||||
return Promise.resolve(keyboardPractice);
|
||||
} else if (url === 'internal://magnet') {
|
||||
} else if (url === 'example://magnet') {
|
||||
return Promise.resolve(magnet);
|
||||
} else if (url === 'internal://manipulate-text-object') {
|
||||
} else if (url === 'example://manipulate-text-object') {
|
||||
return Promise.resolve(manipulateTextObject);
|
||||
} else if (url === 'internal://move-camera-to-position') {
|
||||
} else if (url === 'example://move-camera-to-position') {
|
||||
return Promise.resolve(moveCameraToPosition);
|
||||
} else if (url === 'internal://move-object-in-circle') {
|
||||
} else if (url === 'example://move-object-in-circle') {
|
||||
return Promise.resolve(moveObjectInCircle);
|
||||
} else if (url === 'internal://move-object-toward-position') {
|
||||
} else if (url === 'example://move-object-toward-position') {
|
||||
return Promise.resolve(moveObjectTowardPosition);
|
||||
} else if (url === 'internal://move-object-with-physics') {
|
||||
} else if (url === 'example://move-object-with-physics') {
|
||||
return Promise.resolve(moveObjectWithPhysics);
|
||||
} else if (url === 'internal://multitouch') {
|
||||
} else if (url === 'example://multitouch') {
|
||||
return Promise.resolve(multitouch);
|
||||
} else if (url === 'internal://object-gravity') {
|
||||
} else if (url === 'example://object-gravity') {
|
||||
return Promise.resolve(objectGravity);
|
||||
} else if (url === 'internal://object-selection') {
|
||||
} else if (url === 'example://object-selection') {
|
||||
return Promise.resolve(objectSelection);
|
||||
} else if (url === 'internal://open-url-in-browser') {
|
||||
} else if (url === 'example://open-url-in-browser') {
|
||||
return Promise.resolve(openUrlInBrowser);
|
||||
} else if (url === 'internal://parallax') {
|
||||
} else if (url === 'example://parallax') {
|
||||
return Promise.resolve(parallax);
|
||||
} else if (url === 'internal://parallax-scrolling') {
|
||||
} else if (url === 'example://parallax-scrolling') {
|
||||
return Promise.resolve(parallaxScrolling);
|
||||
} else if (url === 'internal://parse-json-from-api') {
|
||||
} else if (url === 'example://parse-json-from-api') {
|
||||
return Promise.resolve(parseJsonFromApi);
|
||||
} else if (url === 'internal://parse-json-string') {
|
||||
} else if (url === 'example://parse-json-string') {
|
||||
return Promise.resolve(parseJsonString);
|
||||
} else if (url === 'internal://particles-explosions') {
|
||||
} else if (url === 'example://particles-explosions') {
|
||||
return Promise.resolve(particlesExplosions);
|
||||
} else if (url === 'internal://particles-various-effects') {
|
||||
} else if (url === 'example://particles-various-effects') {
|
||||
return Promise.resolve(particlesVariousEffects);
|
||||
} else if (url === 'internal://pathfinding') {
|
||||
} else if (url === 'example://pathfinding') {
|
||||
return Promise.resolve(pathfinding);
|
||||
} else if (url === 'internal://pathfinding-basics') {
|
||||
} else if (url === 'example://pathfinding-basics') {
|
||||
return Promise.resolve(pathfindingBasics);
|
||||
} else if (url === 'internal://physics') {
|
||||
} else if (url === 'example://physics') {
|
||||
return Promise.resolve(physics);
|
||||
} else if (url === 'internal://platformer') {
|
||||
} else if (url === 'example://platformer') {
|
||||
return Promise.resolve(platformer);
|
||||
} else if (url === 'internal://play-stop-sprite-animation') {
|
||||
} else if (url === 'example://play-stop-sprite-animation') {
|
||||
return Promise.resolve(playStopSpriteAnimation);
|
||||
} else if (url === 'internal://rain') {
|
||||
} else if (url === 'example://rain') {
|
||||
return Promise.resolve(rain);
|
||||
} else if (url === 'internal://random-color-picker') {
|
||||
} else if (url === 'example://random-color-picker') {
|
||||
return Promise.resolve(randomColorPicker);
|
||||
} else if (url === 'internal://rotate-toward-mouse') {
|
||||
} else if (url === 'example://rotate-toward-mouse') {
|
||||
return Promise.resolve(rotateTowardMouse);
|
||||
} else if (url === 'internal://rotate-toward-position') {
|
||||
} else if (url === 'example://rotate-toward-position') {
|
||||
return Promise.resolve(rotateTowardPosition);
|
||||
} else if (url === 'internal://rotate-with-keypress') {
|
||||
} else if (url === 'example://rotate-with-keypress') {
|
||||
return Promise.resolve(rotateWithKeypress);
|
||||
} else if (url === 'internal://save-load') {
|
||||
} else if (url === 'example://save-load') {
|
||||
return Promise.resolve(saveLoad);
|
||||
} else if (url === 'internal://shoot-bullet-in-parabola') {
|
||||
} else if (url === 'example://shoot-bullet-in-parabola') {
|
||||
return Promise.resolve(shootBulletInParabola);
|
||||
} else if (url === 'internal://shoot-bullets') {
|
||||
} else if (url === 'example://shoot-bullets') {
|
||||
return Promise.resolve(shootBullets);
|
||||
} else if (url === 'internal://shooting-bullets-explanation') {
|
||||
} else if (url === 'example://shooting-bullets-explanation') {
|
||||
return Promise.resolve(shootingBulletsExplanation);
|
||||
} else if (url === 'internal://snap-object-to-grid') {
|
||||
} else if (url === 'example://snap-object-to-grid') {
|
||||
return Promise.resolve(snapObjectToGrid);
|
||||
} else if (url === 'internal://space-shooter') {
|
||||
} else if (url === 'example://space-shooter') {
|
||||
return Promise.resolve(spaceShooter);
|
||||
} else if (url === 'internal://splash-screen') {
|
||||
} else if (url === 'example://splash-screen') {
|
||||
return Promise.resolve(splashScreen);
|
||||
} else if (url === 'internal://text-entry-object') {
|
||||
} else if (url === 'example://text-entry-object') {
|
||||
return Promise.resolve(textEntryObject);
|
||||
} else if (url === 'internal://text-fade-in-out') {
|
||||
} else if (url === 'example://text-fade-in-out') {
|
||||
return Promise.resolve(textFadeInOut);
|
||||
} else if (url === 'internal://text-to-speech') {
|
||||
} else if (url === 'example://text-to-speech') {
|
||||
return Promise.resolve(textToSpeech);
|
||||
} else if (url === 'internal://toggle-music-play-sound') {
|
||||
} else if (url === 'example://toggle-music-play-sound') {
|
||||
return Promise.resolve(toggleMusicPlaySound);
|
||||
} else if (url === 'internal://type-on-text-effect') {
|
||||
} else if (url === 'example://type-on-text-effect') {
|
||||
return Promise.resolve(typeOnTextEffect);
|
||||
} else if (url === 'internal://z-depth') {
|
||||
} else if (url === 'example://z-depth') {
|
||||
return Promise.resolve(zDepth);
|
||||
} else if (url === 'internal://zombie-laser') {
|
||||
} else if (url === 'example://zombie-laser') {
|
||||
return Promise.resolve(zombieLaser);
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import optionalRequire from './OptionalRequire.js';
|
||||
import URLSearchParams from 'url-search-params';
|
||||
import { isWindows } from './Platform';
|
||||
const electron = optionalRequire('electron');
|
||||
const shell = electron ? electron.shell : null;
|
||||
@@ -76,13 +77,27 @@ export default class Window {
|
||||
return electron.remote.getCurrentWindow().on('close', cb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the arguments passed to the IDE, either from Electron
|
||||
* or from the web-app URL. The resulting object will have a key "_"
|
||||
* containing an array of string, representing all the arguments that
|
||||
* didn't have an option associated with them (see https://github.com/substack/minimist).
|
||||
* (On the web-app, this is emulated using the "project" argument).
|
||||
*/
|
||||
static getArguments() {
|
||||
if (!electron) {
|
||||
console.warn('Unable to get arguments, electron not defined');
|
||||
return {};
|
||||
if (electron) {
|
||||
return electron.remote.getGlobal('args');
|
||||
}
|
||||
|
||||
return electron.remote.getGlobal('args');
|
||||
const argumentsObject = {};
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
params.forEach((value, name) => argumentsObject[name] = value);
|
||||
|
||||
// Emulate the minimist behavior of putting the arguments without option
|
||||
// in "_".
|
||||
argumentsObject._ = argumentsObject.project ? [argumentsObject.project] : [];
|
||||
|
||||
return argumentsObject;
|
||||
}
|
||||
|
||||
static showMessageBox(message, type) {
|
||||
|
@@ -57,9 +57,9 @@ installFullstory();
|
||||
Window.setUpContextMenu();
|
||||
|
||||
let app = null;
|
||||
const appArguments = Window.getArguments();
|
||||
|
||||
if (electron) {
|
||||
const appArguments = Window.getArguments();
|
||||
if (appArguments['server-port']) {
|
||||
app = (
|
||||
<ExternalEditor
|
||||
@@ -73,6 +73,7 @@ if (electron) {
|
||||
authentification={authentification}
|
||||
onReadFromPathOrURL={() => Promise.reject('Should never be called')}
|
||||
resourceExternalEditors={localResourceExternalEditors}
|
||||
initialPathsOrURLsToOpen={[]}
|
||||
/>
|
||||
</ExternalEditor>
|
||||
);
|
||||
@@ -95,6 +96,7 @@ if (electron) {
|
||||
resourceExternalEditors={localResourceExternalEditors}
|
||||
authentification={authentification}
|
||||
extensionsLoader={new LocalJsExtensionsLoader()}
|
||||
initialPathsOrURLsToOpen={appArguments['_']}
|
||||
/>
|
||||
</ElectronEventsBridge>
|
||||
);
|
||||
@@ -117,6 +119,7 @@ if (electron) {
|
||||
resourceExternalEditors={browserResourceExternalEditors}
|
||||
authentification={authentification}
|
||||
extensionsLoader={new BrowserJsExtensionsLoader()}
|
||||
initialPathsOrURLsToOpen={appArguments['_']}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
@@ -8331,6 +8331,10 @@ url-parse@^1.1.8:
|
||||
querystringify "~1.0.0"
|
||||
requires-port "~1.0.0"
|
||||
|
||||
url-search-params@^1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/url-search-params/-/url-search-params-1.0.2.tgz#429958e9bf09f2c980f39dbde49de944efd93c88"
|
||||
|
||||
url@0.10.3:
|
||||
version "0.10.3"
|
||||
resolved "https://registry.yarnpkg.com/url/-/url-0.10.3.tgz#021e4d9c7705f21bbf37d03ceb58767402774c64"
|
||||
|
Reference in New Issue
Block a user