@@ -27,17 +27,15 @@ import {
2727 update_repair_modrinth ,
2828} from ' @/helpers/profile'
2929import { get_game_versions , get_loaders } from ' @/helpers/tags'
30+ import { injectInstanceSettings } from ' @/providers/instance-settings'
3031
31- import type { InstanceSettingsTabProps , Manifest } from ' ../../../helpers/types'
32+ import type { Manifest } from ' ../../../helpers/types'
3233
3334const { handleError } = injectNotificationManager ()
3435const { formatMessage } = useVIntl ()
3536const queryClient = useQueryClient ()
3637
37- const props = defineProps <InstanceSettingsTabProps >()
38- const emit = defineEmits <{
39- unlinked: []
40- }>()
38+ const { instance, offline, isMinecraftServer, onUnlinked } = injectInstanceSettings ()
4139
4240const [
4341 fabric_versions,
@@ -75,9 +73,9 @@ const [
7573])
7674
7775const { data : modpackInfo } = useQuery ({
78- queryKey: computed (() => [' linkedModpackInfo' , props . instance .path ]),
79- queryFn : () => get_linked_modpack_info (props . instance .path , ' must_revalidate' ),
80- enabled: computed (() => !! props . instance .linked_data ?.project_id && ! props . offline ),
76+ queryKey: computed (() => [' linkedModpackInfo' , instance .path ]),
77+ queryFn : () => get_linked_modpack_info (instance .path , ' must_revalidate' ),
78+ enabled: computed (() => !! instance .linked_data ?.project_id && ! offline ),
8179})
8280
8381const repairing = ref (false )
@@ -103,13 +101,13 @@ function getManifest(loader: string) {
103101provideAppBackup ({
104102 async createBackup() {
105103 const allProfiles = await list ()
106- const prefix = ` ${props . instance .name } - Backup # `
104+ const prefix = ` ${instance .name } - Backup # `
107105 const existingNums = allProfiles
108106 .filter ((p ) => p .name .startsWith (prefix ))
109107 .map ((p ) => parseInt (p .name .slice (prefix .length ), 10 ))
110108 .filter ((n ) => ! isNaN (n ))
111109 const nextNum = existingNums .length > 0 ? Math .max (... existingNums ) + 1 : 1
112- const newPath = await duplicate (props . instance .path )
110+ const newPath = await duplicate (instance .path )
113111 await edit (newPath , { name: ` ${prefix }${nextNum } ` })
114112 },
115113})
@@ -120,30 +118,27 @@ provideInstallationSettings({
120118 const rows = [
121119 {
122120 label: formatMessage (commonMessages .platformLabel ),
123- value: formatLoaderLabel (props . instance .loader ),
121+ value: formatLoaderLabel (instance .loader ),
124122 },
125123 {
126124 label: formatMessage (commonMessages .gameVersionLabel ),
127- value: props . instance .game_version ,
125+ value: instance .game_version ,
128126 },
129127 ]
130- if (props . instance .loader !== ' vanilla' && props . instance .loader_version ) {
128+ if (instance .loader !== ' vanilla' && instance .loader_version ) {
131129 rows .push ({
132130 label: formatMessage (messages .loaderVersion , {
133- loader: formatLoaderLabel (props . instance .loader ),
131+ loader: formatLoaderLabel (instance .loader ),
134132 }),
135- value: props . instance .loader_version ,
133+ value: instance .loader_version ,
136134 })
137135 }
138136 return rows
139137 }),
140- isLinked: computed (() => !! props . instance .linked_data ?.locked ),
138+ isLinked: computed (() => !! instance .linked_data ?.locked ),
141139 isBusy: computed (
142140 () =>
143- props .instance .install_stage !== ' installed' ||
144- repairing .value ||
145- reinstalling .value ||
146- !! props .offline ,
141+ instance .install_stage !== ' installed' || repairing .value || reinstalling .value || !! offline ,
147142 ),
148143 modpack: computed (() => {
149144 if (! modpackInfo .value ) return null
@@ -154,9 +149,9 @@ provideInstallationSettings({
154149 versionNumber: modpackInfo .value .version ?.version_number ,
155150 }
156151 }),
157- currentPlatform: computed (() => props . instance .loader ),
158- currentGameVersion: computed (() => props . instance .game_version ),
159- currentLoaderVersion: computed (() => props . instance .loader_version ?? ' ' ),
152+ currentPlatform: computed (() => instance .loader ),
153+ currentGameVersion: computed (() => instance .game_version ),
154+ currentLoaderVersion: computed (() => instance .loader_version ?? ' ' ),
160155 availablePlatforms: loaders ?.value ?.map ((x ) => x .name ) ?? [],
161156
162157 resolveGameVersions(loader , showSnapshots ) {
@@ -199,50 +194,50 @@ provideInstallationSettings({
199194 if (platform !== ' vanilla' && loaderVersionId ) {
200195 editProfile .loader_version = loaderVersionId
201196 }
202- await edit (props . instance .path , editProfile ).catch (handleError )
197+ await edit (instance .path , editProfile ).catch (handleError )
203198 },
204199
205200 afterSave : async () => {
206- await install (props . instance .path , false ).catch (handleError )
201+ await install (instance .path , false ).catch (handleError )
207202 trackEvent (' InstanceRepair' , {
208- loader: props . instance .loader ,
209- game_version: props . instance .game_version ,
203+ loader: instance .loader ,
204+ game_version: instance .game_version ,
210205 })
211206 },
212207
213208 async repair() {
214209 repairing .value = true
215- await install (props . instance .path , true ).catch (handleError )
210+ await install (instance .path , true ).catch (handleError )
216211 repairing .value = false
217212 trackEvent (' InstanceRepair' , {
218- loader: props . instance .loader ,
219- game_version: props . instance .game_version ,
213+ loader: instance .loader ,
214+ game_version: instance .game_version ,
220215 })
221216 },
222217
223218 async reinstallModpack() {
224219 reinstalling .value = true
225- await update_repair_modrinth (props . instance .path ).catch (handleError )
220+ await update_repair_modrinth (instance .path ).catch (handleError )
226221 reinstalling .value = false
227222 trackEvent (' InstanceRepair' , {
228- loader: props . instance .loader ,
229- game_version: props . instance .game_version ,
223+ loader: instance .loader ,
224+ game_version: instance .game_version ,
230225 })
231226 },
232227
233228 async unlinkModpack() {
234- await edit (props . instance .path , {
229+ await edit (instance .path , {
235230 linked_data: null as unknown as undefined ,
236231 })
237232 await queryClient .invalidateQueries ({
238- queryKey: [' linkedModpackInfo' , props . instance .path ],
233+ queryKey: [' linkedModpackInfo' , instance .path ],
239234 })
240- emit ( ' unlinked ' )
235+ onUnlinked ( )
241236 },
242237
243238 getCachedModpackVersions : () => null ,
244239 async fetchModpackVersions() {
245- const versions = await get_project_versions (props . instance .linked_data ! .project_id ! ).catch (
240+ const versions = await get_project_versions (instance .linked_data ! .project_id ! ).catch (
246241 handleError ,
247242 )
248243 return (versions ?? []) as Labrinth .Versions .v2 .Version []
@@ -255,25 +250,25 @@ provideInstallationSettings({
255250 },
256251
257252 async onModpackVersionConfirm(version ) {
258- await update_managed_modrinth_version (props . instance .path , version .id )
253+ await update_managed_modrinth_version (instance .path , version .id )
259254 await queryClient .invalidateQueries ({
260- queryKey: [' linkedModpackInfo' , props . instance .path ],
255+ queryKey: [' linkedModpackInfo' , instance .path ],
261256 })
262257 },
263258
264259 updaterModalProps: computed (() => ({
265260 isApp: true ,
266261 currentVersionId:
267- modpackInfo .value ?.update_version_id ?? props . instance .linked_data ?.version_id ?? ' ' ,
262+ modpackInfo .value ?.update_version_id ?? instance .linked_data ?.version_id ?? ' ' ,
268263 projectIconUrl: modpackInfo .value ?.project ?.icon_url ,
269264 projectName: modpackInfo .value ?.project ?.title ?? ' Modpack' ,
270- currentGameVersion: props . instance .game_version ,
271- currentLoader: props . instance .loader ,
265+ currentGameVersion: instance .game_version ,
266+ currentLoader: instance .loader ,
272267 })),
273268
274269 isServer: false ,
275270 isApp: true ,
276- showModpackVersionActions: ! props . isMinecraftServer ,
271+ showModpackVersionActions: ! isMinecraftServer . value ,
277272 repairing ,
278273 reinstalling ,
279274})
0 commit comments