[go: nahoru, domu]

blob: 201a8b43380baa262ec16d95fcf51df9002bec86 [file] [log] [blame]
Jan Scheffler5bba5fd2021-01-15 17:39:541// 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 Lippe5f62c6f2021-02-25 16:39:267import * as Common from '../common/common.js';
Jan Scheffler5bba5fd2021-01-15 17:39:548import * as Host from '../host/host.js';
Andres Olivaresbd877e02021-02-28 17:20:389import * as Root from '../root/root.js';
10import * as UI from '../ui/ui.js'; // eslint-disable-line no-unused-vars
Jan Scheffler5bba5fd2021-01-15 17:39:5411
12import {releaseNoteText} from './ReleaseNoteText.js';
13
14export const releaseVersionSeen = 'releaseNoteVersionSeen';
15
16export const releaseNoteViewId: string = 'release-note';
17
Sigurd Schneider17c74452021-02-15 12:14:1018let latestReleaseNoteInstance: ReleaseNote;
Jan Scheffler5bba5fd2021-01-15 17:39:5419
20export function latestReleaseNote(): ReleaseNote {
21 // @ts-ignore Included only for layout tests.
22 const globalReleaseNotes: ReleaseNote[] = self.Help.releaseNoteText;
Sigurd Schneider17c74452021-02-15 12:14:1023 if (!latestReleaseNoteInstance) {
24 latestReleaseNoteInstance =
Jan Scheffler5bba5fd2021-01-15 17:39:5425 (globalReleaseNotes || releaseNoteText).reduce((acc, note) => note.version > acc.version ? note : acc);
26 }
Sigurd Schneider17c74452021-02-15 12:14:1027 return latestReleaseNoteInstance;
Jan Scheffler5bba5fd2021-01-15 17:39:5428}
29
30export 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
38export 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 Olivaresbd877e02021-02-28 17:20:3855let helpLateInitializationInstance: HelpLateInitialization;
Jan Scheffler5bba5fd2021-01-15 17:39:5456export class HelpLateInitialization implements Common.Runnable.Runnable {
Andres Olivaresbd877e02021-02-28 17:20:3857 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 Scheffler5bba5fd2021-01-15 17:39:5465 async run(): Promise<void> {
66 if (!Host.InspectorFrontendHost.isUnderTest()) {
Andres Olivaresbd877e02021-02-28 17:20:3867 await Root.Runtime.Runtime.instance().loadModulePromise('help');
Jan Scheffler5bba5fd2021-01-15 17:39:5468 showReleaseNoteIfNeeded();
69 }
70 }
71}
Andres Olivaresbd877e02021-02-28 17:20:3872Common.Runnable.registerLateInitializationRunnable(HelpLateInitialization.instance);
Jan Scheffler5bba5fd2021-01-15 17:39:5473
Andres Olivares1019a422021-01-28 14:50:0074let releaseNotesActionDelegateInstance: ReleaseNotesActionDelegate;
Jan Scheffler5bba5fd2021-01-15 17:39:5475export 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 Schneider15761862021-02-04 08:05:3680 static instance(opts: {forceNew: boolean|null} = {forceNew: null}): ReleaseNotesActionDelegate {
Andres Olivares1019a422021-01-28 14:50:0081 const {forceNew} = opts;
82 if (!releaseNotesActionDelegateInstance || forceNew) {
83 releaseNotesActionDelegateInstance = new ReleaseNotesActionDelegate();
84 }
85
86 return releaseNotesActionDelegateInstance;
87 }
Jan Scheffler5bba5fd2021-01-15 17:39:5488}
89
Andres Olivares1019a422021-01-28 14:50:0090let reportIssueActionDelegateInstance: ReportIssueActionDelegate;
Jan Scheffler5bba5fd2021-01-15 17:39:5491export 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 Schneider15761862021-02-04 08:05:3697 static instance(opts: {forceNew: boolean|null} = {forceNew: null}): ReportIssueActionDelegate {
Andres Olivares1019a422021-01-28 14:50:0098 const {forceNew} = opts;
99 if (!reportIssueActionDelegateInstance || forceNew) {
100 reportIssueActionDelegateInstance = new ReportIssueActionDelegate();
101 }
102
103 return reportIssueActionDelegateInstance;
104 }
Jan Scheffler5bba5fd2021-01-15 17:39:54105}
106export interface ReleaseNoteHighlight {
107 title: string;
108 subtitle: string;
109 link: string;
110}
111export interface ReleaseNote {
112 version: number;
113 header: string;
Sigurd Schneider15761862021-02-04 08:05:36114 highlights: {title: string, subtitle: string, link: string}[];
Jan Scheffler5bba5fd2021-01-15 17:39:54115 link: string;
116}