Skip to content

Commit 4991f66

Browse files
committed
🩹 Fix ajmodel upgrader not opening when double clicked
1 parent 3f99c28 commit 4991f66

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed

src/formats/ajmodel/formatPage.svelte

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,8 @@
11
<script lang="ts" context="module">
2-
import { convertAJModelToBlueprint } from '.'
2+
import { openAJModel } from '.'
33
import { translate } from '../../util/translation'
44
</script>
55

6-
<script lang="ts">
7-
function openAJModel() {
8-
void Promise.any([
9-
electron.dialog.showOpenDialog({
10-
properties: ['openFile'],
11-
filters: [{ name: '.ajmodel', extensions: ['ajmodel'] }],
12-
message: translate('action.upgrade_old_aj_model_loader.select_file'),
13-
}),
14-
]).then(result => {
15-
if (!result.canceled) {
16-
convertAJModelToBlueprint(result.filePaths[0] as string)
17-
}
18-
})
19-
}
20-
</script>
21-
226
<p>{translate('action.upgrade_old_aj_model_loader.body')}</p>
237

248
<button on:click={openAJModel}>

src/formats/ajmodel/index.ts

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,20 @@ import { BLUEPRINT_CODEC } from '../blueprint/codec'
77
import * as modelDatFixerUpper from '../blueprint/dfu'
88
import FormatPage from './formatPage.svelte'
99

10-
registerModelLoader(
11-
{ id: `animated-java:upgrade-aj-model-loader` },
12-
{
13-
icon: 'upload_file',
14-
category: 'animated_java',
15-
name: translate('action.upgrade_old_aj_model_loader.name'),
16-
condition: true,
17-
format_page: {
18-
component: {
19-
template: `<div id="animated-java:upgrade-aj-model-loader-target" style="flex-grow: 1; display: flex; flex-direction: column; justify-content: space-between;"></div>`,
20-
mounted() {
21-
// Don't need to worry about unmounting since the whole panel gets replaced when switching formats
22-
mountSvelteComponent({
23-
component: FormatPage,
24-
target: `#animated-java\\:upgrade-aj-model-loader-target`,
25-
injectIndex: 2,
26-
})
27-
},
28-
},
29-
},
30-
}
31-
)
10+
// Blockbench has a bug where it calls the onStart function multiple times when double-clicking it.
11+
let waitingForAJModel = false
12+
export async function openAJModel() {
13+
if (waitingForAJModel) return
14+
waitingForAJModel = true
15+
const result = await electron.dialog.showOpenDialog({
16+
properties: ['openFile'],
17+
filters: [{ name: '.ajmodel', extensions: ['ajmodel'] }],
18+
message: translate('action.upgrade_old_aj_model_loader.select_file'),
19+
})
20+
waitingForAJModel = false
21+
if (result.canceled) return
22+
convertAJModelToBlueprint(result.filePaths[0])
23+
}
3224

3325
export function convertAJModelToBlueprint(path: string) {
3426
try {
@@ -54,3 +46,27 @@ export function convertAJModelToBlueprint(path: string) {
5446
openUnexpectedErrorDialog(e as Error)
5547
}
5648
}
49+
50+
registerModelLoader(
51+
{ id: `animated-java:upgrade-aj-model-loader` },
52+
{
53+
icon: 'upload_file',
54+
category: 'animated_java',
55+
name: translate('action.upgrade_old_aj_model_loader.name'),
56+
condition: true,
57+
format_page: {
58+
component: {
59+
template: `<div id="animated-java:upgrade-aj-model-loader-target" style="flex-grow: 1; display: flex; flex-direction: column; justify-content: space-between;"></div>`,
60+
mounted() {
61+
// Don't need to worry about unmounting since the whole panel gets replaced when switching formats
62+
mountSvelteComponent({
63+
component: FormatPage,
64+
target: `#animated-java\\:upgrade-aj-model-loader-target`,
65+
injectIndex: 2,
66+
})
67+
},
68+
},
69+
},
70+
onStart: openAJModel,
71+
}
72+
)

0 commit comments

Comments
 (0)