Skip to content

Commit

Permalink
add new option and corresponding logic to maximize popout player wind…
Browse files Browse the repository at this point in the history
…ow; closes #354
  • Loading branch information
rthaut committed Sep 20, 2021
1 parent 48192e9 commit 068e96b
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 12 deletions.
14 changes: 14 additions & 0 deletions app/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@
"OptionsBehaviorLoopDescription": {
"message": "This setting controls whether or not the video(s) in the popout player loop infinitely (until the popout player is closed). <strong>The default for this setting is disabled.</strong>"
},
"OptionsSettingDisabled": {
"message": "This setting is not available when the following setting(s) are enabled: <strong>$SETTINGS$</strong>",
"placeholders": {
"settings": {
"content": "$1"
}
}
},
"OptionsSettingsNotAvailableForTab": {
"message": "These settings do not apply when the popout player is configured to open in a new tab in the current browser window."
},
Expand Down Expand Up @@ -151,6 +159,12 @@
"OptionsSizeModeCustomDescription": {
"message": "Use this setting to specify dimensions (either in pixels or percentages) for the popout player window."
},
"OptionsSizeModeMaximizedLabel": {
"message": "Maximize the Popout Player Window"
},
"OptionsSizeModeMaximizedDescription": {
"message": "Use this setting to automatically maximize (NOT fullscreen) the popout player window after positioning it."
},
"PositionModeLabel": {
"message": "Popout Player Position"
},
Expand Down
9 changes: 8 additions & 1 deletion app/scripts/background/popout.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,14 @@ export const OpenPopoutPlayerInWindow = async (
window = await browser.windows.update(window.id, position);
}

if (openInBackground) {
if ((await Options.GetLocalOption("size", "mode")) === "maximized") {
console.log(
"[Background] OpenPopoutPlayerInWindow() :: Maximizing Popout Player window"
);
window = await browser.windows.update(window.id, {
state: "maximized",
});
} else if (openInBackground) {
if (!isNaN(originTabId) && parseInt(originTabId, 10) > 0) {
// try to move the original window back to the foreground
console.log(
Expand Down
7 changes: 6 additions & 1 deletion app/scripts/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ export const OPTIONS_BEHAVIOR_CONTROLS_VALUES = [
"standard",
"extended",
];
export const OPTIONS_SIZE_MODE_VALUES = ["current", "previous", "custom"];
export const OPTIONS_SIZE_MODE_VALUES = [
"current",
"previous",
"custom",
"maximized",
];
export const OPTIONS_SIZE_UNITS_VALUES = ["pixels", "percentage"];
export const OPTIONS_POSITION_MODE_VALUES = ["auto", "previous", "custom"];

Expand Down
43 changes: 33 additions & 10 deletions app/scripts/options/components/AdvancedTab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import SettingsIcon from "@material-ui/icons/Settings";

import TabPanelHeader from "./TabPanelHeader";

import { useOptionsForDomain } from "../hooks/useOptions";
import { useOptions, useOptionsForDomain } from "../hooks/useOptions";

import { useDebounce } from "react-use";

Expand All @@ -29,13 +29,23 @@ export default function AdvancedTab() {
const { options, setOption } = useOptionsForDomain(DOMAIN);
console.log("AdvancedTab ~ options", options);

const { getOptionForDomain } = useOptions();
const canOpenInBackground =
getOptionForDomain("size", "mode") !== "maximized";

const [isFirefox, setIsFirefox] = React.useState(false);
React.useEffect(() => {
(async () => {
setIsFirefox(await IsFirefox());
})();
}, []);

React.useEffect(() => {
if (!canOpenInBackground) {
setOption("background", false);
}
}, [canOpenInBackground]);

const handlePermissionSwitchToggle = async (
optionName,
permissionsRequest,
Expand Down Expand Up @@ -121,7 +131,7 @@ export default function AdvancedTab() {
function BackgroundTabControl() {
return (
<>
<FormControl>
<FormControl disabled={!canOpenInBackground}>
<FormControlLabel
label={browser.i18n.getMessage(
"OptionsAdvancedOpenInBackgroundLabel"
Expand All @@ -137,14 +147,27 @@ export default function AdvancedTab() {
/>
}
/>
<Typography
color="textSecondary"
dangerouslySetInnerHTML={{
__html: browser.i18n.getMessage(
"OptionsAdvancedOpenInBackgroundDescription"
),
}}
/>
{canOpenInBackground ? (
<Typography
color="textSecondary"
dangerouslySetInnerHTML={{
__html: browser.i18n.getMessage(
"OptionsAdvancedOpenInBackgroundDescription"
),
}}
/>
) : (
<Alert severity="warning">
<Typography
dangerouslySetInnerHTML={{
__html: browser.i18n.getMessage(
"OptionsSettingDisabled",
browser.i18n.getMessage("OptionsSizeModeMaximizedLabel")
),
}}
/>
</Alert>
)}
</FormControl>
</>
);
Expand Down

0 comments on commit 068e96b

Please sign in to comment.