Skip to content

Commit 184303c

Browse files
committed
🛜 Fixed some Offline Loading Errors
- Added a warning when starting up in offline mode. - Fixed a few version manager issues when starting up without an internet connection.
1 parent aa6f4ce commit 184303c

File tree

8 files changed

+66
-9
lines changed

8 files changed

+66
-9
lines changed

src/components/animatedJavaLoadingPopup.svelte

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,24 @@
44
</script>
55

66
<script lang="ts">
7+
import { translate } from '../util/translation'
8+
79
export let loaded: Valuable<boolean>
10+
export let offline: Valuable<boolean>
811
</script>
912

10-
<div class="floating">
11-
{#if $loaded}
12-
<div>Animated Java Loaded Successfully!</div>
13+
<div class={`floating ${$offline ? 'red-border' : 'blue-border'}`}>
14+
{#if $offline}
15+
<div style="display: flex; flex-direction: column;">
16+
{@html translate('popup.loading.offline')
17+
.split('\n')
18+
.map(v => '<p>' + v + '</p>')
19+
.join('')}
20+
</div>
21+
{:else if $loaded}
22+
<div>{translate('popup.loading.success')}</div>
1323
{:else}
14-
<div class="text">Loading Animated Java...</div>
24+
<div class="text">{translate('popup.loading.loading')}</div>
1525
<img src={RunningArmorStand} alt="Running Armor Stand" />
1626
{/if}
1727
</div>
@@ -23,11 +33,16 @@
2333
right: 2rem;
2434
background: var(--color-ui);
2535
padding: 8px 16px;
26-
border: 1px solid var(--color-accent);
2736
display: flex;
2837
align-items: center;
2938
flex-direction: row;
3039
}
40+
.blue-border {
41+
border: 1px solid var(--color-accent);
42+
}
43+
.red-border {
44+
border: 1px solid var(--color-error);
45+
}
3146
.text {
3247
margin-right: 16px;
3348
}

src/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ import { openUnexpectedErrorDialog } from './interface/unexpectedErrorDialog'
6969
import { BLUEPRINT_CODEC, BLUEPRINT_FORMAT } from './blueprintFormat'
7070
import { TextDisplay } from './outliner/textDisplay'
7171
import { getLatestVersionClientDownloadUrl } from './systems/minecraft/assetManager'
72-
import { hideLoadingPopup, showLoadingPopup } from './interface/animatedJavaLoadingPopup'
72+
import {
73+
hideLoadingPopup,
74+
showLoadingPopup,
75+
showOfflineError,
76+
} from './interface/animatedJavaLoadingPopup'
7377
import { getVanillaFont } from './systems/minecraft/fontManager'
7478
import * as assetManager from './systems/minecraft/assetManager'
7579
import * as itemModelManager from './systems/minecraft/itemModelManager'
@@ -81,6 +85,12 @@ import { exportProject } from './systems/exporter'
8185

8286
// Show loading popup
8387
void showLoadingPopup().then(async () => {
88+
if (!window.navigator.onLine) {
89+
showOfflineError()
90+
// return
91+
}
92+
events.NETWORK_CONNECTED.dispatch()
93+
8494
await Promise.all([
8595
new Promise<void>(resolve => events.MINECRAFT_ASSETS_LOADED.subscribe(() => resolve())),
8696
new Promise<void>(resolve => events.MINECRAFT_REGISTRY_LOADED.subscribe(() => resolve())),

src/interface/animatedJavaLoadingPopup.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { injectSvelteCompomponent } from '../util/injectSvelte'
44
import { Valuable } from '../util/stores'
55

66
const LOADED = new Valuable(false)
7+
const OFFLINE = new Valuable(false)
78
let activeComponent: SvelteComponent | undefined
89

910
export async function showLoadingPopup() {
@@ -12,6 +13,7 @@ export async function showLoadingPopup() {
1213
svelteComponent: AnimatedJavaLoadingPopup,
1314
svelteComponentProperties: {
1415
loaded: LOADED,
16+
offline: OFFLINE,
1517
},
1618
elementSelector() {
1719
return document.body
@@ -28,3 +30,14 @@ export function hideLoadingPopup() {
2830
activeComponent = undefined
2931
}, 2000)
3032
}
33+
34+
export function showOfflineError() {
35+
if (!activeComponent) return
36+
OFFLINE.set(true)
37+
// FIXME - Change this into a X button instead of a timeout.
38+
setTimeout(() => {
39+
if (!activeComponent) return
40+
activeComponent.$destroy()
41+
activeComponent = undefined
42+
}, 10000)
43+
}

src/lang/en.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ animated_java.action.create_vanilla_block_display.title: Add Vanilla Block Displ
1212
animated_java.action.open_vanilla_item_display_config.name: Vanilla Item Display Config
1313
animated_java.action.open_vanilla_block_display_config.name: Vanilla Block Display Config
1414

15+
### Popups
16+
animated_java.popup.loading.loading: Loading Animated Java...
17+
animated_java.popup.loading.success: Animated Java Loaded Successfully!
18+
animated_java.popup.loading.offline: |-
19+
Animated Java Failed to Connect!
20+
Some features may be unavailable.
21+
1522
### Dialogs
1623

1724
## About

src/systems/minecraft/blockstateManager.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,7 @@ export async function getBlockState(block: string) {
103103
}
104104

105105
events.LOAD.subscribe(() => {
106-
void checkForRegistryUpdate()
106+
void checkForRegistryUpdate().catch(err => {
107+
console.error(err)
108+
})
107109
})

src/systems/minecraft/registryManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export async function checkForRegistryUpdate() {
178178
requestAnimationFrame(() => events.MINECRAFT_REGISTRY_LOADED.dispatch())
179179
}
180180

181-
events.LOAD.subscribe(() => {
181+
events.NETWORK_CONNECTED.subscribe(() => {
182182
void checkForRegistryUpdate().then(async () => {
183183
await checkForAssetsUpdate()
184184
})

src/systems/minecraft/versionManager.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const VERSION_MANIFEST_URL = 'https://launchermeta.mojang.com/mc/game/version_manifest_v2.json'
1+
export const VERSION_MANIFEST_URL =
2+
'https://launchermeta.mojang.com/mc/game/version_manifest_v2.json'
23

34
interface IMinecraftVersion {
45
id: string
@@ -21,6 +22,13 @@ export interface IMinecraftVersionManifest {
2122
let latestMinecraftVersion: IMinecraftVersion | undefined
2223
export async function getLatestVersion() {
2324
if (latestMinecraftVersion) return latestMinecraftVersion
25+
if (!window.navigator.onLine) {
26+
console.warn('Not connected to the internet! Using last known latest version.')
27+
latestMinecraftVersion = getCurrentVersion()
28+
if (!latestMinecraftVersion)
29+
throw new Error('No internet connection, and no previous latest version cached!')
30+
return latestMinecraftVersion
31+
}
2432
let response: Response | undefined
2533
try {
2634
response = await fetch(VERSION_MANIFEST_URL)

src/util/events.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export const events = {
2020
INJECT_MODS: new PluginEvent('injectMods'),
2121
EXTRACT_MODS: new PluginEvent('extractMods'),
2222

23+
NETWORK_CONNECTED: new PluginEvent('networkConnected'),
24+
2325
MINECRAFT_ASSETS_LOADED: new PluginEvent('minecraftAssetsLoaded'),
2426
MINECRAFT_REGISTRY_LOADED: new PluginEvent('minecraftRegistriesLoaded'),
2527
MINECRAFT_FONTS_LOADED: new PluginEvent('minecraftFontsLoaded'),

0 commit comments

Comments
 (0)