Skip to content

Commit

Permalink
Add ability to control temporary state of group tabs opened by API #3567
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jun 14, 2024
1 parent 85bd93d commit ba82187
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 5 deletions.
1 change: 1 addition & 0 deletions webextensions/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@
"config_groupTabTemporaryStateForNewTabsFromBookmarks_label": { "message": "For tabs opened from bookmarks:" },
"config_groupTabTemporaryStateForNewTabsFromOthers_label": { "message": "For tabs opened at a time from non-bookmark triggers:" },
"config_groupTabTemporaryStateForOrphanedTabs_label": { "message": "Opened to replace a closed parent tab:" },
"config_groupTabTemporaryStateForAPI_label": { "message": "Opened to group tabs from other addons via API:" },

"config_inheritContextualIdentityToChildTabMode_label": { "message": "Container:" },
"config_inheritContextualIdentityToChildTabMode_default": { "message": "(no control)" },
Expand Down
1 change: 1 addition & 0 deletions webextensions/_locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@
"config_groupTabTemporaryStateForNewTabsFromBookmarks_label": { "message": "ブックマークから開かれたタブをグループ化した場合:" },
"config_groupTabTemporaryStateForNewTabsFromOthers_label": { "message": "ブックマーク以外から連続して開かれたタブをグループ化した場合:" },
"config_groupTabTemporaryStateForOrphanedTabs_label": { "message": "閉じられた親タブを置き換える形で開かれた場合:" },
"config_groupTabTemporaryStateForAPI_label": { "message": "他の拡張機能からAPI経由でタブをグループ化した場合:" },

"config_inheritContextualIdentityToChildTabMode_label": { "message": "コンテナー:" },
"config_inheritContextualIdentityToChildTabMode_default": { "message": "(制御しない)" },
Expand Down
28 changes: 26 additions & 2 deletions webextensions/background/browser-action-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -1304,8 +1304,32 @@ const mItems = [
type: 'radio'
}
]
}
]
},
{
title: indent() + browser.i18n.getMessage('config_groupTabTemporaryStateForAPI_label'),
expert: true,
children: [
{
title: browser.i18n.getMessage('config_groupTabTemporaryState_option_default'),
key: 'groupTabTemporaryStateForAPI',
value: Constants.kGROUP_TAB_TEMPORARY_STATE_NOTHING,
type: 'radio'
},
{
title: `${browser.i18n.getMessage('config_groupTabTemporaryState_option_checked_before')}${browser.i18n.getMessage('groupTab_temporary_label')}${browser.i18n.getMessage('config_groupTabTemporaryState_option_checked_after')}`,
key: 'groupTabTemporaryStateForAPI',
value: Constants.kGROUP_TAB_TEMPORARY_STATE_PASSIVE,
type: 'radio'
},
{
title: `${browser.i18n.getMessage('config_groupTabTemporaryState_option_checked_before')}${browser.i18n.getMessage('groupTab_temporaryAggressive_label')}${browser.i18n.getMessage('config_groupTabTemporaryState_option_checked_after')}`,
key: 'groupTabTemporaryStateForAPI',
value: Constants.kGROUP_TAB_TEMPORARY_STATE_AGGRESSIVE,
type: 'radio'
},
],
},
],
},
{
title: browser.i18n.getMessage('config_treeBehavior_caption'),
Expand Down
18 changes: 18 additions & 0 deletions webextensions/background/handle-misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -957,9 +957,27 @@ function onMessageExternal(message, sender) {
case TSTAPI.kGROUP_TABS:
return (async () => {
const tabs = await TSTAPI.getTargetTabs(message, sender);
const temporaryStateParams = (message.temporary && !message.temporaryAggressive) ?
{
temporary: true,
temporaryAggressive: false,
} :
(!message.temporary && message.temporaryAggressive) ?
{
temporary: false,
temporaryAggressive: true,
} :
(message.temporaryAggressive === false && message.temporary === false) ?
{
temporary: false,
temporaryAggressive: false,
} :
{};
const tab = await TabsGroup.groupTabs(Array.from(tabs), {
title: message.title,
broadcast: true,
...TabsGroup.temporaryStateParams(configs.groupTabTemporaryStateForAPI),
...temporaryStateParams,
});
if (!tab)
return null;
Expand Down
15 changes: 12 additions & 3 deletions webextensions/background/tabs-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,22 @@ export function makeGroupTabURI({ title, temporary, temporaryAggressive, openerT
export function temporaryStateParams(state) {
switch (state) {
case Constants.kGROUP_TAB_TEMPORARY_STATE_PASSIVE:
return { temporary: true };
return {
temporary: true,
temporaryAggressive: false,
};
case Constants.kGROUP_TAB_TEMPORARY_STATE_AGGRESSIVE:
return { temporaryAggressive: true };
return {
temporary: false,
temporaryAggressive: true,
};
default:
break;
}
return {};
return {
temporary: false,
temporaryAggressive: false,
};
}

export async function groupTabs(tabs, { broadcast, parent, withDescendants, ...groupTabOptions } = {}) {
Expand Down
1 change: 1 addition & 0 deletions webextensions/common/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ export const configs = new Configs({
groupTabTemporaryStateForChildrenOfPinned: Constants.kGROUP_TAB_TEMPORARY_STATE_PASSIVE,
groupTabTemporaryStateForChildrenOfFirefoxView: Constants.kGROUP_TAB_TEMPORARY_STATE_PASSIVE,
groupTabTemporaryStateForOrphanedTabs: Constants.kGROUP_TAB_TEMPORARY_STATE_AGGRESSIVE,
groupTabTemporaryStateForAPI: Constants.kGROUP_TAB_TEMPORARY_STATE_NOTHING,
renderTreeInGroupTabs: true,
warnOnAutoGroupNewTabs: true,
warnOnAutoGroupNewTabsWithListing: true,
Expand Down
10 changes: 10 additions & 0 deletions webextensions/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,16 @@ <h1>__MSG_config_newTab_caption__</h1>
__MSG_groupTab_temporaryAggressive_label__
__MSG_config_groupTabTemporaryState_option_checked_after__</option>
</select></label></p>
<p><label>__MSG_config_groupTabTemporaryStateForAPI_label__
<select id="groupTabTemporaryStateForAPI">
<option value="0">__MSG_config_groupTabTemporaryState_option_default__</option>
<option value="1">__MSG_config_groupTabTemporaryState_option_checked_before__
__MSG_groupTab_temporary_label__
__MSG_config_groupTabTemporaryState_option_checked_after__</option>
<option value="2">__MSG_config_groupTabTemporaryState_option_checked_before__
__MSG_groupTab_temporaryAggressive_label__
__MSG_config_groupTabTemporaryState_option_checked_after__</option>
</select></label></p>
</fieldset>

</div>
Expand Down

0 comments on commit ba82187

Please sign in to comment.