Skip to content

Commit 491088c

Browse files
committed
fix: rev comments frontend
1 parent 6f11eda commit 491088c

23 files changed

Lines changed: 166 additions & 54 deletions

File tree

‎apps/app-frontend/src/App.vue‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,7 @@ async function handleCommand(e) {
15351535
const splitPath = e.path.split(/[\\/]/)
15361536
const fileName = splitPath ? splitPath[splitPath.length - 1] : e.path
15371537
unknownPackWarningModal.value?.show(
1538-
() => install_create_modpack_instance(location).then(() => undefined),
1538+
() => install_create_modpack_instance(location),
15391539
fileName,
15401540
preview.externalFilesInModpack,
15411541
)

‎apps/app-frontend/src/components/ui/install_flow/UnknownPackWarningModal.vue‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,33 @@
77
:offer-sandbox="offerSandbox"
88
@cancel="reset"
99
@continue="proceed"
10+
@sandbox="proceedSandboxed"
1011
/>
1112
</template>
1213

1314
<script setup lang="ts">
14-
import { UnknownFileWarningModal } from '@modrinth/ui'
15+
import { injectNotificationManager, UnknownFileWarningModal } from '@modrinth/ui'
1516
import { ref, useTemplateRef } from 'vue'
1617
1718
import { useAppSettings } from '@/composables/use-app-settings.ts'
19+
import { enableInstallJobSandbox } from '@/features/sandbox/enable-instance-sandbox'
1820
import { useOfferSandbox } from '@/features/sandbox/use-offer-sandbox'
21+
import type { InstallJobSnapshot } from '@/helpers/install'
1922
import { get as getSettings, set as setSettings } from '@/helpers/settings'
2023
24+
type CreateInstance = () => Promise<InstallJobSnapshot | void>
25+
2126
const appSettings = useAppSettings()
2227
const offerSandbox = useOfferSandbox()
28+
const { handleError } = injectNotificationManager()
2329
2430
const modal = useTemplateRef('modal')
25-
const onProceed = ref<() => Promise<void>>()
31+
const onProceed = ref<CreateInstance>()
2632
const fileName = ref('')
2733
const externalFilesInModpack = ref<string[]>([])
2834
2935
function show(
30-
createInstance: () => Promise<void>,
36+
createInstance: CreateInstance,
3137
selectedFileName = '',
3238
selectedExternalFiles: string[] = [],
3339
) {
@@ -62,5 +68,12 @@ async function proceed(dontShowAgain: boolean) {
6268
if (createInstance) void createInstance()
6369
}
6470
71+
async function proceedSandboxed() {
72+
const createInstance = onProceed.value
73+
reset()
74+
const job = await createInstance?.()
75+
if (job) await enableInstallJobSandbox(job).catch(handleError)
76+
}
77+
6578
defineExpose({ show })
6679
</script>

‎apps/app-frontend/src/components/ui/modal/InstallToPlayModal.vue‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,14 @@
116116

117117
<div class="flex items-center gap-2">
118118
<template v-if="hasExternalFiles">
119-
<Button type="quiet" :color="offerSandbox ? undefined : 'orange'" @click="handleAccept">
119+
<Button
120+
type="quiet"
121+
:color="offerSandbox ? undefined : 'orange'"
122+
@click="handleAccept(false)"
123+
>
120124
{{ formatMessage(messages.installAnyway) }}
121125
</Button>
122-
<Button v-if="offerSandbox" type="colored" color="brand" @click="handleAccept">
126+
<Button v-if="offerSandbox" type="colored" color="brand" @click="handleAccept(true)">
123127
<ShieldCheckIcon />
124128
{{ formatMessage(messages.sandboxAndInstall) }}
125129
</Button>
@@ -133,7 +137,7 @@
133137
<XIcon />
134138
{{ formatMessage(commonMessages.cancelButton) }}
135139
</Button>
136-
<Button type="colored" color="brand" @click="handleAccept">
140+
<Button type="colored" color="brand" @click="handleAccept(false)">
137141
<DownloadIcon />
138142
{{ formatMessage(messages.installButton) }}
139143
</Button>
@@ -278,12 +282,12 @@ async function fetchData(versionId: string) {
278282
}
279283
}
280284
281-
async function handleAccept() {
285+
async function handleAccept(sandbox: boolean) {
282286
hide()
283287
const serverProjectId = project.value?.id
284288
startInstallingServer(serverProjectId)
285289
try {
286-
await installServerProject(serverProjectId)
290+
await installServerProject(serverProjectId, { sandbox })
287291
onInstallComplete.value()
288292
} catch (error) {
289293
console.error('Failed to install server project from InstallToPlayModal:', error)

‎apps/app-frontend/src/components/ui/modal/UpdateToPlayModal.vue‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
:confirm-label="formatMessage(commonMessages.updateButton)"
1111
:confirm-icon="DownloadIcon"
1212
:removed-label="formatMessage(messages.removed)"
13-
@confirm="handleUpdate"
13+
@confirm="handleUpdate(false)"
14+
@sandbox="handleUpdate(true)"
1415
@cancel="handleDecline"
1516
>
1617
<template v-if="instance" #description>
@@ -40,6 +41,7 @@ import {
4041
import dayjs from 'dayjs'
4142
import { computed, ref } from 'vue'
4243
44+
import { enableInstanceSandbox } from '@/features/sandbox/enable-instance-sandbox'
4345
import { useOfferSandbox } from '@/features/sandbox/use-offer-sandbox'
4446
import { get_project_many, get_version, get_version_many } from '@/helpers/cache.js'
4547
import { wait_for_install_job } from '@/helpers/install'
@@ -261,11 +263,12 @@ async function checkUpdateAvailable(inst: GameInstance): Promise<DependencyDiff[
261263
return null
262264
}
263265
264-
async function handleUpdate() {
266+
async function handleUpdate(sandbox: boolean) {
265267
const serverProjectId = instance.value?.link?.project_id
266268
if (serverProjectId) startInstallingServer(serverProjectId)
267269
try {
268270
if (modpackVersionId.value && instance.value) {
271+
if (sandbox) await enableInstanceSandbox(instance.value.id)
269272
const job = await update_managed_modrinth_version(instance.value.id, modpackVersionId.value)
270273
await wait_for_install_job(appEvents, job.job_id)
271274
await onUpdateComplete.value()

‎apps/app-frontend/src/components/ui/shared-instances/SharedInstanceUpdateModal.vue‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
:show-report-button="!isOwner"
1616
:show-external-warnings="!isOwner"
1717
:external-warning-description="formatMessage(messages.externalWarningDescription)"
18-
@confirm="update"
18+
@confirm="update(false)"
19+
@sandbox="update(true)"
1920
@cancel="emit('cancel')"
2021
@report="emit('report', $event)"
2122
>
@@ -41,6 +42,7 @@ import {
4142
} from '@modrinth/ui'
4243
import { computed, ref } from 'vue'
4344
45+
import { enableInstanceSandbox } from '@/features/sandbox/enable-instance-sandbox'
4446
import { useOfferSandbox } from '@/features/sandbox/use-offer-sandbox'
4547
import {
4648
getSharedInstanceUnavailableReason,
@@ -90,11 +92,12 @@ const diffs = computed<ContentDiffItem[]>(
9092
})) ?? [],
9193
)
9294
93-
async function update() {
95+
async function update(sandbox: boolean) {
9496
let successful = false
9597
emit('accepted')
9698
try {
9799
if (instance.value) {
100+
if (sandbox) await enableInstanceSandbox(instance.value.id)
98101
const job = await install_update_shared_instance(instance.value.id)
99102
await wait_for_install_job(appEvents, job.job_id)
100103
await onComplete.value()

‎apps/app-frontend/src/components/ui/shared-instances/shared-instance-install-modal/index.vue‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@
215215
type="quiet"
216216
:color="offerSandbox ? undefined : 'orange'"
217217
:disabled="installing"
218-
@click="accept"
218+
@click="accept(false)"
219219
>
220220
{{ formatMessage(messages.installAnyway) }}
221221
</Button>
@@ -224,7 +224,7 @@
224224
type="colored"
225225
color="brand"
226226
:disabled="installing"
227-
@click="accept"
227+
@click="accept(true)"
228228
>
229229
<ShieldCheckIcon />{{ formatMessage(messages.sandboxAndInstall) }}
230230
</Button>
@@ -242,7 +242,7 @@
242242
<Button type="outlined" class="!border" :disabled="installing" @click="handleCancel">
243243
<XIcon />{{ formatMessage(commonMessages.cancelButton) }}
244244
</Button>
245-
<Button type="colored" color="brand" :disabled="installing" @click="accept">
245+
<Button type="colored" color="brand" :disabled="installing" @click="accept(false)">
246246
<DownloadIcon />{{ formatMessage(messages.installButton) }}
247247
</Button>
248248
</template>
@@ -316,6 +316,7 @@ import { openUrl } from '@tauri-apps/plugin-opener'
316316
import { computed, nextTick, ref } from 'vue'
317317
318318
import { config } from '@/config'
319+
import type { InstallSandboxChoice } from '@/features/sandbox/enable-instance-sandbox'
319320
import { useOfferSandbox } from '@/features/sandbox/use-offer-sandbox'
320321
import { toError } from '@/helpers/errors'
321322
import type { SharedInstanceInstallPreview } from '@/helpers/install'
@@ -342,7 +343,7 @@ const externalFileTable = ref<HTMLElement | null>(null)
342343
const preview = ref<SharedInstanceInstallPreview | null>(null)
343344
const installing = ref(false)
344345
const creator = ref<SharedInstanceCreator | null>(null)
345-
const install = ref<() => void | Promise<void>>(() => {})
346+
const install = ref<(choice: InstallSandboxChoice) => void | Promise<void>>(() => {})
346347
const reportMode = ref(false)
347348
const reportOnly = ref(false)
348349
const isOwner = ref(false)
@@ -396,12 +397,12 @@ const creatorProfileLink = computed(() => {
396397
: undefined
397398
})
398399
399-
async function accept() {
400+
async function accept(sandbox: boolean) {
400401
if (installing.value) return
401402
const executeInstall = install.value
402403
installing.value = true
403404
try {
404-
await executeInstall()
405+
await executeInstall({ sandbox })
405406
hide()
406407
} catch (error) {
407408
console.error('Failed to install shared instance:', error)
@@ -520,7 +521,7 @@ function resetReportState() {
520521
}
521522
function show(
522523
previewValue: SharedInstanceInstallPreview,
523-
installValue: () => void | Promise<void>,
524+
installValue: (choice: InstallSandboxChoice) => void | Promise<void>,
524525
creatorValue?: SharedInstanceCreator,
525526
event?: MouseEvent,
526527
options?: { isOwner?: boolean },

‎apps/app-frontend/src/components/ui/shared-instances/shared-instance-invite-handler/use-shared-instance-invite-handler.ts‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import { type Ref, watch } from 'vue'
1010
import { useRouter } from 'vue-router'
1111

1212
import { useAppSettings } from '@/composables/use-app-settings.ts'
13+
import {
14+
enableInstallJobSandbox,
15+
type InstallSandboxChoice,
16+
} from '@/features/sandbox/enable-instance-sandbox'
1317
import { get_user } from '@/helpers/cache'
1418
import { toError } from '@/helpers/errors'
1519
import {
@@ -28,7 +32,7 @@ import type { AppNotification, SharedInstanceInvite } from './shared-instance-in
2832
type InstallModal = {
2933
show(
3034
preview: Awaited<ReturnType<typeof install_get_shared_instance_preview>>,
31-
install: () => Promise<void>,
35+
install: (choice: InstallSandboxChoice) => Promise<void>,
3236
creator?: SharedInstanceCreator,
3337
): void
3438
}
@@ -69,7 +73,7 @@ export function useSharedInstanceInviteHandler(
6973
| {
7074
instanceId: string
7175
preview: Awaited<ReturnType<typeof install_get_shared_instance_preview>>
72-
install: () => Promise<void>
76+
install: (choice: InstallSandboxChoice) => Promise<void>
7377
creator?: SharedInstanceCreator
7478
onGoToInstance?: () => void | Promise<void>
7579
}
@@ -104,17 +108,17 @@ export function useSharedInstanceInviteHandler(
104108

105109
function showInstall(
106110
preview: Awaited<ReturnType<typeof install_get_shared_instance_preview>>,
107-
install: () => Promise<void>,
111+
install: (choice: InstallSandboxChoice) => Promise<void>,
108112
creator?: SharedInstanceCreator,
109113
) {
110114
if (!installModal.value) throw new Error('Shared instance install modal is not available.')
111115
const generation = notificationGeneration
112116
installModal.value.show(
113117
preview,
114-
async () => {
118+
async (choice) => {
115119
if (generation !== notificationGeneration) return
116120
try {
117-
await install()
121+
await install(choice)
118122
} catch (error) {
119123
notifySharedInstanceError(error)
120124
throw error
@@ -127,7 +131,7 @@ export function useSharedInstanceInviteHandler(
127131
async function showInstallOrAlreadyInstalled(
128132
sharedInstanceId: string,
129133
preview: Awaited<ReturnType<typeof install_get_shared_instance_preview>>,
130-
install: () => Promise<void>,
134+
install: (choice: InstallSandboxChoice) => Promise<void>,
131135
creator?: SharedInstanceCreator,
132136
onGoToInstance?: () => void | Promise<void>,
133137
) {
@@ -195,9 +199,9 @@ export function useSharedInstanceInviteHandler(
195199
await showInstallOrAlreadyInstalled(
196200
invite.sharedInstanceId,
197201
preview,
198-
async () => {
202+
async ({ sandbox }) => {
199203
await install_accept_pending_shared_instance_invite(invite.sharedInstanceId)
200-
await install_shared_instance(
204+
const job = await install_shared_instance(
201205
invite.sharedInstanceId,
202206
invite.sharedInstanceName,
203207
invite.invitedById,
@@ -206,6 +210,7 @@ export function useSharedInstanceInviteHandler(
206210
invite.instanceIconUrl,
207211
invite.instanceIconConfig,
208212
)
213+
if (sandbox) await enableInstallJobSandbox(job)
209214
await markNotificationRead(notification).catch((error) => handleError(toError(error)))
210215
await queryClient.invalidateQueries({ queryKey: ['instances'] })
211216
},
@@ -301,9 +306,9 @@ export function useSharedInstanceInviteHandler(
301306
await showInstallOrAlreadyInstalled(
302307
invite.sharedInstanceId,
303308
invite.preview,
304-
async () => {
309+
async ({ sandbox }) => {
305310
await install_accept_shared_instance_invite(invite.sharedInstanceId, inviteId)
306-
await install_shared_instance(
311+
const job = await install_shared_instance(
307312
invite.sharedInstanceId,
308313
invite.preview.name,
309314
invite.managerId,
@@ -312,6 +317,7 @@ export function useSharedInstanceInviteHandler(
312317
invite.instanceIconUrl,
313318
invite.instanceIconConfig,
314319
)
320+
if (sandbox) await enableInstallJobSandbox(job)
315321
await queryClient.invalidateQueries({ queryKey: ['instances'] })
316322
},
317323
invite.inviter

‎apps/app-frontend/src/features/hosting/use-server-play.ts‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import {
2121
linkedServerMetadata,
2222
useLinkedServerCache,
2323
} from '@/features/instances/linked-server/use-linked-server'
24+
import {
25+
enableInstanceSandbox,
26+
type InstallSandboxChoice,
27+
} from '@/features/sandbox/enable-instance-sandbox'
2428
import { toError } from '@/helpers/errors'
2529
import {
2630
install_get_shared_instance_preview,
@@ -53,7 +57,10 @@ type SharedInstancePreview = Awaited<ReturnType<typeof install_get_shared_instan
5357

5458
export type ServerPlayModals = {
5559
showAccountRequired: () => Promise<boolean> | undefined
56-
showInstallPreview: (preview: SharedInstancePreview, confirm: () => Promise<void>) => void
60+
showInstallPreview: (
61+
preview: SharedInstancePreview,
62+
confirm: (choice: InstallSandboxChoice) => Promise<void>,
63+
) => void
5764
showUpdatePreview: () => void
5865
hideAll: () => void
5966
}
@@ -263,7 +270,15 @@ export function useServerPlay(modals: Ref<ServerPlayModals | undefined>) {
263270
}
264271

265272
const launchMutation = useMutation({
266-
mutationFn: async ({ target, instanceId }: { target: LaunchTarget; instanceId?: string }) => {
273+
mutationFn: async ({
274+
target,
275+
instanceId,
276+
sandbox,
277+
}: {
278+
target: LaunchTarget
279+
instanceId?: string
280+
sandbox?: boolean
281+
}) => {
267282
await assertAccount(target)
268283
const existing = instanceId ? await get(instanceId) : await findInstance(target)
269284
if (
@@ -286,6 +301,7 @@ export function useServerPlay(modals: Ref<ServerPlayModals | undefined>) {
286301
)
287302
const installedId = installJobInstanceId(job)
288303
if (!installedId) throw new Error(formatMessage(messages.notReady))
304+
if (sandbox) await enableInstanceSandbox(installedId)
289305
activeInstall.value = {
290306
serverId: target.serverId,
291307
worldId: target.worldId,
@@ -380,9 +396,9 @@ export function useServerPlay(modals: Ref<ServerPlayModals | undefined>) {
380396
const preview = await install_get_shared_instance_preview(sharedInstanceId, target.name)
381397
await assertAccount(target)
382398
if (target.icon) preview.iconUrl = target.icon
383-
modals.value?.showInstallPreview(preview, async () => {
399+
modals.value?.showInstallPreview(preview, async ({ sandbox }) => {
384400
if (launchMutation.isPending.value) return
385-
await launchMutation.mutateAsync({ target }).catch(() => {})
401+
await launchMutation.mutateAsync({ target, sandbox }).catch(() => {})
386402
})
387403
},
388404
onError: (error) => handleError(toError(error)),

0 commit comments

Comments
 (0)