-
Notifications
You must be signed in to change notification settings - Fork 237
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -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" | ||
|
@@ -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; | ||
|
||
function applyConfigurationType(newConfigurationType: ConfigurationType): void { | ||
if (newConfigurationType) { | ||
|
@@ -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 ***" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
console.log(" - Checking source files: " + srcFolder); | ||
const tsFiles = globby.sync(srcFolder); | ||
tsFiles.map(sourceFile => { | ||
|
There was a problem hiding this comment.
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