Skip to content

Commit

Permalink
Update build
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrews54757 committed Nov 20, 2023
1 parent b658721 commit 7e0345a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion built/web/options/options.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function createKeybindElement(keybind) {
containerElement.appendChild(keybindInput);
keybindsList.appendChild(containerElement);
}
document.getElementById('welcome').href = chrome?.runtime?.getURL('welcome.html') || './../welcome.html';
document.getElementById('welcome').href = EnvUtils.isExtension() ? chrome?.runtime?.getURL('welcome.html') : './../welcome.html';
playMP4URLs.addEventListener('change', () => {
Options.playMP4URLs = playMP4URLs.checked;
optionChanged();
Expand Down
22 changes: 12 additions & 10 deletions built/web/player/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async function loadSubtitles(subs) {
return subs.filter((sub) => sub.data);
}
async function sortSubtitles(subs) {
if (!chrome?.i18n?.detectLanguage) {
if (!EnvUtils.isExtension() || !chrome?.i18n?.detectLanguage) {
return subs;
}
let defLang = 'en';
Expand Down Expand Up @@ -182,16 +182,18 @@ async function setup() {
if (OPTIONS && window.fastStream) window.fastStream.setOptions(OPTIONS);
const urlParams = new URLSearchParams(window.location.search);
const myParam = urlParams.get('frame_id');
chrome?.runtime?.sendMessage({
type: 'faststream',
url: window.location.href,
isExt: true,
frameId: parseInt(myParam) || 0,
}).then((data) => {
chrome.runtime.sendMessage({
type: 'ready',
if (EnvUtils.isExtension()) {
chrome?.runtime?.sendMessage({
type: 'faststream',
url: window.location.href,
isExt: true,
frameId: parseInt(myParam) || 0,
}).then((data) => {
chrome.runtime.sendMessage({
type: 'ready',
});
});
});
}
const version = window.fastStream.version;
console.log('\n %c %c %cFast%cStream %c-%c ' + version + ' %c By Andrews54757 \n', 'background: url(https://user-images.githubusercontent.com/13282284/57593160-3a4fb080-7508-11e9-9507-33d45c4f9e41.png) no-repeat; background-size: 16px 16px; padding: 2px 6px; margin-right: 4px', 'background: rgb(50,50,50); padding:5px 0;', 'color: rgb(200,200,200); background: rgb(50,50,50); padding:5px 0;', 'color: rgb(200,200,200); background: rgb(50,50,50); padding:5px 0;', 'color: rgb(200,200,200); background: rgb(50,50,50); padding:5px 0;', 'color: #afbc2a; background: rgb(50,50,50); padding:5px 0;', 'color: black; background: #e9e9e9; padding:5px 0;');
window.addEventListener('beforeunload', () => {
Expand Down
19 changes: 10 additions & 9 deletions built/web/player/modules/FSBlob.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import {IndexedDBManager} from '../network/IndexedDBManager.mjs';
import {EnvUtils} from '../utils/EnvUtils.mjs';
const BrowserCanAutoOffloadBlobs = EnvUtils.isChrome();
const UseIndexedDB = !BrowserCanAutoOffloadBlobs && IndexedDBManager.isSupported();
export class FSBlob {
constructor() {
if (BrowserCanAutoOffloadBlobs) {
this.blobStore = new Map();
} else {
if (UseIndexedDB) {
this.indexedDBManager = new IndexedDBManager();
this.setupPromise = this.indexedDBManager.setup();
this.blobStorePromises = new Map();
} else {
this.blobStore = new Map();
}
this.blobIndex = 0;
}
Expand All @@ -18,10 +19,10 @@ export class FSBlob {
return true;
}
_saveBlob(identifier, blob) {
if (BrowserCanAutoOffloadBlobs) {
this.blobStore.set(identifier, blob);
} else {
if (UseIndexedDB ) {
this.blobStorePromises.set(identifier, this.saveBlobAsync(identifier, blob));
} else {
this.blobStore.set(identifier, blob);
}
}
saveBlob(blob) {
Expand All @@ -36,11 +37,11 @@ export class FSBlob {
return identifier;
}
async getBlob(identifier) {
if (BrowserCanAutoOffloadBlobs) {
return this.blobStore.get(identifier);
} else {
if (UseIndexedDB) {
await this.blobStorePromises.get(identifier);
return await this.indexedDBManager.getFile(identifier);
} else {
return this.blobStore.get(identifier);
}
}
close() {
Expand Down
2 changes: 1 addition & 1 deletion built/web/player/network/DownloadManager.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export class DownloadManager {
}
async setup() {
// Chrome can move blobs to file storage, so we don't need to use IndexedDB
if (!EnvUtils.isChrome()) {
if (!EnvUtils.isChrome() && IndexedDBManager.isSupported()) {
this.indexedDBManager = new IndexedDBManager();
await this.indexedDBManager.setup();
}
Expand Down
4 changes: 4 additions & 0 deletions built/web/player/network/IndexedDBManager.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ const closeQueue = [];
export class IndexedDBManager {
constructor() {
}
static isSupported() {
return window.indexedDB !== undefined;
}
async setup() {
await this.close();
this.prune();
Expand Down Expand Up @@ -91,6 +94,7 @@ export class IndexedDBManager {
});
}
async clearStorage() {
if (!this.db) return;
return this.transact(this.db, 'files', 'readwrite', (transaction)=>{
const metaDataStore = transaction.objectStore('files');
return this.wrapRequest(metaDataStore.clear());
Expand Down
2 changes: 1 addition & 1 deletion built/web/player/utils/EnvUtils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class EnvUtils {
return navigator.userAgent.indexOf('Chrome') !== -1;
}
static isExtension() {
return !!chrome?.extension;
return typeof chrome !== 'undefined' && !!chrome?.extension;
}
static getVersion() {
// eslint-disable-next-line prefer-const
Expand Down

0 comments on commit 7e0345a

Please sign in to comment.