Skip to content

Commit dc2c5a2

Browse files
committed
fix: make it run on ios 15!
1 parent 31b91e5 commit dc2c5a2

File tree

7 files changed

+70
-28
lines changed

7 files changed

+70
-28
lines changed

index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<div style="font-size: var(--font-size);color: rgb(176, 176, 176);margin-top: 3px;text-align: center" class="subtitle">A true Minecraft client in your browser!</div>
2828
<!-- small text pre -->
2929
<div style="font-size: calc(var(--font-size) * 0.6);color: rgb(150, 150, 150);margin-top: 3px;text-align: center;white-space: pre-line;" class="advanced-info"></div>
30+
<div style="font-size: calc(var(--font-size) * 0.6);color: rgb(255, 100, 100);margin-top: 10px;text-align: center;display: none;" class="ios-warning">Only iOS 15+ is supported due to performance optimizations</div>
3031
</div>
3132
</div>
3233
`
@@ -36,6 +37,13 @@
3637
if (!window.pageLoaded) {
3738
document.documentElement.appendChild(loadingDivElem)
3839
}
40+
41+
// iOS version detection
42+
const getIOSVersion = () => {
43+
const match = navigator.userAgent.match(/OS (\d+)_(\d+)_?(\d+)?/);
44+
return match ? parseInt(match[1], 10) : null;
45+
}
46+
3947
// load error handling
4048
const onError = (errorOrMessage, log = false) => {
4149
let message = errorOrMessage instanceof Error ? (errorOrMessage.stack ?? errorOrMessage.message) : errorOrMessage
@@ -46,6 +54,13 @@
4654
const [errorMessage, ...errorStack] = message.split('\n')
4755
document.querySelector('.initial-loader').querySelector('.subtitle').textContent = errorMessage
4856
document.querySelector('.initial-loader').querySelector('.advanced-info').textContent = errorStack.join('\n')
57+
58+
// Show iOS warning if applicable
59+
const iosVersion = getIOSVersion();
60+
if (iosVersion !== null && iosVersion < 15) {
61+
document.querySelector('.initial-loader').querySelector('.ios-warning').style.display = 'block';
62+
}
63+
4964
if (window.navigator.maxTouchPoints > 1) window.location.hash = '#dev' // show eruda
5065
// unregister all sw
5166
if (window.navigator.serviceWorker) {

patches/[email protected]

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/fonts/pixelart-icons-font.css b/fonts/pixelart-icons-font.css
2-
index 3b2ebe839370d96bf93ef5ca94a827f07e49378d..103ab4d6b9f3b5c9f41d1407e3cbf4ac392fbf41 100644
2+
index 3b2ebe839370d96bf93ef5ca94a827f07e49378d..4f8d76be2ca6e4ddc43c68d0a6f0f69979165ab4 100644
33
--- a/fonts/pixelart-icons-font.css
44
+++ b/fonts/pixelart-icons-font.css
55
@@ -1,16 +1,13 @@
@@ -10,10 +10,11 @@ index 3b2ebe839370d96bf93ef5ca94a827f07e49378d..103ab4d6b9f3b5c9f41d1407e3cbf4ac
1010
+ src:
1111
url("pixelart-icons-font.woff2?t=1711815892278") format("woff2"),
1212
url("pixelart-icons-font.woff?t=1711815892278") format("woff"),
13-
url('pixelart-icons-font.ttf?t=1711815892278') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/
13+
- url('pixelart-icons-font.ttf?t=1711815892278') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/
1414
- url('pixelart-icons-font.svg?t=1711815892278#pixelart-icons-font') format('svg'); /* iOS 4.1- */
15+
+ url('pixelart-icons-font.ttf?t=1711815892278') format('truetype'); /* chrome, firefox, opera, Safari, Android, iOS 4.2+*/
1516
}
16-
17+
1718
[class^="pixelart-icons-font-"], [class*=" pixelart-icons-font-"] {
1819
font-family: 'pixelart-icons-font' !important;
1920
- font-size:24px;

pnpm-lock.yaml

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

renderer/viewer/lib/utils/skins.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,22 @@ export const loadThreeJsTextureFromUrlSync = (imageUrl: string) => {
1616
}
1717
}
1818

19+
export const createCanvas = (width: number, height: number): OffscreenCanvas => {
20+
if (typeof OffscreenCanvas !== 'undefined') {
21+
return new OffscreenCanvas(width, height)
22+
}
23+
const canvas = document.createElement('canvas')
24+
canvas.width = width
25+
canvas.height = height
26+
return canvas as unknown as OffscreenCanvas // todo-low
27+
}
28+
1929
export const loadThreeJsTextureFromUrl = async (imageUrl: string) => {
2030
const loaded = new THREE.TextureLoader().loadAsync(imageUrl)
2131
return loaded
2232
}
2333
export const loadThreeJsTextureFromBitmap = (image: ImageBitmap) => {
24-
const canvas = new OffscreenCanvas(image.width, image.height)
34+
const canvas = createCanvas(image.width, image.height)
2535
const ctx = canvas.getContext('2d')!
2636
ctx.drawImage(image, 0, 0)
2737
const texture = new THREE.Texture(canvas)
@@ -83,7 +93,7 @@ export async function loadSkinImage (skinUrl: string): Promise<{ canvas: Offscre
8393
}
8494

8595
const image = await loadImageFromUrl(skinUrl)
86-
const skinCanvas = new OffscreenCanvas(64, 64)
96+
const skinCanvas = createCanvas(64, 64)
8797
loadSkinToCanvas(skinCanvas, image)
8898
return { canvas: skinCanvas, image }
8999
}

renderer/viewer/three/entities.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { isEntityAttackable } from 'mineflayer-mouse/dist/attackableEntity'
1818
import { Vec3 } from 'vec3'
1919
import { EntityMetadataVersions } from '../../../src/mcDataTypes'
2020
import { ItemSpecificContextProperties } from '../lib/basePlayerState'
21-
import { loadSkinImage, loadSkinFromUsername, stevePngUrl, steveTexture } from '../lib/utils/skins'
21+
import { loadSkinImage, loadSkinFromUsername, stevePngUrl, steveTexture, createCanvas } from '../lib/utils/skins'
2222
import { loadTexture } from '../lib/utils'
2323
import { getBlockMeshFromModel } from './holdingBlock'
2424
import * as Entity from './entity/EntityMesh'
@@ -96,7 +96,7 @@ function getUsernameTexture ({
9696
nameTagBackgroundColor = 'rgba(0, 0, 0, 0.3)',
9797
nameTagTextOpacity = 255
9898
}: any, { fontFamily = 'sans-serif' }: any) {
99-
const canvas = new OffscreenCanvas(64, 64)
99+
const canvas = createCanvas(64, 64)
100100
const ctx = canvas.getContext('2d')
101101
if (!ctx) throw new Error('Could not get 2d context')
102102

@@ -550,7 +550,7 @@ export class Entities {
550550
let skinCanvas: OffscreenCanvas
551551
if (skinUrl === stevePngUrl) {
552552
skinTexture = await steveTexture
553-
const canvas = new OffscreenCanvas(64, 64)
553+
const canvas = createCanvas(64, 64)
554554
const ctx = canvas.getContext('2d')
555555
if (!ctx) throw new Error('Failed to get context')
556556
ctx.drawImage(skinTexture.image, 0, 0)

rsbuild.config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,22 @@ const appConfig = defineConfig({
111111
js: 'source-map',
112112
css: true,
113113
},
114+
minify: {
115+
// js: false,
116+
jsOptions: {
117+
minimizerOptions: {
118+
mangle: {
119+
safari10: true,
120+
keep_classnames: true,
121+
keep_fnames: true,
122+
keep_private_props: true,
123+
},
124+
compress: {
125+
unused: true,
126+
},
127+
},
128+
},
129+
},
114130
distPath: SINGLE_FILE_BUILD ? {
115131
html: './single',
116132
} : undefined,

src/react/StorageConflictModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default () => {
1717
if (!isModalActive/* || conflicts.length === 0 */) return null
1818

1919
const clampText = (text: string) => {
20-
if (typeof text !== "string") text = JSON.stringify(text)
20+
if (typeof text !== 'string') text = JSON.stringify(text)
2121
return text.length > 30 ? text.slice(0, 30) + '...' : text
2222
}
2323

0 commit comments

Comments
 (0)