7
7
POPUP_STYLE_DISK ,
8
8
} from "@bitwarden/common/platform/state" ;
9
9
10
+ import BrowserPopupUtils from "../browser-popup-utils" ;
11
+
10
12
/**
11
13
*
12
14
* Value represents width in pixels
@@ -25,10 +27,12 @@ const POPUP_WIDTH_KEY_DEF = new KeyDefinition<PopupWidthOption>(POPUP_STYLE_DISK
25
27
} ) ;
26
28
27
29
/**
28
- * Updates the extension popup width based on a user setting
30
+ * Handles sizing the popup based on available width/height, which can be affected by
31
+ * user default zoom level.
32
+ * Updates the extension popup width based on a user setting.
29
33
**/
30
34
@Injectable ( { providedIn : "root" } )
31
- export class PopupWidthService {
35
+ export class PopupSizeService {
32
36
private static readonly LocalStorageKey = "bw-popup-width" ;
33
37
private readonly state = inject ( GlobalStateProvider ) . get ( POPUP_WIDTH_KEY_DEF ) ;
34
38
@@ -41,23 +45,39 @@ export class PopupWidthService {
41
45
}
42
46
43
47
/** Begin listening for state changes */
44
- init ( ) {
48
+ async init ( ) {
45
49
this . width$ . subscribe ( ( width : PopupWidthOption ) => {
46
- PopupWidthService . setStyle ( width ) ;
47
- localStorage . setItem ( PopupWidthService . LocalStorageKey , width ) ;
50
+ PopupSizeService . setStyle ( width ) ;
51
+ localStorage . setItem ( PopupSizeService . LocalStorageKey , width ) ;
48
52
} ) ;
53
+
54
+ const isInChromeTab = await BrowserPopupUtils . isInTab ( ) ;
55
+
56
+ if ( ! BrowserPopupUtils . inPopup ( window ) || isInChromeTab ) {
57
+ window . document . body . classList . add ( "body-full" ) ;
58
+ } else if ( window . innerHeight < 400 ) {
59
+ window . document . body . classList . add ( "body-xxs" ) ;
60
+ } else if ( window . innerHeight < 500 ) {
61
+ window . document . body . classList . add ( "body-xs" ) ;
62
+ } else if ( window . innerHeight < 600 ) {
63
+ window . document . body . classList . add ( "body-sm" ) ;
64
+ }
49
65
}
50
66
51
67
private static setStyle ( width : PopupWidthOption ) {
68
+ if ( ! BrowserPopupUtils . inPopup ( window ) ) {
69
+ return ;
70
+ }
52
71
const pxWidth = PopupWidthOptions [ width ] ?? PopupWidthOptions . default ;
72
+
53
73
document . body . style . minWidth = `${ pxWidth } px` ;
54
74
}
55
75
56
76
/**
57
77
* To keep the popup size from flickering on bootstrap, we store the width in `localStorage` so we can quickly & synchronously reference it.
58
78
**/
59
79
static initBodyWidthFromLocalStorage ( ) {
60
- const storedValue = localStorage . getItem ( PopupWidthService . LocalStorageKey ) ;
80
+ const storedValue = localStorage . getItem ( PopupSizeService . LocalStorageKey ) ;
61
81
this . setStyle ( storedValue as any ) ;
62
82
}
63
83
}
0 commit comments