mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-09 13:18:29 +08:00
..except for top-level `const` for which we allow camelCase, PascalCase and UPPER_CASE for the time being to accomodate the status quo in DevTools FE. Also allow `UIStrings` and `str_` which are used for localization all over the place. Bug: chromium:1057042 Change-Id: Ifa0445ac08c78997499ac5f9f33c9a9dc03d37fb Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2692779 Reviewed-by: Mathias Bynens <mathias@chromium.org> Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
105 lines
3.8 KiB
TypeScript
105 lines
3.8 KiB
TypeScript
// Copyright 2017 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
/* eslint-disable rulesdir/no_underscored_properties */
|
|
|
|
import * as Common from '../common/common.js'; // eslint-disable-line no-unused-vars
|
|
import * as Host from '../host/host.js';
|
|
import * as UI from '../ui/ui.js'; // eslint-disable-line no-unused-vars
|
|
|
|
import {releaseNoteText} from './ReleaseNoteText.js';
|
|
|
|
export const releaseVersionSeen = 'releaseNoteVersionSeen';
|
|
|
|
export const releaseNoteViewId: string = 'release-note';
|
|
|
|
let latestReleaseNoteInstance: ReleaseNote;
|
|
|
|
export function latestReleaseNote(): ReleaseNote {
|
|
// @ts-ignore Included only for layout tests.
|
|
const globalReleaseNotes: ReleaseNote[] = self.Help.releaseNoteText;
|
|
if (!latestReleaseNoteInstance) {
|
|
latestReleaseNoteInstance =
|
|
(globalReleaseNotes || releaseNoteText).reduce((acc, note) => note.version > acc.version ? note : acc);
|
|
}
|
|
return latestReleaseNoteInstance;
|
|
}
|
|
|
|
export function showReleaseNoteIfNeeded(): void {
|
|
const releaseNoteVersionSetting = Common.Settings.Settings.instance().createSetting(releaseVersionSeen, 0);
|
|
const releaseNoteVersionSettingValue = releaseNoteVersionSetting.get();
|
|
innerShowReleaseNoteIfNeeded(
|
|
releaseNoteVersionSettingValue, latestReleaseNote().version,
|
|
Common.Settings.Settings.instance().moduleSetting('help.show-release-note').get());
|
|
}
|
|
|
|
export function innerShowReleaseNoteIfNeeded(
|
|
lastSeenVersion: number, latestVersion: number, showReleaseNote: boolean): void {
|
|
const releaseNoteVersionSetting = Common.Settings.Settings.instance().createSetting(releaseVersionSeen, 0);
|
|
if (!lastSeenVersion) {
|
|
releaseNoteVersionSetting.set(latestVersion);
|
|
return;
|
|
}
|
|
if (!showReleaseNote) {
|
|
return;
|
|
}
|
|
if (lastSeenVersion >= latestVersion) {
|
|
return;
|
|
}
|
|
releaseNoteVersionSetting.set(latestVersion);
|
|
UI.ViewManager.ViewManager.instance().showView(releaseNoteViewId, true);
|
|
}
|
|
|
|
export class HelpLateInitialization implements Common.Runnable.Runnable {
|
|
async run(): Promise<void> {
|
|
if (!Host.InspectorFrontendHost.isUnderTest()) {
|
|
showReleaseNoteIfNeeded();
|
|
}
|
|
}
|
|
}
|
|
|
|
let releaseNotesActionDelegateInstance: ReleaseNotesActionDelegate;
|
|
export class ReleaseNotesActionDelegate implements UI.ActionRegistration.ActionDelegate {
|
|
handleAction(_context: UI.Context.Context, _actionId: string): boolean {
|
|
Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(latestReleaseNote().link);
|
|
return true;
|
|
}
|
|
static instance(opts: {forceNew: boolean|null} = {forceNew: null}): ReleaseNotesActionDelegate {
|
|
const {forceNew} = opts;
|
|
if (!releaseNotesActionDelegateInstance || forceNew) {
|
|
releaseNotesActionDelegateInstance = new ReleaseNotesActionDelegate();
|
|
}
|
|
|
|
return releaseNotesActionDelegateInstance;
|
|
}
|
|
}
|
|
|
|
let reportIssueActionDelegateInstance: ReportIssueActionDelegate;
|
|
export class ReportIssueActionDelegate implements UI.ActionRegistration.ActionDelegate {
|
|
handleAction(_context: UI.Context.Context, _actionId: string): boolean {
|
|
Host.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(
|
|
'https://bugs.chromium.org/p/chromium/issues/entry?template=DevTools+issue');
|
|
return true;
|
|
}
|
|
static instance(opts: {forceNew: boolean|null} = {forceNew: null}): ReportIssueActionDelegate {
|
|
const {forceNew} = opts;
|
|
if (!reportIssueActionDelegateInstance || forceNew) {
|
|
reportIssueActionDelegateInstance = new ReportIssueActionDelegate();
|
|
}
|
|
|
|
return reportIssueActionDelegateInstance;
|
|
}
|
|
}
|
|
export interface ReleaseNoteHighlight {
|
|
title: string;
|
|
subtitle: string;
|
|
link: string;
|
|
}
|
|
export interface ReleaseNote {
|
|
version: number;
|
|
header: string;
|
|
highlights: {title: string, subtitle: string, link: string}[];
|
|
link: string;
|
|
}
|