forked from chromium/chromium
-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dpwa] Update the file handler app to load .foo (txt) files.
The file name and the content will be displayed in the app after finished loading. Bug: 1401133 Change-Id: I90af66fcc5da12b6573ec244cc41093d2165052a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4108946 Reviewed-by: Daniel Murphy <dmurph@chromium.org> Commit-Queue: Clifford Cheng <cliffordcheng@chromium.org> Cr-Commit-Position: refs/heads/main@{#1084607}
- Loading branch information
Clifford Cheng
authored and
Chromium LUCI CQ
committed
Dec 16, 2022
1 parent
4243ef0
commit fd8ca9b
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2022 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
|
||
const openedFilesContainer = document.getElementById( | ||
"opened-files-container" | ||
); | ||
|
||
const makeFileViewer = async (launchFile) => { | ||
const readHandle = await launchFile.getFile(); | ||
|
||
const template = document.getElementById("file-viewer-template"); | ||
const fullName = readHandle.name; | ||
const element = template.content.cloneNode(true); | ||
const nameContainer = element.querySelector("[name='file-name']"); | ||
nameContainer.innerText = fullName; | ||
|
||
const contentContainer = element.querySelector("[name='file-contents']"); | ||
contentContainer.innerText = "Loading..."; | ||
// Asynchronously load in the file contents. | ||
try { | ||
contentContainer.value = await readHandle.text(); | ||
} catch (err) { | ||
console.log(`Failed to load contents for file: ${readHandle.name}`, err); | ||
} | ||
|
||
return element; | ||
}; | ||
|
||
var resolveLaunchFinished; | ||
|
||
var launchFinishedPromise = new Promise(resolve => { | ||
window.launchQueue.setConsumer(async (launchParams) => { | ||
console.log("Launched with: ", launchParams); | ||
const viewersContainer = document.getElementById("viewers-container"); | ||
if (!launchParams.files.length) { | ||
viewersContainer.innerText = | ||
"Oh poo, no files. Consider granting the permission next time!"; | ||
return; | ||
} | ||
|
||
for (const launchFile of launchParams.files) { | ||
const editor = await makeFileViewer(launchFile); | ||
openedFilesContainer.appendChild(editor); | ||
} | ||
let results = []; | ||
const fileContents = openedFilesContainer.querySelectorAll( | ||
"[name='file-contents']"); | ||
for (const fileContent of fileContents) { | ||
results.push(fileContent.value); | ||
} | ||
resolve(results); | ||
}) | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters