11<script setup lang="ts">
2- import { computed , inject } from " vue" ;
2+ import { computed , inject , ref } from " vue" ;
33
44import Image from " @/components/general/base/Image.vue" ;
55import MaterialRipple from " @/components/general/base/MaterialRipple.vue" ;
6- import { InstanceStatesContextKey } from " @/constants/application.ts" ;
6+ import { GlobalStatesContextKey , InstanceStatesContextKey } from " @/constants/application.ts" ;
7+ import Errors from " @/lib/errors" ;
78import Instances from " @/lib/instances" ;
8- import type {
9- InstanceStatesType ,
10- InstanceStateType ,
11- } from " @/types/application/instance-states .type.ts" ;
9+ import { log } from " @/lib/logging/scopes/log.ts " ;
10+ import type { ContextGlobalStatesType } from " @/types/application/global-states.type.ts " ;
11+ import type { InstanceStatesType } from " @/types/application/instance-states.type.ts " ;
12+ import type { CurrentInstanceType } from " @/types/launcher/current-instance .type.ts" ;
1213
14+ const globalStates = inject <ContextGlobalStatesType >(GlobalStatesContextKey );
1315const instanceStates = inject <InstanceStatesType >(InstanceStatesContextKey );
1416
15- const currentInstance = computed ((): InstanceStateType | undefined => (
16- Instances .findCurrent (instanceStates )
17+ const currentInstance = computed ((): CurrentInstanceType => (
18+ Instances .findCurrent (globalStates ?. layout ?. currentInstance , instanceStates )
1719));
20+
21+ const disabled = ref <boolean >(false );
22+
23+ async function __changeName(): Promise <void > {
24+ if (! currentInstance .value ) {
25+ return ;
26+ }
27+
28+ disabled .value = true ;
29+
30+ try {
31+ const id = currentInstance .value .id ;
32+ const instance = currentInstance .value .instance ;
33+
34+ Instances .change (id , {
35+ ... instance ,
36+ " name" : ` Vanilla 1.${Math .floor (Math .random () * 21 )} ` ,
37+ });
38+
39+ if (! instanceStates ) {
40+ return ;
41+ }
42+
43+ await Instances .syncMetadata (instanceStates );
44+ } catch (error : unknown ) {
45+ log .error (" Could not change the current instance name:" , Errors .prettify (error ));
46+ }
47+
48+ disabled .value = false ;
49+ }
1850 </script >
1951
2052<template >
2153 <button
2254 v-if =" currentInstance"
55+ @click =" __changeName"
56+ :disabled =" disabled"
2357 id =" __home-page__current-instance-button"
24- class =" relative flex flex-nowrap items-center gap-2 rounded-md p-2"
58+ class =" relative flex flex-nowrap items-center gap-2 rounded-md p-2 transition-[opacity] disabled:cursor-default disabled:opacity-50 "
2559 >
2660 <Image
2761 id =" __home-page__current-instance-logo"
2862 class-names =" rounded-md size-12 p-1"
29- :src =" currentInstance.icon"
30- :alt =" `${currentInstance.name}'s icon`"
63+ :src =" currentInstance.instance. icon"
64+ :alt =" `${currentInstance.instance. name}'s icon`"
3165 />
3266 <span
3367 id =" __home-page__current-instance-information-wrapper"
@@ -37,13 +71,13 @@ const currentInstance = computed((): InstanceStateType | undefined => (
3771 id =" __home-page__current-instance-information-title"
3872 class =" block font-medium"
3973 >
40- {{ currentInstance.name }}
74+ {{ currentInstance.instance. name }}
4175 </span >
4276 <span
4377 id =" __home-page__current-instance-information-version"
4478 class =" block text-neutral-400"
4579 >
46- {{ currentInstance.version }}
80+ {{ currentInstance.instance. version }}
4781 </span >
4882 </span >
4983 <MaterialRipple />
0 commit comments