Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chrome-ext] Update nightly download link and add version check #1720

Merged
merged 1 commit into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/chrome-debug-extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ We recommend building a configuration file to represent the schema of the teleme

## Installing the tool

1. Download either the [official](https://js.monitor.azure.com/release/tools/ai.chrome-ext.zip) or [nightly](https://js.monitor.azure.com/nightly/tools/ai.chrome-ext.zip) build and unzip it into a folder on your PR
1. Download either the [official](https://js.monitor.azure.com/release/tools/ai.chrome-ext.zip) or [nightly](https://js.monitor.azure.com/nightly/tools/ai.chrome-ext.nightly.zip) build and unzip it into a folder on your PR
1. Open the Manage Extensions page in either Chrome or Edge
- Browse to either edge://extensions or chrome://extensions/ respectively
- Or choose Extensions from the ... menu
Expand Down
46 changes: 46 additions & 0 deletions tools/chrome-debug-extension/src/UpdateCheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { dumpObj } from "@microsoft/applicationinsights-core-js";

export declare type VersionCheckCallback = (newVersion: string, details: string) => void;

export function checkForUpdate(callback: VersionCheckCallback, currentVer?: string) {
if (!currentVer && chrome && chrome.runtime) {
let manifest = chrome.runtime.getManifest();
currentVer = manifest.version_name || manifest.version || "";
}

let newVersionLink = "https://js.monitor.azure.com/";
let versionCheck = newVersionLink;

if (currentVer && currentVer.indexOf("-nightly") !== -1) {
newVersionLink += "nightly/tools/ai.chrome-ext.nightly.zip";
versionCheck += "nightly/tools/ai.chrome-ext.nightly.integrity.json";
} else {
newVersionLink += "release/tools/ai.chrome-ext.zip";
versionCheck += "release/tools/ai.chrome-ext.integrity.json";
}

function _updateCheckFailed(reason: any) {
console && console.log("Version check failed -- " + reason);
}

function _checkVersion(value: string) {
if (value) {
try {
let integrity = JSON.parse(value);
if (currentVer !== integrity.version) {
callback && callback(integrity.version, newVersionLink)
}
} catch (e) {
// CDN can return an error which will be HTML
_updateCheckFailed(dumpObj(e));
}
}
}

fetch(versionCheck).then((resp) => {
resp.text().then(_checkVersion, _updateCheckFailed);
}, _updateCheckFailed);
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const ConfigurationSelection = (
<div className='configurationDescription'>
<p>Currently updates must be done manually.</p>
<p>
To update the tool, download either the <a href="https://js.monitor.azure.com/release/tools/ai.chrome-ext.zip" target="_blank">official</a> or <a href="https://js.monitor.azure.com/nightly/tools/ai.chrome-ext.zip" target="_blank">nightly</a> build and unzip it into the folder where you originally installed the tool.
To update the tool, download either the <a href="https://js.monitor.azure.com/release/tools/ai.chrome-ext.zip" target="_blank">official</a> or <a href="https://js.monitor.azure.com/nightly/tools/ai.chrome-ext.nightly.zip" target="_blank">nightly</a> build and unzip it into the folder where you originally installed the tool.
</p>
<p>
For more information, see the instructions <a href="https://github.com/microsoft/ApplicationInsights-JS/blob/master/tools/chrome-debug-extension/README.md" target="_blank">here</a>.
Expand Down
40 changes: 40 additions & 0 deletions tools/chrome-debug-extension/src/telemetryViewerPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getConfiguration } from "./configuration/configuration";
import { ConfigurationType, ConfigurationURLs } from "./configuration/Configuration.types";
import { IConfiguration } from "./configuration/IConfiguration";
import { Session } from "./session";
import { checkForUpdate } from "./UpdateCheck";

type AppPhase =
| "Startup"
Expand All @@ -17,11 +18,14 @@ type AppPhase =
| "ConfigurationLoadFailed";

const configurationTypeStorageKey = "configurationType";
const defaultVersion = "#version#";

export const TelemetryViewerPopup = (): React.ReactElement => {
const [appPhase, setAppPhase] = React.useState<AppPhase>("Startup");
const [session, setSession] = React.useState<Session | undefined>(undefined);
const [configurationType, setConfigurationType] = React.useState<ConfigurationType>(undefined);
let newAvailableVersion: string;
// let newVersionDownload: string;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was originally planning on having some sort of dynamic update -- but that is more work so this is really a placeholder


function applyConfigurationType(newConfigurationType: ConfigurationType): void {
if (newConfigurationType) {
Expand Down Expand Up @@ -72,7 +76,43 @@ export const TelemetryViewerPopup = (): React.ReactElement => {
}
}

function highlightNewVersion() {
let orgTitle = document.title;
let count = 0;
let interval = setInterval(() => {
count ++;
if ((count % 2) == 0) {
document.title = orgTitle;
} else {
document.title = orgTitle + " *** v" + encodeURIComponent(newAvailableVersion) + " Available ***"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very simple "flashing" title to show the new available version number (really just a different version -- assumes that we only move forward)

}
if (count > 10) {
clearInterval(interval);
}
}, 1500);
}

function versionCheck() {
let manifestVersion = defaultVersion;
if (chrome && chrome.runtime) {
let manifest = chrome.runtime.getManifest();
manifestVersion = manifest.version_name || manifest.version || "";
}

if (manifestVersion) {
let newTitle = "Telemetry Viewer - v" + encodeURIComponent(manifestVersion);
document.title = newTitle;
checkForUpdate((newVersion, details) => {
newAvailableVersion = newVersion;
// newVersionDownload = details;
highlightNewVersion();
}, manifestVersion);
}
}

React.useEffect(() => {
versionCheck();

let configurationTypeToSet = undefined;
try {
const savedValue = localStorage.getItem(configurationTypeStorageKey);
Expand Down
2 changes: 1 addition & 1 deletion tools/release-tools/setVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ const setPackageJsonRelease = () => {
}

if (theFilename.indexOf("/package.json") !== -1) {
let srcFolder = theFilename.replace("/package.json", "/**/*.ts");
let srcFolder = theFilename.replace("/package.json", "/**/*.ts", "/**/*.tsx", "/**/*.html");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just update our build level version replacement logic to support updating the build versions in *.tsx and *.html files -- this is used for manually updating versions via npm run setVersion -- 2.x.x and the nightly builds

console.log(" - Checking source files: " + srcFolder);
const tsFiles = globby.sync(srcFolder);
tsFiles.map(sourceFile => {
Expand Down