Bug 1845037 - [devtools] Revert DevTools screenshots to use the default downloads directory r=devtools-reviewers,ochameau

Revert the DevTools bits from Bug 1072345 to be consistent with the Screenshots feature from Firefox.

Differential Revision: https://phabricator.services.mozilla.com/D207413
This commit is contained in:
Julian Descottes 2024-04-15 15:05:57 +00:00
parent 6ebde68fe8
commit c23ab24dbd
2 changed files with 8 additions and 20 deletions

View file

@ -327,9 +327,9 @@ function saveToClipboard(base64URI) {
let _outputDirectory = null; let _outputDirectory = null;
/** /**
* Returns the default directory for screenshots. * Returns the default directory for DevTools screenshots.
* If a specific directory for screenshots is not defined, * For consistency with the Firefox Screenshots feature, this will default to
* it falls back to the system downloads directory. * the preferred downloads directory.
* *
* @return {Promise<String>} Resolves the path as a string * @return {Promise<String>} Resolves the path as a string
*/ */
@ -338,13 +338,7 @@ async function getOutputDirectory() {
return _outputDirectory; return _outputDirectory;
} }
try { _outputDirectory = await lazy.Downloads.getPreferredDownloadsDirectory();
// This will throw if there is not a screenshot directory set for the platform
_outputDirectory = Services.dirsvc.get("Scrnshts", Ci.nsIFile).path;
} catch (e) {
_outputDirectory = await lazy.Downloads.getPreferredDownloadsDirectory();
}
return _outputDirectory; return _outputDirectory;
} }

View file

@ -97,16 +97,10 @@ add_task(async function () {
const dayString = date.getDate().toString().padStart(2, "0"); const dayString = date.getDate().toString().padStart(2, "0");
const expectedDateString = `${date.getFullYear()}-${monthString}-${dayString}`; const expectedDateString = `${date.getFullYear()}-${monthString}-${dayString}`;
let screenshotDir; const { Downloads } = ChromeUtils.importESModule(
try { "resource://gre/modules/Downloads.sys.mjs"
// This will throw if there is not a screenshot directory set for the platform );
screenshotDir = Services.dirsvc.get("Scrnshts", Ci.nsIFile).path; const screenshotDir = await Downloads.getPreferredDownloadsDirectory();
} catch (e) {
const { Downloads } = ChromeUtils.importESModule(
"resource://gre/modules/Downloads.sys.mjs"
);
screenshotDir = await Downloads.getPreferredDownloadsDirectory();
}
const { renderedDate, filePath } = const { renderedDate, filePath } =
/Saved to (?<filePath>.*Screen Shot (?<renderedDate>\d{4}-\d{2}-\d{2}) at \d{2}.\d{2}.\d{2}\.png)/.exec( /Saved to (?<filePath>.*Screen Shot (?<renderedDate>\d{4}-\d{2}-\d{2}) at \d{2}.\d{2}.\d{2}\.png)/.exec(