fixes for firefox and safari:

- ensure progress bar % works on ff, and safari
- don't use URL for parsing custom schemes due to browser differences
- add error messaging for interrupted download
This commit is contained in:
Ilya Kreymer
2020-05-07 11:11:14 -07:00
parent 1cf32c7de4
commit 5f148a8325
4 changed files with 132 additions and 93 deletions
+67 -60
View File
File diff suppressed because one or more lines are too long
+30 -29
View File
@@ -3,7 +3,7 @@ import { unsafeHTML } from 'lit-html/directives/unsafe-html';
import { unsafeSVG } from 'lit-html/directives/unsafe-svg'; import { unsafeSVG } from 'lit-html/directives/unsafe-svg';
import { styleMap } from 'lit-html/directives/style-map'; import { styleMap } from 'lit-html/directives/style-map';
import { digestMessage, getTS, tsToDate, sourceToId } from './pageutils'; import { digestMessage, getTS, tsToDate, sourceToId, parseURLSchemeHostPath } from './pageutils';
import { register } from 'register-service-worker'; import { register } from 'register-service-worker';
import prettyBytes from 'pretty-bytes'; import prettyBytes from 'pretty-bytes';
@@ -33,6 +33,10 @@ function wrapCss(custom) {
const GDRIVE_CLIENT_ID = "160798412227-tko4c82uopud11q105b2lvbogsj77hlg.apps.googleusercontent.com"; const GDRIVE_CLIENT_ID = "160798412227-tko4c82uopud11q105b2lvbogsj77hlg.apps.googleusercontent.com";
const dbworker = new Worker(__SW_PATH__);
// =========================================================================== // ===========================================================================
class AppMain extends LitElement class AppMain extends LitElement
{ {
@@ -270,8 +274,6 @@ class WrLoader extends LitElement
this.coll = ""; this.coll = "";
this.state = "waiting"; this.state = "waiting";
this.loadInfo = null; this.loadInfo = null;
this.worker = new Worker(__SW_PATH__);
} }
static get properties() { static get properties() {
@@ -294,7 +296,7 @@ class WrLoader extends LitElement
} }
initMessages() { initMessages() {
this.worker.addEventListener("message", (event) => { dbworker.addEventListener("message", (event) => {
switch (event.data.msg_type) { switch (event.data.msg_type) {
case "collProgress": case "collProgress":
if (event.data.name === this.coll) { if (event.data.name === this.coll) {
@@ -313,7 +315,7 @@ class WrLoader extends LitElement
} }
this.progress = this.total; this.progress = this.total;
this.percent = 100; this.percent = 100;
this.dispatchEvent(new CustomEvent("coll-loaded", {detail: event.data})); //this.dispatchEvent(new CustomEvent("coll-loaded", {detail: event.data}));
} }
break; break;
} }
@@ -326,31 +328,23 @@ class WrLoader extends LitElement
// custom protocol handlers here... // custom protocol handlers here...
try { try {
const sup = new URL(this.sourceUrl); const {scheme, host, path} = parseURLSchemeHostPath(sourceUrl);
let firstSlash = null;
if (!sup.host) { switch (scheme) {
firstSlash = sup.pathname.indexOf("/", 2); case "googledrive":
}
switch (sup.protocol) {
case "googledrive:":
this.state = "googledrive"; this.state = "googledrive";
if (firstSlash < 0) { this.fileId = host;
firstSlash = undefined;
}
this.fileId = sup.pathname.slice(2, firstSlash);
source = await this.googledriveInit(); source = await this.googledriveInit();
break; break;
case "s3:": case "s3":
sourceUrl = `https://${sup.pathname.slice(2, firstSlash)}.s3.amazonaws.com${sup.pathname.slice(firstSlash)}`; sourceUrl = `https://${host}.s3.amazonaws.com${path}`;
source = {sourceUrl, source = {sourceUrl,
sourceId: this.sourceUrl, sourceId: this.sourceUrl,
name: this.sourceUrl}; name: this.sourceUrl};
break; break;
case "file:": case "file":
if (!this.loadInfo) { if (!this.loadInfo) {
this.state = "errored"; this.state = "errored";
this.error = "File URLs are local and can not be shared. You can choose a file to upload from the main page."; this.error = "File URLs are local and can not be shared. You can choose a file to upload from the main page.";
@@ -375,7 +369,7 @@ class WrLoader extends LitElement
const msg = {"msg_type": "addColl", "name": this.coll, skipExisting: true, file: source}; const msg = {"msg_type": "addColl", "name": this.coll, skipExisting: true, file: source};
this.worker.postMessage(msg); dbworker.postMessage(msg);
} }
googledriveInit() { googledriveInit() {
@@ -406,15 +400,20 @@ class WrLoader extends LitElement
margin: 1em; margin: 1em;
} }
progress:after { .progress-div {
content: attr(data-percent)'%'; position: relative;
width: 400px !important;
}
.progress-label {
position: absolute; position: absolute;
-webkit-transform: translate(-50%, -100%); top: 0;
-ms-transform: translate(-50%, -100%); left: 50%;
transform: translateX(-50%, -100%); transform: translateX(-50%);
font-size: calc(1.5rem / 1.5); font-size: calc(1.5rem / 1.5);
line-height: 1.5rem; line-height: 1.5rem;
} }
.error { .error {
white-space: pre-wrap; white-space: pre-wrap;
text-align: left; text-align: left;
@@ -447,9 +446,11 @@ class WrLoader extends LitElement
case "started": case "started":
return html` return html`
<progress class="progress is-primary is-large" <div class="progress-div">
data-percent="${this.percent}" value="${this.percent}" max="100" <progress id="progress" class="progress is-primary is-large"
style="max-width: 400px"/>`; value="${this.percent}" max="100"></progress>
<label class="progress-label" for="progress">${this.percent}%</label>
</div>`;
case "errored": case "errored":
return html`<div class="error has-text-danger">${this.error}</div>`; return html`<div class="error has-text-danger">${this.error}</div>`;
+32 -1
View File
@@ -39,8 +39,39 @@ async function sourceToId(url) {
return {url, coll}; return {url, coll};
} }
// simple parse of scheme, host, rest of path
// not using URL due to different browser behavior
function parseURLSchemeHostPath(url) {
let inx = url.indexOf("://");
let hostInx = 0;
let scheme = "";
let host = "";
let path = "";
if (inx >= 0) {
scheme = url.slice(0, inx);
inx += 3;
} else {
inx++;
if (url.startsWith("//")) {
inx += 2;
}
}
hostInx = url.indexOf("/", inx);
if (hostInx > 0) {
host = url.slice(inx, hostInx);
path = url.slice(hostInx);
} else {
host = url.slice(inx);
path = "";
}
return {scheme, host, path};
}
export { digestMessage, tsToDate, getTS, sourceToId };
export { digestMessage, tsToDate, getTS, sourceToId, parseURLSchemeHostPath };
+3 -3
View File
File diff suppressed because one or more lines are too long