Skip to content

Commit

Permalink
[main][debug tool] fix the way of calling chrome storage and add new …
Browse files Browse the repository at this point in the history
…url (#2462)
  • Loading branch information
siyuniu-ms authored Jan 14, 2025
1 parent c45c958 commit 81f068e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const ConfigurationSelection = (
function updateCustomConfiguration(newCustomConfiguration: string): void {
setCustomConfigurationDirty(true);
setCustomConfiguration(newCustomConfiguration);
chrome.storage.local.set({ customConfigurationStorageKey: newCustomConfiguration });
chrome.storage.local.set({ [customConfigurationStorageKey]: newCustomConfiguration });

}

Expand All @@ -66,9 +66,9 @@ export const ConfigurationSelection = (

React.useEffect(() => {
try {
doAwait(chrome.storage.local.get(customConfigurationStorageKey), (savedValue: any) => {
doAwait(chrome.storage.local.get([customConfigurationStorageKey]), (savedValue: any) => {
if (savedValue) {
setCustomConfiguration(savedValue);
setCustomConfiguration(savedValue[customConfigurationStorageKey]);
}
if (textAreaRef.current) {
textAreaRef.current.setAttribute("aria-labelledby", "customConfigurationLabel");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const TelemetryViewer = (props: ITelemetryViewerProps): React.ReactElemen

const handleNewFilterSettings = (newFilterSettings: IFilterSettings): void => {
try {
chrome.storage.local.set({ filterSettingsCacheKey: JSON.stringify(newFilterSettings) });
chrome.storage.local.set({ [filterSettingsCacheKey]: JSON.stringify(newFilterSettings) });
} catch {
// Default is OK
}
Expand Down Expand Up @@ -111,12 +111,12 @@ export const TelemetryViewer = (props: ITelemetryViewerProps): React.ReactElemen

React.useEffect(() => {
try {
doAwait(chrome.storage.local.get(filterSettingsCacheKey), (json: any) => {
doAwait(chrome.storage.local.get([filterSettingsCacheKey]), (json: any) => {
if (json) {
// Make sure we have any defaults set
let settings: IFilterSettings = {
...getDefaultFilterSettings(props.session.configuration),
...(JSON.parse(json))
...(JSON.parse(json[filterSettingsCacheKey]))
};

setFilterSettings(settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export function getPopupSettings() : IPopupSettings {
height: 860
};

doAwait(chrome.storage.local.get(popupWindowSettingsCacheKey), (popupSettings: any) => {
doAwait(chrome.storage.local.get([popupWindowSettingsCacheKey]), (popupSettings: any) => {
if (popupSettings) {
try {
settings = JSON.parse(popupSettings);
settings = JSON.parse(popupSettings[popupWindowSettingsCacheKey]);
} catch (e) {
// Just ignore failures and we fallback to the defaults
}
Expand All @@ -38,7 +38,7 @@ function _setPopupSettings(newSettings: IPopupSettings) {
settings[name] = value;
}
});
chrome.storage.local.set({ popupWindowSettingsCacheKey: JSON.stringify(settings) });
chrome.storage.local.set({ [popupWindowSettingsCacheKey]: JSON.stringify(settings) });
}

export function setPopupSize(width?: number, height?: number) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function createDataSource(configuration: IConfiguration): IDataSource {
}

if (!urls || urls.length === 0) {
urls = ["*://*.microsoft.com/OneCollector/*", "*://*.visualstudio.com/v2/track*"];
urls = ["*://*.microsoft.com/OneCollector/*", "*://*.visualstudio.com/v2/track*", "*://*.eastus-8.in.applicationinsights.azure.com/v2/track*"];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class DefaultDataSource implements IDataSource {
let nextListenerId: number = 0;

if (!urls || urls.length === 0) {
urls = ["*://*.microsoft.com/OneCollector/*", "*://*.visualstudio.com/v2/track*"]
urls = ["*://*.microsoft.com/OneCollector/*", "*://*.visualstudio.com/v2/track*", "*://*.eastus-8.in.applicationinsights.azure.com/v2/track*"];
}

_self.startListening = (): void => {
Expand Down
10 changes: 5 additions & 5 deletions tools/chrome-debug-extension/src/telemetryViewerPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const TelemetryViewerPopup = (): React.ReactElement => {

function applyConfigurationType(newConfigurationType: ConfigurationType): void {
if (newConfigurationType) {
chrome.storage.local.set({ configurationType: newConfigurationType });
chrome.storage.local.set({ [configurationTypeStorageKey]: newConfigurationType });
}
setConfigurationType(newConfigurationType);

Expand All @@ -46,9 +46,9 @@ export const TelemetryViewerPopup = (): React.ReactElement => {

if (configurationTypeToLoad === "Custom") {
try {
doAwait(chrome.storage.local.get(customConfigurationStorageKey), (savedValue: any) => {
doAwait(chrome.storage.local.get([customConfigurationStorageKey]), (savedValue: any) => {
if (savedValue) {
const newConfiguration = JSON.parse(savedValue) as IConfiguration;
const newConfiguration = JSON.parse(savedValue[customConfigurationStorageKey]) as IConfiguration;
let newSession = new Session(newConfiguration, session);
session && session.dispose();
setSession(newSession);
Expand Down Expand Up @@ -118,9 +118,9 @@ export const TelemetryViewerPopup = (): React.ReactElement => {

let configurationTypeToSet: ConfigurationType = undefined;
try {
doAwait(chrome.storage.local.get(configurationTypeStorageKey), (savedValue: any) => {
doAwait(chrome.storage.local.get([configurationTypeStorageKey]), (savedValue: any) => {
if (savedValue && Object.keys(ConfigurationURLs).includes(savedValue)) {
configurationTypeToSet = savedValue as ConfigurationType;
configurationTypeToSet = savedValue[configurationTypeStorageKey] as ConfigurationType;
}
setConfigurationType(configurationTypeToSet);
applyConfigurationType(configurationTypeToSet);
Expand Down

0 comments on commit 81f068e

Please sign in to comment.