Skip to content

Commit

Permalink
fix: fullscreen exits on ctrl/escape/special key press in tauri
Browse files Browse the repository at this point in the history
  • Loading branch information
abose committed Dec 13, 2023
1 parent c587fdf commit 272f554
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/extensions/default/NoDistractions/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*
*/

/*global Phoenix*/

define(function (require, exports, module) {


Expand Down Expand Up @@ -51,17 +53,15 @@ define(function (require, exports, module) {
panelsToggled = false,
layoutUpdated = false;

function isInFullScreen() {
return !!document.fullscreenElement;
}

/**
* @private
* Updates the command checked status based on the preference for noDestraction mode
*/
function _updateCheckedState() {
CommandManager.get(CMD_TOGGLE_PURE_CODE).setChecked(PreferencesManager.get(PREFS_PURE_CODE));
CommandManager.get(CMD_TOGGLE_FULLSCREEN).setChecked(isInFullScreen());
Phoenix.app.isFullscreen().then(isFullScreen =>{
CommandManager.get(CMD_TOGGLE_FULLSCREEN).setChecked(isFullScreen);
});
}

/**
Expand All @@ -75,12 +75,10 @@ define(function (require, exports, module) {

async function _toggleFullScreen() {
Metrics.countEvent(Metrics.EVENT_TYPE.UI, 'fullscreen', 'toggle');
if (!isInFullScreen()) {
await document.documentElement.requestFullscreen();
} else if (document.exitFullscreen) {
await document.exitFullscreen();
}
_updateCheckedState();
Phoenix.app.isFullscreen().then(isFullScreen =>{
Phoenix.app.setFullscreen(!isFullScreen)
.then(_updateCheckedState);
});
}

/**
Expand Down
20 changes: 20 additions & 0 deletions src/phoenix/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ Phoenix.app = {
}
window.__TAURI__.window.appWindow.close();
},
isFullscreen: function () {
if(!Phoenix.browser.isTauri) {
// use browser full screen api in browsers.
return Promise.resolve(!!document.fullscreenElement);
}
return window.__TAURI__.window.appWindow.isFullscreen();
},
setFullscreen: function (enable) {
if(!Phoenix.browser.isTauri) {
// use browser full screen api in browsers.
if (enable) {
return document.documentElement.requestFullscreen();
} else if (document.exitFullscreen) {
return document.exitFullscreen();
} else {
return Promise.resolve();
}
}
return window.__TAURI__.window.appWindow.setFullscreen(enable);
},
getDisplayLocation: function (fullVFSPath) {
// reruns a user-friendly location that can be shown to the user to make some sense of the virtual file path.
// The returned path may not be an actual path if it is not resolvable to a platform path, but a text indicating
Expand Down

0 comments on commit 272f554

Please sign in to comment.