Icons ausgetauscht, Musik stoppt im Hintergrund, App-ended-listener hinzugefügt

This commit is contained in:
silas 2018-10-28 23:21:54 +01:00
parent 6aa647a9a3
commit 11e225ccac
10 changed files with 7551 additions and 33 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash
cd $(dirname "$0")/..
npm run build 2
npm run build

View File

@ -2,5 +2,5 @@
cd $(dirname "$0")/..
testcafe firefox test/test.testcafe.js
#node bin/testcafe.js;
#testcafe firefox test/test.testcafe.js
node bin/testcafe.js;

File diff suppressed because one or more lines are too long

View File

@ -55,10 +55,9 @@ AndroidBridge.addDefinition(() => {
window["app"] = app;
window["app"]["pause"] = app.pause;
window["app"]["resume"] = app.resume;
// window["app"]["refreshCurrentSite"] = app.refreshCurrentSite;
window["app"]["setAppEndListener"] = app.setAppEndListener;
});
SettingsSite.setTemplate("html/application/setting-template.html");
// SettingsSite.shouldAddSettingsAction = false;

View File

@ -1,4 +1,4 @@
import { Helper, InitPromise, MultipleShareButton, AndroidBridge, Fragment, Translator } from './pwa-lib.js';
import { Helper, InitPromise, MultipleShareButton, AndroidBridge, PauseSite, Fragment, Translator } from './pwa-lib.js';
class DelayPromise extends Promise {
static async delay(delay) {
@ -323,7 +323,8 @@ class AudioChain {
//sind sonst null, schmeißt in Android 5 einen fehler
delay = Helper.nonNull(delay, 0);
offset = Helper.nonNull(offset, 0);
duration = Helper.nonNull(duration, this.buffer.duration);
//Duration darf nicht gesetzt werden
// duration = Helper.nonNull(duration, -1);
let source = this.context.createBufferSource();
@ -337,7 +338,12 @@ class AudioChain {
source.buffer = this.buffer;
await this.chainFunction(source);
source.start(delay, offset, duration);
if (Helper.isNull(duration)){
source.start(delay, offset);
}
else{
source.start(delay, offset, duration);
}
this.startTime = (new Date()).getTime() - (Helper.nonNull(offset, 0) * 1000);
this.source = source;
this.running = true;
@ -418,14 +424,14 @@ class SoundManager {
return this.channels[channel];
}
async resume(){
async resumeContext(){
if (typeof this.context.resume === "function") {
return this.context.resume();
}
}
async play(channel, audioOrOptions) {
this.resume();
this.resumeContext();
channel = Helper.nonNull(channel, SoundManager.CHANNELS.DEFAULT);
if (Helper.isNull(audioOrOptions)) {
audioOrOptions = {};
@ -477,25 +483,33 @@ class SoundManager {
async resume(channel) {
channel = Helper.nonNull(channel, SoundManager.CHANNELS.DEFAULT);
if (!this.channels[channel].muted && Helper.isNotNull(this.channels[channel].source)) {
if (Helper.isNotNull(this.channels[channel]) && !this.channels[channel].muted && Helper.isNotNull(this.channels[channel].source)) {
return this.channels[channel].source.resume();
}
}
stopAll(){
for (let k in this.channels) {
if (Helper.isNotNull(this.channels[k].source)) {
this.channels[k].source.stop();
}
}
}
resumeAllIfNotMuted(){
for (let k in this.channels) {
if (Helper.isNotNull(this.channels[k]) && !this.channels[k].muted && Helper.isNotNull(this.channels[k].source)) {
this.channels[k].source.resume();
}
}
}
handleVisibilityChange() {
if (document.hidden) {
for (let k in this.channels) {
if (Helper.isNotNull(this.channels[k].source)) {
this.channels[k].source.stop();
}
}
this.stopAll();
}
else {
for (let k in this.channels) {
if (!this.channels[k].muted && Helper.isNotNull(this.channels[k].source)) {
this.channels[k].source.resume();
}
}
this.resumeAllIfNotMuted();
}
}
}
@ -506,6 +520,21 @@ SoundManager.CHANNELS = {
DEFAULT: "default"
};
InitPromise.addPromise(() => {
PauseSite.onPauseListeners.push(() => {
SoundManager.getInstance().stopAll();
});
PauseSite.onStartListeners.push(() => {
SoundManager.getInstance().resumeAllIfNotMuted();
});
});
// AndroidBridge.addDefinition(() => {
// window["soundManagerInstance"] = SoundManager.getInstance();
// window["soundManagerInstance"]["stopAll"] = window["soundManagerInstance"].stopAll;
// window["soundManagerInstance"]["resumeAllIfNotMuted"] = window["soundManagerInstance"].resumeAllIfNotMuted;
// });
class TabbedFragment extends Fragment {
constructor(site) {
super(site, 'pwaAssets/html/fragment/tabbedFragment.html');

View File

@ -2025,7 +2025,7 @@ class SiteContainer {
}
class SiteManager {
constructor(siteDivId, actionBarMenuSelector) {
constructor(siteDivId, actionBarMenuSelector, app) {
this.siteDiv = document.getElementById(siteDivId);
this.siteContainerStack = [];
this.currentSiteContainerToShow = null;
@ -2034,6 +2034,7 @@ class SiteManager {
this.siteStartingPromise = Promise.resolve();
this.defaultActions = [];
this.startSiteName = null;
this.app = app;
this.titleElement = document.querySelector(".top-bar-title");
@ -2140,7 +2141,8 @@ class SiteManager {
if (newSiteContainerIndex < 0) {
manager.showAppEndedMessage();
manager.startSite(manager.startSiteName);
app.endApp();
// manager.startSite(manager.startSiteName);
return;
}
manager.siteDiv.removeAllChildren().appendChild(Helper.createLoadingSymbol());
@ -2292,8 +2294,31 @@ class PauseSite extends AbstractSite {
this.inflateView(pausedElement);
}
onPause() {
console.log("onPause");
for (let i = 0; i < PauseSite.onStartListeners.length; i++) {
if (typeof PauseSite.onStartListeners[i] === "function") {
PauseSite.onStartListeners[i]();
}
}
return super.onPause();
}
onStart() {
console.log("onStart");
for (let i = 0; i < PauseSite.onPauseListeners.length; i++) {
if (typeof PauseSite.onPauseListeners[i] === "function") {
PauseSite.onPauseListeners[i]();
}
}
return super.onPause();
}
}
PauseSite.onPauseListeners = [];
PauseSite.onStartListeners = [];
class App {
constructor() {
this._siteManager = null;
@ -2305,6 +2330,9 @@ class App {
this._addThemeAction = false;
this._showCookieCompliance = true;
this._startSite = null;
this._appEndListener = () => {
return this.startSite(this._startSite);
};
}
getSiteManager()
@ -2450,6 +2478,16 @@ class App {
return this._siteManager.getCurrentSite();
}
async endApp(){
if (typeof this._appEndListener === "function"){
this._appEndListener();
}
}
setAppEndListener(appEndListener){
this._appEndListener = appEndListener;
}
async findSite(filter){
return this._siteManager.findSite(filter);
}

View File

@ -39,14 +39,10 @@ export class WordRotatorDb extends MyDb {
}
async loadNextLevel(rendererTypes) {
console.log("loadNextLevel 1", IDBKeyRange.lowerBound(0));
let levels = await this.loadAll(WordRotatorDb.OBJECT_STORE.LEVEL);
levels = levels.sort((a,b) => {
return (a["difficulty"] - b["difficulty"]);
});
// const levels = await this.loadMany("difficulty", IDBKeyRange.lowerBound(0), WordRotatorDb.OBJECT_STORE.LEVEL);
// const levels = await this.loadMany("difficulty", null, WordRotatorDb.OBJECT_STORE.LEVEL);
console.log("loadNextLevel 2");
let wrongLevels = [];
let newLevels = [];

View File

@ -150,9 +150,7 @@ export class LevelSite extends WordRotatorBaseSite {
this.wonText.style.fontSize = "0";
const db = WordRotatorDb.getInstance();
console.log("nextLevel 2");
const nextLevelJson = await db.loadNextLevel(LevelSite.RENDERER_TYPES);
console.log("nextLevel 3");
if (nextLevelJson === null) {
this.startSite(EndSite);

View File

@ -97,7 +97,7 @@ export class MenuSite extends WordRotatorBaseSite {
}
async startLevelSite() {
SoundManager.getInstance().resume();
SoundManager.getInstance().resumeContext();
this.startSite(LevelSite, Promise.race([this.loadLevelPromise, new Promise(async resolve => {
const db = WordRotatorDb.getInstance();
let level = await db.loadNextLevel(LevelSite.RENDERER_TYPES);

View File

@ -2,7 +2,7 @@ import {Selector} from 'testcafe';
import {ClientFunction} from 'testcafe';
let isLocal = true;
let isMobile = false;
let isMobile = true;
const checkMatrix = async (matrixStringSelector, shouldValues, timeout) => {
let delta = 0.0001;