This commit is contained in:
Renan LE CARO 2025-04-20 13:41:12 +02:00
parent b3949d8c41
commit c88540488d
9 changed files with 78 additions and 77 deletions

View file

@ -29,8 +29,8 @@ android {
applicationId = "me.lecaro.breakout"
minSdk = 21
targetSdk = 34
versionCode = 29085783
versionName = "29085783"
versionCode = 29085797
versionName = "29085797"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true

File diff suppressed because one or more lines are too long

View file

@ -48,16 +48,22 @@ class MainActivity : android.app.Activity() {
private fun downloadFile(url: String) {
try {
if (!url.startsWith("data:application/json;charset=utf-8,")) {
Log.w("DL", "url ignored because it does not start with data:")
return
}
val sdf = SimpleDateFormat("yyyy-M-dd-hh-mm")
val currentDate = sdf.format(Date())
val urlEncoded = url.substring("data:application/json;charset=utf-8,".length)
val str = URLDecoder.decode(urlEncoded, StandardCharsets.UTF_8.name())
writeFileAndShare(str, "breakout-71-save-$currentDate.json", "application/json")
if (url.startsWith("data:application/json;charset=utf-8,")) {
val urlEncoded = url.substring("data:application/json;charset=utf-8,".length)
val str = URLDecoder.decode(urlEncoded, StandardCharsets.UTF_8.name())
writeFileAndShare(str.toByteArray(), "breakout-71-save-$currentDate.json", "application/json")
}
if (url.startsWith("data:video/webm;base64,")) {
val base64Data = url.substring("data:video/webm;base64,".length)
val decodedBytes = android.util.Base64.decode(base64Data, android.util.Base64.DEFAULT)
writeFileAndShare(decodedBytes, "breakout-71-capture-$currentDate.webm", "video/webm")
}
} catch (e: Exception) {
Log.e("DL", "Error ${e.message}")
@ -65,7 +71,7 @@ class MainActivity : android.app.Activity() {
}
}
fun writeFileAndShare(jsonData: String, fileName: String, mime: String) {
fun writeFileAndShare(bytes:ByteArray, fileName: String, mime: String) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// android 10
@ -80,7 +86,7 @@ class MainActivity : android.app.Activity() {
)
uri?.let {
contentResolver.openOutputStream(it)?.use { outputStream ->
outputStream.write(jsonData.toByteArray())
outputStream.write(bytes)
}
}
@ -94,7 +100,7 @@ class MainActivity : android.app.Activity() {
} else {
val file = File(getExternalFilesDir(null), fileName)
file.writeText(jsonData)
file.writeBytes(bytes)
val uri = FileProvider.getUriForFile(
this,
"$packageName.fileprovider", // Adjust if your authority is different

45
dist/index.html vendored

File diff suppressed because one or more lines are too long

View file

@ -1,5 +1,5 @@
// The version of the cache.
const VERSION = "29085783";
const VERSION = "29085797";
// The name of the cache
const CACHE_NAME = `breakout-71-${VERSION}`;

View file

@ -1 +1 @@
"29085783"
"29085797"

View file

@ -423,4 +423,4 @@ export function getCornerOffset(gameState: GameState) {
}
export const isInWebView = !!window.location.href.includes("isInWebView=true");
console.log({isInWebView})
console.log({ isInWebView });

View file

@ -89,6 +89,7 @@ export function startRecordingGame(gameState: GameState) {
const recordedChunks: Blob[] = [];
const instance = new MediaRecorder(captureStream, {
// Required for less mushy result
videoBitsPerSecond: 3500000,
});
mediaRecorder = instance;
@ -136,7 +137,6 @@ export function startRecordingGame(gameState: GameState) {
size: (blob.size / 1000000).toFixed(2),
});
targetDiv.appendChild(a);
};
}

View file

@ -1,77 +1,73 @@
// Settings
import {toast} from "./toast";
import {t} from "./i18n/i18n";
let cachedSettings: { [key: string]: unknown } = {};
try {
for (let key in localStorage) {
try {
cachedSettings[key] = JSON.parse(localStorage.getItem(key) || "null");
} catch (e) {
console.warn(e);
}
for (let key in localStorage) {
try {
cachedSettings[key] = JSON.parse(localStorage.getItem(key) || "null");
} catch (e) {
console.warn(e);
}
}
} catch (e) {
console.warn(e);
console.warn(e);
}
export function getSettingValue<T>(key: string, defaultValue: T) {
return (cachedSettings[key] as T) ?? defaultValue;
return (cachedSettings[key] as T) ?? defaultValue;
}
// We avoid using localstorage synchronously for perf reasons
let needsSaving: Set<string> = new Set();
export function setSettingValue<T>(key: string, value: T) {
needsSaving.add(key);
cachedSettings[key] = value;
needsSaving.add(key);
cachedSettings[key] = value;
}
export function commitSettingsChangesToLocalStorage() {
try {
for (let key of needsSaving) {
localStorage.setItem(key, JSON.stringify(cachedSettings[key]));
}
needsSaving.clear();
} catch (e) {
console.warn(e);
try {
for (let key of needsSaving) {
localStorage.setItem(key, JSON.stringify(cachedSettings[key]));
}
needsSaving.clear();
} catch (e) {
console.warn(e);
}
}
setInterval(() => commitSettingsChangesToLocalStorage(), 500);
export function getTotalScore() {
return getSettingValue("breakout_71_total_score", 0);
return getSettingValue("breakout_71_total_score", 0);
}
export function getCurrentMaxCoins() {
return Math.pow(2, getSettingValue("max_coins", 2)) * 200;
return Math.pow(2, getSettingValue("max_coins", 2)) * 200;
}
export function getCurrentMaxParticles() {
return getCurrentMaxCoins();
return getCurrentMaxCoins();
}
export function cycleMaxCoins() {
setSettingValue("max_coins", (getSettingValue("max_coins", 2) + 1) % 7);
setSettingValue("max_coins", (getSettingValue("max_coins", 2) + 1) % 7);
}
let asked = false;
export async function askForPersistentStorage() {
if (asked) return;
asked = true;
if (!navigator.storage) return
if (!navigator.storage.persist) return
if (!navigator.storage.persisted) return
if (await navigator.storage.persisted()) {
return
}
const persistent = await navigator.storage.persist()
if (!persistent) {
toast(t("settings.storage_refused"));
}
if (asked) return;
asked = true;
if (!navigator.storage) return;
if (!navigator.storage.persist) return;
if (!navigator.storage.persisted) return;
if (await navigator.storage.persisted()) {
return;
}
const persistent = await navigator.storage.persist();
if (!persistent) {
console.warn('No storage granted')
}
}