Jan Scheffler | 5bba5fd | 2021-01-15 17:39:54 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | /* eslint-disable rulesdir/no_underscored_properties */ |
| 6 | |
Tim van der Lippe | 5f62c6f | 2021-02-25 16:39:26 | [diff] [blame] | 7 | import * as Common from '../common/common.js'; |
Jan Scheffler | 5bba5fd | 2021-01-15 17:39:54 | [diff] [blame] | 8 | import * as Host from '../host/host.js'; |
Andres Olivares | bd877e0 | 2021-02-28 17:20:38 | [diff] [blame] | 9 | import * as Root from '../root/root.js'; |
| 10 | import * as UI from '../ui/ui.js'; // eslint-disable-line no-unused-vars |
Jan Scheffler | 5bba5fd | 2021-01-15 17:39:54 | [diff] [blame] | 11 | |
| 12 | import {releaseNoteText} from './ReleaseNoteText.js'; |
| 13 | |
| 14 | export const releaseVersionSeen = 'releaseNoteVersionSeen'; |
| 15 | |
| 16 | export const releaseNoteViewId: string = 'release-note'; |
| 17 | |
Sigurd Schneider | 17c7445 | 2021-02-15 12:14:10 | [diff] [blame] | 18 | let latestReleaseNoteInstance: ReleaseNote; |
Jan Scheffler | 5bba5fd | 2021-01-15 17:39:54 | [diff] [blame] | 19 | |
| 20 | export function latestReleaseNote(): ReleaseNote { |
| 21 | // @ts-ignore Included only for layout tests. |
| 22 | const globalReleaseNotes: ReleaseNote[] = self.Help.releaseNoteText; |
Sigurd Schneider | 17c7445 | 2021-02-15 12:14:10 | [diff] [blame] | 23 | if (!latestReleaseNoteInstance) { |
| 24 | latestReleaseNoteInstance = |
Jan Scheffler | 5bba5fd | 2021-01-15 17:39:54 | [diff] [blame] | 25 | (globalReleaseNotes || releaseNoteText).reduce((acc, note) => note.version > acc.version ? note : acc); |
| 26 | } |
Sigurd Schneider | 17c7445 | 2021-02-15 12:14:10 | [diff] [blame] | 27 | return latestReleaseNoteInstance; |
Jan Scheffler | 5bba5fd | 2021-01-15 17:39:54 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | export function showReleaseNoteIfNeeded(): void { |
| 31 | const releaseNoteVersionSetting = Common.Settings.Settings.instance().createSetting(releaseVersionSeen, 0); |
| 32 | const releaseNoteVersionSettingValue = releaseNoteVersionSetting.get(); |
| 33 | innerShowReleaseNoteIfNeeded( |
| 34 | releaseNoteVersionSettingValue, latestReleaseNote().version, |
| 35 | Common.Settings.Settings.instance().moduleSetting('help.show-release-note').get()); |
| 36 | } |
| 37 | |
| 38 | export function innerShowReleaseNoteIfNeeded( |
| 39 | lastSeenVersion: number, latestVersion: number, showReleaseNote: boolean): void { |
| 40 | const releaseNoteVersionSetting = Common.Settings.Settings.instance().createSetting(releaseVersionSeen, 0); |
| 41 | if (!lastSeenVersion) { |
| 42 | releaseNoteVersionSetting.set(latestVersion); |
| 43 | return; |
| 44 | } |
| 45 | if (!showReleaseNote) { |
| 46 | return; |
| 47 | } |
| 48 | if (lastSeenVersion >= latestVersion) { |
| 49 | return; |
| 50 | } |
| 51 | releaseNoteVersionSetting.set(latestVersion); |
| 52 | UI.ViewManager.ViewManager.instance().showView(releaseNoteViewId, true); |
| 53 | } |
| 54 | |
Andres Olivares | bd877e0 | 2021-02-28 17:20:38 | [diff] [blame] | 55 | let helpLateInitializationInstance: HelpLateInitialization; |
Jan Scheffler | 5bba5fd | 2021-01-15 17:39:54 | [diff] [blame] | 56 | export class HelpLateInitialization implements Common.Runnable.Runnable { |
Andres Olivares | bd877e0 | 2021-02-28 17:20:38 | [diff] [blame] | 57 | static instance(opts: {forceNew: boolean|null} = {forceNew: null}): HelpLateInitialization { |
| 58 | const {forceNew} = opts; |
| 59 | if (!helpLateInitializationInstance || forceNew) { |
| 60 | helpLateInitializationInstance = new HelpLateInitialization(); |
| 61 | } |
| 62 | return helpLateInitializationInstance; |
| 63 | } |
| 64 | |
Jan Scheffler | 5bba5fd | 2021-01-15 17:39:54 | [diff] [blame] | 65 | async run(): Promise<void> { |
| 66 | if (!Host.InspectorFrontendHost.isUnderTest()) { |
Andres Olivares | bd877e0 | 2021-02-28 17:20:38 | [diff] [blame] | 67 | await Root.Runtime.Runtime.instance().loadModulePromise('help'); |
Jan Scheffler | 5bba5fd | 2021-01-15 17:39:54 | [diff] [blame] | 68 | showReleaseNoteIfNeeded(); |
| 69 | } |
| 70 | } |
| 71 | } |
Andres Olivares | bd877e0 | 2021-02-28 17:20:38 | [diff] [blame] | 72 | Common.Runnable.registerLateInitializationRunnable(HelpLateInitialization.instance); |
Jan Scheffler | 5bba5fd | 2021-01-15 17:39:54 | [diff] [blame] | 73 | |
Andres Olivares | 1019a42 | 2021-01-28 14:50:00 | [diff] [blame] | 74 | let releaseNotesActionDelegateInstance: ReleaseNotesActionDelegate; |
Jan Scheffler | 5bba5fd | 2021-01-15 17:39:54 | [diff] [blame] | 75 | export class ReleaseNotesActionDelegate implements UI.ActionRegistration.ActionDelegate { |
| 76 | handleAction(_context: UI.Context.Context, _actionId: string): boolean { |
| 77 | Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(latestReleaseNote().link); |
| 78 | return true; |
| 79 | } |
Sigurd Schneider | 1576186 | 2021-02-04 08:05:36 | [diff] [blame] | 80 | static instance(opts: {forceNew: boolean|null} = {forceNew: null}): ReleaseNotesActionDelegate { |
Andres Olivares | 1019a42 | 2021-01-28 14:50:00 | [diff] [blame] | 81 | const {forceNew} = opts; |
| 82 | if (!releaseNotesActionDelegateInstance || forceNew) { |
| 83 | releaseNotesActionDelegateInstance = new ReleaseNotesActionDelegate(); |
| 84 | } |
| 85 | |
| 86 | return releaseNotesActionDelegateInstance; |
| 87 | } |
Jan Scheffler | 5bba5fd | 2021-01-15 17:39:54 | [diff] [blame] | 88 | } |
| 89 | |
Andres Olivares | 1019a42 | 2021-01-28 14:50:00 | [diff] [blame] | 90 | let reportIssueActionDelegateInstance: ReportIssueActionDelegate; |
Jan Scheffler | 5bba5fd | 2021-01-15 17:39:54 | [diff] [blame] | 91 | export class ReportIssueActionDelegate implements UI.ActionRegistration.ActionDelegate { |
| 92 | handleAction(_context: UI.Context.Context, _actionId: string): boolean { |
| 93 | Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab( |
| 94 | 'https://bugs.chromium.org/p/chromium/issues/entry?template=DevTools+issue'); |
| 95 | return true; |
| 96 | } |
Sigurd Schneider | 1576186 | 2021-02-04 08:05:36 | [diff] [blame] | 97 | static instance(opts: {forceNew: boolean|null} = {forceNew: null}): ReportIssueActionDelegate { |
Andres Olivares | 1019a42 | 2021-01-28 14:50:00 | [diff] [blame] | 98 | const {forceNew} = opts; |
| 99 | if (!reportIssueActionDelegateInstance || forceNew) { |
| 100 | reportIssueActionDelegateInstance = new ReportIssueActionDelegate(); |
| 101 | } |
| 102 | |
| 103 | return reportIssueActionDelegateInstance; |
| 104 | } |
Jan Scheffler | 5bba5fd | 2021-01-15 17:39:54 | [diff] [blame] | 105 | } |
| 106 | export interface ReleaseNoteHighlight { |
| 107 | title: string; |
| 108 | subtitle: string; |
| 109 | link: string; |
| 110 | } |
| 111 | export interface ReleaseNote { |
| 112 | version: number; |
| 113 | header: string; |
Sigurd Schneider | 1576186 | 2021-02-04 08:05:36 | [diff] [blame] | 114 | highlights: {title: string, subtitle: string, link: string}[]; |
Jan Scheffler | 5bba5fd | 2021-01-15 17:39:54 | [diff] [blame] | 115 | link: string; |
| 116 | } |