Skip to content

Commit

Permalink
Apply rightside appearance if the sidebar position detection is "auto…
Browse files Browse the repository at this point in the history
…" and the language is RTL #3689
  • Loading branch information
piroor committed Jan 6, 2025
1 parent f894ae7 commit 159c5a5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
17 changes: 17 additions & 0 deletions webextensions/common/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -1200,3 +1200,20 @@ export function isMacOS() {
export function isWindows() {
return configs.enableWindowsBehaviors || /^Win/i.test(navigator.platform);
}

const RTL_LANGUAGES = new Set([
'ar',
'he',
'fa',
'ur',
]);

export function isRTL() {
const lang = (
navigator.language ||
navigator.userLanguage ||
//(new Intl.DateTimeFormat()).resolvedOptions().locale ||
''
).split('-')[0];
return RTL_LANGUAGES.has(lang);
}
5 changes: 4 additions & 1 deletion webextensions/sidebar/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
shouldApplyAnimation,
loadUserStyleRules,
isMacOS,
isRTL,
notify,
} from '/common/common.js';
import * as ApiTabs from '/common/api-tabs.js';
Expand Down Expand Up @@ -91,6 +92,7 @@ const mContextualIdentitiesStyle = document.querySelector('#contextual-identity
// allow customiation for platform specific styles with selectors like `:root[data-user-agent*="Windows NT 10"]`
document.documentElement.dataset.userAgent = navigator.userAgent;
document.documentElement.classList.toggle('platform-mac', isMacOS());
document.documentElement.classList.toggle('rtl', isRTL());

{
const url = new URL(location.href);
Expand Down Expand Up @@ -1018,6 +1020,7 @@ async function isSidebarRightSide() {
const mayBeRight = window.mozInnerScreenX - window.screenX > (window.outerWidth - window.innerWidth) / 2;
if (configs.sidebarPosition == Constants.kTABBAR_POSITION_AUTO &&
mayBeRight &&
!isRTL() &&
!configs.sidebarPositionRighsideNotificationShown) {
if (mTargetWindow != (await browser.windows.getLastFocused({})).id)
return;
Expand Down Expand Up @@ -1053,7 +1056,7 @@ async function isSidebarRightSide() {
}
}
return configs.sidebarPosition == Constants.kTABBAR_POSITION_AUTO ?
mayBeRight :
(mayBeRight || isRTL()) :
configs.sidebarPosition == Constants.kTABBAR_POSITION_RIGHT;
}

Expand Down

0 comments on commit 159c5a5

Please sign in to comment.