Open popup as tab if browser does not support popup.

This commit is contained in:
FelisCatus 2017-08-03 23:10:02 -04:00
parent d8684c6d24
commit 6f0f3e4636
5 changed files with 13 additions and 2 deletions

View File

@ -272,12 +272,17 @@ class ChromeOptions extends OmegaTarget.Options
url: chrome.extension.getURL('options.html#/ui') url: chrome.extension.getURL('options.html#/ui')
) )
if quickSwitch if quickSwitch or not chrome.browserAction.setPopup?
chrome.browserAction.setPopup?({popup: ''}) chrome.browserAction.setPopup?({popup: ''})
if not @_quickSwitchInit if not @_quickSwitchInit
@_quickSwitchInit = true @_quickSwitchInit = true
chrome.browserAction.onClicked.addListener (tab) => chrome.browserAction.onClicked.addListener (tab) =>
@clearBadge() @clearBadge()
if not @_options['-enableQuickSwitch']
# If we reach here, then the browser does not support popup.
# Let's open the popup page in a tab.
chrome.tabs.create(url: 'popup/index.html')
return
profiles = @_options['-quickSwitchProfiles'] profiles = @_options['-quickSwitchProfiles']
index = profiles.indexOf(@_currentProfileName) index = profiles.indexOf(@_currentProfileName)
index = (index + 1) % profiles.length index = (index + 1) % profiles.length
@ -290,7 +295,7 @@ class ChromeOptions extends OmegaTarget.Options
return if url.substr(0, 4) == 'moz-' return if url.substr(0, 4) == 'moz-'
chrome.tabs.reload(tab.id) chrome.tabs.reload(tab.id)
else else
chrome.browserAction.setPopup?({popup: 'popup/index.html'}) chrome.browserAction.setPopup({popup: 'popup/index.html'})
Promise.resolve() Promise.resolve()
setInspect: (settings) -> setInspect: (settings) ->

View File

@ -21,6 +21,7 @@ html(lang='en' ng-app='omegaPopup' ng-controller='PopupCtrl' ng-csp)
head head
meta(charset='utf-8') meta(charset='utf-8')
title {{'popup_title' | tr}} title {{'popup_title' | tr}}
meta(name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no')
link(rel='stylesheet' href='lib/bootstrap/css/bootstrap.min.css') link(rel='stylesheet' href='lib/bootstrap/css/bootstrap.min.css')
link(rel='stylesheet' href='css/popup.css') link(rel='stylesheet' href='css/popup.css')
body(ng-class='{"with-condition-form": showConditionForm}') body(ng-class='{"with-condition-form": showConditionForm}')

View File

@ -3,6 +3,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>SwitchyOmega Popup</title> <title>SwitchyOmega Popup</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="stylesheet" href="css/index.css"> <link rel="stylesheet" href="css/index.css">
</head> </head>
<body> <body>

View File

@ -14,6 +14,9 @@
function closePopup() { function closePopup() {
window.close(); window.close();
// If the popup is opened as a tab, the above won't work. Let's reload then.
document.body.style.opacity = 0;
setTimeout(function() { history.go(0); }, 300);
} }
function showOptions(e) { function showOptions(e) {

View File

@ -3,6 +3,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>SwitchyOmega Popup</title> <title>SwitchyOmega Popup</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link rel="stylesheet" href="css/dialog.css"> <link rel="stylesheet" href="css/dialog.css">
</head> </head>
<body> <body>