diff --git a/src/components/appRouter.js b/src/components/appRouter.js index 8643e3f47f..9df0ee5f1b 100644 --- a/src/components/appRouter.js +++ b/src/components/appRouter.js @@ -551,7 +551,7 @@ define(['loading', 'globalize', 'events', 'viewManager', 'layoutManager', 'skinM return false; } - if (curr.type === 'home') { + if (!document.querySelector('.dialogContainer') && curr.type === 'home') { return false; } return page.canGoBack(); diff --git a/src/components/apphost.js b/src/components/apphost.js index b1b1c30dc9..d85706b9fd 100644 --- a/src/components/apphost.js +++ b/src/components/apphost.js @@ -311,6 +311,52 @@ define(["appSettings", "browser", "events", "htmlMediaHelper"], function (appSet }); } + /** + * Do exit according to platform + */ + function doExit() { + try { + if (window.NativeShell) { + window.NativeShell.AppHost.exit(); + } else if (browser.tizen) { + tizen.application.getCurrentApplication().exit(); + } else if (browser.web0s) { + webOS.platformBack(); + } else { + window.close(); + } + } catch (err) { + console.log("error closing application: " + err); + } + } + + var exitPromise; + + /** + * Ask user for exit + */ + function askForExit() { + if (!!exitPromise) { + return; + } + + require(["actionsheet"], function (actionsheet) { + exitPromise = actionsheet.show({ + title: Globalize.translate("MessageConfirmAppExit"), + items: [ + {id: "yes", name: Globalize.translate("Yes")}, + {id: "no", name: Globalize.translate("No")} + ] + }).then(function (value) { + if (value === "yes") { + doExit(); + } + }).finally(function () { + exitPromise = null; + }); + }); + } + var deviceId; var deviceName; var appName = "Jellyfin Web"; @@ -326,16 +372,10 @@ define(["appSettings", "browser", "events", "htmlMediaHelper"], function (appSet alert("setWindowState is not supported and should not be called"); }, exit: function () { - if (window.NativeShell) { - window.NativeShell.AppHost.exit(); - } else if (browser.tizen) { - try { - tizen.application.getCurrentApplication().exit(); - } catch (err) { - console.log("error closing application: " + err); - } + if (!!window.appMode && browser.tizen) { + askForExit(); } else { - window.close(); + doExit(); } }, supports: function (command) { diff --git a/src/scripts/inputManager.js b/src/scripts/inputManager.js index 634b5e1b30..c6a64a69f5 100644 --- a/src/scripts/inputManager.js +++ b/src/scripts/inputManager.js @@ -1,4 +1,4 @@ -define(['playbackManager', 'focusManager', 'appRouter', 'dom'], function (playbackManager, focusManager, appRouter, dom) { +define(['playbackManager', 'focusManager', 'appRouter', 'dom', 'apphost'], function (playbackManager, focusManager, appRouter, dom, appHost) { 'use strict'; var lastInputTime = new Date().getTime(); @@ -98,7 +98,11 @@ define(['playbackManager', 'focusManager', 'appRouter', 'dom'], function (playba appRouter.showSettings(); break; case 'back': - appRouter.back(); + if (appRouter.canGoBack()) { + appRouter.back(); + } else if (appHost.supports('exit')) { + appHost.exit(); + } break; case 'forward': break; diff --git a/src/strings/en-us.json b/src/strings/en-us.json index 6dea5a7892..4eb2289c99 100644 --- a/src/strings/en-us.json +++ b/src/strings/en-us.json @@ -945,6 +945,7 @@ "MessageAlreadyInstalled": "This version is already installed.", "MessageAreYouSureDeleteSubtitles": "Are you sure you wish to delete this subtitle file?", "MessageAreYouSureYouWishToRemoveMediaFolder": "Are you sure you wish to remove this media folder?", + "MessageConfirmAppExit": "Do you want to exit?", "MessageConfirmDeleteGuideProvider": "Are you sure you wish to delete this guide provider?", "MessageConfirmDeleteTunerDevice": "Are you sure you wish to delete this device?", "MessageConfirmProfileDeletion": "Are you sure you wish to delete this profile?", diff --git a/src/strings/ru.json b/src/strings/ru.json index 4e612aa5bd..140c5bdb80 100644 --- a/src/strings/ru.json +++ b/src/strings/ru.json @@ -890,6 +890,7 @@ "MessageAlreadyInstalled": "Данная версия уже установлена.", "MessageAreYouSureDeleteSubtitles": "Вы действительно хотите удалить данный файл субитров?", "MessageAreYouSureYouWishToRemoveMediaFolder": "Вы действительно хотите изъять данную медиапапку?", + "MessageConfirmAppExit": "Вы хотите выйти?", "MessageConfirmDeleteGuideProvider": "Вы действительно хотите удалить данного поставщика телегида?", "MessageConfirmDeleteTunerDevice": "Вы действительно хотите удалить данное устройство?", "MessageConfirmProfileDeletion": "Вы действительно хотите удалить данный профиль?",