Skip to content

Commit

Permalink
Add escape behavior option
Browse files Browse the repository at this point in the history
  • Loading branch information
GarboMuffin committed Mar 2, 2024
1 parent 0fc6736 commit deb41c8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 18 deletions.
24 changes: 24 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,10 @@
"string": "Updating the version is completely optional and doesn't affect your project's behavior. It may appear in places like about screens depending on the environment. Should be formatted as X.Y.Z.",
"context": "Additional information about the version number option"
},
"initalWindowSize": {
"string": "Initial window size",
"context": "Name of setting to change the size of the window when the app first opens"
},
"startWindow": {
"string": "Start as window"
},
Expand All @@ -518,6 +522,26 @@
"startFullscreen": {
"string": "Start in fullscreen"
},
"escapeBehavior": {
"string": "When escape key pressed",
"context": "Name of setting to change what happens when someone presses escape"
},
"unFullscreenOnly": {
"string": "Leave fullscreen only",
"context": "When escape key pressed, leave fullscreen if in fullscreen, otherwise do nothing."
},
"exitOnly": {
"string": "Exit only",
"context": "When escape key pressed, always exit the app regardless of fullscreen mode."
},
"unFullscreenOrExit": {
"string": "Leave fullscreen or exit",
"context": "When escape key pressed, leave fullscreen if in fullscreen, otherwise exit."
},
"doNothing": {
"string": "Do nothing",
"context": "When escape key pressed, do nothing."
},
"maxTextureDimension": {
"string": "Increase max vector costume resolution to make large costumes look better. May increase memory use and cause crashes."
},
Expand Down
35 changes: 20 additions & 15 deletions src/p4/PackagerOptions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,8 @@
reset={$options.target.startsWith('zip') ? null : () => {
resetOptions([
'app.packageName',
'app.windowMode'
'app.windowMode',
'app.escapeBehavior'
]);
}}
>
Expand All @@ -902,20 +903,24 @@
<p>{$_('options.versionHelp')}</p>

{#if $options.target.includes('electron')}
<div class="group">
<label class="option">
<input type="radio" name="app-window-mode" bind:group={$options.app.windowMode} value="window">
{$_('options.startWindow')}
</label>
<label class="option">
<input type="radio" name="app-window-mode" bind:group={$options.app.windowMode} value="maximize">
{$_('options.startMaximized')}
</label>
<label class="option">
<input type="radio" name="app-window-mode" bind:group={$options.app.windowMode} value="fullscreen">
{$_('options.startFullscreen')}
</label>
</div>
<label class="option">
{$_('options.initalWindowSize')}
<select bind:value={$options.app.windowMode}>
<option value="window">{$_('options.startWindow')}</option>
<option value="maximize">{$_('options.startMaximized')}</option>
<option value="fullscreen">{$_('options.startFullscreen')}</option>
</select>
</label>

<label class="option">
{$_('options.escapeBehavior')}
<select bind:value={$options.app.escapeBehavior}>
<option value="unfullscreen-only">{$_('options.unFullscreenOnly')}</option>
<option value="exit-only">{$_('options.exitOnly')}</option>
<option value="unfullscreen-or-exit">{$_('options.unFullscreenOrExit')}</option>
<option value="nothing">{$_('options.doNothing')}</option>
</select>
</label>
{/if}

<div class="warning">
Expand Down
12 changes: 9 additions & 3 deletions src/packager/packager.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,8 +696,13 @@ app.on('web-contents-created', (event, contents) => {
if (!window || input.type !== "keyDown") return;
if (input.key === 'F11' || (input.key === 'Enter' && input.alt)) {
window.setFullScreen(!window.isFullScreen());
} else if (input.key === 'Escape' && window.isFullScreen()) {
window.setFullScreen(false);
} else if (input.key === 'Escape') {
const behavior = ${JSON.stringify(this.options.app.escapeBehavior)};
if (window.isFullScreen() && (behavior === 'unfullscreen-only' || behavior === 'unfullscreen-or-exit')) {
window.setFullScreen(false);
} else if (behavior === 'unfullscreen-or-exit' || behavior === 'exit-only') {
window.close();
}
}
});
});
Expand Down Expand Up @@ -1641,7 +1646,8 @@ Packager.DEFAULT_OPTIONS = () => ({
packageName: Packager.getDefaultPackageNameFromFileName(''),
windowTitle: Packager.getWindowTitleFromFileName(''),
windowMode: 'window',
version: '1.0.0'
version: '1.0.0',
escapeBehavior: 'unfullscreen-only'
},
chunks: {
gamepad: false,
Expand Down

0 comments on commit deb41c8

Please sign in to comment.