Added export to web shell and removed 'downloads' API permission

This commit is contained in:
Brian Vaughn
2019-05-22 06:46:42 -07:00
parent 7657eabb9b
commit bc06860894
7 changed files with 28 additions and 42 deletions
-1
View File
@@ -44,7 +44,6 @@
"permissions": [
"<all_urls>",
"background",
"downloads",
"tabs",
"file:///*",
"http://*/*",
-1
View File
@@ -46,7 +46,6 @@
"permissions": [
"<all_urls>",
"downloads",
"activeTab",
"tabs",
"file:///*",
-11
View File
@@ -110,17 +110,6 @@ chrome.runtime.onMessage.addListener((request, sender) => {
setIconAndPopup(reactBuildType, sender.tab.id);
}
if (request.exportFile) {
let { contents, filename } = request;
if (!Array.isArray(contents)) {
contents = [contents];
}
const blob = new Blob(contents, { type: 'text/plain' });
const url = URL.createObjectURL(blob);
chrome.downloads.download({ filename, saveAs: true, url });
}
if (request.captureScreenshot) {
const { commitIndex, rootID } = request;
try {
-8
View File
@@ -85,13 +85,6 @@ function createPanelIfReactLoaded() {
localStorage.setItem(LOCAL_STORAGE_SUPPORTS_PROFILING_KEY, 'true');
chrome.devtools.inspectedWindow.eval('window.location.reload();');
});
bridge.addListener('exportFile', ({ contents, filename }) => {
chrome.runtime.sendMessage({
exportFile: true,
contents,
filename,
});
});
bridge.addListener('captureScreenshot', ({ commitIndex, rootID }) => {
chrome.runtime.sendMessage(
{
@@ -124,7 +117,6 @@ function createPanelIfReactLoaded() {
store = new Store(bridge, {
isProfiling,
supportsCaptureScreenshots: true,
supportsFileDownloads: browserName === 'Chrome',
supportsReloadAndProfile: true,
supportsProfiling,
});
-10
View File
@@ -45,7 +45,6 @@ const LOCAL_STORAGE_COLLAPSE_ROOTS_BY_DEFAULT_KEY =
type Config = {|
isProfiling?: boolean,
supportsCaptureScreenshots?: boolean,
supportsFileDownloads?: boolean,
supportsReloadAndProfile?: boolean,
supportsProfiling?: boolean,
|};
@@ -99,7 +98,6 @@ export default class Store extends EventEmitter {
// These options may be initially set by a confiugraiton option when constructing the Store.
// In the case of "supportsProfiling", the option may be updated based on the injected renderers.
_supportsCaptureScreenshots: boolean = false;
_supportsFileDownloads: boolean = false;
_supportsProfiling: boolean = false;
_supportsReloadAndProfile: boolean = false;
@@ -127,7 +125,6 @@ export default class Store extends EventEmitter {
const {
supportsCaptureScreenshots,
supportsFileDownloads,
supportsProfiling,
supportsReloadAndProfile,
} = config;
@@ -137,9 +134,6 @@ export default class Store extends EventEmitter {
localStorage.getItem(LOCAL_STORAGE_CAPTURE_SCREENSHOTS_KEY) ===
'true';
}
if (supportsFileDownloads) {
this._supportsFileDownloads = true;
}
if (supportsProfiling) {
this._supportsProfiling = true;
}
@@ -309,10 +303,6 @@ export default class Store extends EventEmitter {
return this._supportsCaptureScreenshots;
}
get supportsFileDownloads(): boolean {
return this._supportsFileDownloads;
}
get supportsProfiling(): boolean {
return this._supportsProfiling;
}
@@ -10,6 +10,7 @@ import {
prepareProfilingDataExport,
prepareProfilingDataFrontendFromExport,
} from './utils';
import { downloadFile } from '../utils';
import styles from './ProfilingImportExportButtons.css';
@@ -34,8 +35,10 @@ export default function ProfilingImportExportButtons() {
profilerStore.profilingData
);
// TODO (profarc) Generate anchor "download" tag and click it
console.log('profilingDataExport:', profilingDataExport);
downloadFile(
'profile-data.json',
JSON.stringify(profilingDataExport, null, 2)
);
}
}, [rootID, profilerStore.profilingData]);
@@ -95,15 +98,13 @@ export default function ProfilingImportExportButtons() {
>
<ButtonIcon type="import" />
</Button>
{store.supportsFileDownloads && (
<Button
disabled={isProfiling || !profilerStore.hasProfilingData}
onClick={downloadData}
title="Save profile..."
>
<ButtonIcon type="export" />
</Button>
)}
<Button
disabled={isProfiling || !profilerStore.hasProfilingData}
onClick={downloadData}
title="Save profile..."
>
<ButtonIcon type="export" />
</Button>
</Fragment>
);
}
+16
View File
@@ -146,3 +146,19 @@ export function serializeHooksForCopy(hooks: HooksTree | null): string {
return '';
}
}
export function downloadFile(filename: string, text: string): void {
const element = document.createElement('a');
element.setAttribute(
'href',
'data:text/plain;charset=utf-8,' + encodeURIComponent(text)
);
element.setAttribute('download', filename);
element.style.display = 'none';
((document.body: any): HTMLBodyElement).appendChild(element);
element.click();
((document.body: any): HTMLBodyElement).removeChild(element);
}