mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-21 15:26:17 -04:00
Add Base64ZipDialog to PairDrop via share-menu on iOS
This commit is contained in:
parent
a60d60009a
commit
c53221ba01
3 changed files with 71 additions and 4 deletions
|
@ -990,6 +990,45 @@ class ReceiveTextDialog extends Dialog {
|
|||
}
|
||||
}
|
||||
|
||||
class Base64ZipDialog extends Dialog {
|
||||
|
||||
constructor() {
|
||||
super('base64ZipDialog');
|
||||
const urlParams = new URL(window.location).searchParams;
|
||||
const base64zip = urlParams.get('base64zip');
|
||||
this.$pasteBtn = this.$el.querySelector('#base64ZipPasteBtn')
|
||||
this.$pasteBtn.addEventListener('click', _ => this.processClipboard())
|
||||
if (base64zip) this.show();
|
||||
}
|
||||
|
||||
async processClipboard() {
|
||||
this.$pasteBtn.pointerEvents = "none";
|
||||
this.$pasteBtn.innerText = "Processing...";
|
||||
try {
|
||||
const base64zip = await navigator.clipboard.readText();
|
||||
let bstr = atob(base64zip), n = bstr.length, u8arr = new Uint8Array(n);
|
||||
while (n--) {
|
||||
u8arr[n] = bstr.charCodeAt(n);
|
||||
}
|
||||
|
||||
const zipBlob = new File([u8arr], 'archive.zip');
|
||||
|
||||
let files = [];
|
||||
const zipEntries = await zipper.getEntries(zipBlob);
|
||||
for (let i = 0; i < zipEntries.length; i++) {
|
||||
let fileBlob = await zipper.getData(zipEntries[i]);
|
||||
files.push(new File([fileBlob], zipEntries[i].filename));
|
||||
}
|
||||
Events.fire('activate-paste-mode', {files: files, text: ""})
|
||||
} catch (e) {
|
||||
Events.fire('notify-user', 'Clipboard content is malformed.')
|
||||
} finally {
|
||||
window.history.replaceState({}, "Rewrite URL", '/');
|
||||
this.hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Toast extends Dialog {
|
||||
constructor() {
|
||||
super('toast');
|
||||
|
@ -1155,9 +1194,8 @@ class WebShareTargetUI {
|
|||
})
|
||||
caches.delete("share_target_files").then( _ => console.log("shared files deleted from cache"));
|
||||
}
|
||||
window.history.replaceState({}, "Rewrite URL", '/'); //remove room_key from url
|
||||
window.history.replaceState({}, "Rewrite URL", '/');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1391,6 +1429,7 @@ class PairDrop {
|
|||
const receiveTextDialog = new ReceiveTextDialog();
|
||||
const pairDeviceDialog = new PairDeviceDialog();
|
||||
const clearDevicesDialog = new ClearDevicesDialog();
|
||||
const base64ZipDialog = new Base64ZipDialog();
|
||||
const toast = new Toast();
|
||||
const notifications = new Notifications();
|
||||
const networkStatusUI = new NetworkStatusUI();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue