Skip to content

Commit 272f554

Browse files
committed
fix: fullscreen exits on ctrl/escape/special key press in tauri
1 parent c587fdf commit 272f554

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

src/extensions/default/NoDistractions/main.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
*
2020
*/
2121

22+
/*global Phoenix*/
23+
2224
define(function (require, exports, module) {
2325

2426

@@ -51,17 +53,15 @@ define(function (require, exports, module) {
5153
panelsToggled = false,
5254
layoutUpdated = false;
5355

54-
function isInFullScreen() {
55-
return !!document.fullscreenElement;
56-
}
57-
5856
/**
5957
* @private
6058
* Updates the command checked status based on the preference for noDestraction mode
6159
*/
6260
function _updateCheckedState() {
6361
CommandManager.get(CMD_TOGGLE_PURE_CODE).setChecked(PreferencesManager.get(PREFS_PURE_CODE));
64-
CommandManager.get(CMD_TOGGLE_FULLSCREEN).setChecked(isInFullScreen());
62+
Phoenix.app.isFullscreen().then(isFullScreen =>{
63+
CommandManager.get(CMD_TOGGLE_FULLSCREEN).setChecked(isFullScreen);
64+
});
6565
}
6666

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

7676
async function _toggleFullScreen() {
7777
Metrics.countEvent(Metrics.EVENT_TYPE.UI, 'fullscreen', 'toggle');
78-
if (!isInFullScreen()) {
79-
await document.documentElement.requestFullscreen();
80-
} else if (document.exitFullscreen) {
81-
await document.exitFullscreen();
82-
}
83-
_updateCheckedState();
78+
Phoenix.app.isFullscreen().then(isFullScreen =>{
79+
Phoenix.app.setFullscreen(!isFullScreen)
80+
.then(_updateCheckedState);
81+
});
8482
}
8583

8684
/**

src/phoenix/shell.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,26 @@ Phoenix.app = {
6363
}
6464
window.__TAURI__.window.appWindow.close();
6565
},
66+
isFullscreen: function () {
67+
if(!Phoenix.browser.isTauri) {
68+
// use browser full screen api in browsers.
69+
return Promise.resolve(!!document.fullscreenElement);
70+
}
71+
return window.__TAURI__.window.appWindow.isFullscreen();
72+
},
73+
setFullscreen: function (enable) {
74+
if(!Phoenix.browser.isTauri) {
75+
// use browser full screen api in browsers.
76+
if (enable) {
77+
return document.documentElement.requestFullscreen();
78+
} else if (document.exitFullscreen) {
79+
return document.exitFullscreen();
80+
} else {
81+
return Promise.resolve();
82+
}
83+
}
84+
return window.__TAURI__.window.appWindow.setFullscreen(enable);
85+
},
6686
getDisplayLocation: function (fullVFSPath) {
6787
// reruns a user-friendly location that can be shown to the user to make some sense of the virtual file path.
6888
// The returned path may not be an actual path if it is not resolvable to a platform path, but a text indicating

0 commit comments

Comments
 (0)