Skip to content

Commit

Permalink
Web version should be compatible with Safari
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrews54757 committed Nov 20, 2023
1 parent 7090688 commit b658721
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 22 deletions.
2 changes: 1 addition & 1 deletion chrome/options/options.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ function createKeybindElement(keybind) {
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;
Expand Down
22 changes: 12 additions & 10 deletions chrome/player/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ async function loadSubtitles(subs) {
}

async function sortSubtitles(subs) {
if (!chrome?.i18n?.detectLanguage) {
if (!EnvUtils.isExtension() || !chrome?.i18n?.detectLanguage) {
return subs;
}

Expand Down Expand Up @@ -215,16 +215,18 @@ async function setup() {
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;');
Expand Down
19 changes: 10 additions & 9 deletions chrome/player/modules/FSBlob.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ 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 @@ -23,10 +24,10 @@ export class FSBlob {
}

_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);
}
}

Expand All @@ -44,11 +45,11 @@ export class FSBlob {
}

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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion chrome/player/network/DownloadManager.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,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
5 changes: 5 additions & 0 deletions chrome/player/network/IndexedDBManager.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export class IndexedDBManager {
constructor() {
}

static isSupported() {
return window.indexedDB !== undefined;
}

async setup() {
await this.close();
this.prune();
Expand Down Expand Up @@ -107,6 +111,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 chrome/player/utils/EnvUtils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class EnvUtils {
}

static isExtension() {
return !!chrome?.extension;
return typeof chrome !== 'undefined' && !!chrome?.extension;
}

static getVersion() {
Expand Down

0 comments on commit b658721

Please sign in to comment.