55
66import '../../../ui/components/chrome_link/chrome_link.js' ;
77import '../../../ui/components/settings/settings.js' ;
8+ import '../../../ui/components/tooltips/tooltips.js' ;
89
910import type * as Common from '../../../core/common/common.js' ;
1011import type * as Host from '../../../core/host/host.js' ;
1112import * as i18n from '../../../core/i18n/i18n.js' ;
1213import type * as Platform from '../../../core/platform/platform.js' ;
14+ import * as Buttons from '../../../ui/components/buttons/buttons.js' ;
1315import * as ComponentHelpers from '../../../ui/components/helpers/helpers.js' ;
1416import * as Lit from '../../../ui/lit/lit.js' ;
1517
@@ -28,16 +30,16 @@ const UIStrings = {
2830 * to a checkbox that is disabled.
2931 */
3032 preferencesSyncDisabled : 'To turn this setting on, you must first enable settings sync in Chrome.' ,
31- /**
32- * @description Label for a link that take the user to the "Sync" section of the
33- * chrome settings. The link is shown in the DevTools Settings UI.
34- */
35- settings : 'Go to Settings' ,
3633 /**
3734 * @description Label for the account email address. Shown in the DevTools Settings UI in
3835 * front of the email address currently used for Chrome Sync.
3936 */
4037 signedIn : 'Signed into Chrome as:' ,
38+ /**
39+ * @description Label for the account settings. Shown in the DevTools Settings UI in
40+ * case the user is not logged in to Chrome.
41+ */
42+ notSignedIn : 'You\'re not signed into Chrome.' ,
4143} as const ;
4244const str_ = i18n . i18n . registerUIStrings ( 'panels/settings/components/SyncSection.ts' , UIStrings ) ;
4345const i18nString = i18n . i18n . getLocalizedString . bind ( undefined , str_ ) ;
@@ -61,7 +63,7 @@ export class SyncSection extends HTMLElement {
6163
6264 #render( ) : void {
6365 if ( ! this . #syncSetting) {
64- throw new Error ( 'SyncSection not properly initialized' ) ;
66+ throw new Error ( 'SyncSection is not properly initialized' ) ;
6567 }
6668
6769 // TODO: this should not probably happen in render, instead, the setting
@@ -73,41 +75,72 @@ export class SyncSection extends HTMLElement {
7375 Lit . render ( html `
7476 < style > ${ syncSectionStyles } </ style >
7577 < fieldset >
76- ${ renderAccountInfoOrWarning ( this . #syncInfo) }
77- < setting-checkbox .data =${
78- { setting : this . #syncSetting} } >
79- </ setting-checkbox >
78+ ${ renderAccountInfo ( this . #syncInfo) }
79+ ${ renderSettingCheckboxIfNeeded ( this . #syncInfo, this . #syncSetting) }
8080 </ fieldset >
8181 ` , this . #shadow, { host : this } ) ;
8282 // clang-format on
8383 }
8484}
8585
86- /* x-link doesn't work with custom click/keydown handlers */
86+ function renderSettingCheckboxIfNeeded (
87+ syncInfo : Host . InspectorFrontendHostAPI . SyncInformation ,
88+ syncSetting : Common . Settings . Setting < boolean > ) : Lit . LitTemplate {
89+ if ( ! syncInfo . accountEmail ) {
90+ return Lit . nothing ;
91+ }
8792
88- function renderAccountInfoOrWarning ( syncInfo : Host . InspectorFrontendHostAPI . SyncInformation ) : Lit . TemplateResult {
89- if ( ! syncInfo . isSyncActive ) {
90- const link = 'chrome://settings/syncSetup' as Platform . DevToolsPath . UrlString ;
91- // Disabled until https://crbug.com/1079231 is fixed.
92- // clang-format off
93- return html `
94- < span class ="warning ">
95- ${ i18nString ( UIStrings . syncDisabled ) }
96- < devtools-chrome-link .href =${ link } > ${ i18nString ( UIStrings . settings ) } </ devtools-chrome-link >
97- </ span > ` ;
98- // clang-format on
93+ // clang-format off
94+ return html `
95+ < div class ="setting-checkbox-container ">
96+ < setting-checkbox class ="setting-checkbox " .data =${ { setting : syncSetting } } >
97+ </ setting-checkbox >
98+ ${ renderWarningIfNeeded ( syncInfo ) }
99+ </ div >
100+ ` ;
101+ // clang-format on
102+ }
103+
104+ function renderWarningIfNeeded ( syncInfo : Host . InspectorFrontendHostAPI . SyncInformation ) : Lit . LitTemplate {
105+ const hasWarning = ! syncInfo . isSyncActive || ! syncInfo . arePreferencesSynced ;
106+ if ( ! hasWarning ) {
107+ return Lit . nothing ;
99108 }
100- if ( ! syncInfo . arePreferencesSynced ) {
101- const link = 'chrome://settings/syncSetup/advanced' as Platform . DevToolsPath . UrlString ;
102- // Disabled until https://crbug.com/1079231 is fixed.
109+
110+ const warningLink = ! syncInfo . isSyncActive ?
111+ 'chrome://settings/syncSetup' as Platform . DevToolsPath . UrlString :
112+ 'chrome://settings/syncSetup/advanced' as Platform . DevToolsPath . UrlString ;
113+ const warningText =
114+ ! syncInfo . isSyncActive ? i18nString ( UIStrings . syncDisabled ) : i18nString ( UIStrings . preferencesSyncDisabled ) ;
115+ // clang-format off
116+ return html `
117+ < devtools-chrome-link .href =${ warningLink } >
118+ < devtools-button
119+ aria-describedby =settings-sync-info
120+ .iconName =${ 'info' }
121+ .variant =${ Buttons . Button . Variant . ICON }
122+ .size=${ Buttons . Button . Size . SMALL } >
123+ </ devtools-button >
124+ </ devtools-chrome-link >
125+ < devtools-tooltip
126+ id =settings-sync-info
127+ variant =simple >
128+ ${ warningText }
129+ </ devtools-tooltip >
130+ ` ;
131+ // clang-format on
132+ }
133+
134+ function renderAccountInfo ( syncInfo : Host . InspectorFrontendHostAPI . SyncInformation ) : Lit . LitTemplate {
135+ if ( ! syncInfo . accountEmail ) {
103136 // clang-format off
104137 return html `
105- < span class ="warning ">
106- ${ i18nString ( UIStrings . preferencesSyncDisabled ) }
107- < devtools-chrome-link .href =${ link } > ${ i18nString ( UIStrings . settings ) } </ devtools-chrome-link >
108- </ span > ` ;
138+ < div class ="not-signed-in "> ${ i18nString ( UIStrings . notSignedIn ) } </ div >
139+ ` ;
109140 // clang-format on
110141 }
142+
143+ // clang-format off
111144 return html `
112145 < div class ="account-info ">
113146 < img src ="data:image/png;base64, ${ syncInfo . accountImage } " alt ="Account avatar " />
@@ -116,6 +149,7 @@ function renderAccountInfoOrWarning(syncInfo: Host.InspectorFrontendHostAPI.Sync
116149 < span > ${ syncInfo . accountEmail } </ span >
117150 </ div >
118151 </ div > ` ;
152+ // clang-format on
119153}
120154
121155customElements . define ( 'devtools-sync-section' , SyncSection ) ;
0 commit comments