Compare commits
138
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a85e88339f | ||
|
|
d4eb492772 | ||
|
|
e1aa1b47ec | ||
|
|
023447fe85 | ||
|
|
1baf1a041e | ||
|
|
6a0d9b719c | ||
|
|
ba43b9d5bc | ||
|
|
1c671943b7 | ||
|
|
eef7d02f45 | ||
|
|
947a739672 | ||
|
|
799d542227 | ||
|
|
77258eee9d | ||
|
|
a4615c7b73 | ||
|
|
146b88afce | ||
|
|
9bdc965cd5 | ||
|
|
d6d4fcf8a0 | ||
|
|
8cc4782497 | ||
|
|
77b381b8d0 | ||
|
|
4124f26095 | ||
|
|
041d288b25 | ||
|
|
86306b8ddd | ||
|
|
8599a014ad | ||
|
|
bf175160b0 | ||
|
|
d17a66e44f | ||
|
|
3198eac35a | ||
|
|
d83a65a052 | ||
|
|
00f0f111d8 | ||
|
|
0edf96fc2c | ||
|
|
871b0ee001 | ||
|
|
adebde714d | ||
|
|
0195cbf5ac | ||
|
|
13a56f4200 | ||
|
|
d3a510eee6 | ||
|
|
8b94e7dbbe | ||
|
|
ccb96a8cf1 | ||
|
|
0f35a5f707 | ||
|
|
6fb73490d3 | ||
|
|
2dcf26c9d9 | ||
|
|
9ccacba3fd | ||
|
|
54499dd9da | ||
|
|
fce6c60759 | ||
|
|
dcbad9447d | ||
|
|
4abf643852 | ||
|
|
a8d8e1674b | ||
|
|
60f3fd8816 | ||
|
|
c71c220446 | ||
|
|
a95153d0b1 | ||
|
|
853147b04d | ||
|
|
8d61826c5f | ||
|
|
2e92887eb2 | ||
|
|
47bdb1e79c | ||
|
|
d6fdb4f453 | ||
|
|
4ba1ed279f | ||
|
|
afdd091971 | ||
|
|
99e0aa9d14 | ||
|
|
22bc631293 | ||
|
|
3d3682023e | ||
|
|
f253d5529b | ||
|
|
253141b6ff | ||
|
|
946a477397 | ||
|
|
eabac1f11e | ||
|
|
c9a2eeb53d | ||
|
|
b776b99f26 | ||
|
|
daeedc4951 | ||
|
|
79addd4aba | ||
|
|
cadb7bbdcd | ||
|
|
7f3ab9d79b | ||
|
|
037bff2db3 | ||
|
|
1406f7ded3 | ||
|
|
c54acd2e36 | ||
|
|
1b6534ad8c | ||
|
|
2477fc62ca | ||
|
|
3f6678ac2f | ||
|
|
e36329ff0e | ||
|
|
c718d75774 | ||
|
|
544611738d | ||
|
|
98396c6bcd | ||
|
|
403a883e0b | ||
|
|
53c749aaea | ||
|
|
addc31c7c1 | ||
|
|
25978bcd8f | ||
|
|
117eaad9ff | ||
|
|
91e2c369f5 | ||
|
|
ae2992d7f8 | ||
|
|
20d5d2baab | ||
|
|
748d24b264 | ||
|
|
bb0b094002 | ||
|
|
386db4bdb5 | ||
|
|
f98dbf1592 | ||
|
|
48aff7550a | ||
|
|
c000e6a535 | ||
|
|
2ed2791316 | ||
|
|
d422f3aeaf | ||
|
|
a21fe3750b | ||
|
|
8a447f33f6 | ||
|
|
f73bc89f84 | ||
|
|
4f220201b3 | ||
|
|
83ee962c16 | ||
|
|
f7380f1590 | ||
|
|
121da431ed | ||
|
|
b7c16594ce | ||
|
|
fae16a0184 | ||
|
|
6e9485c2f5 | ||
|
|
ed61a5942c | ||
|
|
5a289c3a15 | ||
|
|
91e63fdb2c | ||
|
|
214066ae5f | ||
|
|
2f34faa50f | ||
|
|
a57dfb828e | ||
|
|
eec6b47ee7 | ||
|
|
f776bf8995 | ||
|
|
69a00888ba | ||
|
|
996044bdc2 | ||
|
|
4674f31dd3 | ||
|
|
fe61337a34 | ||
|
|
b633f7cdf0 | ||
|
|
8df1ac8a86 | ||
|
|
a99a0a6e30 | ||
|
|
773cf387a3 | ||
|
|
7414477bbd | ||
|
|
e8f10ab1ef | ||
|
|
e91ba2ae74 | ||
|
|
95a3e00b03 | ||
|
|
f490600ee2 | ||
|
|
b57219f348 | ||
|
|
ead942abb2 | ||
|
|
d2c32ed14f | ||
|
|
4b9b9ebf47 | ||
|
|
457dfd8c30 | ||
|
|
8ec5cf104c | ||
|
|
306328367e | ||
|
|
3901749d93 | ||
|
|
cee0c3bbd4 | ||
|
|
63ca20db04 | ||
|
|
0388e339db | ||
|
|
d4554b0f4c | ||
|
|
d5471bb36c | ||
|
|
f238eeae0e |
No files matched your search
@@ -12,13 +12,18 @@ on:
|
|||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
issues: write
|
issues: write
|
||||||
pull-requests: read
|
pull-requests: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
comment:
|
comment:
|
||||||
name: Post changelog comment
|
name: Post changelog comment
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
issues: write
|
||||||
|
pull-requests: write
|
||||||
|
contents: read
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Post or update changelog comment
|
- name: Post or update changelog comment
|
||||||
uses: actions/github-script@d746ffe35508b1917358783b479e04febd2b8f71 # v9.0.0
|
uses: actions/github-script@d746ffe35508b1917358783b479e04febd2b8f71 # v9.0.0
|
||||||
|
|||||||
@@ -22,5 +22,5 @@ jobs:
|
|||||||
node-version-file: .nvmrc
|
node-version-file: .nvmrc
|
||||||
- uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable
|
- uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable
|
||||||
- uses: cargo-bins/cargo-binstall@dc19f1e48450eefe5a29b8da6c6b00a87d730b37 # v1.18.1
|
- uses: cargo-bins/cargo-binstall@dc19f1e48450eefe5a29b8da6c6b00a87d730b37 # v1.18.1
|
||||||
- run: cargo binstall --no-confirm cargo-shear
|
- run: cargo binstall --no-confirm cargo-shear@1.13.4
|
||||||
- run: cargo shear
|
- run: cargo shear
|
||||||
Generated
+50
-2
@@ -1889,6 +1889,28 @@ version = "0.2.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
|
checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fontconfig-parser"
|
||||||
|
version = "0.5.8"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bbc773e24e02d4ddd8395fd30dc147524273a83e54e0f312d986ea30de5f5646"
|
||||||
|
dependencies = [
|
||||||
|
"roxmltree",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fontdb"
|
||||||
|
version = "0.24.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2660c5e9157bf76d2db1294e4a9feba604ef610819a3b591088d0d8392a3290f"
|
||||||
|
dependencies = [
|
||||||
|
"fontconfig-parser",
|
||||||
|
"log",
|
||||||
|
"memmap2",
|
||||||
|
"slotmap",
|
||||||
|
"tinyvec",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "foreign-types"
|
name = "foreign-types"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
@@ -3477,6 +3499,15 @@ version = "2.8.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memmap2"
|
||||||
|
version = "0.9.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d1219ed1b7f229ee7104d281dd01d6802fe28bb6e95d292942c4daacdeb798c0"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memoffset"
|
name = "memoffset"
|
||||||
version = "0.9.1"
|
version = "0.9.1"
|
||||||
@@ -5102,6 +5133,12 @@ dependencies = [
|
|||||||
"windows-sys 0.52.0",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "roxmltree"
|
||||||
|
version = "0.20.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6c20b6793b5c2fa6553b250154b78d6d0db37e72700ae35fad9387a46f487c97"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rsa"
|
name = "rsa"
|
||||||
version = "0.9.10"
|
version = "0.9.10"
|
||||||
@@ -5758,6 +5795,15 @@ version = "0.4.12"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
|
checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "slotmap"
|
||||||
|
version = "1.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bdd58c3c93c3d278ca835519292445cb4b0d4dc59ccfdf7ceadaab3f8aeb4038"
|
||||||
|
dependencies = [
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "smallvec"
|
name = "smallvec"
|
||||||
version = "1.15.2"
|
version = "1.15.2"
|
||||||
@@ -6795,7 +6841,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "theseus"
|
name = "theseus"
|
||||||
version = "1.0.0-beta15"
|
version = "1.0.2-beta7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ariadne",
|
"ariadne",
|
||||||
"async-minecraft-ping",
|
"async-minecraft-ping",
|
||||||
@@ -6899,7 +6945,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "theseus_gui"
|
name = "theseus_gui"
|
||||||
version = "1.0.0-beta15"
|
version = "1.0.2-beta7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ashpd",
|
"ashpd",
|
||||||
"async_zip",
|
"async_zip",
|
||||||
@@ -6912,6 +6958,7 @@ dependencies = [
|
|||||||
"either",
|
"either",
|
||||||
"enumset",
|
"enumset",
|
||||||
"flate2",
|
"flate2",
|
||||||
|
"fontdb",
|
||||||
"futures",
|
"futures",
|
||||||
"hyper",
|
"hyper",
|
||||||
"hyper-util",
|
"hyper-util",
|
||||||
@@ -6926,6 +6973,7 @@ dependencies = [
|
|||||||
"path-util",
|
"path-util",
|
||||||
"quartz_nbt",
|
"quartz_nbt",
|
||||||
"regex",
|
"regex",
|
||||||
|
"semver",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_with",
|
"serde_with",
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ encoding_rs = "0.8.35"
|
|||||||
enumset = "1.1.10"
|
enumset = "1.1.10"
|
||||||
eyre = "0.6.12"
|
eyre = "0.6.12"
|
||||||
flate2 = "1.1.4"
|
flate2 = "1.1.4"
|
||||||
|
fontdb = "0.24.0"
|
||||||
fs4 = { version = "0.13.1", default-features = false }
|
fs4 = { version = "0.13.1", default-features = false }
|
||||||
futures = "0.3.31"
|
futures = "0.3.31"
|
||||||
futures-lite = "2.6.1"
|
futures-lite = "2.6.1"
|
||||||
@@ -83,6 +84,7 @@ rgb = "0.8.52"
|
|||||||
rustls = { version = "0.23.42", default-features = false, features = ["ring", "std", "tls12"] }
|
rustls = { version = "0.23.42", default-features = false, features = ["ring", "std", "tls12"] }
|
||||||
rustls-native-certs = "0.8.4"
|
rustls-native-certs = "0.8.4"
|
||||||
rustls-pki-types = "1.15.0"
|
rustls-pki-types = "1.15.0"
|
||||||
|
semver = "1.0.28"
|
||||||
serde = "1.0.228"
|
serde = "1.0.228"
|
||||||
serde_bytes = "0.11.19"
|
serde_bytes = "0.11.19"
|
||||||
serde_cbor = "0.11.2"
|
serde_cbor = "0.11.2"
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ extend-exclude = [
|
|||||||
"packages/app-lib/src/api/content_search/WikiEntries.txt",
|
"packages/app-lib/src/api/content_search/WikiEntries.txt",
|
||||||
# Bundled Monaco editor runtime contains upstream generated assets.
|
# Bundled Monaco editor runtime contains upstream generated assets.
|
||||||
"apps/app-frontend/public/monaco/",
|
"apps/app-frontend/public/monaco/",
|
||||||
|
# Minecraft language-name data (from mcmeta); contains language codes that look like typos.
|
||||||
|
"apps/app-frontend/src/components/ui/settings/instances/game-settings-modal/languages.ts",
|
||||||
]
|
]
|
||||||
|
|
||||||
[default.extend-words]
|
[default.extend-words]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@modrinth/app-frontend",
|
"name": "@modrinth/app-frontend",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "1.0.0-beta15",
|
"version": "1.0.2-beta8",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ import InstancePlayerModal from '@/components/instance/InstancePlayerModal.vue'
|
|||||||
import TaggedModDownloadsModal from '@/components/instance/TaggedModDownloadsModal.vue'
|
import TaggedModDownloadsModal from '@/components/instance/TaggedModDownloadsModal.vue'
|
||||||
import InstanceExportModal from '@/components/lab/recipe-generator/InstanceExportModal.vue'
|
import InstanceExportModal from '@/components/lab/recipe-generator/InstanceExportModal.vue'
|
||||||
import AccountsCard from '@/components/ui/AccountsCard.vue'
|
import AccountsCard from '@/components/ui/AccountsCard.vue'
|
||||||
|
import AnniversaryCelebration from '@/components/ui/AnniversaryCelebration.vue'
|
||||||
import AppActionBar from '@/components/ui/AppActionBar.vue'
|
import AppActionBar from '@/components/ui/AppActionBar.vue'
|
||||||
import AxolotlLogo from '@/components/ui/AxolotlLogo.vue'
|
import AxolotlLogo from '@/components/ui/AxolotlLogo.vue'
|
||||||
import Breadcrumbs from '@/components/ui/Breadcrumbs.vue'
|
import Breadcrumbs from '@/components/ui/Breadcrumbs.vue'
|
||||||
@@ -93,12 +94,14 @@ import NavButton from '@/components/ui/NavButton.vue'
|
|||||||
import NavRail from '@/components/ui/NavRail.vue'
|
import NavRail from '@/components/ui/NavRail.vue'
|
||||||
import OnboardingOverlay from '@/components/ui/onboarding/OnboardingOverlay.vue'
|
import OnboardingOverlay from '@/components/ui/onboarding/OnboardingOverlay.vue'
|
||||||
import QuickInstanceSwitcher from '@/components/ui/QuickInstanceSwitcher.vue'
|
import QuickInstanceSwitcher from '@/components/ui/QuickInstanceSwitcher.vue'
|
||||||
import SkinSiteSessionFrame from '@/components/ui/SkinSiteSessionFrame.vue'
|
import RemoteAnnouncements from '@/components/ui/RemoteAnnouncements.vue'
|
||||||
import StartupAnnouncementModal from '@/components/ui/StartupAnnouncementModal.vue'
|
|
||||||
import SplashScreen from '@/components/ui/SplashScreen.vue'
|
import SplashScreen from '@/components/ui/SplashScreen.vue'
|
||||||
|
import StartupAnnouncementModal from '@/components/ui/StartupAnnouncementModal.vue'
|
||||||
import WindowControls from '@/components/ui/WindowControls.vue'
|
import WindowControls from '@/components/ui/WindowControls.vue'
|
||||||
import { useCheckDisableMouseover } from '@/composables/macCssFix.js'
|
import { useCheckDisableMouseover } from '@/composables/macCssFix.js'
|
||||||
|
import { initSkinSiteSession } from '@/composables/skin-site-session'
|
||||||
import { useDropImport } from '@/composables/useDropImport'
|
import { useDropImport } from '@/composables/useDropImport'
|
||||||
|
import { setupKeyboardShortcuts } from '@/composables/useKeyboardShortcuts'
|
||||||
import { minecraftLaunchErrorKey } from '@/composables/useMinecraftLaunchError'
|
import { minecraftLaunchErrorKey } from '@/composables/useMinecraftLaunchError'
|
||||||
import { useNetworkStatus } from '@/composables/useNetworkStatus'
|
import { useNetworkStatus } from '@/composables/useNetworkStatus'
|
||||||
import { AxolotlBrandConfig, config, getOfficialLabrinthBaseUrl } from '@/config'
|
import { AxolotlBrandConfig, config, getOfficialLabrinthBaseUrl } from '@/config'
|
||||||
@@ -130,6 +133,7 @@ import {
|
|||||||
} from '@/helpers/settings.ts'
|
} from '@/helpers/settings.ts'
|
||||||
import { getSidebarExpanded, setSidebarExpanded } from '@/helpers/sidebar-state.ts'
|
import { getSidebarExpanded, setSidebarExpanded } from '@/helpers/sidebar-state.ts'
|
||||||
import { get_opening_command, initialize_state } from '@/helpers/state'
|
import { get_opening_command, initialize_state } from '@/helpers/state'
|
||||||
|
import { installUiScale, setUiScale } from '@/helpers/ui-scale'
|
||||||
import {
|
import {
|
||||||
areUpdatesEnabled,
|
areUpdatesEnabled,
|
||||||
backupAppDbForUpdate,
|
backupAppDbForUpdate,
|
||||||
@@ -143,7 +147,6 @@ import {
|
|||||||
isNetworkMetered,
|
isNetworkMetered,
|
||||||
setRestartAfterPendingUpdate,
|
setRestartAfterPendingUpdate,
|
||||||
} from '@/helpers/utils.js'
|
} from '@/helpers/utils.js'
|
||||||
import { installUiScale, setUiScale } from '@/helpers/ui-scale'
|
|
||||||
import { start_join_server, start_join_singleplayer_world } from '@/helpers/worlds.ts'
|
import { start_join_server, start_join_singleplayer_world } from '@/helpers/worlds.ts'
|
||||||
import i18n, { resolveInitialLocale } from '@/i18n.config'
|
import i18n, { resolveInitialLocale } from '@/i18n.config'
|
||||||
import {
|
import {
|
||||||
@@ -182,6 +185,8 @@ const onSchematicWorkshopPage = computed(() => route.path === '/lab/schematic-pr
|
|||||||
const isSchematicFile = (path: string) => /\.(litematic|schematic|schem)$/i.test(path)
|
const isSchematicFile = (path: string) => /\.(litematic|schematic|schem)$/i.test(path)
|
||||||
const APP_LEFT_NAV_WIDTH = '4rem'
|
const APP_LEFT_NAV_WIDTH = '4rem'
|
||||||
|
|
||||||
|
setupKeyboardShortcuts()
|
||||||
|
|
||||||
const discoverContentPath = computed(() => {
|
const discoverContentPath = computed(() => {
|
||||||
const projectType = route.params.projectType
|
const projectType = route.params.projectType
|
||||||
if (
|
if (
|
||||||
@@ -1154,6 +1159,7 @@ async function setupApp() {
|
|||||||
stateInitialized.value = true
|
stateInitialized.value = true
|
||||||
showOnboarding.value = !onboarded
|
showOnboarding.value = !onboarded
|
||||||
void reconcileMojangAuthSourceAtStartup().catch(handleError)
|
void reconcileMojangAuthSourceAtStartup().catch(handleError)
|
||||||
|
void initSkinSiteSession().catch(handleError)
|
||||||
|
|
||||||
isMaximized.value = await getCurrentWindow().isMaximized()
|
isMaximized.value = await getCurrentWindow().isMaximized()
|
||||||
|
|
||||||
@@ -1260,7 +1266,7 @@ async function replayOnboarding(mode) {
|
|||||||
|
|
||||||
async function finishOnboarding() {
|
async function finishOnboarding() {
|
||||||
const wasReplay = onboardingReplay.value
|
const wasReplay = onboardingReplay.value
|
||||||
const settings = onboardingSettings.value ?? (await getSettings())
|
const settings = await getSettings()
|
||||||
if (!onboardingReplay.value) {
|
if (!onboardingReplay.value) {
|
||||||
if (onboardingMode.value === 'instance') {
|
if (onboardingMode.value === 'instance') {
|
||||||
settings.onboarding_instance_tour_completed = true
|
settings.onboarding_instance_tour_completed = true
|
||||||
@@ -2221,10 +2227,11 @@ provideAppUpdateDownloadProgress(appUpdateDownload)
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
<AnniversaryCelebration />
|
||||||
<SplashScreen v-if="!stateFailed" ref="splashScreen" data-tauri-drag-region />
|
<SplashScreen v-if="!stateFailed" ref="splashScreen" data-tauri-drag-region />
|
||||||
<SkinSiteSessionFrame v-if="stateInitialized" />
|
|
||||||
<InstancePlayerModal v-if="stateInitialized" />
|
<InstancePlayerModal v-if="stateInitialized" />
|
||||||
<StartupAnnouncementModal ref="startupAnnouncementModal" />
|
<StartupAnnouncementModal ref="startupAnnouncementModal" />
|
||||||
|
<RemoteAnnouncements :ready="stateInitialized && !showOnboarding && !stateFailed" />
|
||||||
<div id="teleports"></div>
|
<div id="teleports"></div>
|
||||||
<div
|
<div
|
||||||
v-if="stateInitialized && themeStore.customBackgroundPath && !themeStore.transparentBackground"
|
v-if="stateInitialized && themeStore.customBackgroundPath && !themeStore.transparentBackground"
|
||||||
|
|||||||
@@ -32,6 +32,326 @@ export const ANNOUNCEMENT_CHANGE_TYPES: readonly AnnouncementChangeType[] = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
export const launcherAnnouncements: readonly LauncherAnnouncement[] = [
|
export const launcherAnnouncements: readonly LauncherAnnouncement[] = [
|
||||||
|
{
|
||||||
|
id: 'launcher-1.0.2-beta8',
|
||||||
|
version: '1.0.2-beta8',
|
||||||
|
publishedAt: '2026-10-18',
|
||||||
|
title: {
|
||||||
|
'en-US': 'Starlight Launcher 1.0.2-beta8',
|
||||||
|
'zh-CN': 'Starlight Launcher 1.0.2-beta8',
|
||||||
|
},
|
||||||
|
changes: {
|
||||||
|
added: [
|
||||||
|
{
|
||||||
|
'en-US': 'The skin site is now fully native inside the launcher: sign-in, registration, password reset, account settings, players, downloads, world map and player review all run through the launcher UI instead of an embedded web page.',
|
||||||
|
'zh-CN': '皮肤站全面改为启动器原生界面:登录、注册、找回密码、账号设置、角色管理、资源下载、服务器地图与玩家审核均不再依赖内嵌网页。',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'en-US': 'Added a bug tracker: browse and filter issues, read details and comments, post replies, create new issues and follow notifications.',
|
||||||
|
'zh-CN': '新增问题追踪:可浏览与筛选问题、查看详情与评论、发表回复、提交新问题并接收通知。',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'en-US': 'Added an admin console with a permission gate: system overview, announcements, users, players, player review and launcher releases.',
|
||||||
|
'zh-CN': '新增管理控制台(带权限校验):系统概览、公告管理、用户管理、玩家管理、玩家审核与启动器版本管理。',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
changed: [
|
||||||
|
{
|
||||||
|
'en-US': 'Hosted modpack downloads now go through the dedicated download server, keeping large downloads off the main API host.',
|
||||||
|
'zh-CN': '整合包下载改为走独立的下载服务器,避免大文件下载挤占主 API 服务。',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
fixed: [
|
||||||
|
{
|
||||||
|
'en-US': 'LogShare now collects logs with a lightweight reader, fixing crash log uploads that previously failed.',
|
||||||
|
'zh-CN': 'LogShare 改用轻量日志收集,修复崩溃日志上传失败的问题。',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'en-US': 'The onboarding tour now scrolls each step into view when the step changes.',
|
||||||
|
'zh-CN': '引导教程在切换步骤时自动滚动到目标元素。',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'en-US': 'Fixed a type mismatch while collecting crash context credentials.',
|
||||||
|
'zh-CN': '修复崩溃上下文凭据收集中的类型不匹配问题。',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'launcher-1.0.2-beta7',
|
||||||
|
version: '1.0.2-beta7',
|
||||||
|
publishedAt: '2026-10-17',
|
||||||
|
title: {
|
||||||
|
'en-US': 'Starlight Launcher 1.0.2-beta7',
|
||||||
|
'zh-CN': 'Starlight Launcher 1.0.2-beta7',
|
||||||
|
},
|
||||||
|
changes: {
|
||||||
|
fixed: [
|
||||||
|
{
|
||||||
|
'en-US': 'Fixed real-time log backlog that could stall the console under heavy output.',
|
||||||
|
'zh-CN': '修复实时日志积压导致控制台卡顿的问题。',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'en-US': 'The update channel now defaults to the build type: installing a Beta build starts on the Beta channel instead of Release.',
|
||||||
|
'zh-CN': '更新通道默认值改为跟随安装包版本:安装 Beta 版后默认使用 Beta 通道,不再回落为 Release。',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'en-US': 'On Linux, the default game directory for StarLight instances no longer points at the system install path (e.g. /usr/bin); it falls back to the home directory.',
|
||||||
|
'zh-CN': 'Linux 上 StarLight 实例的默认游戏目录不再指向系统安装路径(如 /usr/bin),改为回退到用户主目录。',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'launcher-1.0.2-beta6',
|
||||||
|
version: '1.0.2-beta6',
|
||||||
|
publishedAt: '2026-10-11',
|
||||||
|
title: {
|
||||||
|
'en-US': 'Starlight Launcher 1.0.2-beta6',
|
||||||
|
'zh-CN': 'Starlight Launcher 1.0.2-beta6',
|
||||||
|
},
|
||||||
|
changes: {
|
||||||
|
added: [
|
||||||
|
{
|
||||||
|
'en-US': 'Added keyboard shortcut settings: enable and rebind navigation and quick-scrolling shortcuts.',
|
||||||
|
'zh-CN': '新增键盘快捷键设置:可启用并自定义导航与快速滚动快捷键。',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'en-US': 'Added crash log sharing and AI analysis: share crash diagnostics to LogShare for a structured summary and optional AI analysis, with a rebuilt crash window that browses log files and streams the analysis.',
|
||||||
|
'zh-CN': '新增崩溃日志分享与 AI 分析:可将崩溃诊断分享到 LogShare 获取结构化摘要与 AI 分析;崩溃窗口重做为双栏布局,可浏览日志文件并流式查看分析结果。',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'en-US': 'Crash logs now also collect JVM crash reports (hs_err_pid*.log) and launcher logs.',
|
||||||
|
'zh-CN': '崩溃日志现在也会收集 JVM 崩溃报告(hs_err_pid*.log)与启动器日志。',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'en-US': 'Added a launcher log export entry.',
|
||||||
|
'zh-CN': '新增启动器日志导出入口。',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'en-US': 'Instance groups can now be reordered by dragging.',
|
||||||
|
'zh-CN': '实例分组支持拖拽重排。',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
changed: [
|
||||||
|
{
|
||||||
|
'en-US': 'Synced the latest supported AI chat model list from LobeHub.',
|
||||||
|
'zh-CN': '同步 LobeHub 最新的 AI 聊天模型列表。',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
fixed: [
|
||||||
|
{
|
||||||
|
'en-US': 'Fixed remote announcements not refreshing.',
|
||||||
|
'zh-CN': '修复远端公告不刷新的问题。',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'en-US': 'Completed the Chinese translations for the armor preview feature.',
|
||||||
|
'zh-CN': '补齐盔甲预览功能的中文翻译。',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'launcher-1.0.2-beta5',
|
||||||
|
version: '1.0.2-beta5',
|
||||||
|
publishedAt: '2026-10-11',
|
||||||
|
title: {
|
||||||
|
'en-US': 'Starlight Launcher 1.0.2-beta5',
|
||||||
|
'zh-CN': 'Starlight Launcher 1.0.2-beta5',
|
||||||
|
},
|
||||||
|
changes: {
|
||||||
|
added: [
|
||||||
|
{
|
||||||
|
'en-US': 'Added a remote announcements center: a bell in the top bar opens a panel listing launcher announcements fetched from the Starlight skin site.',
|
||||||
|
'zh-CN': '新增远程公告中心:顶栏的铃铛可打开公告面板,展示从 Starlight 皮肤站拉取的启动器公告。',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'en-US': 'Added a custom Minecraft window title option: set a global toggle and default title, and let each instance override it. The game window is renamed on Windows.',
|
||||||
|
'zh-CN': '新增自定义 Minecraft 窗口标题:可设置全局开关与默认标题,并允许各实例单独覆盖;Windows 下会重命名游戏窗口。',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
fixed: [
|
||||||
|
{
|
||||||
|
'en-US': 'Completed the Chinese translations for the armor preview feature.',
|
||||||
|
'zh-CN': '补齐盔甲预览功能的中文翻译。',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'launcher-1.0.2-beta4',
|
||||||
|
version: '1.0.2-beta4',
|
||||||
|
publishedAt: '2026-10-08',
|
||||||
|
title: {
|
||||||
|
'en-US': 'Starlight Launcher 1.0.2-beta4',
|
||||||
|
'zh-CN': 'Starlight Launcher 1.0.2-beta4',
|
||||||
|
},
|
||||||
|
changes: {
|
||||||
|
added: [
|
||||||
|
{
|
||||||
|
'en-US': 'Added armor and armor-trim rendering to the skin preview, letting you try on armor pieces and trim patterns directly in the skin editor.',
|
||||||
|
'zh-CN': '皮肤预览新增盔甲与盔甲纹饰渲染,可在皮肤编辑器内直接试穿各部位盔甲并调整纹饰图案。',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'en-US': 'Armor preview selections in the skin editor are now saved locally, so they persist across sessions.',
|
||||||
|
'zh-CN': '皮肤编辑器中的盔甲预览选择现在会保存在本地,跨会话保留。',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
changed: [
|
||||||
|
{
|
||||||
|
'en-US': 'Improved download scheduling to reduce concurrency automatically when tasks are waiting for capacity, making large Minecraft installations more reliable on constrained connections.',
|
||||||
|
'zh-CN': '优化下载任务调度:任务因容量不足排队时会自动降低并发,提升大型 Minecraft 版本在受限网络环境下的安装稳定性。',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
fixed: [
|
||||||
|
{
|
||||||
|
'en-US': 'Fixed downloads timing out while waiting for internal connection capacity, which could cause Minecraft installations to fail even when the network was available.',
|
||||||
|
'zh-CN': '修复下载任务等待内部连接容量时过早超时,导致网络正常的情况下 Minecraft 安装仍可能失败的问题。',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'en-US': 'Fixed instance group changes not saving for some instances.',
|
||||||
|
'zh-CN': '修复部分实例的分组修改无法保存的问题。',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'launcher-1.0.2-beta3',
|
||||||
|
version: '1.0.2-beta3',
|
||||||
|
publishedAt: '2026-10-04',
|
||||||
|
title: {
|
||||||
|
'en-US': 'Starlight Launcher 1.0.2-beta3',
|
||||||
|
'zh-CN': 'Starlight Launcher 1.0.2-beta3',
|
||||||
|
},
|
||||||
|
changes: {
|
||||||
|
fixed: [
|
||||||
|
{
|
||||||
|
'en-US': 'Fixed the anniversary celebration banner not showing above the window title bar, and made the banner background semi-transparent so the content behind it stays visible.',
|
||||||
|
'zh-CN': '修复周年庆庆祝横幅被窗口标题栏遮挡、无法显示的问题,并将横幅背景改为半透明,避免遮住下方内容。',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'launcher-1.0.2-beta2',
|
||||||
|
version: '1.0.2-beta2',
|
||||||
|
publishedAt: '2026-10-04',
|
||||||
|
title: {
|
||||||
|
'en-US': 'Starlight Launcher 1.0.2-beta2',
|
||||||
|
'zh-CN': 'Starlight Launcher 1.0.2-beta2',
|
||||||
|
},
|
||||||
|
changes: {
|
||||||
|
fixed: [
|
||||||
|
{
|
||||||
|
'en-US': 'Fixed the launcher failing to start with "no such table: synced_pack_catalog": the cross-instance sync migration was missing the synced_pack_catalog and synced_pack_instances tables.',
|
||||||
|
'zh-CN': '修复启动器因 "no such table: synced_pack_catalog" 无法启动的问题:跨实例同步迁移遗漏了 synced_pack_catalog 与 synced_pack_instances 两张表。',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'launcher-1.0.2-beta1',
|
||||||
|
version: '1.0.2-beta1',
|
||||||
|
publishedAt: '2026-10-04',
|
||||||
|
title: {
|
||||||
|
'en-US': 'Starlight Launcher 1.0.2-beta1',
|
||||||
|
'zh-CN': 'Starlight Launcher 1.0.2-beta1',
|
||||||
|
},
|
||||||
|
changes: {
|
||||||
|
added: [
|
||||||
|
{
|
||||||
|
'en-US': 'Cross-instance sync: share game options, resource packs, data packs, multiplayer servers, command history, and creative hotbars across instances, with per-option toggles and a fine-grained game-settings editor.',
|
||||||
|
'zh-CN': '跨实例同步:可跨实例共享游戏选项、资源包、数据包、多人服务器、命令历史与创造模式快捷栏,支持逐项开关与精细的游戏设置编辑器。',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'en-US': 'Starlight turns 12! On October 4th every year the launcher now shows a celebration banner and falling confetti. The anniversary number is computed from 2014.',
|
||||||
|
'zh-CN': 'Starlight 十二周年!每年 10 月 4 日,启动器会显示庆祝横幅与飘落的彩带、蛋糕,周年数按 2014 年起算。',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'en-US': 'Added a developer feature flag to preview the anniversary celebration at any time.',
|
||||||
|
'zh-CN': '新增开发者功能开关,可随时预览周年庆效果。',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'launcher-1.0.1',
|
||||||
|
version: '1.0.1',
|
||||||
|
publishedAt: '2026-10-03',
|
||||||
|
title: {
|
||||||
|
'en-US': 'Starlight Launcher 1.0.1',
|
||||||
|
'zh-CN': 'Starlight Launcher 1.0.1',
|
||||||
|
},
|
||||||
|
changes: {
|
||||||
|
added: [
|
||||||
|
{
|
||||||
|
'en-US': 'Instance backups: create deduplicated snapshots of an instance while it is closed, preview and restore them, exclude specific files or folders, and move the backup repository.',
|
||||||
|
'zh-CN': '实例备份:在实例关闭时创建去重快照,可预览与恢复,支持排除指定文件或文件夹,并可迁移备份仓库。',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'en-US': "Customize the launcher's UI font and monospace font in appearance settings.",
|
||||||
|
'zh-CN': '在外观设置中自定义启动器界面字体与等宽字体。',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
fixed: [
|
||||||
|
{
|
||||||
|
'en-US': 'Fixed beta builds not auto-updating from beta9 to beta10 (prerelease versions were compared as text instead of by number).',
|
||||||
|
'zh-CN': '修复 beta 版本无法从 beta9 自动更新到 beta10 的问题(预发布版本此前按文本而非数字比较)。',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'en-US': 'Fixed a cross-crate visibility issue that prevented the launcher from compiling with the ignore-SSL-errors option.',
|
||||||
|
'zh-CN': '修复因跨 crate 可见性导致的编译失败,此前启用“忽略 SSL 证书错误”选项时无法编译。',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'launcher-1.0.1-beta10',
|
||||||
|
version: '1.0.1-beta10',
|
||||||
|
publishedAt: '2026-10-02',
|
||||||
|
title: {
|
||||||
|
'en-US': 'Starlight Launcher 1.0.1-beta10',
|
||||||
|
'zh-CN': 'Starlight Launcher 1.0.1-beta10',
|
||||||
|
},
|
||||||
|
changes: {
|
||||||
|
added: [
|
||||||
|
{
|
||||||
|
'en-US': 'Reworked the instance-page tour into four steps covering content, files, worlds, and logs.',
|
||||||
|
'zh-CN': '重做实例页导览,分为内容、文件、世界、日志四步。',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'en-US': 'When the install location is a drive root, the installer now creates a Starlight subfolder automatically.',
|
||||||
|
'zh-CN': '安装位置选到盘符根目录时,安装器会自动创建 Starlight 子文件夹。',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
fixed: [
|
||||||
|
{
|
||||||
|
'en-US': 'Fixed the launcher UI scale reverting after a restart.',
|
||||||
|
'zh-CN': '修复启动器界面缩放重启后恢复原状的问题。',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'en-US': 'Fixed developer feature flags not saving.',
|
||||||
|
'zh-CN': '修复开发者功能开关无法保存的问题。',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'en-US': 'Fixed instance group edits not saving for instances without an applied content set.',
|
||||||
|
'zh-CN': '修复没有应用内容集的实例无法保存分组修改的问题。',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'en-US': 'Fixed the launcher crashing on startup when feature flags were out of sync between the frontend and backend.',
|
||||||
|
'zh-CN': '修复前后端功能开关不同步导致启动器启动崩溃的问题。',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'en-US': 'Fixed being unable to copy text inside the embedded skin site.',
|
||||||
|
'zh-CN': '修复内嵌皮肤站中无法复制文本的问题。',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'en-US': 'Fixed the onboarding prompt not dismissing when clicking anywhere.',
|
||||||
|
'zh-CN': '修复导览提示点击任意位置无法关闭的问题。',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: 'launcher-1.0.1-beta9',
|
id: 'launcher-1.0.1-beta9',
|
||||||
version: '1.0.1-beta9',
|
version: '1.0.1-beta9',
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
@@ -1,11 +1,10 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ButtonStyled, NewModal, useVIntl } from '@modrinth/ui'
|
import { ButtonStyled, NewModal, useVIntl } from '@modrinth/ui'
|
||||||
import { computed, onUnmounted, ref, watch } from 'vue'
|
import { computed, onUnmounted, ref, watch } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
|
||||||
|
|
||||||
import MinecraftLoginModal from '@/components/ui/MinecraftLoginModal.vue'
|
import MinecraftLoginModal from '@/components/ui/MinecraftLoginModal.vue'
|
||||||
|
import SkinSiteLoginModal from '@/components/ui/skin-site/SkinSiteLoginModal.vue'
|
||||||
import {
|
import {
|
||||||
openSkinSiteLogin,
|
|
||||||
requestSkinSitePlayers,
|
requestSkinSitePlayers,
|
||||||
skinSitePlayers,
|
skinSitePlayers,
|
||||||
skinSiteStatus,
|
skinSiteStatus,
|
||||||
@@ -28,7 +27,7 @@ const { formatMessage } = useVIntl()
|
|||||||
|
|
||||||
const modal = ref<InstanceType<typeof NewModal>>()
|
const modal = ref<InstanceType<typeof NewModal>>()
|
||||||
const microsoftLogin = ref<InstanceType<typeof MinecraftLoginModal>>()
|
const microsoftLogin = ref<InstanceType<typeof MinecraftLoginModal>>()
|
||||||
const router = useRouter()
|
const skinSiteLoginModal = ref<InstanceType<typeof SkinSiteLoginModal>>()
|
||||||
const accounts = ref<PlayerChoice[]>([])
|
const accounts = ref<PlayerChoice[]>([])
|
||||||
const active = ref(false)
|
const active = ref(false)
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
@@ -137,9 +136,8 @@ function signInSkinSite() {
|
|||||||
rejectSelection?.(new PlayerSelectionNavigatedAwayError())
|
rejectSelection?.(new PlayerSelectionNavigatedAwayError())
|
||||||
resolveSelection = undefined
|
resolveSelection = undefined
|
||||||
rejectSelection = undefined
|
rejectSelection = undefined
|
||||||
openSkinSiteLogin()
|
skinSiteLoginModal.value?.show()
|
||||||
modal.value?.hide()
|
modal.value?.hide()
|
||||||
void router.push('/starlight-skin')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const unregister = registerInstancePlayerPicker((id, saved) => {
|
const unregister = registerInstancePlayerPicker((id, saved) => {
|
||||||
@@ -246,5 +244,6 @@ onUnmounted(() => {
|
|||||||
<p v-if="saving" class="m-0" role="status">{{ formatMessage(messages.saving) }}</p>
|
<p v-if="saving" class="m-0" role="status">{{ formatMessage(messages.saving) }}</p>
|
||||||
</div>
|
</div>
|
||||||
</NewModal>
|
</NewModal>
|
||||||
|
<SkinSiteLoginModal ref="skinSiteLoginModal" @signed-in="refresh" />
|
||||||
<MinecraftLoginModal ref="microsoftLogin" @complete="refresh" />
|
<MinecraftLoginModal ref="microsoftLogin" @complete="refresh" />
|
||||||
</template>
|
</template>
|
||||||
@@ -244,6 +244,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</Accordion>
|
</Accordion>
|
||||||
<MinecraftLoginModal ref="minecraftLoginModal" @complete="onMicrosoftLogin" />
|
<MinecraftLoginModal ref="minecraftLoginModal" @complete="onMicrosoftLogin" />
|
||||||
|
<SkinSiteLoginModal ref="skinSiteLoginModal" @signed-in="onSkinSiteSignedIn" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
@@ -269,12 +270,12 @@ import { useQueryClient } from '@tanstack/vue-query'
|
|||||||
import { listen } from '@tauri-apps/api/event'
|
import { listen } from '@tauri-apps/api/event'
|
||||||
import type { Ref } from 'vue'
|
import type { Ref } from 'vue'
|
||||||
import { computed, nextTick, onUnmounted, ref, watch } from 'vue'
|
import { computed, nextTick, onUnmounted, ref, watch } from 'vue'
|
||||||
import { useRoute, useRouter } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
|
|
||||||
import axolotlLogo from '@/assets/netherstar.png'
|
import axolotlLogo from '@/assets/netherstar.png'
|
||||||
import MinecraftLoginModal from '@/components/ui/MinecraftLoginModal.vue'
|
import MinecraftLoginModal from '@/components/ui/MinecraftLoginModal.vue'
|
||||||
|
import SkinSiteLoginModal from '@/components/ui/skin-site/SkinSiteLoginModal.vue'
|
||||||
import {
|
import {
|
||||||
openSkinSiteLogin,
|
|
||||||
requestSkinSitePlayers,
|
requestSkinSitePlayers,
|
||||||
selectedSkinSitePlayerId,
|
selectedSkinSitePlayerId,
|
||||||
selectSkinSitePlayer,
|
selectSkinSitePlayer,
|
||||||
@@ -298,21 +299,20 @@ import { getPlayerHeadUrl } from '@/helpers/rendering/batch-skin-renderer.ts'
|
|||||||
import type { Skin } from '@/helpers/skins'
|
import type { Skin } from '@/helpers/skins'
|
||||||
import { get_available_skins } from '@/helpers/skins'
|
import { get_available_skins } from '@/helpers/skins'
|
||||||
import { handleSevereError } from '@/store/error.js'
|
import { handleSevereError } from '@/store/error.js'
|
||||||
import { useTheming } from '@/store/state'
|
|
||||||
|
|
||||||
const { formatMessage } = useVIntl()
|
const { formatMessage } = useVIntl()
|
||||||
const { handleError } = injectNotificationManager()
|
const { handleError } = injectNotificationManager()
|
||||||
const { browserOffline, offline, refreshBrowserOffline } = useNetworkStatus()
|
const { browserOffline, offline, refreshBrowserOffline } = useNetworkStatus()
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const router = useRouter()
|
const skinSiteLoginModal = ref<InstanceType<typeof SkinSiteLoginModal>>()
|
||||||
const themeStore = useTheming()
|
|
||||||
|
|
||||||
async function goToSkinSiteLogin() {
|
async function goToSkinSiteLogin() {
|
||||||
openSkinSiteLogin()
|
skinSiteLoginModal.value?.show()
|
||||||
// The login action must reveal the iframe even if Minimal Home was selected.
|
}
|
||||||
themeStore.homeLayout = 'standard'
|
|
||||||
await router.push('/').catch(handleError)
|
function onSkinSiteSignedIn() {
|
||||||
|
void requestSkinSitePlayers().catch(() => {})
|
||||||
}
|
}
|
||||||
const refreshingNetwork = ref(false)
|
const refreshingNetwork = ref(false)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,246 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { defineMessages, useVIntl } from '@modrinth/ui'
|
||||||
|
import { computed, onUnmounted, ref, watch } from 'vue'
|
||||||
|
|
||||||
|
import { anniversaryYear, ordinal, shouldCelebrate } from '@/helpers/anniversary'
|
||||||
|
import { useTheming } from '@/store/state'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const themeStore = useTheming()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
banner: {
|
||||||
|
id: 'app.anniversary.banner',
|
||||||
|
defaultMessage: 'Happy {ordinal} Anniversary, Starlight!',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
/** Emoji that drift down from the top of the window. */
|
||||||
|
const CONFETTI_EMOJI = ['🎂', '🎉', '🎊', '🎈', '✨', '🧁', '🍰']
|
||||||
|
|
||||||
|
type Confetti = {
|
||||||
|
id: number
|
||||||
|
emoji: string
|
||||||
|
left: number
|
||||||
|
delay: number
|
||||||
|
duration: number
|
||||||
|
size: number
|
||||||
|
drift: number
|
||||||
|
}
|
||||||
|
|
||||||
|
const visible = ref(false)
|
||||||
|
const years = ref(0)
|
||||||
|
const confetti = ref<Confetti[]>([])
|
||||||
|
let spawnTimer: number | undefined
|
||||||
|
let nextId = 0
|
||||||
|
|
||||||
|
function spawnConfetti(): void {
|
||||||
|
const emoji = CONFETTI_EMOJI[Math.floor(Math.random() * CONFETTI_EMOJI.length)]
|
||||||
|
confetti.value.push({
|
||||||
|
id: nextId++,
|
||||||
|
emoji,
|
||||||
|
left: Math.random() * 100,
|
||||||
|
delay: 0,
|
||||||
|
duration: 6 + Math.random() * 5,
|
||||||
|
size: 1 + Math.random() * 1.4,
|
||||||
|
drift: (Math.random() - 0.5) * 160,
|
||||||
|
})
|
||||||
|
// Keep the DOM small; drop the oldest once we exceed a cap.
|
||||||
|
if (confetti.value.length > 60) confetti.value.splice(0, 10)
|
||||||
|
}
|
||||||
|
|
||||||
|
const forced = computed(() => themeStore.getFeatureFlag('force_anniversary_celebration'))
|
||||||
|
|
||||||
|
function startCelebration(): void {
|
||||||
|
if (spawnTimer !== undefined) return
|
||||||
|
years.value = anniversaryYear()
|
||||||
|
visible.value = true
|
||||||
|
// Seed a few so the screen is not empty on the first frame.
|
||||||
|
for (let i = 0; i < 12; i++) spawnConfetti()
|
||||||
|
spawnTimer = window.setInterval(spawnConfetti, 700)
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopCelebration(): void {
|
||||||
|
if (spawnTimer !== undefined) {
|
||||||
|
window.clearInterval(spawnTimer)
|
||||||
|
spawnTimer = undefined
|
||||||
|
}
|
||||||
|
confetti.value = []
|
||||||
|
visible.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => shouldCelebrate(forced.value),
|
||||||
|
(active) => (active ? startCelebration() : stopCelebration()),
|
||||||
|
{ immediate: true },
|
||||||
|
)
|
||||||
|
|
||||||
|
onUnmounted(stopCelebration)
|
||||||
|
|
||||||
|
const bannerText = computed(() =>
|
||||||
|
formatMessage(messages.banner, { ordinal: ordinal(years.value) }),
|
||||||
|
)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Transition name="anniversary-fade">
|
||||||
|
<div v-if="visible" class="anniversary-root" aria-live="polite">
|
||||||
|
<!-- Falling confetti layer (click-through). -->
|
||||||
|
<div class="anniversary-confetti" aria-hidden="true">
|
||||||
|
<span
|
||||||
|
v-for="piece in confetti"
|
||||||
|
:key="piece.id"
|
||||||
|
class="anniversary-piece"
|
||||||
|
:style="{
|
||||||
|
left: piece.left + '%',
|
||||||
|
fontSize: piece.size + 'rem',
|
||||||
|
animationDelay: piece.delay + 's',
|
||||||
|
animationDuration: piece.duration + 's',
|
||||||
|
'--drift': piece.drift + 'px',
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
{{ piece.emoji }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Top banner. -->
|
||||||
|
<div class="anniversary-banner">
|
||||||
|
<span class="anniversary-banner-emoji">🎂</span>
|
||||||
|
<span class="anniversary-banner-text">{{ bannerText }}</span>
|
||||||
|
<span class="anniversary-banner-emoji">🎉</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Transition>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.anniversary-root {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
/* Above content, below modals/drag overlays (which use z-[200]). */
|
||||||
|
z-index: 150;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.anniversary-confetti {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.anniversary-piece {
|
||||||
|
position: absolute;
|
||||||
|
top: -3rem;
|
||||||
|
will-change: transform;
|
||||||
|
animation-name: anniversary-fall;
|
||||||
|
animation-timing-function: linear;
|
||||||
|
animation-iteration-count: 1;
|
||||||
|
animation-fill-mode: forwards;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes anniversary-fall {
|
||||||
|
0% {
|
||||||
|
transform: translate3d(0, 0, 0) rotate(0deg);
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
10% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: translate3d(var(--drift, 0), 110vh, 0) rotate(360deg);
|
||||||
|
opacity: 0.85;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.anniversary-banner {
|
||||||
|
position: absolute;
|
||||||
|
/* 避开原生窗口标题栏(Windows/macOS 系统装饰条会盖住 top:0 的内容);
|
||||||
|
titlebar-area-height 是 Tauri 暴露的标题栏高度变量,不支持时降级为 0 */
|
||||||
|
top: env(titlebar-area-height, 0px);
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
padding: 0.4rem 1rem;
|
||||||
|
font-weight: 700;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
letter-spacing: 0.02em;
|
||||||
|
color: #fff;
|
||||||
|
/* 半透明深色兜底:即使下面的渐变背景失效,白字也不会在浅色页面上隐形 */
|
||||||
|
background-color: rgba(20, 16, 28, 0.35);
|
||||||
|
/* 半透明彩色渐变:让窗口下方的内容能透出来 */
|
||||||
|
background-image: linear-gradient(
|
||||||
|
90deg,
|
||||||
|
rgba(244, 114, 182, 0.8),
|
||||||
|
rgba(250, 204, 21, 0.8),
|
||||||
|
rgba(74, 222, 128, 0.8),
|
||||||
|
rgba(56, 189, 248, 0.8),
|
||||||
|
rgba(167, 139, 250, 0.8),
|
||||||
|
rgba(244, 114, 182, 0.8)
|
||||||
|
);
|
||||||
|
background-size: 300% 100%;
|
||||||
|
animation: anniversary-gradient 8s linear infinite;
|
||||||
|
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
|
||||||
|
text-shadow:
|
||||||
|
0 1px 2px rgba(0, 0, 0, 0.55),
|
||||||
|
0 0 4px rgba(0, 0, 0, 0.35);
|
||||||
|
}
|
||||||
|
|
||||||
|
.anniversary-banner-text {
|
||||||
|
animation: anniversary-pulse 1.8s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
.anniversary-banner-emoji {
|
||||||
|
animation: anniversary-bounce 1.4s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes anniversary-gradient {
|
||||||
|
0% {
|
||||||
|
background-position: 0% 50%;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
background-position: 300% 50%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes anniversary-pulse {
|
||||||
|
0%,
|
||||||
|
100% {
|
||||||
|
transform: scale(1);
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
transform: scale(1.06);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes anniversary-bounce {
|
||||||
|
0%,
|
||||||
|
100% {
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
transform: translateY(-3px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.anniversary-fade-enter-active,
|
||||||
|
.anniversary-fade-leave-active {
|
||||||
|
transition: opacity 0.6s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.anniversary-fade-enter-from,
|
||||||
|
.anniversary-fade-leave-to {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
.anniversary-piece,
|
||||||
|
.anniversary-banner,
|
||||||
|
.anniversary-banner-text,
|
||||||
|
.anniversary-banner-emoji {
|
||||||
|
animation: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -67,6 +67,23 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
|
<ButtonStyled
|
||||||
|
v-tooltip="formatMessage(messages.announcements)"
|
||||||
|
type="transparent"
|
||||||
|
circular
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
:aria-label="formatMessage(messages.announcements)"
|
||||||
|
class="relative"
|
||||||
|
@click="openAnnouncementCenter"
|
||||||
|
>
|
||||||
|
<NewspaperIcon />
|
||||||
|
<span
|
||||||
|
v-if="announcementUnreadCount"
|
||||||
|
class="absolute right-0 top-0 size-2 rounded-full bg-red ring-2 ring-bg-raised"
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
</ButtonStyled>
|
||||||
<ButtonStyled
|
<ButtonStyled
|
||||||
v-if="!isDownloadsPage && hasActiveDownloads && !hasVisibleActiveDownloadToasts"
|
v-if="!isDownloadsPage && hasActiveDownloads && !hasVisibleActiveDownloadToasts"
|
||||||
color="brand"
|
color="brand"
|
||||||
@@ -190,6 +207,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {
|
import {
|
||||||
BellIcon,
|
BellIcon,
|
||||||
|
NewspaperIcon,
|
||||||
DownloadIcon,
|
DownloadIcon,
|
||||||
DropdownIcon,
|
DropdownIcon,
|
||||||
OnlineIndicatorIcon,
|
OnlineIndicatorIcon,
|
||||||
@@ -211,7 +229,7 @@ import {
|
|||||||
} from '@modrinth/ui'
|
} from '@modrinth/ui'
|
||||||
import { convertFileSrc } from '@tauri-apps/api/core'
|
import { convertFileSrc } from '@tauri-apps/api/core'
|
||||||
import { Dropdown } from 'floating-vue'
|
import { Dropdown } from 'floating-vue'
|
||||||
import { computed, onBeforeUnmount, ref, watch } from 'vue'
|
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||||
import { useRoute, useRouter } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
|
|
||||||
import AppUpdateButton from '@/components/ui/app-update-button/index.vue'
|
import AppUpdateButton from '@/components/ui/app-update-button/index.vue'
|
||||||
@@ -222,6 +240,10 @@ import { get_many as getInstances } from '@/helpers/instance'
|
|||||||
import { get_all as getRunningProcesses, kill as killProcess } from '@/helpers/process'
|
import { get_all as getRunningProcesses, kill as killProcess } from '@/helpers/process'
|
||||||
import type { LoadingBar } from '@/helpers/state'
|
import type { LoadingBar } from '@/helpers/state'
|
||||||
import { progress_bars_list } from '@/helpers/state'
|
import { progress_bars_list } from '@/helpers/state'
|
||||||
|
import {
|
||||||
|
OPEN_REMOTE_ANNOUNCEMENT_CENTER_EVENT,
|
||||||
|
REMOTE_ANNOUNCEMENTS_UPDATED_EVENT,
|
||||||
|
} from '@/helpers/remote-announcements'
|
||||||
import type { GameInstance } from '@/helpers/types'
|
import type { GameInstance } from '@/helpers/types'
|
||||||
import { downloadBarTypes, injectDownloadManager } from '@/providers/download-manager'
|
import { downloadBarTypes, injectDownloadManager } from '@/providers/download-manager'
|
||||||
|
|
||||||
@@ -231,6 +253,25 @@ const popupNotificationManager = injectPopupNotificationManager()
|
|||||||
const downloadManager = injectDownloadManager()
|
const downloadManager = injectDownloadManager()
|
||||||
const { formatMessage } = useVIntl()
|
const { formatMessage } = useVIntl()
|
||||||
|
|
||||||
|
const announcementUnreadCount = ref(0)
|
||||||
|
|
||||||
|
function openAnnouncementCenter() {
|
||||||
|
window.dispatchEvent(new CustomEvent(OPEN_REMOTE_ANNOUNCEMENT_CENTER_EVENT))
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateAnnouncementCount(event: Event) {
|
||||||
|
const detail = (event as CustomEvent<{ unreadKeys?: string[] }>).detail
|
||||||
|
announcementUnreadCount.value = detail?.unreadKeys?.length ?? 0
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
window.addEventListener(REMOTE_ANNOUNCEMENTS_UPDATED_EVENT, updateAnnouncementCount)
|
||||||
|
})
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
window.removeEventListener(REMOTE_ANNOUNCEMENTS_UPDATED_EVENT, updateAnnouncementCount)
|
||||||
|
})
|
||||||
|
|
||||||
type NotificationHistoryItem = {
|
type NotificationHistoryItem = {
|
||||||
key: string
|
key: string
|
||||||
createdAt?: number
|
createdAt?: number
|
||||||
@@ -370,6 +411,10 @@ const messages = defineMessages({
|
|||||||
id: 'app.action-bar.notifications',
|
id: 'app.action-bar.notifications',
|
||||||
defaultMessage: 'Notifications',
|
defaultMessage: 'Notifications',
|
||||||
},
|
},
|
||||||
|
announcements: {
|
||||||
|
id: 'app.action-bar.announcements',
|
||||||
|
defaultMessage: 'Announcements',
|
||||||
|
},
|
||||||
clearNotifications: {
|
clearNotifications: {
|
||||||
id: 'app.action-bar.notifications.clear',
|
id: 'app.action-bar.notifications.clear',
|
||||||
defaultMessage: 'Clear all',
|
defaultMessage: 'Clear all',
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,425 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
commonMessages,
|
||||||
|
defineMessages,
|
||||||
|
NewModal,
|
||||||
|
useModalStack,
|
||||||
|
useVIntl,
|
||||||
|
} from '@modrinth/ui'
|
||||||
|
import { renderString } from '@modrinth/utils'
|
||||||
|
import { fetch as tauriFetch } from '@tauri-apps/plugin-http'
|
||||||
|
import { openUrl } from '@tauri-apps/plugin-opener'
|
||||||
|
import { computed, nextTick, onMounted, onUnmounted, reactive, ref, watch } from 'vue'
|
||||||
|
|
||||||
|
import {
|
||||||
|
announcementKey,
|
||||||
|
isAnnouncementActive,
|
||||||
|
mapBroadcastAnnouncements,
|
||||||
|
OPEN_REMOTE_ANNOUNCEMENT_CENTER_EVENT,
|
||||||
|
parseAnnouncements,
|
||||||
|
REMOTE_ANNOUNCEMENTS_UPDATED_EVENT,
|
||||||
|
type RemoteAnnouncement,
|
||||||
|
safeAnnouncementUrl,
|
||||||
|
} from '@/helpers/remote-announcements'
|
||||||
|
|
||||||
|
import {
|
||||||
|
requestSkinSiteDownloadToken,
|
||||||
|
skinSiteStatus,
|
||||||
|
waitForSkinSiteSession,
|
||||||
|
} from '@/composables/skin-site-session.ts'
|
||||||
|
|
||||||
|
const props = defineProps<{ ready: boolean; previewOnly?: boolean }>()
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { hasModal } = useModalStack()
|
||||||
|
const messages = defineMessages({
|
||||||
|
view: { id: 'app.remote-announcements.view', defaultMessage: 'View announcement' },
|
||||||
|
unread: { id: 'app.remote-announcements.unread', defaultMessage: 'Unread' },
|
||||||
|
readAll: {
|
||||||
|
id: 'app.remote-announcements.read-all',
|
||||||
|
defaultMessage: 'Mark all announcements as read',
|
||||||
|
},
|
||||||
|
centerTitle: { id: 'app.remote-announcements.center-title', defaultMessage: 'Announcements' },
|
||||||
|
empty: { id: 'app.remote-announcements.empty', defaultMessage: 'No announcements' },
|
||||||
|
previewTitle: {
|
||||||
|
id: 'app.remote-announcements.preview-title',
|
||||||
|
defaultMessage: 'Announcement style preview',
|
||||||
|
},
|
||||||
|
previewSummary: {
|
||||||
|
id: 'app.remote-announcements.preview-summary',
|
||||||
|
defaultMessage:
|
||||||
|
'This is a local preview. Select View announcement to preview the full Markdown content.',
|
||||||
|
},
|
||||||
|
previewContent: {
|
||||||
|
id: 'app.remote-announcements.preview-content',
|
||||||
|
defaultMessage:
|
||||||
|
'## Announcement preview\n\nThis is **sample content**, not a published announcement.\n\n- Supports headings, lists, and links\n- Close buttons are always available\n\n> Previewing does not change real announcement read status.\n\n| Type | Display |\n| --- | --- |\n| Modal | Full Markdown content |\n| Popup | Summary, then full content |\n\n[Visit the website](https://skin.starlight.cool/)',
|
||||||
|
},
|
||||||
|
previewAction: { id: 'app.remote-announcements.preview-action', defaultMessage: 'Visit website' },
|
||||||
|
})
|
||||||
|
const modal = ref<InstanceType<typeof NewModal>>()
|
||||||
|
const selected = ref<RemoteAnnouncement | null>(null)
|
||||||
|
const active = ref(false)
|
||||||
|
const centerOpen = ref(false)
|
||||||
|
const startupNotice = ref<RemoteAnnouncement | null>(null)
|
||||||
|
const html = computed(() => renderString(selected.value?.content ?? ''))
|
||||||
|
const stateKey = 'starlight-remote-announcements-v2'
|
||||||
|
const read = reactive(new Set<string>())
|
||||||
|
const queuedThisSession = new Set<string>()
|
||||||
|
const startupNotified = new Set<string>()
|
||||||
|
let items: RemoteAnnouncement[] = []
|
||||||
|
let pending: RemoteAnnouncement[] = []
|
||||||
|
let cacheKey = 'starlight-remote-announcements-cache-v1'
|
||||||
|
let cacheLoaded = false
|
||||||
|
let disposed = false
|
||||||
|
let interval: ReturnType<typeof setInterval> | undefined
|
||||||
|
let advanceTimer: ReturnType<typeof setTimeout> | undefined
|
||||||
|
|
||||||
|
function persist() {
|
||||||
|
if (props.previewOnly) return
|
||||||
|
try {
|
||||||
|
localStorage.setItem(
|
||||||
|
stateKey,
|
||||||
|
JSON.stringify({
|
||||||
|
read: [...read].slice(-1000),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
} catch {
|
||||||
|
// localStorage may be unavailable (private mode / quota)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function emitState() {
|
||||||
|
window.dispatchEvent(
|
||||||
|
new CustomEvent(REMOTE_ANNOUNCEMENTS_UPDATED_EVENT, {
|
||||||
|
detail: {
|
||||||
|
items,
|
||||||
|
unreadKeys: items.filter((item) => !read.has(announcementKey(item))).map(announcementKey),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
function openCenter(item?: RemoteAnnouncement) {
|
||||||
|
if (!props.ready || disposed) return
|
||||||
|
void refresh()
|
||||||
|
centerOpen.value = true
|
||||||
|
if (item) {
|
||||||
|
startupNotice.value = null
|
||||||
|
selectAnnouncement(item)
|
||||||
|
} else if (!selected.value && items.length) {
|
||||||
|
selectAnnouncement(items[0])
|
||||||
|
}
|
||||||
|
void nextTick(() => modal.value?.show())
|
||||||
|
}
|
||||||
|
function handleOpenCenter() {
|
||||||
|
if (props.previewOnly) return
|
||||||
|
openCenter()
|
||||||
|
}
|
||||||
|
async function show(item: RemoteAnnouncement) {
|
||||||
|
if (
|
||||||
|
disposed ||
|
||||||
|
!props.ready ||
|
||||||
|
!isAnnouncementActive(item) ||
|
||||||
|
(hasModal.value && !active.value && !centerOpen.value)
|
||||||
|
)
|
||||||
|
return
|
||||||
|
centerOpen.value = true
|
||||||
|
active.value = true
|
||||||
|
selectAnnouncement(item)
|
||||||
|
await nextTick()
|
||||||
|
if (!disposed) modal.value?.show()
|
||||||
|
}
|
||||||
|
function selectAnnouncement(item: RemoteAnnouncement) {
|
||||||
|
selected.value = item
|
||||||
|
const key = announcementKey(item)
|
||||||
|
read.add(key)
|
||||||
|
pending = pending.filter((entry) => announcementKey(entry) !== key)
|
||||||
|
persist()
|
||||||
|
emitState()
|
||||||
|
}
|
||||||
|
function markAllRead() {
|
||||||
|
for (const item of items) {
|
||||||
|
read.add(announcementKey(item))
|
||||||
|
}
|
||||||
|
pending = []
|
||||||
|
persist()
|
||||||
|
emitState()
|
||||||
|
}
|
||||||
|
function advance() {
|
||||||
|
if (disposed || !props.ready || hasModal.value || active.value) return
|
||||||
|
const next = pending.shift()
|
||||||
|
if (next) {
|
||||||
|
void show(next)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for (const item of items) {
|
||||||
|
const key = announcementKey(item)
|
||||||
|
if (
|
||||||
|
item.type === 'notification' &&
|
||||||
|
!startupNotified.has(key) &&
|
||||||
|
!read.has(key) &&
|
||||||
|
isAnnouncementActive(item)
|
||||||
|
) {
|
||||||
|
startupNotice.value = item
|
||||||
|
startupNotified.add(key)
|
||||||
|
setTimeout(() => {
|
||||||
|
if (startupNotice.value === item) {
|
||||||
|
startupNotice.value = null
|
||||||
|
advance()
|
||||||
|
}
|
||||||
|
}, 8000)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function closed() {
|
||||||
|
active.value = false
|
||||||
|
centerOpen.value = false
|
||||||
|
if (advanceTimer) clearTimeout(advanceTimer)
|
||||||
|
advanceTimer = setTimeout(advance, 350)
|
||||||
|
}
|
||||||
|
function sync(next: RemoteAnnouncement[], fresh: boolean) {
|
||||||
|
items = next.filter((item) => isAnnouncementActive(item))
|
||||||
|
const keys = new Set(items.map(announcementKey))
|
||||||
|
pending = pending.filter((item) => keys.has(announcementKey(item)))
|
||||||
|
if (selected.value && !keys.has(announcementKey(selected.value))) selected.value = null
|
||||||
|
emitState()
|
||||||
|
if (fresh) {
|
||||||
|
for (const item of items) {
|
||||||
|
const key = announcementKey(item)
|
||||||
|
if (
|
||||||
|
item.type === 'modal' &&
|
||||||
|
!queuedThisSession.has(key) &&
|
||||||
|
(!read.has(key) || item.priority === 'critical')
|
||||||
|
) {
|
||||||
|
queuedThisSession.add(key)
|
||||||
|
pending.push(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
advance()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function loadCache() {
|
||||||
|
if (cacheLoaded || !cacheKey) return
|
||||||
|
cacheLoaded = true
|
||||||
|
try {
|
||||||
|
const cached = JSON.parse(localStorage.getItem(cacheKey) ?? 'null')
|
||||||
|
if (cached && typeof cached.savedAt === 'number' && Date.now() - cached.savedAt < 86400000) {
|
||||||
|
const parsed = parseAnnouncements(cached.items)
|
||||||
|
if (parsed) sync(parsed, false)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Ignore malformed or expired cache payloads
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function saveCache(next: RemoteAnnouncement[]) {
|
||||||
|
if (!cacheKey) return
|
||||||
|
try {
|
||||||
|
localStorage.setItem(cacheKey, JSON.stringify({ savedAt: Date.now(), items: next }))
|
||||||
|
} catch {
|
||||||
|
// localStorage may be unavailable (private mode / quota)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function refresh() {
|
||||||
|
if (disposed) return
|
||||||
|
loadCache()
|
||||||
|
if (skinSiteStatus.value !== 'signed-in') return
|
||||||
|
try {
|
||||||
|
await waitForSkinSiteSession()
|
||||||
|
const token = await requestSkinSiteDownloadToken()
|
||||||
|
const response = await tauriFetch('https://skin.starlight.cool/starlight/skin/broadcast/all', {
|
||||||
|
method: 'GET',
|
||||||
|
headers: { Authorization: `Bearer ${token}` },
|
||||||
|
})
|
||||||
|
if (!response.ok) return
|
||||||
|
const data = await response.json()
|
||||||
|
const parsed = mapBroadcastAnnouncements((data as { payload?: unknown } | null)?.payload)
|
||||||
|
if (parsed && !disposed) {
|
||||||
|
sync(parsed, true)
|
||||||
|
saveCache(parsed)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Remote fetch failed; previously cached items remain displayed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function openLink(value: unknown) {
|
||||||
|
const url = safeAnnouncementUrl(value)
|
||||||
|
if (!url) return
|
||||||
|
try {
|
||||||
|
await openUrl(url)
|
||||||
|
} catch {
|
||||||
|
// Opener may reject unknown schemes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function contentClick(event: MouseEvent) {
|
||||||
|
const link = event.target instanceof Element ? event.target.closest('a') : null
|
||||||
|
if (!link) return
|
||||||
|
event.preventDefault()
|
||||||
|
event.stopPropagation()
|
||||||
|
void openLink(link.getAttribute('href'))
|
||||||
|
}
|
||||||
|
function preview(type: RemoteAnnouncement['type'], withAction = false) {
|
||||||
|
if (!props.previewOnly || !props.ready || hasModal.value || disposed) return
|
||||||
|
const now = new Date().toISOString()
|
||||||
|
const item: RemoteAnnouncement = {
|
||||||
|
id: 'local-preview-' + type,
|
||||||
|
title: formatMessage(messages.previewTitle),
|
||||||
|
summary: formatMessage(messages.previewSummary),
|
||||||
|
content: formatMessage(messages.previewContent),
|
||||||
|
type,
|
||||||
|
priority: 'normal',
|
||||||
|
starts_at: now,
|
||||||
|
ends_at: null,
|
||||||
|
published_at: now,
|
||||||
|
action_label: withAction ? formatMessage(messages.previewAction) : null,
|
||||||
|
action_url: withAction ? 'https://skin.starlight.cool/' : null,
|
||||||
|
}
|
||||||
|
read.clear()
|
||||||
|
queuedThisSession.clear()
|
||||||
|
sync([item], true)
|
||||||
|
}
|
||||||
|
defineExpose({ preview })
|
||||||
|
onMounted(() => {
|
||||||
|
if (props.previewOnly) return
|
||||||
|
try {
|
||||||
|
const saved = JSON.parse(localStorage.getItem(stateKey) ?? 'null')
|
||||||
|
if (saved && Array.isArray(saved.read))
|
||||||
|
for (const key of saved.read) if (typeof key === 'string') read.add(key)
|
||||||
|
} catch {
|
||||||
|
// Ignore malformed local read-state
|
||||||
|
}
|
||||||
|
window.addEventListener(OPEN_REMOTE_ANNOUNCEMENT_CENTER_EVENT, handleOpenCenter)
|
||||||
|
const start = () => {
|
||||||
|
if (disposed) return
|
||||||
|
void refresh()
|
||||||
|
interval = setInterval(() => {
|
||||||
|
sync(items, false)
|
||||||
|
advance()
|
||||||
|
}, 15000)
|
||||||
|
}
|
||||||
|
// Defer the startup request until after first paint.
|
||||||
|
if (typeof requestIdleCallback === 'function') {
|
||||||
|
requestIdleCallback(start, { timeout: 2000 })
|
||||||
|
} else {
|
||||||
|
setTimeout(start, 500)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
watch(skinSiteStatus, (status) => {
|
||||||
|
if (disposed || props.previewOnly) return
|
||||||
|
if (status === 'signed-in') void refresh()
|
||||||
|
})
|
||||||
|
watch([() => props.ready, hasModal], () => {
|
||||||
|
if (advanceTimer) clearTimeout(advanceTimer)
|
||||||
|
advanceTimer = setTimeout(advance, 350)
|
||||||
|
})
|
||||||
|
onUnmounted(() => {
|
||||||
|
disposed = true
|
||||||
|
if (interval) clearInterval(interval)
|
||||||
|
if (advanceTimer) clearTimeout(advanceTimer)
|
||||||
|
window.removeEventListener(OPEN_REMOTE_ANNOUNCEMENT_CENTER_EVENT, handleOpenCenter)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div
|
||||||
|
v-if="startupNotice"
|
||||||
|
class="fixed right-4 top-16 z-50 w-[22rem] max-w-[calc(100vw-2rem)] rounded-xl border border-surface-5 bg-surface-3 p-3 shadow-lg"
|
||||||
|
>
|
||||||
|
<button class="w-full text-left" @click="startupNotice && openCenter(startupNotice)">
|
||||||
|
<div class="mb-1 text-xs font-semibold uppercase text-brand">
|
||||||
|
{{ formatMessage(messages.unread) }}
|
||||||
|
</div>
|
||||||
|
<div class="font-semibold text-[var(--color-text-primary)]">{{ startupNotice.title }}</div>
|
||||||
|
<div
|
||||||
|
v-if="startupNotice.summary"
|
||||||
|
class="mt-1 line-clamp-2 text-sm text-[var(--color-text-tertiary)]"
|
||||||
|
>
|
||||||
|
{{ startupNotice.summary }}
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<NewModal
|
||||||
|
ref="modal"
|
||||||
|
:header="formatMessage(messages.centerTitle)"
|
||||||
|
:on-hide="closed"
|
||||||
|
max-width="80vw"
|
||||||
|
width="80vw"
|
||||||
|
max-content-height="calc(80vh - 8rem)"
|
||||||
|
scrollable
|
||||||
|
>
|
||||||
|
<div class="flex h-[calc(80vh-8rem)] min-h-0 gap-3">
|
||||||
|
<aside class="flex min-h-0 w-[32%] min-w-[14rem] flex-col border-r border-surface-5 pr-3">
|
||||||
|
<div class="mb-2 flex items-center justify-between">
|
||||||
|
<span class="font-semibold text-[var(--color-text-primary)]">{{
|
||||||
|
formatMessage(messages.centerTitle)
|
||||||
|
}}</span>
|
||||||
|
<Button
|
||||||
|
v-if="items.some((item) => !read.has(announcementKey(item)))"
|
||||||
|
@click="markAllRead"
|
||||||
|
>{{ formatMessage(messages.readAll) }}</Button
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-if="!items.length"
|
||||||
|
class="py-8 text-center text-sm text-[var(--color-text-tertiary)]"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.empty) }}
|
||||||
|
</div>
|
||||||
|
<div v-else class="flex min-h-0 flex-col gap-1 overflow-auto">
|
||||||
|
<button
|
||||||
|
v-for="item in items"
|
||||||
|
:key="announcementKey(item)"
|
||||||
|
class="flex items-start gap-2 rounded-lg p-2 text-left hover:bg-surface-4"
|
||||||
|
:class="{
|
||||||
|
'bg-surface-4': selected && announcementKey(selected) === announcementKey(item),
|
||||||
|
}"
|
||||||
|
@click="selectAnnouncement(item)"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
class="mt-1.5 size-2 shrink-0 rounded-full"
|
||||||
|
:class="read.has(announcementKey(item)) ? 'opacity-0' : 'bg-red'"
|
||||||
|
/>
|
||||||
|
<span class="min-w-0 flex-1">
|
||||||
|
<span class="block truncate font-medium text-[var(--color-text-primary)]">{{
|
||||||
|
item.title
|
||||||
|
}}</span>
|
||||||
|
<span class="block line-clamp-2 text-xs text-[var(--color-text-tertiary)]">{{
|
||||||
|
item.summary || item.content
|
||||||
|
}}</span>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
<section v-if="selected" class="min-h-0 min-w-0 flex-1 overflow-auto px-1">
|
||||||
|
<h2 class="mb-4 text-xl font-semibold text-[var(--color-text-primary)]">
|
||||||
|
{{ selected.title }}
|
||||||
|
</h2>
|
||||||
|
<div
|
||||||
|
class="markdown-body break-words"
|
||||||
|
@click="contentClick"
|
||||||
|
@auxclick="contentClick"
|
||||||
|
v-html="html"
|
||||||
|
/>
|
||||||
|
<div class="mt-4 flex justify-end">
|
||||||
|
<Button
|
||||||
|
v-if="selected.action_url && selected.action_label"
|
||||||
|
type="colored"
|
||||||
|
color="brand"
|
||||||
|
@click="openLink(selected.action_url)"
|
||||||
|
>{{ selected.action_label }}</Button
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<div
|
||||||
|
v-else
|
||||||
|
class="flex flex-1 items-center justify-center text-sm text-[var(--color-text-tertiary)]"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.empty) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<template #actions>
|
||||||
|
<div class="flex flex-wrap justify-end gap-2">
|
||||||
|
<Button @click="modal?.hide()">{{ formatMessage(commonMessages.closeButton) }} </Button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</NewModal>
|
||||||
|
</template>
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { defineMessages, useVIntl } from '@modrinth/ui'
|
|
||||||
|
|
||||||
import { skinSiteFrameUrl } from '@/composables/skin-site-session'
|
|
||||||
|
|
||||||
const { formatMessage } = useVIntl()
|
|
||||||
const messages = defineMessages({
|
|
||||||
frameTitle: {
|
|
||||||
id: 'app.starlight-skin.frame-title',
|
|
||||||
defaultMessage: 'StarLight Skin Site',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<iframe
|
|
||||||
:src="skinSiteFrameUrl"
|
|
||||||
:title="formatMessage(messages.frameTitle)"
|
|
||||||
class="block h-full min-h-0 w-full border-0"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { onMounted, onUnmounted, ref, watch } from 'vue'
|
|
||||||
|
|
||||||
import {
|
|
||||||
receiveSkinSiteMessage,
|
|
||||||
resetSkinSiteSession,
|
|
||||||
setSkinSiteFrame,
|
|
||||||
SKIN_SITE_ORIGIN,
|
|
||||||
skinSiteStatus,
|
|
||||||
skinSiteUser,
|
|
||||||
} from '@/composables/skin-site-session'
|
|
||||||
import { clearHostedSession } from '@/helpers/hosted-packs'
|
|
||||||
|
|
||||||
const frame = ref<HTMLIFrameElement>()
|
|
||||||
let lastMessage = 0
|
|
||||||
let expiryTimer: ReturnType<typeof setInterval> | undefined
|
|
||||||
|
|
||||||
watch(
|
|
||||||
[skinSiteStatus, () => skinSiteUser.value?.uuid],
|
|
||||||
() => {
|
|
||||||
void clearHostedSession().catch(() => {})
|
|
||||||
},
|
|
||||||
{ flush: 'sync' },
|
|
||||||
)
|
|
||||||
|
|
||||||
function connect() {
|
|
||||||
resetSkinSiteSession()
|
|
||||||
lastMessage = 0
|
|
||||||
const contentWindow = frame.value?.contentWindow ?? null
|
|
||||||
setSkinSiteFrame(contentWindow)
|
|
||||||
contentWindow?.postMessage({ type: 'starlight-skin-session-connect' }, SKIN_SITE_ORIGIN)
|
|
||||||
}
|
|
||||||
|
|
||||||
function receive(event: MessageEvent) {
|
|
||||||
if (receiveSkinSiteMessage(event, frame.value?.contentWindow ?? null)) lastMessage = Date.now()
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
window.addEventListener('message', receive)
|
|
||||||
connect()
|
|
||||||
expiryTimer = setInterval(() => {
|
|
||||||
if (lastMessage && Date.now() - lastMessage > 90_000) resetSkinSiteSession()
|
|
||||||
}, 10_000)
|
|
||||||
})
|
|
||||||
|
|
||||||
onUnmounted(() => {
|
|
||||||
window.removeEventListener('message', receive)
|
|
||||||
clearInterval(expiryTimer)
|
|
||||||
setSkinSiteFrame(null)
|
|
||||||
resetSkinSiteSession()
|
|
||||||
void clearHostedSession().catch(() => {})
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<iframe
|
|
||||||
ref="frame"
|
|
||||||
:src="`${SKIN_SITE_ORIGIN}/`"
|
|
||||||
title="StarLight Skin Site session"
|
|
||||||
aria-hidden="true"
|
|
||||||
tabindex="-1"
|
|
||||||
class="pointer-events-none fixed -left-[10000px] top-0 h-px w-px opacity-0"
|
|
||||||
@load="connect"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { FileIcon, FolderIcon, MinusIcon, PlusIcon } from '@modrinth/assets'
|
||||||
|
import { Button, defineMessages, injectNotificationManager, useVIntl } from '@modrinth/ui'
|
||||||
|
import { open } from '@tauri-apps/plugin-dialog'
|
||||||
|
import { ref } from 'vue'
|
||||||
|
|
||||||
|
import {
|
||||||
|
type BackupExclusion,
|
||||||
|
type BackupExclusionKind,
|
||||||
|
canonicalizeBackupExclusions,
|
||||||
|
formatBackupExclusionPath,
|
||||||
|
normalizeBackupExclusion,
|
||||||
|
} from '@/helpers/instance-backup'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
instanceId: string
|
||||||
|
instanceRoot: string
|
||||||
|
modelValue: BackupExclusion[]
|
||||||
|
disabled?: boolean
|
||||||
|
}>()
|
||||||
|
const emit = defineEmits<{ 'update:modelValue': [value: BackupExclusion[]] }>()
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError } = injectNotificationManager()
|
||||||
|
const picking = ref<BackupExclusionKind | null>(null)
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
empty: {
|
||||||
|
id: 'instance.backups.exclusions.empty',
|
||||||
|
defaultMessage: 'No files or folders are excluded.',
|
||||||
|
},
|
||||||
|
addFile: {
|
||||||
|
id: 'instance.backups.exclusions.add-file',
|
||||||
|
defaultMessage: 'Add excluded file',
|
||||||
|
},
|
||||||
|
addFolder: {
|
||||||
|
id: 'instance.backups.exclusions.add-folder',
|
||||||
|
defaultMessage: 'Add excluded folder',
|
||||||
|
},
|
||||||
|
remove: {
|
||||||
|
id: 'instance.backups.exclusions.remove',
|
||||||
|
defaultMessage: 'Remove {path} from exclusions',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
function pickedPath(result: unknown): string | null {
|
||||||
|
if (typeof result === 'string') return result
|
||||||
|
if (result && typeof result === 'object' && 'path' in result) {
|
||||||
|
const path = (result as { path?: unknown }).path
|
||||||
|
return typeof path === 'string' ? path : null
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
async function addExclusion(kind: BackupExclusionKind) {
|
||||||
|
if (props.disabled || picking.value) return
|
||||||
|
picking.value = kind
|
||||||
|
try {
|
||||||
|
const result = await open({
|
||||||
|
directory: kind === 'directory',
|
||||||
|
multiple: false,
|
||||||
|
defaultPath: props.instanceRoot,
|
||||||
|
})
|
||||||
|
const selectedPath = pickedPath(result)
|
||||||
|
if (!selectedPath) return
|
||||||
|
const exclusion = await normalizeBackupExclusion(props.instanceId, selectedPath, kind)
|
||||||
|
emit('update:modelValue', canonicalizeBackupExclusions([...props.modelValue, exclusion]))
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
picking.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeExclusion(path: string) {
|
||||||
|
emit(
|
||||||
|
'update:modelValue',
|
||||||
|
props.modelValue.filter((exclusion) => exclusion.path !== path),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-3">
|
||||||
|
<p v-if="modelValue.length === 0" class="m-0 text-sm text-[var(--color-text-tertiary)]">
|
||||||
|
{{ formatMessage(messages.empty) }}
|
||||||
|
</p>
|
||||||
|
<div
|
||||||
|
v-else
|
||||||
|
class="divide-y divide-solid divide-surface-4 rounded-lg border border-solid border-surface-4"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-for="exclusion in modelValue"
|
||||||
|
:key="exclusion.path"
|
||||||
|
class="flex min-h-11 items-center gap-3 px-3 py-2"
|
||||||
|
>
|
||||||
|
<FolderIcon
|
||||||
|
v-if="exclusion.kind === 'directory'"
|
||||||
|
class="size-5 shrink-0 text-[var(--color-text-tertiary)]"
|
||||||
|
/>
|
||||||
|
<FileIcon v-else class="size-5 shrink-0 text-[var(--color-text-tertiary)]" />
|
||||||
|
<code class="min-w-0 flex-1 truncate text-sm text-[var(--color-text-primary)]">{{
|
||||||
|
formatBackupExclusionPath(exclusion)
|
||||||
|
}}</code>
|
||||||
|
<Button
|
||||||
|
type="quiet"
|
||||||
|
size="2xs"
|
||||||
|
circular
|
||||||
|
icon-only
|
||||||
|
:disabled="disabled || picking !== null"
|
||||||
|
:aria-label="
|
||||||
|
formatMessage(messages.remove, { path: formatBackupExclusionPath(exclusion) })
|
||||||
|
"
|
||||||
|
@click="removeExclusion(exclusion.path)"
|
||||||
|
><MinusIcon />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-wrap gap-2">
|
||||||
|
<Button type="outlined" :disabled="disabled || picking !== null" @click="addExclusion('file')"
|
||||||
|
><PlusIcon />
|
||||||
|
{{ formatMessage(messages.addFile) }}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="outlined"
|
||||||
|
:disabled="disabled || picking !== null"
|
||||||
|
@click="addExclusion('directory')"
|
||||||
|
><PlusIcon />
|
||||||
|
{{ formatMessage(messages.addFolder) }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,675 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { FileArchiveIcon, SaveIcon, TrashIcon, UndoIcon, XIcon } from '@modrinth/assets'
|
||||||
|
import {
|
||||||
|
Admonition,
|
||||||
|
Button,
|
||||||
|
commonMessages,
|
||||||
|
defineMessages,
|
||||||
|
injectNotificationManager,
|
||||||
|
NewModal,
|
||||||
|
useFormatBytes,
|
||||||
|
useFormatDateTime,
|
||||||
|
useVIntl,
|
||||||
|
} from '@modrinth/ui'
|
||||||
|
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
||||||
|
|
||||||
|
import { get_full_path } from '@/helpers/instance'
|
||||||
|
import {
|
||||||
|
type BackupExclusion,
|
||||||
|
type BackupOperation,
|
||||||
|
type BackupOperationState,
|
||||||
|
type BackupProgressStage,
|
||||||
|
type BackupRestorePreview,
|
||||||
|
type BackupSnapshot,
|
||||||
|
cancelBackup,
|
||||||
|
deleteBackup,
|
||||||
|
disableBackups,
|
||||||
|
enableBackups,
|
||||||
|
getBackupConfig,
|
||||||
|
type InstanceBackupConfig,
|
||||||
|
type InstanceBackupEligibility,
|
||||||
|
listBackupOperations,
|
||||||
|
listBackups,
|
||||||
|
listenBackupProgress,
|
||||||
|
restoreBackup,
|
||||||
|
startBackup,
|
||||||
|
startBackupRestorePreview,
|
||||||
|
updateBackupExclusions,
|
||||||
|
} from '@/helpers/instance-backup'
|
||||||
|
import { injectInstanceSettings } from '@/providers/instance-settings'
|
||||||
|
|
||||||
|
import BackupExclusionSelector from './BackupExclusionSelector.vue'
|
||||||
|
|
||||||
|
const { instance } = injectInstanceSettings()
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const formatBytes = useFormatBytes()
|
||||||
|
const formatDate = useFormatDateTime({ dateStyle: 'medium', timeStyle: 'short' })
|
||||||
|
const { handleError } = injectNotificationManager()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'instance.backups.title', defaultMessage: 'Instance backups' },
|
||||||
|
description: {
|
||||||
|
id: 'instance.backups.description',
|
||||||
|
defaultMessage: 'Create deduplicated snapshots of the whole instance while it is closed.',
|
||||||
|
},
|
||||||
|
loading: { id: 'instance.backups.loading', defaultMessage: 'Loading backup settings...' },
|
||||||
|
unavailable: { id: 'instance.backups.unavailable', defaultMessage: 'Backups are unavailable' },
|
||||||
|
notInstalled: {
|
||||||
|
id: 'instance.backups.unavailable.not-installed',
|
||||||
|
defaultMessage: 'Finish installing this instance before enabling backups.',
|
||||||
|
},
|
||||||
|
symlinkInstance: {
|
||||||
|
id: 'instance.backups.unavailable.symlink',
|
||||||
|
defaultMessage: 'Imported symbolic-link instances cannot be backed up.',
|
||||||
|
},
|
||||||
|
directLinked: {
|
||||||
|
id: 'instance.backups.unavailable.direct-linked',
|
||||||
|
defaultMessage: 'Instances linked directly to another launcher cannot be backed up.',
|
||||||
|
},
|
||||||
|
externalDirectory: {
|
||||||
|
id: 'instance.backups.unavailable.external-directory',
|
||||||
|
defaultMessage: 'Instances that use an external game directory cannot be backed up.',
|
||||||
|
},
|
||||||
|
rootMissing: {
|
||||||
|
id: 'instance.backups.unavailable.root-missing',
|
||||||
|
defaultMessage: 'The instance folder is missing.',
|
||||||
|
},
|
||||||
|
rootLink: {
|
||||||
|
id: 'instance.backups.unavailable.root-link',
|
||||||
|
defaultMessage: 'Instances whose root folder is a link cannot be backed up.',
|
||||||
|
},
|
||||||
|
choose: {
|
||||||
|
id: 'instance.backups.choose',
|
||||||
|
defaultMessage:
|
||||||
|
'Everything is backed up by default. Add files or folders that should be excluded.',
|
||||||
|
},
|
||||||
|
enable: { id: 'instance.backups.enable', defaultMessage: 'Enable backups' },
|
||||||
|
editExclusions: { id: 'instance.backups.edit-exclusions', defaultMessage: 'Edit exclusions' },
|
||||||
|
saveExclusions: {
|
||||||
|
id: 'instance.backups.save-exclusions',
|
||||||
|
defaultMessage: 'Save exclusions',
|
||||||
|
},
|
||||||
|
allIncluded: {
|
||||||
|
id: 'instance.backups.all-included',
|
||||||
|
defaultMessage: 'All instance files and folders are included.',
|
||||||
|
},
|
||||||
|
excludedPaths: {
|
||||||
|
id: 'instance.backups.excluded-paths',
|
||||||
|
defaultMessage: 'Excluded: {paths}',
|
||||||
|
},
|
||||||
|
backupNow: { id: 'instance.backups.backup-now', defaultMessage: 'Back up now' },
|
||||||
|
cancelBackup: { id: 'instance.backups.cancel', defaultMessage: 'Cancel backup' },
|
||||||
|
stageScanning: {
|
||||||
|
id: 'instance.backups.stage.scanning',
|
||||||
|
defaultMessage: 'Scanning files',
|
||||||
|
},
|
||||||
|
stageHashing: { id: 'instance.backups.stage.hashing', defaultMessage: 'Hashing files' },
|
||||||
|
stageSaving: { id: 'instance.backups.stage.saving', defaultMessage: 'Saving snapshot index' },
|
||||||
|
stageQueued: { id: 'instance.backups.stage.queued', defaultMessage: 'Waiting to start' },
|
||||||
|
stageValidating: {
|
||||||
|
id: 'instance.backups.stage.validating',
|
||||||
|
defaultMessage: 'Validating restore',
|
||||||
|
},
|
||||||
|
stageMaterializing: {
|
||||||
|
id: 'instance.backups.stage.materializing',
|
||||||
|
defaultMessage: 'Preparing changed files',
|
||||||
|
},
|
||||||
|
stageApplying: {
|
||||||
|
id: 'instance.backups.stage.applying',
|
||||||
|
defaultMessage: 'Applying changed files',
|
||||||
|
},
|
||||||
|
stagePreview: {
|
||||||
|
id: 'instance.backups.stage.preview',
|
||||||
|
defaultMessage: 'Analyzing restore changes',
|
||||||
|
},
|
||||||
|
progressBytes: {
|
||||||
|
id: 'instance.backups.progress-bytes',
|
||||||
|
defaultMessage: '{processed} of {total}',
|
||||||
|
},
|
||||||
|
stageFailed: { id: 'instance.backups.stage.failed', defaultMessage: 'Backup failed' },
|
||||||
|
stageInterrupted: {
|
||||||
|
id: 'instance.backups.stage.interrupted',
|
||||||
|
defaultMessage: 'Backup operation was interrupted',
|
||||||
|
},
|
||||||
|
snapshots: { id: 'instance.backups.snapshots', defaultMessage: 'Snapshots' },
|
||||||
|
empty: { id: 'instance.backups.empty', defaultMessage: 'No backups have been created yet.' },
|
||||||
|
snapshotMeta: {
|
||||||
|
id: 'instance.backups.snapshot-meta',
|
||||||
|
defaultMessage: '{files, plural, one {# file} other {# files}} · {size}',
|
||||||
|
},
|
||||||
|
addedSize: { id: 'instance.backups.added-size', defaultMessage: '{size} newly stored' },
|
||||||
|
restore: { id: 'instance.backups.restore', defaultMessage: 'Restore backup' },
|
||||||
|
delete: { id: 'instance.backups.delete', defaultMessage: 'Delete backup' },
|
||||||
|
disable: { id: 'instance.backups.disable', defaultMessage: 'Disable backups' },
|
||||||
|
disableBlocked: {
|
||||||
|
id: 'instance.backups.disable-blocked',
|
||||||
|
defaultMessage: 'Delete every snapshot before disabling backups.',
|
||||||
|
},
|
||||||
|
restoreTitle: { id: 'instance.backups.restore-title', defaultMessage: 'Restore this backup?' },
|
||||||
|
restoreBody: {
|
||||||
|
id: 'instance.backups.restore-body',
|
||||||
|
defaultMessage:
|
||||||
|
'Upcoming operations: add {added, plural, one {# file} other {# files}}, modify {modified, plural, one {# file} other {# files}}, and delete {deleted, plural, one {# file} other {# files}}. Continue?',
|
||||||
|
},
|
||||||
|
deleteTitle: { id: 'instance.backups.delete-title', defaultMessage: 'Delete this backup?' },
|
||||||
|
deleteBody: {
|
||||||
|
id: 'instance.backups.delete-body',
|
||||||
|
defaultMessage:
|
||||||
|
'This snapshot will be permanently deleted. Unused stored files will also be removed.',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const config = ref<InstanceBackupConfig | null>(null)
|
||||||
|
const snapshots = ref<BackupSnapshot[]>([])
|
||||||
|
const instanceRoot = ref('')
|
||||||
|
const loading = ref(true)
|
||||||
|
const editingExclusions = ref(false)
|
||||||
|
const excludedPaths = ref<BackupExclusion[]>([])
|
||||||
|
const action = ref<string | null>(null)
|
||||||
|
const operation = ref<BackupOperation | null>(null)
|
||||||
|
const selectedSnapshot = ref<BackupSnapshot | null>(null)
|
||||||
|
const restorePreview = ref<BackupRestorePreview | null>(null)
|
||||||
|
const deleteModal = ref<InstanceType<typeof NewModal>>()
|
||||||
|
const restoreModal = ref<InstanceType<typeof NewModal>>()
|
||||||
|
let unlisten: (() => void) | null = null
|
||||||
|
|
||||||
|
const eligible = computed(() => config.value?.eligibility === 'eligible')
|
||||||
|
const terminalStates: BackupOperationState[] = ['completed', 'cancelled', 'failed', 'interrupted']
|
||||||
|
const isRunning = computed(
|
||||||
|
() => operation.value !== null && !terminalStates.includes(operation.value.state),
|
||||||
|
)
|
||||||
|
const canCancel = computed(() => operation.value?.cancellable === true)
|
||||||
|
const operationLabel = computed(() => {
|
||||||
|
if (operation.value?.operation_type === 'restore_preview') {
|
||||||
|
return formatMessage(messages.stagePreview)
|
||||||
|
}
|
||||||
|
switch (operation.value?.state) {
|
||||||
|
case 'queued':
|
||||||
|
return formatMessage(messages.stageQueued)
|
||||||
|
case 'hashing':
|
||||||
|
return formatMessage(messages.stageHashing)
|
||||||
|
case 'saving':
|
||||||
|
return formatMessage(messages.stageSaving)
|
||||||
|
case 'validating':
|
||||||
|
return formatMessage(messages.stageValidating)
|
||||||
|
case 'materializing':
|
||||||
|
return formatMessage(messages.stageMaterializing)
|
||||||
|
case 'applying':
|
||||||
|
return formatMessage(messages.stageApplying)
|
||||||
|
default:
|
||||||
|
return formatMessage(messages.stageScanning)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
function operationFromEvent(event: {
|
||||||
|
operationId: string
|
||||||
|
operationType: BackupOperation['operation_type']
|
||||||
|
instanceId?: string
|
||||||
|
stage: BackupProgressStage
|
||||||
|
processedBytes: number
|
||||||
|
totalBytes: number
|
||||||
|
snapshotId?: string
|
||||||
|
message?: string
|
||||||
|
}): BackupOperation {
|
||||||
|
const now = Date.now()
|
||||||
|
const state: BackupOperationState =
|
||||||
|
event.stage === 'restoring' || event.stage === 'copying'
|
||||||
|
? 'materializing'
|
||||||
|
: event.stage === 'deleting'
|
||||||
|
? 'queued'
|
||||||
|
: event.stage
|
||||||
|
return {
|
||||||
|
id: event.operationId,
|
||||||
|
operation_type: event.operationType,
|
||||||
|
instance_id: event.instanceId ?? instance.value.id,
|
||||||
|
snapshot_id: event.snapshotId,
|
||||||
|
state,
|
||||||
|
processed_bytes: event.processedBytes,
|
||||||
|
total_bytes: event.totalBytes,
|
||||||
|
cancellable: event.stage === 'scanning' || event.stage === 'hashing',
|
||||||
|
cancel_requested: false,
|
||||||
|
error: event.message,
|
||||||
|
created_at: operation.value?.id === event.operationId ? operation.value.created_at : now,
|
||||||
|
updated_at: now,
|
||||||
|
finished_at: ['completed', 'cancelled', 'failed'].includes(event.stage) ? now : undefined,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshOperation() {
|
||||||
|
const operations = await listBackupOperations(instance.value.id)
|
||||||
|
const latest = operations[0] ?? null
|
||||||
|
operation.value =
|
||||||
|
latest && (isRunningState(latest.state) || ['failed', 'interrupted'].includes(latest.state))
|
||||||
|
? latest
|
||||||
|
: null
|
||||||
|
if (operation.value?.operation_type === 'restore_preview' && operation.value.snapshot_id) {
|
||||||
|
selectedSnapshot.value =
|
||||||
|
snapshots.value.find((snapshot) => snapshot.id === operation.value?.snapshot_id) ?? null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function isRunningState(state: BackupOperationState) {
|
||||||
|
return !terminalStates.includes(state)
|
||||||
|
}
|
||||||
|
|
||||||
|
const eligibilityMessages: Record<
|
||||||
|
Exclude<InstanceBackupEligibility, 'eligible'>,
|
||||||
|
keyof typeof messages
|
||||||
|
> = {
|
||||||
|
not_installed: 'notInstalled',
|
||||||
|
symlink_instance: 'symlinkInstance',
|
||||||
|
direct_linked_instance: 'directLinked',
|
||||||
|
external_game_directory: 'externalDirectory',
|
||||||
|
root_missing: 'rootMissing',
|
||||||
|
root_is_link: 'rootLink',
|
||||||
|
}
|
||||||
|
|
||||||
|
const unavailableReason = computed(() => {
|
||||||
|
const eligibility = config.value?.eligibility
|
||||||
|
if (!eligibility || eligibility === 'eligible') return ''
|
||||||
|
return formatMessage(messages[eligibilityMessages[eligibility]])
|
||||||
|
})
|
||||||
|
|
||||||
|
async function refresh() {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const nextConfig = await getBackupConfig(instance.value.id)
|
||||||
|
config.value = nextConfig
|
||||||
|
excludedPaths.value = nextConfig.enabled ? [...nextConfig.excluded_paths] : []
|
||||||
|
const [nextRoot, nextSnapshots] = await Promise.all([
|
||||||
|
nextConfig.eligibility === 'eligible' ? get_full_path(instance.value.id) : '',
|
||||||
|
listBackups(instance.value.id),
|
||||||
|
])
|
||||||
|
instanceRoot.value = nextRoot
|
||||||
|
snapshots.value = nextSnapshots
|
||||||
|
await refreshOperation()
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function runAction(name: string, task: () => Promise<void>) {
|
||||||
|
action.value = name
|
||||||
|
try {
|
||||||
|
await task()
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
action.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function enable() {
|
||||||
|
void runAction('enable', async () => {
|
||||||
|
config.value = await enableBackups(instance.value.id, excludedPaths.value)
|
||||||
|
editingExclusions.value = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function beginEditingExclusions() {
|
||||||
|
excludedPaths.value = [...(config.value?.excluded_paths ?? [])]
|
||||||
|
editingExclusions.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveExclusions() {
|
||||||
|
void runAction('exclusions', async () => {
|
||||||
|
config.value = await updateBackupExclusions(instance.value.id, excludedPaths.value)
|
||||||
|
editingExclusions.value = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function start() {
|
||||||
|
void runAction('start', async () => {
|
||||||
|
const id = await startBackup(instance.value.id)
|
||||||
|
operation.value = {
|
||||||
|
id,
|
||||||
|
operation_type: 'create',
|
||||||
|
instance_id: instance.value.id,
|
||||||
|
state: 'queued',
|
||||||
|
processed_bytes: 0,
|
||||||
|
total_bytes: 0,
|
||||||
|
cancellable: true,
|
||||||
|
cancel_requested: false,
|
||||||
|
created_at: Date.now(),
|
||||||
|
updated_at: Date.now(),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancel() {
|
||||||
|
if (!operation.value || !canCancel.value) return
|
||||||
|
void runAction('cancel', async () => {
|
||||||
|
if (await cancelBackup(operation.value!.id)) {
|
||||||
|
operation.value = {
|
||||||
|
...operation.value!,
|
||||||
|
cancellable: false,
|
||||||
|
cancel_requested: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function confirmDelete(snapshot: BackupSnapshot) {
|
||||||
|
selectedSnapshot.value = snapshot
|
||||||
|
deleteModal.value?.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
function confirmRestore(snapshot: BackupSnapshot) {
|
||||||
|
void runAction(`preview:${snapshot.id}`, async () => {
|
||||||
|
selectedSnapshot.value = snapshot
|
||||||
|
const id = await startBackupRestorePreview(snapshot.id)
|
||||||
|
operation.value = {
|
||||||
|
id,
|
||||||
|
operation_type: 'restore_preview',
|
||||||
|
instance_id: instance.value.id,
|
||||||
|
snapshot_id: snapshot.id,
|
||||||
|
state: 'queued',
|
||||||
|
processed_bytes: 0,
|
||||||
|
total_bytes: snapshot.logical_size,
|
||||||
|
cancellable: true,
|
||||||
|
cancel_requested: false,
|
||||||
|
created_at: Date.now(),
|
||||||
|
updated_at: Date.now(),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeSnapshot() {
|
||||||
|
if (!selectedSnapshot.value) return
|
||||||
|
void runAction(`delete:${selectedSnapshot.value.id}`, async () => {
|
||||||
|
await deleteBackup(selectedSnapshot.value!.id)
|
||||||
|
await refresh()
|
||||||
|
deleteModal.value?.hide()
|
||||||
|
selectedSnapshot.value = null
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function restoreSnapshot() {
|
||||||
|
if (!selectedSnapshot.value || !restorePreview.value) return
|
||||||
|
void runAction(`restore:${selectedSnapshot.value.id}`, async () => {
|
||||||
|
const id = await restoreBackup(selectedSnapshot.value!.id, restorePreview.value!.plan_token)
|
||||||
|
operation.value = {
|
||||||
|
id,
|
||||||
|
operation_type: 'restore',
|
||||||
|
instance_id: instance.value.id,
|
||||||
|
snapshot_id: selectedSnapshot.value!.id,
|
||||||
|
state: 'queued',
|
||||||
|
processed_bytes: 0,
|
||||||
|
total_bytes: selectedSnapshot.value!.logical_size,
|
||||||
|
cancellable: true,
|
||||||
|
cancel_requested: false,
|
||||||
|
created_at: Date.now(),
|
||||||
|
updated_at: Date.now(),
|
||||||
|
}
|
||||||
|
restoreModal.value?.hide()
|
||||||
|
selectedSnapshot.value = null
|
||||||
|
restorePreview.value = null
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function disable() {
|
||||||
|
void runAction('disable', async () => {
|
||||||
|
await disableBackups(instance.value.id)
|
||||||
|
await refresh()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
unlisten = await listenBackupProgress(async (event) => {
|
||||||
|
if (
|
||||||
|
!['create', 'restore', 'restore_preview'].includes(event.operationType) ||
|
||||||
|
event.instanceId !== instance.value.id
|
||||||
|
)
|
||||||
|
return
|
||||||
|
operation.value = operationFromEvent(event)
|
||||||
|
if (event.operationType === 'restore_preview' && event.stage === 'completed') {
|
||||||
|
const completed = (await listBackupOperations(instance.value.id)).find(
|
||||||
|
(candidate) => candidate.id === event.operationId,
|
||||||
|
)
|
||||||
|
const snapshot = snapshots.value.find((candidate) => candidate.id === event.snapshotId)
|
||||||
|
if (completed?.restore_preview && snapshot) {
|
||||||
|
selectedSnapshot.value = snapshot
|
||||||
|
restorePreview.value = completed.restore_preview
|
||||||
|
operation.value = null
|
||||||
|
restoreModal.value?.show()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (['completed', 'cancelled', 'failed'].includes(event.stage)) {
|
||||||
|
void refresh()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
await refresh()
|
||||||
|
})
|
||||||
|
|
||||||
|
onUnmounted(() => unlisten?.())
|
||||||
|
watch(
|
||||||
|
() => instance.value.id,
|
||||||
|
() => void refresh(),
|
||||||
|
)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-5">
|
||||||
|
<header>
|
||||||
|
<h2 class="m-0 text-lg font-semibold text-[var(--color-text-primary)]">
|
||||||
|
{{ formatMessage(messages.title) }}
|
||||||
|
</h2>
|
||||||
|
<p class="m-0 mt-1 text-[var(--color-text-tertiary)]">
|
||||||
|
{{ formatMessage(messages.description) }}
|
||||||
|
</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<p v-if="loading" class="m-0 text-[var(--color-text-tertiary)]">
|
||||||
|
{{ formatMessage(messages.loading) }}
|
||||||
|
</p>
|
||||||
|
<Admonition v-else-if="!eligible" type="warning" :header="formatMessage(messages.unavailable)">
|
||||||
|
{{ unavailableReason }}
|
||||||
|
</Admonition>
|
||||||
|
<template v-else-if="config">
|
||||||
|
<div v-if="!config.enabled || editingExclusions" class="flex flex-col gap-4">
|
||||||
|
<p class="m-0 text-[var(--color-text-tertiary)]">{{ formatMessage(messages.choose) }}</p>
|
||||||
|
<BackupExclusionSelector
|
||||||
|
v-model="excludedPaths"
|
||||||
|
:instance-id="instance.id"
|
||||||
|
:instance-root="instanceRoot"
|
||||||
|
:disabled="action !== null"
|
||||||
|
/>
|
||||||
|
<div class="flex flex-wrap gap-2">
|
||||||
|
<Button :disabled="action !== null" @click="config.enabled ? saveExclusions() : enable()"
|
||||||
|
><SaveIcon />
|
||||||
|
{{ formatMessage(config.enabled ? messages.saveExclusions : messages.enable) }}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
v-if="config.enabled"
|
||||||
|
type="outlined"
|
||||||
|
:disabled="action !== null"
|
||||||
|
@click="editingExclusions = false"
|
||||||
|
><XIcon />
|
||||||
|
{{ formatMessage(commonMessages.cancelButton) }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template v-else>
|
||||||
|
<div class="flex flex-col gap-2 rounded-lg border border-solid border-surface-4 p-3">
|
||||||
|
<p class="m-0 text-sm text-[var(--color-text-tertiary)]">
|
||||||
|
{{
|
||||||
|
config.excluded_paths.length === 0
|
||||||
|
? formatMessage(messages.allIncluded)
|
||||||
|
: formatMessage(messages.excludedPaths, {
|
||||||
|
paths: config.excluded_paths.map((entry) => entry.path).join(', '),
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
</p>
|
||||||
|
<div class="flex flex-wrap gap-2">
|
||||||
|
<Button :disabled="isRunning || action !== null" @click="start"
|
||||||
|
><FileArchiveIcon />
|
||||||
|
{{ formatMessage(messages.backupNow) }}
|
||||||
|
</Button>
|
||||||
|
<Button v-if="canCancel" type="outlined" :disabled="action !== null" @click="cancel"
|
||||||
|
><XIcon />
|
||||||
|
{{ formatMessage(messages.cancelBackup) }}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="outlined"
|
||||||
|
:disabled="isRunning || action !== null"
|
||||||
|
@click="beginEditingExclusions"
|
||||||
|
>{{ formatMessage(messages.editExclusions) }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<p v-if="isRunning" class="m-0 text-sm font-medium text-[var(--color-text-primary)]">
|
||||||
|
{{ operationLabel }}
|
||||||
|
<span
|
||||||
|
v-if="(operation?.total_bytes ?? 0) > 0"
|
||||||
|
class="ml-2 text-[var(--color-text-tertiary)]"
|
||||||
|
>
|
||||||
|
{{
|
||||||
|
formatMessage(messages.progressBytes, {
|
||||||
|
processed: formatBytes(operation?.processed_bytes ?? 0),
|
||||||
|
total: formatBytes(operation?.total_bytes ?? 0),
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
<p
|
||||||
|
v-else-if="operation?.state === 'failed' || operation?.state === 'interrupted'"
|
||||||
|
class="m-0 text-sm text-red"
|
||||||
|
>
|
||||||
|
{{
|
||||||
|
formatMessage(
|
||||||
|
operation.state === 'interrupted'
|
||||||
|
? messages.stageInterrupted
|
||||||
|
: messages.stageFailed,
|
||||||
|
)
|
||||||
|
}}<span v-if="operation.error">: {{ operation.error }}</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<section class="flex flex-col gap-3">
|
||||||
|
<h3 class="m-0 text-base font-semibold text-[var(--color-text-primary)]">
|
||||||
|
{{ formatMessage(messages.snapshots) }}
|
||||||
|
</h3>
|
||||||
|
<p v-if="snapshots.length === 0" class="m-0 text-[var(--color-text-tertiary)]">
|
||||||
|
{{ formatMessage(messages.empty) }}
|
||||||
|
</p>
|
||||||
|
<div
|
||||||
|
v-else
|
||||||
|
class="divide-y divide-solid divide-surface-4 rounded-lg border border-solid border-surface-4"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-for="snapshot in snapshots"
|
||||||
|
:key="snapshot.id"
|
||||||
|
class="flex items-center gap-3 px-3 py-3"
|
||||||
|
>
|
||||||
|
<FileArchiveIcon class="size-5 shrink-0 text-[var(--color-text-tertiary)]" />
|
||||||
|
<div class="min-w-0 flex-1">
|
||||||
|
<p class="m-0 font-semibold text-[var(--color-text-primary)]">
|
||||||
|
{{ formatDate(new Date(snapshot.created_at)) }}
|
||||||
|
</p>
|
||||||
|
<p class="m-0 text-sm text-[var(--color-text-tertiary)]">
|
||||||
|
{{
|
||||||
|
formatMessage(messages.snapshotMeta, {
|
||||||
|
files: snapshot.file_count,
|
||||||
|
size: formatBytes(snapshot.logical_size),
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
·
|
||||||
|
{{
|
||||||
|
formatMessage(messages.addedSize, { size: formatBytes(snapshot.added_size) })
|
||||||
|
}}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
type="quiet"
|
||||||
|
size="2xs"
|
||||||
|
circular
|
||||||
|
icon-only
|
||||||
|
:disabled="action !== null || isRunning"
|
||||||
|
:aria-label="formatMessage(messages.restore)"
|
||||||
|
@click="confirmRestore(snapshot)"
|
||||||
|
><UndoIcon />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="quiet"
|
||||||
|
color="red"
|
||||||
|
size="2xs"
|
||||||
|
circular
|
||||||
|
icon-only
|
||||||
|
:disabled="action !== null || isRunning"
|
||||||
|
:aria-label="formatMessage(messages.delete)"
|
||||||
|
@click="confirmDelete(snapshot)"
|
||||||
|
><TrashIcon />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<div class="flex flex-col items-start gap-2">
|
||||||
|
<Button
|
||||||
|
type="outlined"
|
||||||
|
color="red"
|
||||||
|
:disabled="snapshots.length > 0 || action !== null || isRunning"
|
||||||
|
@click="disable"
|
||||||
|
>{{ formatMessage(messages.disable) }}
|
||||||
|
</Button>
|
||||||
|
<p v-if="snapshots.length > 0" class="m-0 text-sm text-[var(--color-text-tertiary)]">
|
||||||
|
{{ formatMessage(messages.disableBlocked) }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<NewModal
|
||||||
|
ref="deleteModal"
|
||||||
|
:header="formatMessage(messages.deleteTitle)"
|
||||||
|
fade="danger"
|
||||||
|
max-width="500px"
|
||||||
|
>
|
||||||
|
<Admonition type="critical">{{ formatMessage(messages.deleteBody) }}</Admonition>
|
||||||
|
<template #actions>
|
||||||
|
<div class="flex items-center justify-end gap-2">
|
||||||
|
<Button
|
||||||
|
type="outlined"
|
||||||
|
:disabled="action?.startsWith('delete:')"
|
||||||
|
@click="deleteModal?.hide()"
|
||||||
|
>{{ formatMessage(commonMessages.cancelButton) }}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="colored"
|
||||||
|
color="red"
|
||||||
|
:disabled="action?.startsWith('delete:')"
|
||||||
|
@click="removeSnapshot"
|
||||||
|
><TrashIcon />{{ formatMessage(messages.delete) }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</NewModal>
|
||||||
|
<NewModal ref="restoreModal" :header="formatMessage(messages.restoreTitle)" max-width="500px">
|
||||||
|
<Admonition v-if="restorePreview" type="warning">
|
||||||
|
{{
|
||||||
|
formatMessage(messages.restoreBody, {
|
||||||
|
added: restorePreview.added_files,
|
||||||
|
modified: restorePreview.modified_files,
|
||||||
|
deleted: restorePreview.deleted_files,
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
</Admonition>
|
||||||
|
<template #actions>
|
||||||
|
<div class="flex items-center justify-end gap-2">
|
||||||
|
<Button
|
||||||
|
type="outlined"
|
||||||
|
:disabled="action?.startsWith('restore:')"
|
||||||
|
@click="restoreModal?.hide()"
|
||||||
|
>{{ formatMessage(commonMessages.cancelButton) }}
|
||||||
|
</Button>
|
||||||
|
<Button :disabled="action?.startsWith('restore:')" @click="restoreSnapshot"
|
||||||
|
><UndoIcon />{{ formatMessage(messages.restore) }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</NewModal>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,618 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { EditIcon } from '@modrinth/assets'
|
||||||
|
import {
|
||||||
|
commonMessages,
|
||||||
|
defineMessages,
|
||||||
|
IconButton,
|
||||||
|
injectNotificationManager,
|
||||||
|
Toggle,
|
||||||
|
useVIntl,
|
||||||
|
} from '@modrinth/ui'
|
||||||
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
|
||||||
|
import { computed, nextTick, onScopeDispose, ref } from 'vue'
|
||||||
|
|
||||||
|
import { gameSettingsKeys } from '@/helpers/game-options'
|
||||||
|
import {
|
||||||
|
type GlobalSyncedOptions,
|
||||||
|
isSyncedOptionAvailable,
|
||||||
|
set_global_synced_option,
|
||||||
|
type SyncedOption,
|
||||||
|
} from '@/helpers/instance'
|
||||||
|
import {
|
||||||
|
canSourceMultiplayerServers,
|
||||||
|
gameOptionsSyncSourcesQueryOptions,
|
||||||
|
globalSyncedOptionsQueryOptions,
|
||||||
|
initializedSyncedOptionsQueryOptions,
|
||||||
|
syncedOptionsKeys,
|
||||||
|
syncedServersQueryOptions,
|
||||||
|
} from '@/helpers/synced-options'
|
||||||
|
import { syncedPackKeys, syncedPackQueryOptions } from '@/helpers/synced-packs'
|
||||||
|
import { instanceKeys, instanceListQueryOptions } from '@/pages/instance/query-options'
|
||||||
|
|
||||||
|
import SettingsRow from '../settings/SettingsRow.vue'
|
||||||
|
import SettingsSection from '../settings/SettingsSection.vue'
|
||||||
|
import CommandHistoryModal from '../settings/instances/command-history-modal.vue'
|
||||||
|
import SyncedServersModal from '../settings/instances/servers-modal.vue'
|
||||||
|
import SyncedPacksModal from '../settings/instances/SyncedPacksModal.vue'
|
||||||
|
import SyncSourceModal from '../settings/instances/SyncSourceModal.vue'
|
||||||
|
import GameSettingsModal from '../settings/instances/game-settings-modal/index.vue'
|
||||||
|
|
||||||
|
const { handleError } = injectNotificationManager()
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
const syncedPacksModal = ref<InstanceType<typeof SyncedPacksModal>>()
|
||||||
|
const commandHistoryModal = ref<InstanceType<typeof CommandHistoryModal>>()
|
||||||
|
const syncedServersModal = ref<InstanceType<typeof SyncedServersModal>>()
|
||||||
|
const gameSettingsModal = ref<InstanceType<typeof GameSettingsModal> | null>(null)
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
globalOptionsTitle: {
|
||||||
|
id: 'app.settings.synced-options.title',
|
||||||
|
defaultMessage: 'Options synced across all instances',
|
||||||
|
},
|
||||||
|
resourcePacks: {
|
||||||
|
id: 'app.settings.synced-options.resource-packs',
|
||||||
|
defaultMessage: 'Sync resource packs',
|
||||||
|
},
|
||||||
|
resourcePacksDescription: {
|
||||||
|
id: 'app.settings.synced-options.resource-packs.description',
|
||||||
|
defaultMessage: 'Use the same resource packs across your instances.',
|
||||||
|
},
|
||||||
|
dataPacks: { id: 'app.settings.synced-options.data-packs', defaultMessage: 'Sync data packs' },
|
||||||
|
dataPacksDescription: {
|
||||||
|
id: 'app.settings.synced-options.data-packs.description',
|
||||||
|
defaultMessage: 'Use the same datapacks across your instances',
|
||||||
|
},
|
||||||
|
packsDisabled: {
|
||||||
|
id: 'app.settings.synced-options.packs.disabled',
|
||||||
|
defaultMessage: 'Enable syncing before editing shared packs.',
|
||||||
|
},
|
||||||
|
gameSettings: {
|
||||||
|
id: 'app.settings.synced-options.game-settings',
|
||||||
|
defaultMessage: 'Sync game options',
|
||||||
|
},
|
||||||
|
gameSettingsDescription: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.description',
|
||||||
|
defaultMessage: 'Use the same game options across your instances.',
|
||||||
|
},
|
||||||
|
gameSettingsButton: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.button',
|
||||||
|
defaultMessage: 'Edit game settings',
|
||||||
|
},
|
||||||
|
gameSettingsDisabledTooltip: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.disabled-tooltip',
|
||||||
|
defaultMessage: 'Enable game settings sync before choosing individual settings.',
|
||||||
|
},
|
||||||
|
noGameOptionsToEdit: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.no-options-to-edit',
|
||||||
|
defaultMessage: "You haven't got any options yet to edit",
|
||||||
|
},
|
||||||
|
multiplayerServers: {
|
||||||
|
id: 'app.settings.synced-options.multiplayer-servers',
|
||||||
|
defaultMessage: 'Sync multiplayer servers',
|
||||||
|
},
|
||||||
|
multiplayerServersDescription: {
|
||||||
|
id: 'app.settings.synced-options.multiplayer-servers.description',
|
||||||
|
defaultMessage: 'Use the same multiplayer servers across your instances.',
|
||||||
|
},
|
||||||
|
commandHistory: {
|
||||||
|
id: 'app.settings.synced-options.command-history',
|
||||||
|
defaultMessage: 'Sync command history',
|
||||||
|
},
|
||||||
|
commandHistoryDescription: {
|
||||||
|
id: 'app.settings.synced-options.command-history.description',
|
||||||
|
defaultMessage: 'Use the same command history across your instances.',
|
||||||
|
},
|
||||||
|
creativeHotbars: {
|
||||||
|
id: 'app.settings.synced-options.creative-hotbars',
|
||||||
|
defaultMessage: 'Sync saved creative hotbars',
|
||||||
|
},
|
||||||
|
creativeHotbarsDescription: {
|
||||||
|
id: 'app.settings.synced-options.creative-hotbars.description',
|
||||||
|
defaultMessage: 'Use the same saved creative hotbars across your instances.',
|
||||||
|
},
|
||||||
|
gameSettingsSyncSourceTitle: {
|
||||||
|
id: 'app.settings.synced-options.choose-sync-source.game-settings-title',
|
||||||
|
defaultMessage: 'Choose game settings source',
|
||||||
|
},
|
||||||
|
multiplayerServersSyncSourceDescription: {
|
||||||
|
id: 'app.settings.synced-options.choose-sync-source.multiplayer-servers-description',
|
||||||
|
defaultMessage:
|
||||||
|
'Choose which instance to copy your multiplayer servers from. These servers are only used for the initial sync, and you can edit them from any instance afterward.',
|
||||||
|
},
|
||||||
|
multiplayerServersSyncSourceTitle: {
|
||||||
|
id: 'app.settings.synced-options.choose-sync-source.multiplayer-servers-title',
|
||||||
|
defaultMessage: 'Choose multiplayer servers source',
|
||||||
|
},
|
||||||
|
commandHistorySyncSourceDescription: {
|
||||||
|
id: 'app.settings.synced-options.choose-sync-source.command-history-description',
|
||||||
|
defaultMessage:
|
||||||
|
'Choose which instance to copy your command history from. This history is only used for the initial sync, and you can edit it from any instance afterward.',
|
||||||
|
},
|
||||||
|
commandHistorySyncSourceTitle: {
|
||||||
|
id: 'app.settings.synced-options.choose-sync-source.command-history-title',
|
||||||
|
defaultMessage: 'Choose command history source',
|
||||||
|
},
|
||||||
|
creativeHotbarsSyncSourceDescription: {
|
||||||
|
id: 'app.settings.synced-options.choose-sync-source.creative-hotbars-description',
|
||||||
|
defaultMessage:
|
||||||
|
'Choose which instance to copy your saved creative hotbars from. These hotbars are only used for the initial sync, and you can edit them from any instance afterward.',
|
||||||
|
},
|
||||||
|
creativeHotbarsSyncSourceTitle: {
|
||||||
|
id: 'app.settings.synced-options.choose-sync-source.creative-hotbars-title',
|
||||||
|
defaultMessage: 'Choose creative hotbars source',
|
||||||
|
},
|
||||||
|
gameSettingsSyncSourceDescription: {
|
||||||
|
id: 'app.settings.synced-options.choose-sync-source.game-settings-description',
|
||||||
|
defaultMessage:
|
||||||
|
'Choose which instance to copy your game settings from. These settings are only used for the initial sync, and you can edit them from any instance afterward.',
|
||||||
|
},
|
||||||
|
resourcePacksSyncSourceTitle: {
|
||||||
|
id: 'app.settings.synced-options.choose-sync-source.resource-packs-title',
|
||||||
|
defaultMessage: 'Choose resource packs source',
|
||||||
|
},
|
||||||
|
resourcePacksSyncSourceDescription: {
|
||||||
|
id: 'app.sync-instances-update.choose-source.resource-packs',
|
||||||
|
defaultMessage:
|
||||||
|
'Choose which instance to copy your resource packs from. These packs are only used for the initial sync, and you can edit them from any instance afterward.',
|
||||||
|
},
|
||||||
|
dataPacksSyncSourceTitle: {
|
||||||
|
id: 'app.settings.synced-options.choose-sync-source.data-packs-title',
|
||||||
|
defaultMessage: 'Choose data packs source',
|
||||||
|
},
|
||||||
|
dataPacksSyncSourceDescription: {
|
||||||
|
id: 'app.sync-instances-update.choose-source.data-packs',
|
||||||
|
defaultMessage:
|
||||||
|
'Choose which instance to copy your data packs from. These packs are only used for the initial sync, and you can edit them from any instance afterward.',
|
||||||
|
},
|
||||||
|
noServersSyncedYet: {
|
||||||
|
id: 'app.settings.synced-options.multiplayer-servers.none-synced-yet',
|
||||||
|
defaultMessage: "You haven't synced any servers yet",
|
||||||
|
},
|
||||||
|
noResourcePacksSyncedYet: {
|
||||||
|
id: 'app.settings.synced-options.resource-packs.none-synced-yet',
|
||||||
|
defaultMessage: "You haven't synced any resource packs yet",
|
||||||
|
},
|
||||||
|
noDataPacksSyncedYet: {
|
||||||
|
id: 'app.settings.synced-options.data-packs.none-synced-yet',
|
||||||
|
defaultMessage: "You haven't synced any data packs yet",
|
||||||
|
},
|
||||||
|
noInstancesToEdit: {
|
||||||
|
id: 'app.settings.synced-options.edit.no-instances',
|
||||||
|
defaultMessage: 'Add an instance before editing synced data.',
|
||||||
|
},
|
||||||
|
noSyncedDataToEdit: {
|
||||||
|
id: 'app.settings.synced-options.edit.no-synced-data',
|
||||||
|
defaultMessage: 'Choose a sync source before editing this setting.',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const globalRows: Array<{
|
||||||
|
option: SyncedOption
|
||||||
|
title: keyof typeof messages
|
||||||
|
description?: keyof typeof messages
|
||||||
|
editable?: 'game-settings' | 'servers' | 'commands' | 'resourcepack' | 'datapack'
|
||||||
|
}> = [
|
||||||
|
{
|
||||||
|
option: 'game_options',
|
||||||
|
title: 'gameSettings',
|
||||||
|
description: 'gameSettingsDescription',
|
||||||
|
editable: 'game-settings',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
option: 'multiplayer_servers',
|
||||||
|
title: 'multiplayerServers',
|
||||||
|
description: 'multiplayerServersDescription',
|
||||||
|
editable: 'servers',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
option: 'resource_packs',
|
||||||
|
title: 'resourcePacks',
|
||||||
|
description: 'resourcePacksDescription',
|
||||||
|
editable: 'resourcepack',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
option: 'data_packs',
|
||||||
|
title: 'dataPacks',
|
||||||
|
description: 'dataPacksDescription',
|
||||||
|
editable: 'datapack',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
option: 'command_history',
|
||||||
|
title: 'commandHistory',
|
||||||
|
description: 'commandHistoryDescription',
|
||||||
|
editable: 'commands',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
option: 'creative_hotbars',
|
||||||
|
title: 'creativeHotbars',
|
||||||
|
description: 'creativeHotbarsDescription',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
const availableGlobalRows = globalRows.filter((row) => isSyncedOptionAvailable(row.option))
|
||||||
|
|
||||||
|
const defaultGlobalOptions: GlobalSyncedOptions = {
|
||||||
|
resource_packs: false,
|
||||||
|
data_packs: false,
|
||||||
|
game_options: false,
|
||||||
|
command_history: false,
|
||||||
|
multiplayer_servers: false,
|
||||||
|
creative_hotbars: false,
|
||||||
|
screenshots: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
const globalOptionsQuery = useQuery(globalSyncedOptionsQueryOptions())
|
||||||
|
const initializedOptionsQuery = useQuery(initializedSyncedOptionsQueryOptions())
|
||||||
|
const gameOptionSourcesQuery = useQuery(gameOptionsSyncSourcesQueryOptions())
|
||||||
|
const resourcePacksQuery = useQuery(syncedPackQueryOptions('resourcepack'))
|
||||||
|
const dataPacksQuery = useQuery(syncedPackQueryOptions('datapack'))
|
||||||
|
const globalOptions = computed(() => globalOptionsQuery.data.value ?? defaultGlobalOptions)
|
||||||
|
const initializedOptions = computed(
|
||||||
|
() => initializedOptionsQuery.data.value ?? defaultGlobalOptions,
|
||||||
|
)
|
||||||
|
const gameOptionSources = computed(() => gameOptionSourcesQuery.data.value ?? [])
|
||||||
|
const instancesQuery = useQuery(instanceListQueryOptions())
|
||||||
|
const instances = computed(() => instancesQuery.data.value ?? [])
|
||||||
|
const serversQuery = useQuery(syncedServersQueryOptions())
|
||||||
|
const syncedServers = computed(() => serversQuery.data.value ?? [])
|
||||||
|
const eligibleGameOptionSourceIds = computed(
|
||||||
|
() =>
|
||||||
|
new Set(
|
||||||
|
gameOptionSources.value.filter((source) => source.eligible).map((source) => source.source_id),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
const hasGameOptionsToEdit = computed(
|
||||||
|
() =>
|
||||||
|
initializedOptions.value.game_options ||
|
||||||
|
instances.value.some(
|
||||||
|
(instance) =>
|
||||||
|
instance?.synced_options?.game_options &&
|
||||||
|
eligibleGameOptionSourceIds.value.has(instance.id),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
const baseOption = ref<SyncedOption | null>(null)
|
||||||
|
const baseInstanceId = ref('')
|
||||||
|
const baseModal = ref<InstanceType<typeof SyncSourceModal> | null>(null)
|
||||||
|
const baseSourcesLoading = computed(() =>
|
||||||
|
baseOption.value === null
|
||||||
|
? false
|
||||||
|
: baseOption.value === 'game_options'
|
||||||
|
? gameOptionSourcesQuery.isPending.value
|
||||||
|
: instancesQuery.isPending.value,
|
||||||
|
)
|
||||||
|
const baseSourcesError = computed(() =>
|
||||||
|
baseOption.value === 'game_options'
|
||||||
|
? gameOptionSourcesQuery.isError.value && !gameOptionSourcesQuery.data.value
|
||||||
|
: instancesQuery.isError.value && !instancesQuery.data.value,
|
||||||
|
)
|
||||||
|
let baseSourceGeneration = 0
|
||||||
|
|
||||||
|
const baseInstanceTitle = computed(() => {
|
||||||
|
switch (baseOption.value) {
|
||||||
|
case 'game_options':
|
||||||
|
return formatMessage(messages.gameSettingsSyncSourceTitle)
|
||||||
|
case 'multiplayer_servers':
|
||||||
|
return formatMessage(messages.multiplayerServersSyncSourceTitle)
|
||||||
|
case 'command_history':
|
||||||
|
return formatMessage(messages.commandHistorySyncSourceTitle)
|
||||||
|
case 'creative_hotbars':
|
||||||
|
return formatMessage(messages.creativeHotbarsSyncSourceTitle)
|
||||||
|
case 'resource_packs':
|
||||||
|
return formatMessage(messages.resourcePacksSyncSourceTitle)
|
||||||
|
case 'data_packs':
|
||||||
|
return formatMessage(messages.dataPacksSyncSourceTitle)
|
||||||
|
default:
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const baseInstanceDescription = computed(() => {
|
||||||
|
switch (baseOption.value) {
|
||||||
|
case 'game_options':
|
||||||
|
return formatMessage(messages.gameSettingsSyncSourceDescription)
|
||||||
|
case 'multiplayer_servers':
|
||||||
|
return formatMessage(messages.multiplayerServersSyncSourceDescription)
|
||||||
|
case 'command_history':
|
||||||
|
return formatMessage(messages.commandHistorySyncSourceDescription)
|
||||||
|
case 'creative_hotbars':
|
||||||
|
return formatMessage(messages.creativeHotbarsSyncSourceDescription)
|
||||||
|
case 'resource_packs':
|
||||||
|
return formatMessage(messages.resourcePacksSyncSourceDescription)
|
||||||
|
case 'data_packs':
|
||||||
|
return formatMessage(messages.dataPacksSyncSourceDescription)
|
||||||
|
default:
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const baseInstances = computed(() =>
|
||||||
|
baseOption.value === 'game_options'
|
||||||
|
? gameOptionSources.value.map((source) => ({
|
||||||
|
id: source.source_id,
|
||||||
|
name: source.name,
|
||||||
|
icon_path: source.icon_path,
|
||||||
|
eligible: source.eligible,
|
||||||
|
}))
|
||||||
|
: instances.value.map((instance) => ({
|
||||||
|
id: instance.id,
|
||||||
|
name: instance.name,
|
||||||
|
icon_path: instance.icon_path,
|
||||||
|
eligible:
|
||||||
|
!instance.quarantined &&
|
||||||
|
(baseOption.value !== 'multiplayer_servers' || canSourceMultiplayerServers(instance)),
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
|
||||||
|
async function invalidateSyncedOptions() {
|
||||||
|
await Promise.all([
|
||||||
|
queryClient.invalidateQueries({ queryKey: instanceKeys.all }),
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['instance-synced-options'] }),
|
||||||
|
queryClient.invalidateQueries({ queryKey: syncedOptionsKeys.global }),
|
||||||
|
queryClient.invalidateQueries({ queryKey: syncedOptionsKeys.initialized }),
|
||||||
|
queryClient.invalidateQueries({ queryKey: syncedOptionsKeys.gameSources }),
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['worlds'] }),
|
||||||
|
queryClient.invalidateQueries({ queryKey: syncedPackKeys.all }),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
function emptySyncedContentMessage(row: (typeof globalRows)[number]) {
|
||||||
|
if (
|
||||||
|
row.editable === 'servers' &&
|
||||||
|
(instances.value.length === 0 || syncedServers.value.length === 0)
|
||||||
|
) {
|
||||||
|
return messages.noServersSyncedYet
|
||||||
|
}
|
||||||
|
if (row.editable === 'resourcepack' && !resourcePacksQuery.data.value?.length) {
|
||||||
|
return messages.noResourcePacksSyncedYet
|
||||||
|
}
|
||||||
|
if (row.editable === 'datapack' && !dataPacksQuery.data.value?.length) {
|
||||||
|
return messages.noDataPacksSyncedYet
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function canEditGlobalOption(row: (typeof globalRows)[number]): boolean {
|
||||||
|
if (!row.editable || !globalOptions.value[row.option]) return false
|
||||||
|
if (emptySyncedContentMessage(row)) return false
|
||||||
|
if (row.editable === 'resourcepack' || row.editable === 'datapack') return true
|
||||||
|
if (row.editable === 'game-settings') return hasGameOptionsToEdit.value
|
||||||
|
return instances.value.length > 0 && initializedOptions.value[row.option]
|
||||||
|
}
|
||||||
|
|
||||||
|
function editGlobalOptionTooltip(row: (typeof globalRows)[number]): string {
|
||||||
|
const emptyMessage = emptySyncedContentMessage(row)
|
||||||
|
if (emptyMessage) return formatMessage(emptyMessage)
|
||||||
|
if (row.editable === 'resourcepack' || row.editable === 'datapack') {
|
||||||
|
return formatMessage(
|
||||||
|
globalOptions.value[row.option] ? commonMessages.editButton : messages.packsDisabled,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (row.editable === 'game-settings') {
|
||||||
|
if (!hasGameOptionsToEdit.value) return formatMessage(messages.noGameOptionsToEdit)
|
||||||
|
if (!globalOptions.value[row.option]) {
|
||||||
|
return formatMessage(messages.gameSettingsDisabledTooltip)
|
||||||
|
}
|
||||||
|
return formatMessage(messages.gameSettingsButton)
|
||||||
|
}
|
||||||
|
if (instances.value.length === 0) {
|
||||||
|
return formatMessage(messages.noInstancesToEdit)
|
||||||
|
}
|
||||||
|
if (!initializedOptions.value[row.option]) {
|
||||||
|
return formatMessage(messages.noSyncedDataToEdit)
|
||||||
|
}
|
||||||
|
return formatMessage(commonMessages.editButton)
|
||||||
|
}
|
||||||
|
|
||||||
|
type GlobalOptionMutationVariables = {
|
||||||
|
option: SyncedOption
|
||||||
|
enabled: boolean
|
||||||
|
baseInstanceId?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const globalOptionMutation = useMutation({
|
||||||
|
mutationKey: syncedOptionsKeys.set,
|
||||||
|
mutationFn: ({ option, enabled, baseInstanceId }: GlobalOptionMutationVariables) =>
|
||||||
|
set_global_synced_option(option, enabled, baseInstanceId),
|
||||||
|
onError: handleError,
|
||||||
|
onSuccess: async (options, { option, enabled }) => {
|
||||||
|
queryClient.setQueryData(syncedOptionsKeys.global, options)
|
||||||
|
if (option === 'game_options') {
|
||||||
|
await queryClient.invalidateQueries({ queryKey: gameSettingsKeys.synced })
|
||||||
|
}
|
||||||
|
if (enabled && option === 'multiplayer_servers') {
|
||||||
|
await queryClient.invalidateQueries({ queryKey: syncedOptionsKeys.servers })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onSettled: async (_data, _error, { option }) => {
|
||||||
|
if (queryClient.isMutating({ mutationKey: syncedOptionsKeys.set }) === 1) {
|
||||||
|
if (option === 'resource_packs' || option === 'data_packs') {
|
||||||
|
void Promise.all([
|
||||||
|
queryClient.invalidateQueries({ queryKey: instanceKeys.all }),
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['instance-synced-options'] }),
|
||||||
|
queryClient.invalidateQueries({ queryKey: syncedOptionsKeys.global }),
|
||||||
|
queryClient.invalidateQueries({ queryKey: syncedOptionsKeys.initialized }),
|
||||||
|
queryClient.invalidateQueries({ queryKey: syncedPackKeys.all }),
|
||||||
|
])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await invalidateSyncedOptions()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const canToggleGlobalOptions = computed(
|
||||||
|
() =>
|
||||||
|
!!globalOptionsQuery.data.value &&
|
||||||
|
!globalOptionMutation.isPending.value &&
|
||||||
|
!baseSourcesLoading.value,
|
||||||
|
)
|
||||||
|
|
||||||
|
async function chooseBaseInstance(option: SyncedOption) {
|
||||||
|
const generation = ++baseSourceGeneration
|
||||||
|
baseOption.value = option
|
||||||
|
baseInstanceId.value = ''
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (option === 'game_options') {
|
||||||
|
await queryClient.fetchQuery(gameOptionsSyncSourcesQueryOptions())
|
||||||
|
} else {
|
||||||
|
await queryClient.fetchQuery({ ...instanceListQueryOptions(), staleTime: 0 })
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (generation !== baseSourceGeneration) return
|
||||||
|
handleError(error)
|
||||||
|
baseModal.value?.show()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (generation !== baseSourceGeneration) return
|
||||||
|
const eligibleSources = baseInstances.value.filter((source) => source.eligible)
|
||||||
|
baseInstanceId.value = eligibleSources[0]?.id ?? ''
|
||||||
|
if (eligibleSources.length > 1) {
|
||||||
|
baseModal.value?.show()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await globalOptionMutation.mutateAsync({
|
||||||
|
option,
|
||||||
|
enabled: true,
|
||||||
|
baseInstanceId: eligibleSources[0]?.id,
|
||||||
|
})
|
||||||
|
await nextTick()
|
||||||
|
if (!baseModal.value?.hide()) clearBaseSource()
|
||||||
|
} catch {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleGlobalOption(option: SyncedOption, enabled: boolean) {
|
||||||
|
if (!isSyncedOptionAvailable(option) || !canToggleGlobalOptions.value) return
|
||||||
|
if (enabled && option !== 'screenshots') {
|
||||||
|
void chooseBaseInstance(option)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
globalOptionMutation.mutate({ option, enabled })
|
||||||
|
}
|
||||||
|
|
||||||
|
async function confirmBaseInstance() {
|
||||||
|
if (!baseOption.value || !baseInstanceId.value) return
|
||||||
|
try {
|
||||||
|
await globalOptionMutation.mutateAsync({
|
||||||
|
option: baseOption.value,
|
||||||
|
enabled: true,
|
||||||
|
baseInstanceId: baseInstanceId.value,
|
||||||
|
})
|
||||||
|
await nextTick()
|
||||||
|
baseModal.value?.hide()
|
||||||
|
} catch {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function editGlobalOption(row: (typeof globalRows)[number]) {
|
||||||
|
if (!isSyncedOptionAvailable(row.option)) return
|
||||||
|
if (row.editable === 'resourcepack' || row.editable === 'datapack') {
|
||||||
|
void syncedPacksModal.value?.show(row.editable)
|
||||||
|
} else if (row.editable === 'game-settings') {
|
||||||
|
openGameSettings()
|
||||||
|
} else if (row.editable === 'commands') {
|
||||||
|
void commandHistoryModal.value?.show()
|
||||||
|
} else {
|
||||||
|
void syncedServersModal.value?.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function openGameSettings() {
|
||||||
|
if (!hasGameOptionsToEdit.value) return
|
||||||
|
gameSettingsModal.value?.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleGameSettingsSaved() {
|
||||||
|
await invalidateSyncedOptions()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function clearBaseSource() {
|
||||||
|
baseSourceGeneration++
|
||||||
|
baseOption.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
onScopeDispose(clearBaseSource)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-6">
|
||||||
|
<SyncedPacksModal ref="syncedPacksModal" />
|
||||||
|
<CommandHistoryModal ref="commandHistoryModal" />
|
||||||
|
<SyncedServersModal ref="syncedServersModal" />
|
||||||
|
<GameSettingsModal ref="gameSettingsModal" @saved="handleGameSettingsSaved" />
|
||||||
|
|
||||||
|
<SyncSourceModal
|
||||||
|
ref="baseModal"
|
||||||
|
v-model="baseInstanceId"
|
||||||
|
:title="baseInstanceTitle"
|
||||||
|
:description="baseInstanceDescription"
|
||||||
|
:sources="baseInstances"
|
||||||
|
:loading="baseSourcesLoading"
|
||||||
|
:error="baseSourcesError"
|
||||||
|
:pending="globalOptionMutation.isPending.value"
|
||||||
|
@confirm="confirmBaseInstance"
|
||||||
|
@close="clearBaseSource"
|
||||||
|
@retry="baseOption && chooseBaseInstance(baseOption)"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<SettingsSection>
|
||||||
|
<template #header>
|
||||||
|
<h2
|
||||||
|
id="settings-target-instance-sync-options"
|
||||||
|
tabindex="-1"
|
||||||
|
class="m-0 text-lg font-semibold text-[var(--color-text-primary)]"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.globalOptionsTitle) }}
|
||||||
|
</h2>
|
||||||
|
</template>
|
||||||
|
<SettingsRow v-for="row in availableGlobalRows" :key="row.option">
|
||||||
|
<template #label>
|
||||||
|
<span :id="`settings-target-instance-sync-${row.option}`" tabindex="-1">
|
||||||
|
{{ formatMessage(messages[row.title]) }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
<template v-if="row.description" #description>
|
||||||
|
{{ formatMessage(messages[row.description]) }}
|
||||||
|
</template>
|
||||||
|
<template #control>
|
||||||
|
<span v-if="row.editable" v-tooltip="editGlobalOptionTooltip(row)" class="flex">
|
||||||
|
<IconButton
|
||||||
|
type="outlined"
|
||||||
|
circular
|
||||||
|
:disabled="
|
||||||
|
!canEditGlobalOption(row) ||
|
||||||
|
initializedOptionsQuery.isPending.value ||
|
||||||
|
globalOptionMutation.isPending.value
|
||||||
|
"
|
||||||
|
:label="
|
||||||
|
formatMessage(
|
||||||
|
row.editable === 'game-settings'
|
||||||
|
? messages.gameSettingsButton
|
||||||
|
: commonMessages.editButton,
|
||||||
|
)
|
||||||
|
"
|
||||||
|
@click="editGlobalOption(row)"
|
||||||
|
>
|
||||||
|
<EditIcon aria-hidden="true" />
|
||||||
|
</IconButton>
|
||||||
|
</span>
|
||||||
|
<Toggle
|
||||||
|
:id="`global-sync-${row.option}`"
|
||||||
|
:model-value="globalOptions[row.option]"
|
||||||
|
:disabled="!canToggleGlobalOptions"
|
||||||
|
:aria-label="formatMessage(messages[row.title])"
|
||||||
|
@update:model-value="(enabled) => toggleGlobalOption(row.option, enabled)"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</SettingsRow>
|
||||||
|
</SettingsSection>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -36,24 +36,29 @@ const fullscreenSetting: Ref<boolean> = ref(
|
|||||||
instance.value.force_fullscreen ?? globalSettings.force_fullscreen,
|
instance.value.force_fullscreen ?? globalSettings.force_fullscreen,
|
||||||
)
|
)
|
||||||
const maximizeWindowSetting = ref(instance.value.maximize_window ?? globalSettings.maximize_window)
|
const maximizeWindowSetting = ref(instance.value.maximize_window ?? globalSettings.maximize_window)
|
||||||
|
const windowTitle = ref(instance.value.window_title ?? '')
|
||||||
|
|
||||||
const editInstanceObject = computed(() => {
|
const editInstanceObject = computed(() => {
|
||||||
|
const title = windowTitle.value.trim() ? windowTitle.value.trim() : null
|
||||||
if (!overrideWindowSettings.value) {
|
if (!overrideWindowSettings.value) {
|
||||||
return {
|
return {
|
||||||
force_fullscreen: null,
|
force_fullscreen: null,
|
||||||
maximize_window: null,
|
maximize_window: null,
|
||||||
game_resolution: null,
|
game_resolution: null,
|
||||||
|
// The title is independent of the window-size override checkbox.
|
||||||
|
window_title: title,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
force_fullscreen: fullscreenSetting.value,
|
force_fullscreen: fullscreenSetting.value,
|
||||||
maximize_window: maximizeWindowSetting.value,
|
maximize_window: maximizeWindowSetting.value,
|
||||||
game_resolution: fullscreenSetting.value ? null : resolution.value,
|
game_resolution: fullscreenSetting.value ? null : resolution.value,
|
||||||
|
window_title: title,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
[overrideWindowSettings, resolution, fullscreenSetting, maximizeWindowSetting],
|
[overrideWindowSettings, resolution, fullscreenSetting, maximizeWindowSetting, windowTitle],
|
||||||
async () => {
|
async () => {
|
||||||
await edit(instance.value.id, editInstanceObject.value)
|
await edit(instance.value.id, editInstanceObject.value)
|
||||||
},
|
},
|
||||||
@@ -109,6 +114,18 @@ const messages = defineMessages({
|
|||||||
id: 'instance.settings.tabs.window.height.enter',
|
id: 'instance.settings.tabs.window.height.enter',
|
||||||
defaultMessage: 'Enter height...',
|
defaultMessage: 'Enter height...',
|
||||||
},
|
},
|
||||||
|
windowTitle: {
|
||||||
|
id: 'instance.settings.tabs.window.window-title',
|
||||||
|
defaultMessage: 'Window title',
|
||||||
|
},
|
||||||
|
windowTitleDescription: {
|
||||||
|
id: 'instance.settings.tabs.window.window-title.description',
|
||||||
|
defaultMessage: 'Customize the Minecraft window title. Leave empty to keep the default.',
|
||||||
|
},
|
||||||
|
enterWindowTitle: {
|
||||||
|
id: 'instance.settings.tabs.window.window-title.enter',
|
||||||
|
defaultMessage: 'Enter window title...',
|
||||||
|
},
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -200,5 +217,25 @@ const messages = defineMessages({
|
|||||||
:placeholder="formatMessage(messages.enterHeight)"
|
:placeholder="formatMessage(messages.enterHeight)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div
|
||||||
|
v-if="globalSettings.custom_window_title_enabled"
|
||||||
|
class="flex items-center gap-4 justify-between"
|
||||||
|
>
|
||||||
|
<div class="flex flex-col gap-1">
|
||||||
|
<h2 class="m-0 inline-flex items-center gap-2 text-lg font-semibold text-contrast">
|
||||||
|
{{ formatMessage(messages.windowTitle) }}
|
||||||
|
</h2>
|
||||||
|
<p class="m-0">
|
||||||
|
{{ formatMessage(messages.windowTitleDescription) }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<StyledInput
|
||||||
|
id="window-title"
|
||||||
|
v-model="windowTitle"
|
||||||
|
autocomplete="off"
|
||||||
|
type="text"
|
||||||
|
:placeholder="formatMessage(messages.enterWindowTitle)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { KeyboardSensor, PointerSensor, useDraggable } from '@dnd-kit/vue'
|
||||||
|
import { useEventListener } from '@vueuse/core'
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
|
|
||||||
|
import type { GameInstance } from '@/helpers/types'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
instance: GameInstance
|
||||||
|
instanceGroupId: string
|
||||||
|
disabled: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'contextmenu' | 'card-click', event: MouseEvent): void
|
||||||
|
(e: 'start-long-press' | 'cancel-long-press'): void
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const cardElement = ref<HTMLElement>()
|
||||||
|
|
||||||
|
const instanceCardSensors = [
|
||||||
|
PointerSensor.configure({
|
||||||
|
preventActivation: () => false,
|
||||||
|
}),
|
||||||
|
KeyboardSensor,
|
||||||
|
]
|
||||||
|
|
||||||
|
const dragDisabled = computed(() => props.disabled)
|
||||||
|
|
||||||
|
const { isDragging } = useDraggable({
|
||||||
|
id: computed(() => `instance:${props.instanceGroupId}:${props.instance.id}`),
|
||||||
|
element: cardElement,
|
||||||
|
disabled: dragDisabled,
|
||||||
|
sensors: instanceCardSensors,
|
||||||
|
data: computed(() => ({
|
||||||
|
instanceId: props.instance.id,
|
||||||
|
fromGroup: props.instanceGroupId,
|
||||||
|
})),
|
||||||
|
})
|
||||||
|
|
||||||
|
let wantsClick = false
|
||||||
|
|
||||||
|
useEventListener(window, 'pointerdown', () => {
|
||||||
|
wantsClick = true
|
||||||
|
})
|
||||||
|
useEventListener(window, 'pointerup', () => {
|
||||||
|
if (isDragging.value) {
|
||||||
|
wantsClick = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
useEventListener(window, 'blur', () => {
|
||||||
|
wantsClick = false
|
||||||
|
})
|
||||||
|
|
||||||
|
function onCardClick(event: MouseEvent) {
|
||||||
|
if (!wantsClick || isDragging.value) return
|
||||||
|
wantsClick = false
|
||||||
|
emit('card-click', event)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onContextMenu(event: MouseEvent) {
|
||||||
|
emit('contextmenu', event)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onMouseDown() {
|
||||||
|
if (!dragDisabled.value) {
|
||||||
|
emit('start-long-press')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onMouseUp() {
|
||||||
|
emit('cancel-long-press')
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div
|
||||||
|
ref="cardElement"
|
||||||
|
class="group relative min-w-0 w-full"
|
||||||
|
@click="onCardClick"
|
||||||
|
@mousedown="onMouseDown"
|
||||||
|
@mouseup="onMouseUp"
|
||||||
|
@mouseleave="onMouseUp"
|
||||||
|
@touchstart="!dragDisabled && onMouseDown()"
|
||||||
|
@touchend="onMouseUp"
|
||||||
|
@touchcancel="onMouseUp"
|
||||||
|
@contextmenu.prevent.stop="onContextMenu"
|
||||||
|
>
|
||||||
|
<slot :is-dragging="isDragging" />
|
||||||
|
<slot v-if="!isDragging" name="overlay" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,521 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { useDroppable } from '@dnd-kit/vue'
|
||||||
|
import {
|
||||||
|
ArrowDownIcon,
|
||||||
|
ArrowUpIcon,
|
||||||
|
DropdownIcon,
|
||||||
|
EditIcon,
|
||||||
|
PlusIcon,
|
||||||
|
TrashIcon,
|
||||||
|
XIcon,
|
||||||
|
} from '@modrinth/assets'
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Checkbox,
|
||||||
|
commonMessages,
|
||||||
|
defineMessages,
|
||||||
|
IconButton,
|
||||||
|
InlineEditableText,
|
||||||
|
NewModal,
|
||||||
|
TagItem,
|
||||||
|
useVIntl,
|
||||||
|
} from '@modrinth/ui'
|
||||||
|
import { computed, nextTick, ref, watch } from 'vue'
|
||||||
|
|
||||||
|
import ContextMenu from '@/components/ui/ContextMenu.vue'
|
||||||
|
import Instance from '@/components/ui/Instance.vue'
|
||||||
|
import DraggableInstanceCard from '@/components/ui/library/DraggableInstanceCard.vue'
|
||||||
|
import { UNGROUPED_GROUP_KEY } from '@/composables/useGridGrouping'
|
||||||
|
import { FAVORITES_GROUP_ID } from '@/composables/useInstanceGroups'
|
||||||
|
import type { GameInstance } from '@/helpers/types'
|
||||||
|
|
||||||
|
const MAX_GROUP_NAME_LENGTH = 256
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
ungrouped: { id: 'app.instances.group.ungrouped', defaultMessage: 'No group' },
|
||||||
|
pinned: { id: 'app.instances.group.pinned', defaultMessage: 'Pinned' },
|
||||||
|
emptyGroup: {
|
||||||
|
id: 'app.instances.group.empty',
|
||||||
|
defaultMessage: 'Drag and drop to add instances.',
|
||||||
|
},
|
||||||
|
editGroupName: {
|
||||||
|
id: 'app.instances.group.edit-name',
|
||||||
|
defaultMessage: 'Edit group name',
|
||||||
|
},
|
||||||
|
deleteGroup: {
|
||||||
|
id: 'app.instances.group.delete-group',
|
||||||
|
defaultMessage: 'Delete group',
|
||||||
|
},
|
||||||
|
deleteGroupDescription: {
|
||||||
|
id: 'app.instances.group.delete-description',
|
||||||
|
defaultMessage: 'Instances in this group will be ungrouped.',
|
||||||
|
},
|
||||||
|
moveGroupUp: {
|
||||||
|
id: 'app.instances.group.move-up',
|
||||||
|
defaultMessage: 'Move group up',
|
||||||
|
},
|
||||||
|
moveGroupDown: {
|
||||||
|
id: 'app.instances.group.move-down',
|
||||||
|
defaultMessage: 'Move group down',
|
||||||
|
},
|
||||||
|
addToGroup: {
|
||||||
|
id: 'app.instances.group.add-to-group',
|
||||||
|
defaultMessage: 'Add to group',
|
||||||
|
},
|
||||||
|
newInstance: {
|
||||||
|
id: 'app.instances.group.new-instance',
|
||||||
|
defaultMessage: 'New instance',
|
||||||
|
},
|
||||||
|
collapseGroup: {
|
||||||
|
id: 'app.instances.group.collapse',
|
||||||
|
defaultMessage: 'Collapse group',
|
||||||
|
},
|
||||||
|
expandGroup: {
|
||||||
|
id: 'app.instances.group.expand',
|
||||||
|
defaultMessage: 'Expand group',
|
||||||
|
},
|
||||||
|
renameGroup: {
|
||||||
|
id: 'app.instances.group.rename-group',
|
||||||
|
defaultMessage: 'Rename group',
|
||||||
|
},
|
||||||
|
groupNameEmpty: {
|
||||||
|
id: 'app.instances.group.name-empty',
|
||||||
|
defaultMessage: 'Group names cannot be empty.',
|
||||||
|
},
|
||||||
|
groupNameTooLong: {
|
||||||
|
id: 'app.instances.group.name-too-long',
|
||||||
|
defaultMessage: 'Group names cannot be longer than {maxLength} characters.',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
sectionKey: string
|
||||||
|
groupName?: string
|
||||||
|
instances: GameInstance[]
|
||||||
|
grouping: string
|
||||||
|
isCollapsed: boolean
|
||||||
|
displayMode: string
|
||||||
|
selectMode: boolean
|
||||||
|
selectedInstanceIds: Set<string>
|
||||||
|
isSortAscending?: boolean
|
||||||
|
hideHeader?: boolean
|
||||||
|
canMoveUp?: boolean
|
||||||
|
canMoveDown?: boolean
|
||||||
|
groupPendingNameEdit?: string | null
|
||||||
|
}>()
|
||||||
|
|
||||||
|
// Events are grouped only where the payload shapes genuinely match; the
|
||||||
|
// per-event names are documentation, not part of the type.
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'toggleCollapse' | 'deleteGroup' | 'addToGroup' | 'startLongPress', id: string): void
|
||||||
|
(e: 'handleCheckboxClick' | 'handleCardClick', instanceId: string, event: MouseEvent): void
|
||||||
|
(e: 'handleContextMenu', event: MouseEvent, instanceId: string, sectionKey: string): void
|
||||||
|
(e: 'renameGroup', oldKey: string, newKey: string): void
|
||||||
|
(e: 'cancelLongPress' | 'newInstance' | 'renameComplete'): void
|
||||||
|
(e: 'moveGroup', groupKey: string, direction: -1 | 1): void
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const groupOptions = ref<InstanceType<typeof ContextMenu>>()
|
||||||
|
const groupContainerRef = ref<HTMLElement>()
|
||||||
|
const groupNameInput = ref<InstanceType<typeof InlineEditableText>>()
|
||||||
|
const deletingGroup = ref(false)
|
||||||
|
const confirmDeleteGroupModal = ref<InstanceType<typeof NewModal>>()
|
||||||
|
const groupName = ref(props.groupName ?? props.sectionKey)
|
||||||
|
|
||||||
|
const isUngrouped = computed(() => props.sectionKey === UNGROUPED_GROUP_KEY)
|
||||||
|
const isFavorites = computed(() => props.sectionKey === FAVORITES_GROUP_ID)
|
||||||
|
const isCustomGroup = computed(
|
||||||
|
() => props.grouping === 'Group' && !isUngrouped.value && !isFavorites.value,
|
||||||
|
)
|
||||||
|
const isGroupDragActive = computed(() => props.grouping === 'Group')
|
||||||
|
const effectiveCollapsed = computed(() => (props.hideHeader ? false : props.isCollapsed))
|
||||||
|
|
||||||
|
const { isDropTarget } = useDroppable({
|
||||||
|
id: computed(() => `instance-group:${props.sectionKey}`),
|
||||||
|
element: groupContainerRef,
|
||||||
|
disabled: computed(() => props.hideHeader || !isGroupDragActive.value),
|
||||||
|
data: computed(() => ({
|
||||||
|
groupId: props.sectionKey,
|
||||||
|
})),
|
||||||
|
})
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => [props.sectionKey, props.groupName],
|
||||||
|
() => {
|
||||||
|
groupName.value = props.groupName ?? props.sectionKey
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.groupPendingNameEdit,
|
||||||
|
async (pendingId) => {
|
||||||
|
if (pendingId !== props.sectionKey) return
|
||||||
|
|
||||||
|
await nextTick()
|
||||||
|
groupContainerRef.value?.scrollIntoView({ block: 'nearest' })
|
||||||
|
await groupNameInput.value?.startEditing()
|
||||||
|
emit('renameComplete')
|
||||||
|
},
|
||||||
|
{ immediate: true, flush: 'post' },
|
||||||
|
)
|
||||||
|
|
||||||
|
function validateGroupName(value: string) {
|
||||||
|
const normalized = value.trim()
|
||||||
|
if (normalized.length === 0) return false
|
||||||
|
if (normalized.length > MAX_GROUP_NAME_LENGTH) return false
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
async function updateGroupName(value: string) {
|
||||||
|
const newName = value.trim()
|
||||||
|
if (!newName || newName === groupName.value) return false
|
||||||
|
emit('renameGroup', props.sectionKey, newName)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
function openGroupContextMenu(event: MouseEvent) {
|
||||||
|
groupOptions.value?.showMenu(
|
||||||
|
event,
|
||||||
|
props.sectionKey,
|
||||||
|
isCustomGroup.value
|
||||||
|
? [
|
||||||
|
{ name: 'new_instance' },
|
||||||
|
{ name: 'add_instances' },
|
||||||
|
{ name: 'edit_name' },
|
||||||
|
{ type: 'divider' },
|
||||||
|
{ name: 'delete_group', color: 'danger' },
|
||||||
|
]
|
||||||
|
: [{ name: 'new_instance' }],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleGroupOption({ option }: { option: string }) {
|
||||||
|
if (option === 'new_instance') {
|
||||||
|
emit('newInstance')
|
||||||
|
} else if (option === 'add_instances') {
|
||||||
|
emit('addToGroup', props.sectionKey)
|
||||||
|
} else if (option === 'edit_name') {
|
||||||
|
groupNameInput.value?.startEditing()
|
||||||
|
} else if (option === 'delete_group') {
|
||||||
|
requestGroupDeletion()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function requestGroupDeletion() {
|
||||||
|
if (isUngrouped.value || isFavorites.value) return
|
||||||
|
|
||||||
|
if (props.instances.length > 0) {
|
||||||
|
confirmDeleteGroupModal.value?.show()
|
||||||
|
} else {
|
||||||
|
void removeGroup()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function removeGroup() {
|
||||||
|
if (deletingGroup.value) return
|
||||||
|
|
||||||
|
deletingGroup.value = true
|
||||||
|
emit('deleteGroup', props.sectionKey)
|
||||||
|
setTimeout(() => {
|
||||||
|
deletingGroup.value = false
|
||||||
|
confirmDeleteGroupModal.value?.hide()
|
||||||
|
}, 300)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onCardClick(instanceId: string, event: MouseEvent) {
|
||||||
|
emit('handleCardClick', instanceId, event)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onStartLongPress(instanceId: string) {
|
||||||
|
emit('startLongPress', instanceId)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div
|
||||||
|
ref="groupContainerRef"
|
||||||
|
class="instance-group group/instance-container relative select-none pb-3"
|
||||||
|
@contextmenu.prevent.stop="openGroupContextMenu"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-if="!hideHeader && isDropTarget && isGroupDragActive"
|
||||||
|
class="pointer-events-none absolute -inset-2 inset-y-0 z-20 rounded-xl border-2 border-dashed border-contrast opacity-40 bg-transparent transition-opacity duration-150"
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
v-if="!hideHeader && (grouping === 'Group' || sectionKey !== UNGROUPED_GROUP_KEY)"
|
||||||
|
class="group/header flex h-10 w-full items-center gap-2 border-0 border-b border-solid border-b-surface-5"
|
||||||
|
:class="{ 'group-drag-handle cursor-grab': isCustomGroup }"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
class="flex min-w-0 cursor-pointer items-center gap-2"
|
||||||
|
@click="emit('toggleCollapse', sectionKey)"
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
class="flex shrink-0 items-center border-0 bg-transparent p-0 cursor-pointer"
|
||||||
|
type="button"
|
||||||
|
:aria-expanded="!effectiveCollapsed"
|
||||||
|
:aria-label="
|
||||||
|
formatMessage(effectiveCollapsed ? messages.expandGroup : messages.collapseGroup)
|
||||||
|
"
|
||||||
|
@click.stop="emit('toggleCollapse', sectionKey)"
|
||||||
|
>
|
||||||
|
<DropdownIcon
|
||||||
|
class="size-5 shrink-0 text-[var(--color-text-tertiary)] transition-transform duration-300"
|
||||||
|
:class="{ 'rotate-180': !effectiveCollapsed }"
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
<InlineEditableText
|
||||||
|
v-if="!isUngrouped && !isFavorites"
|
||||||
|
ref="groupNameInput"
|
||||||
|
v-model="groupName"
|
||||||
|
activation-mode="manual"
|
||||||
|
class="text-base font-semibold !h-10 text-[var(--color-text-default)] select-none"
|
||||||
|
max-width="24rem"
|
||||||
|
:max-length="MAX_GROUP_NAME_LENGTH"
|
||||||
|
:on-change="updateGroupName"
|
||||||
|
:validate="validateGroupName"
|
||||||
|
/>
|
||||||
|
<span v-else class="text-base font-semibold text-[var(--color-text-default)] select-none">
|
||||||
|
{{ isFavorites ? formatMessage(messages.pinned) : formatMessage(messages.ungrouped) }}
|
||||||
|
</span>
|
||||||
|
<TagItem v-if="instances.length" class="shrink-0 border-surface-3 bg-surface-2">
|
||||||
|
{{ instances.length }}
|
||||||
|
</TagItem>
|
||||||
|
</div>
|
||||||
|
<div class="min-w-0 flex-1" />
|
||||||
|
<div
|
||||||
|
v-if="isCustomGroup"
|
||||||
|
class="flex shrink-0 items-center opacity-0 transition-opacity duration-250 group-hover/header:opacity-100 focus-within:opacity-100"
|
||||||
|
>
|
||||||
|
<IconButton
|
||||||
|
v-tooltip="formatMessage(messages.moveGroupUp)"
|
||||||
|
:label="formatMessage(messages.moveGroupUp)"
|
||||||
|
type="quiet"
|
||||||
|
size="sm"
|
||||||
|
:disabled="!canMoveUp"
|
||||||
|
@click.stop="emit('moveGroup', sectionKey, -1)"
|
||||||
|
>
|
||||||
|
<ArrowUpIcon />
|
||||||
|
</IconButton>
|
||||||
|
<IconButton
|
||||||
|
v-tooltip="formatMessage(messages.moveGroupDown)"
|
||||||
|
:label="formatMessage(messages.moveGroupDown)"
|
||||||
|
type="quiet"
|
||||||
|
size="sm"
|
||||||
|
:disabled="!canMoveDown"
|
||||||
|
@click.stop="emit('moveGroup', sectionKey, 1)"
|
||||||
|
>
|
||||||
|
<ArrowDownIcon />
|
||||||
|
</IconButton>
|
||||||
|
<IconButton
|
||||||
|
v-tooltip="formatMessage(messages.editGroupName)"
|
||||||
|
:label="formatMessage(messages.editGroupName)"
|
||||||
|
type="quiet"
|
||||||
|
size="sm"
|
||||||
|
@click.stop="groupNameInput?.startEditing()"
|
||||||
|
>
|
||||||
|
<EditIcon />
|
||||||
|
</IconButton>
|
||||||
|
<IconButton
|
||||||
|
v-tooltip="formatMessage(messages.addToGroup)"
|
||||||
|
:label="formatMessage(messages.addToGroup)"
|
||||||
|
type="quiet"
|
||||||
|
size="sm"
|
||||||
|
@click.stop="emit('addToGroup', sectionKey)"
|
||||||
|
>
|
||||||
|
<PlusIcon />
|
||||||
|
</IconButton>
|
||||||
|
<IconButton
|
||||||
|
v-tooltip="formatMessage(messages.deleteGroup)"
|
||||||
|
:label="formatMessage(messages.deleteGroup)"
|
||||||
|
type="quiet"
|
||||||
|
size="sm"
|
||||||
|
:disabled="deletingGroup"
|
||||||
|
@click.stop="handleGroupOption({ option: 'delete_group' })"
|
||||||
|
>
|
||||||
|
<TrashIcon />
|
||||||
|
</IconButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-if="!effectiveCollapsed" class="mt-2.5">
|
||||||
|
<section
|
||||||
|
class="grid grid-cols-[repeat(auto-fill,minmax(16rem,1fr))] w-full gap-3 mr-auto scroll-smooth overflow-y-auto"
|
||||||
|
:class="{
|
||||||
|
'grid-cols-[repeat(auto-fill,minmax(13rem,1fr))] gap-4': displayMode === 'cards',
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
<template v-for="instance in instances" :key="instance.id">
|
||||||
|
<DraggableInstanceCard
|
||||||
|
v-if="isGroupDragActive"
|
||||||
|
:instance="instance"
|
||||||
|
:instance-group-id="sectionKey"
|
||||||
|
:disabled="selectMode"
|
||||||
|
@card-click="(event: MouseEvent) => onCardClick(instance.id, event)"
|
||||||
|
@contextmenu="
|
||||||
|
(event: MouseEvent) => emit('handleContextMenu', event, instance.id, props.sectionKey)
|
||||||
|
"
|
||||||
|
@start-long-press="onStartLongPress(instance.id)"
|
||||||
|
@cancel-long-press="emit('cancelLongPress')"
|
||||||
|
>
|
||||||
|
<template #default="{ isDragging }">
|
||||||
|
<div
|
||||||
|
:class="{
|
||||||
|
'pointer-events-none': selectMode,
|
||||||
|
'relative cursor-pointer select-none rounded-lg transition-all hover:brightness-90 active:scale-[0.98]': true,
|
||||||
|
}"
|
||||||
|
@click.capture="
|
||||||
|
(event: MouseEvent) => {
|
||||||
|
if (event.shiftKey && !selectMode) {
|
||||||
|
event.stopPropagation()
|
||||||
|
emit('handleCardClick', instance.id, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<Instance
|
||||||
|
:instance="instance"
|
||||||
|
:disabled="selectMode || isDragging"
|
||||||
|
:variant="displayMode === 'cards' ? 'library' : 'standard'"
|
||||||
|
:class="{
|
||||||
|
'opacity-50': selectMode && !selectedInstanceIds.has(instance.id),
|
||||||
|
}"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<template #overlay>
|
||||||
|
<div
|
||||||
|
class="absolute right-2 bottom-2 z-10 transition-opacity"
|
||||||
|
:class="
|
||||||
|
selectMode && selectedInstanceIds.has(instance.id)
|
||||||
|
? ''
|
||||||
|
: 'opacity-0 group-hover:opacity-100'
|
||||||
|
"
|
||||||
|
@click.stop="emit('handleCheckboxClick', instance.id, $event)"
|
||||||
|
>
|
||||||
|
<Checkbox :model-value="selectedInstanceIds.has(instance.id)" />
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-if="!selectMode"
|
||||||
|
class="absolute right-2 top-2 opacity-0 group-hover:opacity-100 transition-opacity"
|
||||||
|
@click.stop="
|
||||||
|
emit('handleContextMenu', $event as MouseEvent, instance.id, props.sectionKey)
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<Button type="quiet" size="2xs" circular icon-only
|
||||||
|
><slot name="moreIcon" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</DraggableInstanceCard>
|
||||||
|
|
||||||
|
<div v-else class="group relative">
|
||||||
|
<div
|
||||||
|
class="relative cursor-pointer select-none rounded-lg transition-all hover:brightness-90 active:scale-[0.98]"
|
||||||
|
@click.capture="
|
||||||
|
(event: MouseEvent) => {
|
||||||
|
if (event.shiftKey && !selectMode) {
|
||||||
|
event.stopPropagation()
|
||||||
|
emit('handleCardClick', instance.id, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"
|
||||||
|
@click="emit('handleCardClick', instance.id, $event as MouseEvent)"
|
||||||
|
@mousedown="!selectMode && emit('startLongPress', instance.id)"
|
||||||
|
@mouseup="emit('cancelLongPress')"
|
||||||
|
@mouseleave="emit('cancelLongPress')"
|
||||||
|
@touchstart="!selectMode && emit('startLongPress', instance.id)"
|
||||||
|
@touchend="emit('cancelLongPress')"
|
||||||
|
@touchcancel="emit('cancelLongPress')"
|
||||||
|
>
|
||||||
|
<div :class="{ 'pointer-events-none': selectMode }">
|
||||||
|
<Instance
|
||||||
|
:instance="instance"
|
||||||
|
:disabled="selectMode"
|
||||||
|
:variant="displayMode === 'cards' ? 'library' : 'standard'"
|
||||||
|
:class="{
|
||||||
|
'opacity-50': selectMode && !selectedInstanceIds.has(instance.id),
|
||||||
|
}"
|
||||||
|
@contextmenu.prevent.stop="
|
||||||
|
(event: MouseEvent) =>
|
||||||
|
emit('handleContextMenu', event, instance.id, props.sectionKey)
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="absolute right-2 bottom-2 z-10 transition-opacity"
|
||||||
|
:class="
|
||||||
|
selectMode && selectedInstanceIds.has(instance.id)
|
||||||
|
? ''
|
||||||
|
: 'opacity-0 group-hover:opacity-100'
|
||||||
|
"
|
||||||
|
@click.stop="emit('handleCheckboxClick', instance.id, $event)"
|
||||||
|
>
|
||||||
|
<Checkbox :model-value="selectedInstanceIds.has(instance.id)" />
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-if="!selectMode"
|
||||||
|
class="absolute right-2 top-2 opacity-0 group-hover:opacity-100 transition-opacity"
|
||||||
|
@click.stop="
|
||||||
|
emit('handleContextMenu', $event as MouseEvent, instance.id, props.sectionKey)
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<Button type="quiet" size="2xs" circular icon-only><slot name="moreIcon" /> </Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<p
|
||||||
|
v-if="instances.length === 0"
|
||||||
|
class="col-span-full m-0 pt-1 pl-0.5 text-base font-base text-[var(--color-text-tertiary)] opacity-80"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.emptyGroup) }}
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ContextMenu ref="groupOptions" @option-clicked="handleGroupOption">
|
||||||
|
<template #new_instance>
|
||||||
|
<PlusIcon />
|
||||||
|
{{ formatMessage(messages.newInstance) }}
|
||||||
|
</template>
|
||||||
|
<template #add_instances>
|
||||||
|
<PlusIcon />
|
||||||
|
{{ formatMessage(messages.addToGroup) }}
|
||||||
|
</template>
|
||||||
|
<template #edit_name>
|
||||||
|
<EditIcon />
|
||||||
|
{{ formatMessage(messages.editGroupName) }}
|
||||||
|
</template>
|
||||||
|
<template #delete_group>
|
||||||
|
<TrashIcon />
|
||||||
|
{{ formatMessage(messages.deleteGroup) }}
|
||||||
|
</template>
|
||||||
|
</ContextMenu>
|
||||||
|
|
||||||
|
<NewModal
|
||||||
|
ref="confirmDeleteGroupModal"
|
||||||
|
:header="formatMessage(messages.deleteGroup)"
|
||||||
|
fade="danger"
|
||||||
|
width="500px"
|
||||||
|
>
|
||||||
|
<p class="m-0 text-base text-[var(--color-text-default)]">
|
||||||
|
{{ formatMessage(messages.deleteGroupDescription) }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<template #actions>
|
||||||
|
<div class="flex justify-end gap-2">
|
||||||
|
<Button type="outlined" @click="confirmDeleteGroupModal?.hide()">
|
||||||
|
<XIcon />
|
||||||
|
{{ formatMessage(commonMessages.cancelButton) }}
|
||||||
|
</Button>
|
||||||
|
<Button type="colored" color="red" :disabled="deletingGroup" @click="removeGroup">
|
||||||
|
<TrashIcon />
|
||||||
|
{{ formatMessage(messages.deleteGroup) }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</NewModal>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
export interface CrashLogFile {
|
||||||
|
age: number
|
||||||
|
filename: string
|
||||||
|
log_type: 'InfoLog' | 'CrashReport' | 'JvmCrash' | 'LauncherLog'
|
||||||
|
output?: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
const RUN_ASSOCIATION_WINDOW_SECONDS = 3 * 60
|
||||||
|
|
||||||
|
export function shouldUseLogShareAutoAnalysis(settings: {
|
||||||
|
ai_source: 'logshare' | 'custom'
|
||||||
|
auto_upload: boolean
|
||||||
|
no_storage?: boolean
|
||||||
|
}): boolean {
|
||||||
|
return settings.ai_source === 'logshare' && settings.auto_upload
|
||||||
|
}
|
||||||
|
|
||||||
|
function isRelevantLog(file: CrashLogFile): boolean {
|
||||||
|
const lower = file.filename.toLowerCase()
|
||||||
|
if (file.log_type === 'CrashReport') return lower.endsWith('.txt')
|
||||||
|
if (file.log_type === 'JvmCrash') return lower.startsWith('hs_err') && lower.endsWith('.log')
|
||||||
|
return ['latest.log', 'debug.log', 'launcher_log.txt', 'latest_stdout.log'].includes(lower)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function selectCrashLogFiles(files: CrashLogFile[]): CrashLogFile[] {
|
||||||
|
const sorted = files.filter(isRelevantLog).sort((left, right) => right.age - left.age)
|
||||||
|
const anchor = sorted[0]?.age
|
||||||
|
if (anchor === undefined) return []
|
||||||
|
|
||||||
|
const singletonTypes = new Set<CrashLogFile['log_type']>()
|
||||||
|
return sorted.filter((file) => {
|
||||||
|
if (anchor - file.age > RUN_ASSOCIATION_WINDOW_SECONDS) return false
|
||||||
|
if (file.log_type !== 'CrashReport' && file.log_type !== 'JvmCrash') return true
|
||||||
|
if (singletonTypes.has(file.log_type)) return false
|
||||||
|
singletonTypes.add(file.log_type)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function crashLogKey(file: CrashLogFile): string {
|
||||||
|
return `${file.log_type}:${file.filename}`
|
||||||
|
}
|
||||||
|
|
||||||
|
export function crashLogLabel(file: CrashLogFile): string {
|
||||||
|
return file.log_type === 'CrashReport' ? `crash-reports/${file.filename}` : file.filename
|
||||||
|
}
|
||||||
|
|
||||||
|
export function preferredCrashLogKey(files: CrashLogFile[]): string {
|
||||||
|
const preferred =
|
||||||
|
files.find((file) => file.log_type === 'CrashReport') ??
|
||||||
|
files.find((file) => file.log_type === 'JvmCrash') ??
|
||||||
|
files.find((file) => file.filename.toLowerCase() === 'latest.log') ??
|
||||||
|
files[0]
|
||||||
|
return preferred ? crashLogKey(preferred) : ''
|
||||||
|
}
|
||||||
|
|
||||||
|
export function combineCrashLogs(files: CrashLogFile[]): string {
|
||||||
|
return files
|
||||||
|
.filter((file) => file.output)
|
||||||
|
.map((file) => `===== ${crashLogLabel(file)} =====\n${file.output}`)
|
||||||
|
.join('\n\n')
|
||||||
|
}
|
||||||
@@ -61,6 +61,7 @@ import {
|
|||||||
ButtonStyled,
|
ButtonStyled,
|
||||||
commonMessages,
|
commonMessages,
|
||||||
defineMessages,
|
defineMessages,
|
||||||
|
injectNotificationManager,
|
||||||
NewModal,
|
NewModal,
|
||||||
RadioButtons,
|
RadioButtons,
|
||||||
StyledInput,
|
StyledInput,
|
||||||
@@ -72,6 +73,7 @@ import { edit, list } from '@/helpers/instance'
|
|||||||
import type { GameInstance } from '@/helpers/types'
|
import type { GameInstance } from '@/helpers/types'
|
||||||
|
|
||||||
const { formatMessage } = useVIntl()
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError } = injectNotificationManager()
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
instanceIds: string[]
|
instanceIds: string[]
|
||||||
@@ -148,7 +150,7 @@ async function deleteGroup(group: string) {
|
|||||||
for (const instance of allInstances.value) {
|
for (const instance of allInstances.value) {
|
||||||
if (instance.groups.includes(group)) {
|
if (instance.groups.includes(group)) {
|
||||||
const newGroups = instance.groups.filter((g) => g !== group)
|
const newGroups = instance.groups.filter((g) => g !== group)
|
||||||
await edit(instance.id, { groups: newGroups }).catch(() => {})
|
await edit(instance.id, { groups: newGroups }).catch(handleError)
|
||||||
instance.groups = newGroups
|
instance.groups = newGroups
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -167,7 +169,7 @@ async function confirm() {
|
|||||||
const groups = selectedGroup.value ? [selectedGroup.value.trim().substring(0, 32)] : []
|
const groups = selectedGroup.value ? [selectedGroup.value.trim().substring(0, 32)] : []
|
||||||
|
|
||||||
for (const instanceId of props.instanceIds) {
|
for (const instanceId of props.instanceIds) {
|
||||||
await edit(instanceId, { groups }).catch(() => {})
|
await edit(instanceId, { groups }).catch(handleError)
|
||||||
}
|
}
|
||||||
|
|
||||||
emit('applied')
|
emit('applied')
|
||||||
|
|||||||
@@ -0,0 +1,313 @@
|
|||||||
|
<template>
|
||||||
|
<NewModal ref="modal" no-padding scrollable actions-divider max-width="560px" width="560px">
|
||||||
|
<template #title>
|
||||||
|
<span class="text-2xl font-semibold text-[var(--color-text-primary)]">
|
||||||
|
{{
|
||||||
|
existingGroupName
|
||||||
|
? formatMessage(messages.addToGroupTitle, { groupName: existingGroupName })
|
||||||
|
: formatMessage(messages.header)
|
||||||
|
}}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-if="!existingGroupName">
|
||||||
|
<div class="flex flex-col gap-2.5 p-6">
|
||||||
|
<label for="new-group-name" class="font-semibold text-[var(--color-text-primary)]">
|
||||||
|
{{ formatMessage(messages.groupName) }}
|
||||||
|
</label>
|
||||||
|
<StyledInput
|
||||||
|
id="new-group-name"
|
||||||
|
ref="groupNameInput"
|
||||||
|
v-model="newGroupName"
|
||||||
|
:placeholder="formatMessage(messages.groupNamePlaceholder)"
|
||||||
|
:maxlength="32"
|
||||||
|
@click="groupNameInput?.select()"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="h-px bg-divider" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div class="flex h-[400px] flex-col gap-3 overflow-y-auto bg-surface-2 py-4">
|
||||||
|
<div class="px-6">
|
||||||
|
<StyledInput
|
||||||
|
v-model="newGroupSearch"
|
||||||
|
:icon="SearchIcon"
|
||||||
|
:placeholder="formatMessage(messages.searchInstance)"
|
||||||
|
class="w-full"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="newGroupInstances.length === 0"
|
||||||
|
class="flex items-center justify-center py-12 text-[var(--color-text-tertiary)]"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.noInstancesFound) }}
|
||||||
|
</div>
|
||||||
|
<div v-else class="flex flex-col gap-1">
|
||||||
|
<div
|
||||||
|
v-for="instance in newGroupInstances"
|
||||||
|
:key="instance.id"
|
||||||
|
class="flex items-center justify-between gap-4 px-6 py-1.5 hover:bg-surface-3"
|
||||||
|
:class="{ 'opacity-60': selectedNewGroupInstanceIds.has(instance.id) }"
|
||||||
|
>
|
||||||
|
<div class="flex min-w-0 items-center gap-2.5">
|
||||||
|
<InstanceIcon
|
||||||
|
:icon-path="instance.icon_path"
|
||||||
|
:instance-id="instance.id"
|
||||||
|
:loader="instance.loader"
|
||||||
|
class="!size-[2rem] !rounded-md"
|
||||||
|
/>
|
||||||
|
<div class="flex min-w-0 items-center gap-2">
|
||||||
|
<span class="truncate font-semibold text-[var(--color-text-primary)]">{{
|
||||||
|
instance.name
|
||||||
|
}}</span>
|
||||||
|
<TagItem v-if="instance.groups && instance.groups.length > 0" class="shrink-0">
|
||||||
|
{{ getGroupName(instance.groups[0]) }}
|
||||||
|
</TagItem>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
:type="selectedNewGroupInstanceIds.has(instance.id) ? 'outlined' : 'base'"
|
||||||
|
@click="toggleNewGroupInstance(instance.id)"
|
||||||
|
>
|
||||||
|
<CheckIcon v-if="selectedNewGroupInstanceIds.has(instance.id)" />
|
||||||
|
{{
|
||||||
|
formatMessage(
|
||||||
|
selectedNewGroupInstanceIds.has(instance.id) ? messages.added : messages.add,
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template #actions>
|
||||||
|
<div class="flex items-center justify-end gap-2">
|
||||||
|
<Button type="outlined" @click="modal?.hide()">
|
||||||
|
<XIcon />
|
||||||
|
{{ formatMessage(messages.cancel) }}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="colored"
|
||||||
|
color="brand"
|
||||||
|
:disabled="existingGroupName ? !canSaveGroups : !canCreateGroup"
|
||||||
|
@click="existingGroupName ? handleSaveGroups() : handleCreateGroup()"
|
||||||
|
>
|
||||||
|
<SpinnerIcon v-if="creatingGroup" class="animate-spin" />
|
||||||
|
<CheckIcon v-else-if="existingGroupName" />
|
||||||
|
<PlusIcon v-else />
|
||||||
|
{{ formatMessage(existingGroupName ? messages.saveChanges : messages.createGroup) }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</NewModal>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { CheckIcon, PlusIcon, SearchIcon, SpinnerIcon, XIcon } from '@modrinth/assets'
|
||||||
|
import { Button, defineMessages, NewModal, StyledInput, TagItem, useVIntl } from '@modrinth/ui'
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
|
|
||||||
|
import InstanceIcon from '@/components/ui/InstanceIcon.vue'
|
||||||
|
import { FAVORITES_GROUP_ID } from '@/composables/useInstanceGroups'
|
||||||
|
import { list } from '@/helpers/instance'
|
||||||
|
import { create_group, list_groups, set_group_memberships } from '@/helpers/instance-groups'
|
||||||
|
import type { GameInstance } from '@/helpers/types'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
instanceIds: string[]
|
||||||
|
existingGroupName?: string
|
||||||
|
existingGroupId?: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'applied'): void
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
header: {
|
||||||
|
id: 'app.instances.batch-edit-groups.header',
|
||||||
|
defaultMessage: 'Create group',
|
||||||
|
},
|
||||||
|
addToGroupTitle: {
|
||||||
|
id: 'app.instances.batch-edit-groups.add-to-group-title',
|
||||||
|
defaultMessage: 'Add instances to "{groupName}"',
|
||||||
|
},
|
||||||
|
groupName: {
|
||||||
|
id: 'app.instances.batch-edit-groups.group-name',
|
||||||
|
defaultMessage: 'Group name',
|
||||||
|
},
|
||||||
|
groupNamePlaceholder: {
|
||||||
|
id: 'app.instances.batch-edit-groups.group-name-placeholder',
|
||||||
|
defaultMessage: 'Enter group name',
|
||||||
|
},
|
||||||
|
searchInstance: {
|
||||||
|
id: 'app.instances.batch-edit-groups.search-instance',
|
||||||
|
defaultMessage: 'Search instances',
|
||||||
|
},
|
||||||
|
noInstancesFound: {
|
||||||
|
id: 'app.instances.batch-edit-groups.no-instances-found',
|
||||||
|
defaultMessage: 'No instances found',
|
||||||
|
},
|
||||||
|
add: {
|
||||||
|
id: 'app.instances.batch-edit-groups.add',
|
||||||
|
defaultMessage: 'Add',
|
||||||
|
},
|
||||||
|
added: {
|
||||||
|
id: 'app.instances.batch-edit-groups.added',
|
||||||
|
defaultMessage: 'Added',
|
||||||
|
},
|
||||||
|
cancel: {
|
||||||
|
id: 'app.instances.batch-edit-groups.cancel',
|
||||||
|
defaultMessage: 'Cancel',
|
||||||
|
},
|
||||||
|
createGroup: {
|
||||||
|
id: 'app.instances.batch-edit-groups.create',
|
||||||
|
defaultMessage: 'Create group',
|
||||||
|
},
|
||||||
|
pinnedGroupName: {
|
||||||
|
id: 'app.instances.group.pinned',
|
||||||
|
defaultMessage: 'Pinned',
|
||||||
|
},
|
||||||
|
saveChanges: {
|
||||||
|
id: 'app.instances.batch-edit-groups.save-changes',
|
||||||
|
defaultMessage: 'Save',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const modal = ref<InstanceType<typeof NewModal>>()
|
||||||
|
const groupNameInput = ref<InstanceType<typeof StyledInput>>()
|
||||||
|
const newGroupName = ref('')
|
||||||
|
const newGroupSearch = ref('')
|
||||||
|
const creatingGroup = ref(false)
|
||||||
|
const allInstances = ref<GameInstance[]>([])
|
||||||
|
const groupNameMap = ref(new Map<string, string>())
|
||||||
|
const selectedNewGroupInstanceIds = ref(new Set<string>())
|
||||||
|
|
||||||
|
const canCreateGroup = computed(() => newGroupName.value.trim().length > 0)
|
||||||
|
|
||||||
|
const canSaveGroups = computed(() => {
|
||||||
|
if (!props.existingGroupName) return false
|
||||||
|
const groupId = props.existingGroupId
|
||||||
|
if (!groupId) return false
|
||||||
|
return allInstances.value.some((instance) => {
|
||||||
|
const isSelected = selectedNewGroupInstanceIds.value.has(instance.id)
|
||||||
|
const hasGroup = (instance.groups || []).includes(groupId)
|
||||||
|
return isSelected !== hasGroup
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const newGroupInstances = computed(() => {
|
||||||
|
const search = newGroupSearch.value.toLowerCase()
|
||||||
|
return allInstances.value.filter((instance) => {
|
||||||
|
if (!search) return true
|
||||||
|
return instance.name.toLowerCase().includes(search)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
function getGroupName(groupId: string) {
|
||||||
|
if (groupId === FAVORITES_GROUP_ID) {
|
||||||
|
return formatMessage(messages.pinnedGroupName)
|
||||||
|
}
|
||||||
|
return groupNameMap.value.get(groupId) || groupId
|
||||||
|
}
|
||||||
|
|
||||||
|
function show(ids?: string[]) {
|
||||||
|
newGroupSearch.value = ''
|
||||||
|
creatingGroup.value = false
|
||||||
|
Promise.all([list(), list_groups()]).then(([instances, groups]) => {
|
||||||
|
allInstances.value = instances as GameInstance[]
|
||||||
|
const map = new Map<string, string>()
|
||||||
|
for (const g of groups) {
|
||||||
|
map.set(g.id, g.name)
|
||||||
|
}
|
||||||
|
groupNameMap.value = map
|
||||||
|
|
||||||
|
if (!props.existingGroupName) {
|
||||||
|
const customGroups = groups.filter((g: { id: string }) => g.id !== 'group:favorites')
|
||||||
|
let groupNumber = customGroups.length + 1
|
||||||
|
const existingNames = new Set(groups.map((g: { name: string }) => g.name.toLowerCase()))
|
||||||
|
while (existingNames.has(`group ${groupNumber}`)) {
|
||||||
|
groupNumber++
|
||||||
|
}
|
||||||
|
newGroupName.value = `Group ${groupNumber}`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (props.existingGroupName) {
|
||||||
|
const groupId = props.existingGroupId
|
||||||
|
selectedNewGroupInstanceIds.value = new Set(
|
||||||
|
allInstances.value.filter((i) => (i.groups || []).includes(groupId || '')).map((i) => i.id),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
selectedNewGroupInstanceIds.value = new Set(ids ?? props.instanceIds)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
modal.value?.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleNewGroupInstance(instanceId: string) {
|
||||||
|
const next = new Set(selectedNewGroupInstanceIds.value)
|
||||||
|
if (next.has(instanceId)) {
|
||||||
|
next.delete(instanceId)
|
||||||
|
} else {
|
||||||
|
next.add(instanceId)
|
||||||
|
}
|
||||||
|
selectedNewGroupInstanceIds.value = next
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleCreateGroup() {
|
||||||
|
const name = newGroupName.value.trim()
|
||||||
|
if (!name || selectedNewGroupInstanceIds.value.size === 0) return
|
||||||
|
|
||||||
|
creatingGroup.value = true
|
||||||
|
|
||||||
|
const group = await create_group(name).catch(() => null)
|
||||||
|
if (!group) {
|
||||||
|
creatingGroup.value = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedNewGroupInstanceIds.value.size > 0) {
|
||||||
|
const updates = [...selectedNewGroupInstanceIds.value].map((instanceId) => ({
|
||||||
|
instance_id: instanceId,
|
||||||
|
group_ids: [group.id],
|
||||||
|
}))
|
||||||
|
await set_group_memberships(updates).catch(() => {})
|
||||||
|
}
|
||||||
|
|
||||||
|
creatingGroup.value = false
|
||||||
|
modal.value?.hide()
|
||||||
|
emit('applied')
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleSaveGroups() {
|
||||||
|
if (!props.existingGroupName) return
|
||||||
|
|
||||||
|
creatingGroup.value = true
|
||||||
|
const groupId = props.existingGroupId
|
||||||
|
|
||||||
|
const changedInstances = allInstances.value.filter((instance) => {
|
||||||
|
const isSelected = selectedNewGroupInstanceIds.value.has(instance.id)
|
||||||
|
const hasGroup = (instance.groups || []).includes(groupId || '')
|
||||||
|
return isSelected !== hasGroup
|
||||||
|
})
|
||||||
|
|
||||||
|
const updates = changedInstances.map((instance) => {
|
||||||
|
const isSelected = selectedNewGroupInstanceIds.value.has(instance.id)
|
||||||
|
return {
|
||||||
|
instance_id: instance.id,
|
||||||
|
group_ids: isSelected ? [groupId!] : [],
|
||||||
|
}
|
||||||
|
})
|
||||||
|
await set_group_memberships(updates).catch(() => {})
|
||||||
|
|
||||||
|
creatingGroup.value = false
|
||||||
|
modal.value?.hide()
|
||||||
|
emit('applied')
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ show })
|
||||||
|
</script>
|
||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
FileArchiveIcon,
|
FileArchiveIcon,
|
||||||
InfoIcon,
|
InfoIcon,
|
||||||
MonitorIcon,
|
MonitorIcon,
|
||||||
|
RefreshCwIcon,
|
||||||
WrenchIcon,
|
WrenchIcon,
|
||||||
} from '@modrinth/assets'
|
} from '@modrinth/assets'
|
||||||
import {
|
import {
|
||||||
@@ -20,8 +21,10 @@ import type { PlatformTag } from '@modrinth/utils'
|
|||||||
import { useQuery, useQueryClient } from '@tanstack/vue-query'
|
import { useQuery, useQueryClient } from '@tanstack/vue-query'
|
||||||
import { computed, nextTick, ref, watch } from 'vue'
|
import { computed, nextTick, ref, watch } from 'vue'
|
||||||
|
|
||||||
|
import BackupSettings from '@/components/ui/instance_settings/BackupSettings.vue'
|
||||||
import CoreComponentsSettings from '@/components/ui/instance_settings/CoreComponentsSettings.vue'
|
import CoreComponentsSettings from '@/components/ui/instance_settings/CoreComponentsSettings.vue'
|
||||||
import GeneralSettings from '@/components/ui/instance_settings/GeneralSettings.vue'
|
import GeneralSettings from '@/components/ui/instance_settings/GeneralSettings.vue'
|
||||||
|
import SyncSettings from '@/components/ui/instance_settings/SyncSettings.vue'
|
||||||
import HooksSettings from '@/components/ui/instance_settings/HooksSettings.vue'
|
import HooksSettings from '@/components/ui/instance_settings/HooksSettings.vue'
|
||||||
import InstallationSettings from '@/components/ui/instance_settings/InstallationSettings.vue'
|
import InstallationSettings from '@/components/ui/instance_settings/InstallationSettings.vue'
|
||||||
import JavaSettings from '@/components/ui/instance_settings/JavaSettings.vue'
|
import JavaSettings from '@/components/ui/instance_settings/JavaSettings.vue'
|
||||||
@@ -52,8 +55,9 @@ let serverMetadataGeneration = 0
|
|||||||
const instanceRef = computed(() => props.instance)
|
const instanceRef = computed(() => props.instance)
|
||||||
const tabbedModal = ref<InstanceType<typeof TabbedModal> | null>(null)
|
const tabbedModal = ref<InstanceType<typeof TabbedModal> | null>(null)
|
||||||
|
|
||||||
function hide() {
|
function hide(onAfterClose?: () => void) {
|
||||||
tabbedModal.value?.hide()
|
tabbedModal.value?.hide()
|
||||||
|
if (onAfterClose) nextTick(onAfterClose)
|
||||||
}
|
}
|
||||||
|
|
||||||
provideInstanceSettings({
|
provideInstanceSettings({
|
||||||
@@ -105,6 +109,14 @@ const tabs = computed<TabbedModalTab[]>(() => [
|
|||||||
icon: WrenchIcon,
|
icon: WrenchIcon,
|
||||||
content: InstallationSettings,
|
content: InstallationSettings,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: defineMessage({
|
||||||
|
id: 'instance.settings.tabs.backups',
|
||||||
|
defaultMessage: 'Backups',
|
||||||
|
}),
|
||||||
|
icon: FileArchiveIcon,
|
||||||
|
content: BackupSettings,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
// Core component editing is instance-specific and advanced, so it is intentionally excluded from first-run onboarding.
|
// Core component editing is instance-specific and advanced, so it is intentionally excluded from first-run onboarding.
|
||||||
name: defineMessage({
|
name: defineMessage({
|
||||||
@@ -138,6 +150,14 @@ const tabs = computed<TabbedModalTab[]>(() => [
|
|||||||
icon: CodeIcon,
|
icon: CodeIcon,
|
||||||
content: HooksSettings,
|
content: HooksSettings,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: defineMessage({
|
||||||
|
id: 'instance.settings.tabs.sync',
|
||||||
|
defaultMessage: 'Sync',
|
||||||
|
}),
|
||||||
|
icon: RefreshCwIcon,
|
||||||
|
content: SyncSettings,
|
||||||
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
function getSupportedModpackLoaders() {
|
function getSupportedModpackLoaders() {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ const progressWidth = computed(() => `${Math.min(100, (props.current / props.tot
|
|||||||
<h2 :id="`onboarding-title-${step.id}`">{{ formatMessage(step.title) }}</h2>
|
<h2 :id="`onboarding-title-${step.id}`">{{ formatMessage(step.title) }}</h2>
|
||||||
</div>
|
</div>
|
||||||
<ButtonStyled circular type="transparent">
|
<ButtonStyled circular type="transparent">
|
||||||
<button :aria-label="formatMessage(onboardingMessages.skip)" @click.stop="$emit('skip')">
|
<button data-onboarding-skip :aria-label="formatMessage(onboardingMessages.skip)" @click.stop="$emit('skip')">
|
||||||
<XIcon />
|
<XIcon />
|
||||||
</button>
|
</button>
|
||||||
</ButtonStyled>
|
</ButtonStyled>
|
||||||
|
|||||||
@@ -252,6 +252,42 @@ export const onboardingMessages = defineMessages({
|
|||||||
id: 'app.onboarding.instance-tabs.description',
|
id: 'app.onboarding.instance-tabs.description',
|
||||||
defaultMessage: 'Use these tabs for content, files, screenshots, worlds, and logs. Tidy chaos.',
|
defaultMessage: 'Use these tabs for content, files, screenshots, worlds, and logs. Tidy chaos.',
|
||||||
},
|
},
|
||||||
|
instanceContentTabTitle: {
|
||||||
|
id: 'app.onboarding.instance-content-tab.title',
|
||||||
|
defaultMessage: 'Content',
|
||||||
|
},
|
||||||
|
instanceContentTabDescription: {
|
||||||
|
id: 'app.onboarding.instance-content-tab.description',
|
||||||
|
defaultMessage:
|
||||||
|
'Manage this instance’s mods, resource packs, and shaders here. Search, enable or disable entries, check for updates, and browse for more.',
|
||||||
|
},
|
||||||
|
instanceFilesTabTitle: {
|
||||||
|
id: 'app.onboarding.instance-files-tab.title',
|
||||||
|
defaultMessage: 'Files',
|
||||||
|
},
|
||||||
|
instanceFilesTabDescription: {
|
||||||
|
id: 'app.onboarding.instance-files-tab.description',
|
||||||
|
defaultMessage:
|
||||||
|
'Browse the instance folder and open configs or logs in the built-in editor without leaving the launcher.',
|
||||||
|
},
|
||||||
|
instanceWorldsTabTitle: {
|
||||||
|
id: 'app.onboarding.instance-worlds-tab.title',
|
||||||
|
defaultMessage: 'Worlds',
|
||||||
|
},
|
||||||
|
instanceWorldsTabDescription: {
|
||||||
|
id: 'app.onboarding.instance-worlds-tab.description',
|
||||||
|
defaultMessage:
|
||||||
|
'Manage saved worlds: back them up, rename, edit world settings, and open the world folder.',
|
||||||
|
},
|
||||||
|
instanceLogsTabTitle: {
|
||||||
|
id: 'app.onboarding.instance-logs-tab.title',
|
||||||
|
defaultMessage: 'Logs',
|
||||||
|
},
|
||||||
|
instanceLogsTabDescription: {
|
||||||
|
id: 'app.onboarding.instance-logs-tab.description',
|
||||||
|
defaultMessage:
|
||||||
|
'Read the instance’s live logs to trace crashes and errors without digging through files.',
|
||||||
|
},
|
||||||
labTitle: {
|
labTitle: {
|
||||||
id: 'app.onboarding.lab.title',
|
id: 'app.onboarding.lab.title',
|
||||||
defaultMessage: 'Useful tools, built in',
|
defaultMessage: 'Useful tools, built in',
|
||||||
@@ -509,15 +545,29 @@ export const onboardingTours: Record<OnboardingMode, OnboardingStep[]> = {
|
|||||||
onboardingMessages.instanceActionsTitle,
|
onboardingMessages.instanceActionsTitle,
|
||||||
onboardingMessages.instanceActionsDescription,
|
onboardingMessages.instanceActionsDescription,
|
||||||
),
|
),
|
||||||
step(
|
inspect(
|
||||||
'instance-tabs',
|
'instance-content-tab',
|
||||||
'inspect',
|
'instance-tab-content',
|
||||||
copy(
|
onboardingMessages.instanceContentTabTitle,
|
||||||
onboardingMessages.instanceTabsTitle,
|
onboardingMessages.instanceContentTabDescription,
|
||||||
onboardingMessages.instanceTabsDescription,
|
),
|
||||||
onboardingMessages.finishArea,
|
inspect(
|
||||||
),
|
'instance-files-tab',
|
||||||
{ targetId: 'instance-tabs' },
|
'instance-tab-files',
|
||||||
|
onboardingMessages.instanceFilesTabTitle,
|
||||||
|
onboardingMessages.instanceFilesTabDescription,
|
||||||
|
),
|
||||||
|
inspect(
|
||||||
|
'instance-worlds-tab',
|
||||||
|
'instance-tab-worlds',
|
||||||
|
onboardingMessages.instanceWorldsTabTitle,
|
||||||
|
onboardingMessages.instanceWorldsTabDescription,
|
||||||
|
),
|
||||||
|
inspect(
|
||||||
|
'instance-logs-tab',
|
||||||
|
'instance-tab-logs',
|
||||||
|
onboardingMessages.instanceLogsTabTitle,
|
||||||
|
onboardingMessages.instanceLogsTabDescription,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,6 +197,27 @@ export function useOnboardingTour(
|
|||||||
requestAnimationFrame(updateRect)
|
requestAnimationFrame(updateRect)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bring the current step target into view when the tour jumps to a step
|
||||||
|
// whose target lives inside a scrollable container (e.g. the settings
|
||||||
|
// sidebar). Without this the bubble can point at an off-screen element.
|
||||||
|
function ensureTargetVisible() {
|
||||||
|
const target = targetElement.value
|
||||||
|
if (!target) return
|
||||||
|
const rect = target.getBoundingClientRect()
|
||||||
|
const outOfView =
|
||||||
|
rect.top < 0 ||
|
||||||
|
rect.left < 0 ||
|
||||||
|
rect.bottom > window.innerHeight ||
|
||||||
|
rect.right > window.innerWidth
|
||||||
|
if (!outOfView) return
|
||||||
|
target.scrollIntoView({ block: 'center', inline: 'nearest', behavior: 'smooth' })
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
if (targetElement.value === target) {
|
||||||
|
targetRect.value = target.getBoundingClientRect()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function goTo(destination: StepDestination) {
|
function goTo(destination: StepDestination) {
|
||||||
if (destination === 'complete') {
|
if (destination === 'complete') {
|
||||||
events.complete()
|
events.complete()
|
||||||
@@ -279,8 +300,11 @@ export function useOnboardingTour(
|
|||||||
function handleDocumentClick(event: MouseEvent) {
|
function handleDocumentClick(event: MouseEvent) {
|
||||||
if (!visible.value) return
|
if (!visible.value) return
|
||||||
const clickedElement = event.target instanceof Element ? event.target : null
|
const clickedElement = event.target instanceof Element ? event.target : null
|
||||||
if (clickedElement?.closest('[data-onboarding-overlay-ui]')) return
|
|
||||||
|
|
||||||
|
// 跳过/关闭按钮由其自身处理,不在全局点击里推进
|
||||||
|
if (clickedElement?.closest('[data-onboarding-skip]')) return
|
||||||
|
|
||||||
|
// inspect 步:点击任意位置(含导览气泡本身)都继续下一步
|
||||||
if (step.value.interaction === 'inspect') {
|
if (step.value.interaction === 'inspect') {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
event.stopImmediatePropagation()
|
event.stopImmediatePropagation()
|
||||||
@@ -288,6 +312,9 @@ export function useOnboardingTour(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 非 inspect 步:点在导览 UI 自身时不处理
|
||||||
|
if (clickedElement?.closest('[data-onboarding-overlay-ui]')) return
|
||||||
|
|
||||||
if (!step.value.targetId || !['navigate', 'activate'].includes(step.value.interaction)) return
|
if (!step.value.targetId || !['navigate', 'activate'].includes(step.value.interaction)) return
|
||||||
if (clickedElement && handleBranchClick(clickedElement)) return
|
if (clickedElement && handleBranchClick(clickedElement)) return
|
||||||
if (!targetElement.value?.contains(event.target as Node)) return
|
if (!targetElement.value?.contains(event.target as Node)) return
|
||||||
@@ -337,6 +364,7 @@ export function useOnboardingTour(
|
|||||||
await nextTick()
|
await nextTick()
|
||||||
updateBubbleSize()
|
updateBubbleSize()
|
||||||
updateTarget()
|
updateTarget()
|
||||||
|
ensureTargetVisible()
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(mode, () => {
|
watch(mode, () => {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import { convertFileSrc } from '@tauri-apps/api/core'
|
|||||||
import { appDataDir, join } from '@tauri-apps/api/path'
|
import { appDataDir, join } from '@tauri-apps/api/path'
|
||||||
import { open } from '@tauri-apps/plugin-dialog'
|
import { open } from '@tauri-apps/plugin-dialog'
|
||||||
import { exists, mkdir, readFile, remove, writeFile } from '@tauri-apps/plugin-fs'
|
import { exists, mkdir, readFile, remove, writeFile } from '@tauri-apps/plugin-fs'
|
||||||
import { computed, ref, watch } from 'vue'
|
import { computed, onMounted, ref, watch } from 'vue'
|
||||||
|
|
||||||
import { get, set } from '@/helpers/settings.ts'
|
import { get, set } from '@/helpers/settings.ts'
|
||||||
import { getOS } from '@/helpers/utils'
|
import { getOS } from '@/helpers/utils'
|
||||||
@@ -41,6 +41,19 @@ import {
|
|||||||
parseCustomAccentColor,
|
parseCustomAccentColor,
|
||||||
} from '@/store/theme.ts'
|
} from '@/store/theme.ts'
|
||||||
|
|
||||||
|
import {
|
||||||
|
buildFontFamilyOptions,
|
||||||
|
canonicalFontFamily,
|
||||||
|
DEFAULT_MONO_FONT_STACK,
|
||||||
|
DEFAULT_UI_FONT_STACK,
|
||||||
|
type FontFamilyOption,
|
||||||
|
type FontFamilyOptionOrDivider,
|
||||||
|
optionValueToFontSetting,
|
||||||
|
resolveFontFamily,
|
||||||
|
type SystemFontFamily,
|
||||||
|
} from '@/helpers/font-family.ts'
|
||||||
|
import { getSystemFontFamilies } from '@/helpers/system-fonts.ts'
|
||||||
|
|
||||||
import SettingsRow from './SettingsRow.vue'
|
import SettingsRow from './SettingsRow.vue'
|
||||||
import SettingsSection from './SettingsSection.vue'
|
import SettingsSection from './SettingsSection.vue'
|
||||||
|
|
||||||
@@ -363,6 +376,63 @@ const messages = defineMessages({
|
|||||||
defaultMessage:
|
defaultMessage:
|
||||||
'Hide the downloads button in the sidebar when there are no active download tasks.',
|
'Hide the downloads button in the sidebar when there are no active download tasks.',
|
||||||
},
|
},
|
||||||
|
fontsTitle: { id: 'app.appearance-settings.fonts.title', defaultMessage: 'Fonts' },
|
||||||
|
fontsDescription: {
|
||||||
|
id: 'app.appearance-settings.fonts.description',
|
||||||
|
defaultMessage: 'Choose the fonts the launcher interface and its logs are rendered in.',
|
||||||
|
},
|
||||||
|
uiFontTitle: { id: 'app.appearance-settings.fonts.ui-font', defaultMessage: 'Interface font' },
|
||||||
|
uiFontDescription: {
|
||||||
|
id: 'app.appearance-settings.fonts.ui-font-description',
|
||||||
|
defaultMessage:
|
||||||
|
'Used across the launcher interface. Only fonts installed on this system are listed.',
|
||||||
|
},
|
||||||
|
monoFontTitle: {
|
||||||
|
id: 'app.appearance-settings.fonts.mono-font',
|
||||||
|
defaultMessage: 'Monospace font',
|
||||||
|
},
|
||||||
|
monoFontDescription: {
|
||||||
|
id: 'app.appearance-settings.fonts.mono-font-description',
|
||||||
|
defaultMessage: 'Used for logs, the server console, and other monospace content.',
|
||||||
|
},
|
||||||
|
fontDefault: {
|
||||||
|
id: 'app.appearance-settings.fonts.default',
|
||||||
|
defaultMessage: 'Launcher default',
|
||||||
|
},
|
||||||
|
fontMonospace: {
|
||||||
|
id: 'app.appearance-settings.fonts.monospace',
|
||||||
|
defaultMessage: 'Monospace',
|
||||||
|
},
|
||||||
|
fontMissing: {
|
||||||
|
id: 'app.appearance-settings.fonts.missing',
|
||||||
|
defaultMessage: 'Not installed',
|
||||||
|
},
|
||||||
|
fontSearchPlaceholder: {
|
||||||
|
id: 'app.appearance-settings.fonts.search-placeholder',
|
||||||
|
defaultMessage: 'Search installed fonts',
|
||||||
|
},
|
||||||
|
fontNoResults: {
|
||||||
|
id: 'app.appearance-settings.fonts.no-results',
|
||||||
|
defaultMessage: 'No matching fonts',
|
||||||
|
},
|
||||||
|
fontLoadFailed: {
|
||||||
|
id: 'app.appearance-settings.fonts.load-failed',
|
||||||
|
defaultMessage: "Couldn't read the list of installed fonts.",
|
||||||
|
},
|
||||||
|
fontRetry: { id: 'app.appearance-settings.fonts.retry', defaultMessage: 'Retry' },
|
||||||
|
fontReset: {
|
||||||
|
id: 'app.appearance-settings.fonts.reset',
|
||||||
|
defaultMessage: 'Reset',
|
||||||
|
},
|
||||||
|
fontPreviewLabel: { id: 'app.appearance-settings.fonts.preview', defaultMessage: 'Preview' },
|
||||||
|
fontUiPreviewSample: {
|
||||||
|
id: 'app.appearance-settings.fonts.ui-preview-sample',
|
||||||
|
defaultMessage: 'The quick brown fox jumps over the lazy dog.',
|
||||||
|
},
|
||||||
|
fontMonoPreviewSample: {
|
||||||
|
id: 'app.appearance-settings.fonts.mono-preview-sample',
|
||||||
|
defaultMessage: 'const x = () => 0; // monospace',
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const os = ref(await getOS())
|
const os = ref(await getOS())
|
||||||
@@ -373,6 +443,78 @@ const customBackgroundPreview = computed(() =>
|
|||||||
: null,
|
: null,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const systemFonts = ref<SystemFontFamily[]>([])
|
||||||
|
const systemFontsLoading = ref(true)
|
||||||
|
const systemFontsFailed = ref(false)
|
||||||
|
|
||||||
|
async function loadSystemFonts() {
|
||||||
|
systemFontsLoading.value = true
|
||||||
|
systemFontsFailed.value = false
|
||||||
|
|
||||||
|
try {
|
||||||
|
systemFonts.value = await getSystemFontFamilies()
|
||||||
|
} catch (error) {
|
||||||
|
systemFontsFailed.value = true
|
||||||
|
console.warn('Failed to read the list of installed fonts', error)
|
||||||
|
} finally {
|
||||||
|
systemFontsLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectedOptionLabel(options: FontFamilyOptionOrDivider[], value: string): string {
|
||||||
|
const option = options.find(
|
||||||
|
(entry): entry is FontFamilyOption => 'value' in entry && entry.value === value,
|
||||||
|
)
|
||||||
|
|
||||||
|
return option?.label ?? ''
|
||||||
|
}
|
||||||
|
|
||||||
|
const uiFontOptions = computed<FontFamilyOptionOrDivider[]>(() =>
|
||||||
|
buildFontFamilyOptions(systemFonts.value, {
|
||||||
|
defaultLabel: formatMessage(messages.fontDefault),
|
||||||
|
missingLabel: formatMessage(messages.fontMissing),
|
||||||
|
selected: settings.value.ui_font,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
const monoFontOptions = computed<FontFamilyOptionOrDivider[]>(() =>
|
||||||
|
buildFontFamilyOptions(systemFonts.value, {
|
||||||
|
defaultLabel: formatMessage(messages.fontDefault),
|
||||||
|
missingLabel: formatMessage(messages.fontMissing),
|
||||||
|
monospaceLabel: formatMessage(messages.fontMonospace),
|
||||||
|
selected: settings.value.mono_font,
|
||||||
|
groupMonospaced: true,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
const uiFontSelection = computed({
|
||||||
|
get: () => canonicalFontFamily(systemFonts.value, settings.value.ui_font),
|
||||||
|
set: (value: string) => {
|
||||||
|
settings.value.ui_font = optionValueToFontSetting(value)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const monoFontSelection = computed({
|
||||||
|
get: () => canonicalFontFamily(systemFonts.value, settings.value.mono_font),
|
||||||
|
set: (value: string) => {
|
||||||
|
settings.value.mono_font = optionValueToFontSetting(value)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const uiFontSearchValue = computed(() =>
|
||||||
|
selectedOptionLabel(uiFontOptions.value, uiFontSelection.value),
|
||||||
|
)
|
||||||
|
const monoFontSearchValue = computed(() =>
|
||||||
|
selectedOptionLabel(monoFontOptions.value, monoFontSelection.value),
|
||||||
|
)
|
||||||
|
|
||||||
|
const uiFontPreview = computed(() =>
|
||||||
|
resolveFontFamily(settings.value.ui_font, DEFAULT_UI_FONT_STACK),
|
||||||
|
)
|
||||||
|
const monoFontPreview = computed(() =>
|
||||||
|
resolveFontFamily(settings.value.mono_font, DEFAULT_MONO_FONT_STACK),
|
||||||
|
)
|
||||||
|
|
||||||
function updateUiScale(value: number) {
|
function updateUiScale(value: number) {
|
||||||
const clamped = Math.min(200, Math.max(50, Math.round(value)))
|
const clamped = Math.min(200, Math.max(50, Math.round(value)))
|
||||||
setUiScale(clamped)
|
setUiScale(clamped)
|
||||||
@@ -489,6 +631,8 @@ watch(
|
|||||||
settings.value.transparent_background_blur,
|
settings.value.transparent_background_blur,
|
||||||
settings.value.sidebar_instance_count,
|
settings.value.sidebar_instance_count,
|
||||||
settings.value.close_behavior,
|
settings.value.close_behavior,
|
||||||
|
settings.value.ui_font,
|
||||||
|
settings.value.mono_font,
|
||||||
] as const,
|
] as const,
|
||||||
([
|
([
|
||||||
path,
|
path,
|
||||||
@@ -499,6 +643,8 @@ watch(
|
|||||||
transparentBlur,
|
transparentBlur,
|
||||||
sidebarInstanceCount,
|
sidebarInstanceCount,
|
||||||
closeBehavior,
|
closeBehavior,
|
||||||
|
uiFont,
|
||||||
|
monoFont,
|
||||||
]) => {
|
]) => {
|
||||||
themeStore.customBackgroundPath = path
|
themeStore.customBackgroundPath = path
|
||||||
themeStore.customBackgroundBlur = blur
|
themeStore.customBackgroundBlur = blur
|
||||||
@@ -509,10 +655,19 @@ watch(
|
|||||||
themeStore.setTransparentBackgroundClass()
|
themeStore.setTransparentBackgroundClass()
|
||||||
themeStore.sidebarInstanceCount = sidebarInstanceCount
|
themeStore.sidebarInstanceCount = sidebarInstanceCount
|
||||||
themeStore.closeBehavior = closeBehavior as CloseBehavior
|
themeStore.closeBehavior = closeBehavior as CloseBehavior
|
||||||
|
themeStore.uiFont = uiFont
|
||||||
|
themeStore.monoFont = monoFont
|
||||||
|
themeStore.setUiFont()
|
||||||
|
themeStore.setMonoFont()
|
||||||
},
|
},
|
||||||
{ immediate: true },
|
{ immediate: true },
|
||||||
)
|
)
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
if (props.scope === 'interface') {
|
||||||
|
void loadSystemFonts()
|
||||||
|
}
|
||||||
|
})
|
||||||
watch(
|
watch(
|
||||||
settings,
|
settings,
|
||||||
async () => {
|
async () => {
|
||||||
@@ -1148,6 +1303,118 @@ watch(
|
|||||||
</SettingsRow>
|
</SettingsRow>
|
||||||
</SettingsSection>
|
</SettingsSection>
|
||||||
|
|
||||||
|
<SettingsSection v-if="props.scope === 'interface'">
|
||||||
|
<template #header>
|
||||||
|
<h2
|
||||||
|
id="settings-target-appearance-fonts"
|
||||||
|
tabindex="-1"
|
||||||
|
class="m-0 text-lg font-semibold text-contrast"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.fontsTitle) }}
|
||||||
|
</h2>
|
||||||
|
<p class="m-0 mt-1 text-sm leading-relaxed text-secondary">
|
||||||
|
{{ formatMessage(messages.fontsDescription) }}
|
||||||
|
</p>
|
||||||
|
</template>
|
||||||
|
<SettingsRow stacked>
|
||||||
|
<template #label>
|
||||||
|
<span id="settings-target-appearance-ui-font" tabindex="-1">
|
||||||
|
{{ formatMessage(messages.uiFontTitle) }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
<template #description>{{ formatMessage(messages.uiFontDescription) }}</template>
|
||||||
|
<template #control>
|
||||||
|
<div class="flex w-full flex-col gap-3">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<div class="min-w-0 flex-1">
|
||||||
|
<Combobox
|
||||||
|
v-model="uiFontSelection"
|
||||||
|
:options="uiFontOptions"
|
||||||
|
searchable
|
||||||
|
:search-value="uiFontSearchValue"
|
||||||
|
:search-placeholder="formatMessage(messages.fontSearchPlaceholder)"
|
||||||
|
:no-options-message="formatMessage(messages.fontNoResults)"
|
||||||
|
show-no-options-when-empty
|
||||||
|
:disabled="systemFontsLoading"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
type="quiet"
|
||||||
|
:disabled="settings.ui_font === null"
|
||||||
|
@click="settings.ui_font = null"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.fontReset) }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col gap-1">
|
||||||
|
<span class="text-xs text-secondary">
|
||||||
|
{{ formatMessage(messages.fontPreviewLabel) }}
|
||||||
|
</span>
|
||||||
|
<div
|
||||||
|
class="rounded-[var(--radius-md)] bg-surface-3 px-3 py-2 text-base text-contrast"
|
||||||
|
:style="{ fontFamily: uiFontPreview }"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.fontUiPreviewSample) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</SettingsRow>
|
||||||
|
<SettingsRow stacked>
|
||||||
|
<template #label>
|
||||||
|
<span id="settings-target-appearance-mono-font" tabindex="-1">
|
||||||
|
{{ formatMessage(messages.monoFontTitle) }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
<template #description>{{ formatMessage(messages.monoFontDescription) }}</template>
|
||||||
|
<template #control>
|
||||||
|
<div class="flex w-full flex-col gap-3">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<div class="min-w-0 flex-1">
|
||||||
|
<Combobox
|
||||||
|
v-model="monoFontSelection"
|
||||||
|
:options="monoFontOptions"
|
||||||
|
searchable
|
||||||
|
:search-value="monoFontSearchValue"
|
||||||
|
:search-placeholder="formatMessage(messages.fontSearchPlaceholder)"
|
||||||
|
:no-options-message="formatMessage(messages.fontNoResults)"
|
||||||
|
show-no-options-when-empty
|
||||||
|
:disabled="systemFontsLoading"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
type="quiet"
|
||||||
|
:disabled="settings.mono_font === null"
|
||||||
|
@click="settings.mono_font = null"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.fontReset) }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col gap-1">
|
||||||
|
<span class="text-xs text-secondary">
|
||||||
|
{{ formatMessage(messages.fontPreviewLabel) }}
|
||||||
|
</span>
|
||||||
|
<div
|
||||||
|
class="rounded-[var(--radius-md)] bg-surface-3 px-3 py-2 text-xs text-contrast"
|
||||||
|
:style="{ fontFamily: monoFontPreview }"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.fontMonoPreviewSample) }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</SettingsRow>
|
||||||
|
<div
|
||||||
|
v-if="systemFontsFailed"
|
||||||
|
class="flex items-center justify-between gap-3 px-4 pb-4 text-sm text-secondary"
|
||||||
|
>
|
||||||
|
<span>{{ formatMessage(messages.fontLoadFailed) }}</span>
|
||||||
|
<Button type="quiet" @click="loadSystemFonts">
|
||||||
|
{{ formatMessage(messages.fontRetry) }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</SettingsSection>
|
||||||
|
|
||||||
<SettingsSection v-if="props.scope === 'content-downloads'">
|
<SettingsSection v-if="props.scope === 'content-downloads'">
|
||||||
<SettingsRow>
|
<SettingsRow>
|
||||||
<template #label>
|
<template #label>
|
||||||
|
|||||||
@@ -0,0 +1,167 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { FolderIcon } from '@modrinth/assets'
|
||||||
|
import {
|
||||||
|
Admonition,
|
||||||
|
Button,
|
||||||
|
defineMessages,
|
||||||
|
injectFilePicker,
|
||||||
|
injectNotificationManager,
|
||||||
|
useFormatBytes,
|
||||||
|
useVIntl,
|
||||||
|
} from '@modrinth/ui'
|
||||||
|
import { onMounted, onUnmounted, ref } from 'vue'
|
||||||
|
|
||||||
|
import {
|
||||||
|
type BackupRepositoryStatus,
|
||||||
|
getBackupRepositoryStatus,
|
||||||
|
listBackupOperations,
|
||||||
|
listenBackupProgress,
|
||||||
|
moveBackupRepository,
|
||||||
|
} from '@/helpers/instance-backup'
|
||||||
|
|
||||||
|
import SettingsRow from './SettingsRow.vue'
|
||||||
|
import SettingsSection from './SettingsSection.vue'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const formatBytes = useFormatBytes()
|
||||||
|
const filePicker = injectFilePicker()
|
||||||
|
const { handleError } = injectNotificationManager()
|
||||||
|
const status = ref<BackupRepositoryStatus | null>(null)
|
||||||
|
const loading = ref(true)
|
||||||
|
const moving = ref(false)
|
||||||
|
const movedBytes = ref(0)
|
||||||
|
const moveTotalBytes = ref(0)
|
||||||
|
const movingOperationId = ref<string | null>(null)
|
||||||
|
let unlisten: (() => void) | null = null
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'settings.backups.repository.title', defaultMessage: 'Backup repository' },
|
||||||
|
description: {
|
||||||
|
id: 'settings.backups.repository.description',
|
||||||
|
defaultMessage: 'Deduplicated instance backup data and its independent index database.',
|
||||||
|
},
|
||||||
|
location: { id: 'settings.backups.repository.location', defaultMessage: 'Location' },
|
||||||
|
locationDescription: {
|
||||||
|
id: 'settings.backups.repository.location-description',
|
||||||
|
defaultMessage:
|
||||||
|
'Changing the location moves the complete repository. Choose a new or empty folder.',
|
||||||
|
},
|
||||||
|
change: { id: 'settings.backups.repository.change', defaultMessage: 'Change folder' },
|
||||||
|
moving: { id: 'settings.backups.repository.moving', defaultMessage: 'Moving repository...' },
|
||||||
|
movingProgress: {
|
||||||
|
id: 'settings.backups.repository.moving-progress',
|
||||||
|
defaultMessage: 'Moving repository: {processed} of {total}',
|
||||||
|
},
|
||||||
|
usage: { id: 'settings.backups.repository.usage', defaultMessage: 'Storage usage' },
|
||||||
|
usageDescription: {
|
||||||
|
id: 'settings.backups.repository.usage-description',
|
||||||
|
defaultMessage:
|
||||||
|
'{stored} stored for {logical} of backup data across {count, plural, one {# snapshot} other {# snapshots}}.',
|
||||||
|
},
|
||||||
|
unavailable: {
|
||||||
|
id: 'settings.backups.repository.unavailable',
|
||||||
|
defaultMessage: 'Repository unavailable',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
async function refresh() {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
status.value = await getBackupRepositoryStatus()
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function changeLocation() {
|
||||||
|
const selection = await filePicker.pickFolder?.()
|
||||||
|
if (!selection) return
|
||||||
|
moving.value = true
|
||||||
|
movedBytes.value = 0
|
||||||
|
moveTotalBytes.value = 0
|
||||||
|
try {
|
||||||
|
movingOperationId.value = await moveBackupRepository(selection.path)
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
moving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
unlisten = await listenBackupProgress((event) => {
|
||||||
|
if (event.operationType !== 'repository_move') return
|
||||||
|
if (movingOperationId.value && event.operationId !== movingOperationId.value) return
|
||||||
|
movingOperationId.value = event.operationId
|
||||||
|
moving.value = !event.finalState
|
||||||
|
movedBytes.value = event.processedBytes
|
||||||
|
moveTotalBytes.value = event.totalBytes
|
||||||
|
if (event.finalState) void refresh()
|
||||||
|
})
|
||||||
|
const activeMove = (await listBackupOperations(undefined, true)).find(
|
||||||
|
(operation) => operation.operation_type === 'repository_move',
|
||||||
|
)
|
||||||
|
if (activeMove) {
|
||||||
|
movingOperationId.value = activeMove.id
|
||||||
|
moving.value = true
|
||||||
|
movedBytes.value = activeMove.processed_bytes
|
||||||
|
moveTotalBytes.value = activeMove.total_bytes
|
||||||
|
}
|
||||||
|
await refresh()
|
||||||
|
})
|
||||||
|
|
||||||
|
onUnmounted(() => unlisten?.())
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<SettingsSection
|
||||||
|
:title="formatMessage(messages.title)"
|
||||||
|
:description="formatMessage(messages.description)"
|
||||||
|
>
|
||||||
|
<SettingsRow>
|
||||||
|
<template #label>{{ formatMessage(messages.location) }}</template>
|
||||||
|
<template #description>
|
||||||
|
<span class="break-all">{{ status?.path ?? '...' }}</span>
|
||||||
|
<span class="mt-1 block">{{ formatMessage(messages.locationDescription) }}</span>
|
||||||
|
</template>
|
||||||
|
<template #control>
|
||||||
|
<Button type="outlined" :disabled="loading || moving" @click="changeLocation"
|
||||||
|
><FolderIcon />
|
||||||
|
{{
|
||||||
|
formatMessage(
|
||||||
|
moving && moveTotalBytes > 0
|
||||||
|
? messages.movingProgress
|
||||||
|
: moving
|
||||||
|
? messages.moving
|
||||||
|
: messages.change,
|
||||||
|
{
|
||||||
|
processed: formatBytes(movedBytes),
|
||||||
|
total: formatBytes(moveTotalBytes),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}}
|
||||||
|
</Button>
|
||||||
|
</template>
|
||||||
|
</SettingsRow>
|
||||||
|
<SettingsRow v-if="status">
|
||||||
|
<template #label>{{ formatMessage(messages.usage) }}</template>
|
||||||
|
<template #description>
|
||||||
|
{{
|
||||||
|
formatMessage(messages.usageDescription, {
|
||||||
|
stored: formatBytes(status.stored_size),
|
||||||
|
logical: formatBytes(status.logical_size),
|
||||||
|
count: status.snapshot_count,
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
</template>
|
||||||
|
</SettingsRow>
|
||||||
|
<Admonition
|
||||||
|
v-if="status && !status.available"
|
||||||
|
type="critical"
|
||||||
|
:header="formatMessage(messages.unavailable)"
|
||||||
|
>
|
||||||
|
{{ status.error }}
|
||||||
|
</Admonition>
|
||||||
|
</SettingsSection>
|
||||||
|
</template>
|
||||||
@@ -6,6 +6,8 @@ import { ref, watch } from 'vue'
|
|||||||
import { get, set } from '@/helpers/settings.ts'
|
import { get, set } from '@/helpers/settings.ts'
|
||||||
|
|
||||||
import CrashAnalysisAISettings from './CrashAnalysisAISettings.vue'
|
import CrashAnalysisAISettings from './CrashAnalysisAISettings.vue'
|
||||||
|
import LogShareSettings from './LogShareSettings.vue'
|
||||||
|
import SharedLogsSettings from './SharedLogsSettings.vue'
|
||||||
import SettingsRow from './SettingsRow.vue'
|
import SettingsRow from './SettingsRow.vue'
|
||||||
import SettingsSection from './SettingsSection.vue'
|
import SettingsSection from './SettingsSection.vue'
|
||||||
|
|
||||||
@@ -38,6 +40,26 @@ const messages = defineMessages({
|
|||||||
id: 'app.settings.defaults.maximize-window.unsupported',
|
id: 'app.settings.defaults.maximize-window.unsupported',
|
||||||
defaultMessage: 'Not supported on this operating system.',
|
defaultMessage: 'Not supported on this operating system.',
|
||||||
},
|
},
|
||||||
|
windowTitleEnabled: {
|
||||||
|
id: 'app.settings.defaults.window-title.enabled',
|
||||||
|
defaultMessage: 'Custom Minecraft window title',
|
||||||
|
},
|
||||||
|
windowTitleEnabledDescription: {
|
||||||
|
id: 'app.settings.defaults.window-title.enabled-description',
|
||||||
|
defaultMessage: 'Allow instances to customize the Minecraft window title.',
|
||||||
|
},
|
||||||
|
defaultWindowTitle: {
|
||||||
|
id: 'app.settings.defaults.window-title.default',
|
||||||
|
defaultMessage: 'Default window title',
|
||||||
|
},
|
||||||
|
defaultWindowTitleDescription: {
|
||||||
|
id: 'app.settings.defaults.window-title.default-description',
|
||||||
|
defaultMessage: 'Used when an instance leaves its window title empty.',
|
||||||
|
},
|
||||||
|
defaultWindowTitlePlaceholder: {
|
||||||
|
id: 'app.settings.defaults.window-title.default-placeholder',
|
||||||
|
defaultMessage: 'Enter default window title...',
|
||||||
|
},
|
||||||
width: { id: 'app.settings.defaults.width', defaultMessage: 'Width' },
|
width: { id: 'app.settings.defaults.width', defaultMessage: 'Width' },
|
||||||
widthDescription: {
|
widthDescription: {
|
||||||
id: 'app.settings.defaults.width-description',
|
id: 'app.settings.defaults.width-description',
|
||||||
@@ -212,6 +234,36 @@ watch(
|
|||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</SettingsRow>
|
</SettingsRow>
|
||||||
|
<SettingsRow>
|
||||||
|
<template #label>
|
||||||
|
<span id="settings-target-defaults-window-title" tabindex="-1">
|
||||||
|
{{ formatMessage(messages.windowTitleEnabled) }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
<template #description>{{
|
||||||
|
formatMessage(messages.windowTitleEnabledDescription)
|
||||||
|
}}</template>
|
||||||
|
<template #control>
|
||||||
|
<Toggle id="custom-window-title-enabled" v-model="settings.custom_window_title_enabled" />
|
||||||
|
</template>
|
||||||
|
</SettingsRow>
|
||||||
|
<SettingsRow stacked>
|
||||||
|
<template #label>{{ formatMessage(messages.defaultWindowTitle) }}</template>
|
||||||
|
<template #description>{{
|
||||||
|
formatMessage(messages.defaultWindowTitleDescription)
|
||||||
|
}}</template>
|
||||||
|
<template #control>
|
||||||
|
<StyledInput
|
||||||
|
id="default-window-title"
|
||||||
|
v-model="settings.default_window_title"
|
||||||
|
:disabled="!settings.custom_window_title_enabled"
|
||||||
|
autocomplete="off"
|
||||||
|
type="text"
|
||||||
|
:placeholder="formatMessage(messages.defaultWindowTitlePlaceholder)"
|
||||||
|
wrapper-class="w-full"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</SettingsRow>
|
||||||
</SettingsSection>
|
</SettingsSection>
|
||||||
|
|
||||||
<SettingsSection>
|
<SettingsSection>
|
||||||
@@ -341,5 +393,7 @@ watch(
|
|||||||
</SettingsSection>
|
</SettingsSection>
|
||||||
|
|
||||||
<CrashAnalysisAISettings />
|
<CrashAnalysisAISettings />
|
||||||
|
<LogShareSettings />
|
||||||
|
<SharedLogsSettings />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -71,6 +71,7 @@ const featureFlagLabels: Record<FeatureFlag, string> = {
|
|||||||
advanced_filters_collapsed: '高级筛选默认折叠',
|
advanced_filters_collapsed: '高级筛选默认折叠',
|
||||||
multiplayer_in_app: '多人联机',
|
multiplayer_in_app: '多人联机',
|
||||||
auto_install_dependencies: '自动安装依赖',
|
auto_install_dependencies: '自动安装依赖',
|
||||||
|
force_anniversary_celebration: '强制显示周年庆庆祝(调试)',
|
||||||
}
|
}
|
||||||
|
|
||||||
const settings = ref(await getSettings())
|
const settings = ref(await getSettings())
|
||||||
|
|||||||
@@ -0,0 +1,231 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
defineMessages,
|
||||||
|
type KeyBinding,
|
||||||
|
KeybindingChips,
|
||||||
|
KeybindingModal,
|
||||||
|
Toggle,
|
||||||
|
useVIntl,
|
||||||
|
} from '@modrinth/ui'
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
|
|
||||||
|
import { getNavShortcutEnabled, setNavShortcutEnabled } from '@/helpers/nav-shortcut-state'
|
||||||
|
import { getQuickScrollEnabled, setQuickScrollEnabled } from '@/helpers/scroll-top-state'
|
||||||
|
import { NAV_ACTIONS, SCROLL_ACTIONS, type ShortcutAction } from '@/helpers/shortcut-actions'
|
||||||
|
import {
|
||||||
|
buildConflicts,
|
||||||
|
clearStoredBinding,
|
||||||
|
resolveAllBindings,
|
||||||
|
storeBinding,
|
||||||
|
} from '@/helpers/shortcut-bindings'
|
||||||
|
import { useTheming } from '@/store/theme'
|
||||||
|
|
||||||
|
import SettingsRow from './SettingsRow.vue'
|
||||||
|
import SettingsSection from './SettingsSection.vue'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const themeStore = useTheming()
|
||||||
|
|
||||||
|
themeStore.quickScrollEnabled = getQuickScrollEnabled()
|
||||||
|
themeStore.shortcutBindings = resolveAllBindings()
|
||||||
|
for (const action of NAV_ACTIONS) {
|
||||||
|
themeStore[action.enabledField] = getNavShortcutEnabled(action.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
scrollTitle: {
|
||||||
|
id: 'app.shortcut-settings.scroll-title',
|
||||||
|
defaultMessage: 'Quick scrolling',
|
||||||
|
},
|
||||||
|
scrollDescription: {
|
||||||
|
id: 'app.shortcut-settings.scroll-description',
|
||||||
|
defaultMessage: 'Move through long pages with the keyboard.',
|
||||||
|
},
|
||||||
|
enable: { id: 'app.shortcut-settings.enable', defaultMessage: 'Enable quick scrolling' },
|
||||||
|
navTitle: {
|
||||||
|
id: 'app.shortcut-settings.nav-title',
|
||||||
|
defaultMessage: 'Navigation shortcuts',
|
||||||
|
},
|
||||||
|
navDescription: {
|
||||||
|
id: 'app.shortcut-settings.nav-description',
|
||||||
|
defaultMessage: 'Jump to a menu item with its shortcut. Each shortcut is off until enabled.',
|
||||||
|
},
|
||||||
|
changeShortcut: {
|
||||||
|
id: 'app.shortcut-settings.change-shortcut',
|
||||||
|
defaultMessage: 'Change the shortcut for {action}',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
function actionLabel(action: ShortcutAction) {
|
||||||
|
return formatMessage(action.label)
|
||||||
|
}
|
||||||
|
|
||||||
|
function actionDescription(action: ShortcutAction) {
|
||||||
|
return formatMessage(action.description)
|
||||||
|
}
|
||||||
|
|
||||||
|
function bindingFor(action: ShortcutAction): KeyBinding {
|
||||||
|
return themeStore.shortcutBindings[action.id] ?? action.defaultBinding
|
||||||
|
}
|
||||||
|
|
||||||
|
function sameBinding(left: KeyBinding, right: KeyBinding) {
|
||||||
|
return (
|
||||||
|
left.device === right.device &&
|
||||||
|
left.code === right.code &&
|
||||||
|
left.mod === right.mod &&
|
||||||
|
left.shift === right.shift &&
|
||||||
|
left.alt === right.alt
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const editing = ref<ShortcutAction | null>(null)
|
||||||
|
const keybindingModal = ref<InstanceType<typeof KeybindingModal>>()
|
||||||
|
|
||||||
|
const editingLabel = computed(() => (editing.value ? actionLabel(editing.value) : undefined))
|
||||||
|
const editingBinding = computed(() => (editing.value ? bindingFor(editing.value) : null))
|
||||||
|
const editingDefault = computed(() => editing.value?.defaultBinding ?? null)
|
||||||
|
const editingConflicts = computed(() =>
|
||||||
|
editing.value
|
||||||
|
? buildConflicts(editing.value.id, (id) => {
|
||||||
|
const action = [...SCROLL_ACTIONS, ...NAV_ACTIONS].find((candidate) => candidate.id === id)
|
||||||
|
return action ? actionLabel(action) : id
|
||||||
|
})
|
||||||
|
: [],
|
||||||
|
)
|
||||||
|
|
||||||
|
function openShortcut(action: ShortcutAction) {
|
||||||
|
editing.value = action
|
||||||
|
keybindingModal.value?.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveShortcut(binding: KeyBinding) {
|
||||||
|
const action = editing.value
|
||||||
|
if (!action) return
|
||||||
|
|
||||||
|
// A combination matching the default is stored as "not changed", so a later
|
||||||
|
// change to the default still reaches this shortcut.
|
||||||
|
if (sameBinding(binding, action.defaultBinding)) clearStoredBinding(action.id)
|
||||||
|
else storeBinding(action.id, binding)
|
||||||
|
|
||||||
|
themeStore.shortcutBindings = { ...themeStore.shortcutBindings, [action.id]: binding }
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleQuickScroll(value: unknown) {
|
||||||
|
themeStore.quickScrollEnabled = !!value
|
||||||
|
setQuickScrollEnabled(themeStore.quickScrollEnabled)
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleNavShortcut(action: ShortcutAction, value: unknown) {
|
||||||
|
themeStore[action.enabledField] = !!value
|
||||||
|
setNavShortcutEnabled(action.id, !!value)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-6">
|
||||||
|
<SettingsSection>
|
||||||
|
<template #header>
|
||||||
|
<h2 class="m-0 text-lg font-semibold text-[var(--color-text-primary)]">
|
||||||
|
{{ formatMessage(messages.scrollTitle) }}
|
||||||
|
</h2>
|
||||||
|
<p class="m-0 mt-1 text-sm leading-relaxed text-[var(--color-text-tertiary)]">
|
||||||
|
{{ formatMessage(messages.scrollDescription) }}
|
||||||
|
</p>
|
||||||
|
</template>
|
||||||
|
<SettingsRow>
|
||||||
|
<template #label>
|
||||||
|
<span id="settings-target-shortcuts-enable" tabindex="-1">
|
||||||
|
{{ formatMessage(messages.enable) }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
<template #control>
|
||||||
|
<Toggle
|
||||||
|
id="quick-scroll-enabled"
|
||||||
|
:model-value="themeStore.quickScrollEnabled"
|
||||||
|
@update:model-value="toggleQuickScroll"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</SettingsRow>
|
||||||
|
<SettingsRow v-for="action in SCROLL_ACTIONS" :key="action.id">
|
||||||
|
<template #label>
|
||||||
|
<span :id="`settings-target-${action.id}`" tabindex="-1">{{ actionLabel(action) }}</span>
|
||||||
|
</template>
|
||||||
|
<template #description>{{ actionDescription(action) }}</template>
|
||||||
|
<template #control>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="keybinding-trigger"
|
||||||
|
:aria-label="formatMessage(messages.changeShortcut, { action: actionLabel(action) })"
|
||||||
|
@click="openShortcut(action)"
|
||||||
|
>
|
||||||
|
<KeybindingChips :binding="bindingFor(action)" />
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
</SettingsRow>
|
||||||
|
</SettingsSection>
|
||||||
|
|
||||||
|
<SettingsSection>
|
||||||
|
<template #header>
|
||||||
|
<h2
|
||||||
|
id="settings-target-shortcuts-nav"
|
||||||
|
tabindex="-1"
|
||||||
|
class="m-0 text-lg font-semibold text-[var(--color-text-primary)]"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.navTitle) }}
|
||||||
|
</h2>
|
||||||
|
<p class="m-0 mt-1 text-sm leading-relaxed text-[var(--color-text-tertiary)]">
|
||||||
|
{{ formatMessage(messages.navDescription) }}
|
||||||
|
</p>
|
||||||
|
</template>
|
||||||
|
<SettingsRow v-for="action in NAV_ACTIONS" :key="action.id">
|
||||||
|
<template #label>{{ actionLabel(action) }}</template>
|
||||||
|
<template #description>{{ actionDescription(action) }}</template>
|
||||||
|
<template #control>
|
||||||
|
<div class="flex flex-wrap items-center justify-end gap-3">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="keybinding-trigger"
|
||||||
|
:aria-label="formatMessage(messages.changeShortcut, { action: actionLabel(action) })"
|
||||||
|
@click="openShortcut(action)"
|
||||||
|
>
|
||||||
|
<KeybindingChips :binding="bindingFor(action)" />
|
||||||
|
</button>
|
||||||
|
<Toggle
|
||||||
|
:id="`nav-shortcut-${action.id}`"
|
||||||
|
:model-value="themeStore[action.enabledField]"
|
||||||
|
@update:model-value="(value) => toggleNavShortcut(action, value)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</SettingsRow>
|
||||||
|
</SettingsSection>
|
||||||
|
|
||||||
|
<KeybindingModal
|
||||||
|
ref="keybindingModal"
|
||||||
|
:action-label="editingLabel"
|
||||||
|
:binding="editingBinding"
|
||||||
|
:default-binding="editingDefault"
|
||||||
|
:conflicts="editingConflicts"
|
||||||
|
@save="saveShortcut"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.keybinding-trigger {
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: var(--radius-md);
|
||||||
|
border: 1px solid transparent;
|
||||||
|
background: transparent;
|
||||||
|
padding: 0.25rem 0.375rem;
|
||||||
|
transition:
|
||||||
|
background-color 0.15s ease,
|
||||||
|
border-color 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.keybinding-trigger:hover,
|
||||||
|
.keybinding-trigger:focus-visible {
|
||||||
|
border-color: var(--surface-4);
|
||||||
|
background: var(--surface-3);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,192 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { DownloadIcon, FolderOpenIcon, XIcon } from '@modrinth/assets'
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Checkbox,
|
||||||
|
Combobox,
|
||||||
|
commonMessages,
|
||||||
|
defineMessages,
|
||||||
|
injectNotificationManager,
|
||||||
|
injectPopupNotificationManager,
|
||||||
|
NewModal,
|
||||||
|
useVIntl,
|
||||||
|
} from '@modrinth/ui'
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
|
|
||||||
|
import { exportLauncherLogs, highlightInFolder } from '@/helpers/utils'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError } = injectNotificationManager()
|
||||||
|
const popupNotificationManager = injectPopupNotificationManager()
|
||||||
|
|
||||||
|
const modal = ref<InstanceType<typeof NewModal>>()
|
||||||
|
const exporting = ref(false)
|
||||||
|
const selectedRange = ref<'last30Minutes' | 'last2Hours' | 'all'>('last2Hours')
|
||||||
|
const selectedLevel = ref<'all' | 'debug' | 'info'>('all')
|
||||||
|
const includeSystemInfo = ref(true)
|
||||||
|
const includeInstanceLogs = ref(false)
|
||||||
|
const includeCrashAnalysis = ref(false)
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.settings.logs.export.modal.title', defaultMessage: 'Export logs' },
|
||||||
|
description: {
|
||||||
|
id: 'app.settings.logs.export.modal.description',
|
||||||
|
defaultMessage:
|
||||||
|
'Choose how much detail to include. Exported logs have access tokens, Minecraft tokens, and IP addresses replaced with placeholders.',
|
||||||
|
},
|
||||||
|
rangeLabel: { id: 'app.settings.logs.export.modal.range', defaultMessage: 'Time range' },
|
||||||
|
rangeLast30Minutes: {
|
||||||
|
id: 'app.settings.logs.export.modal.range.30-minutes',
|
||||||
|
defaultMessage: 'Last 30 minutes',
|
||||||
|
},
|
||||||
|
rangeLast2Hours: {
|
||||||
|
id: 'app.settings.logs.export.modal.range.2-hours',
|
||||||
|
defaultMessage: 'Last 2 hours',
|
||||||
|
},
|
||||||
|
rangeAll: { id: 'app.settings.logs.export.modal.range.all', defaultMessage: 'All sessions' },
|
||||||
|
levelLabel: { id: 'app.settings.logs.export.modal.level', defaultMessage: 'Log level' },
|
||||||
|
levelAll: { id: 'app.settings.logs.export.modal.level.all', defaultMessage: 'All levels' },
|
||||||
|
levelDebug: {
|
||||||
|
id: 'app.settings.logs.export.modal.level.debug',
|
||||||
|
defaultMessage: 'Debug and above',
|
||||||
|
},
|
||||||
|
levelInfo: { id: 'app.settings.logs.export.modal.level.info', defaultMessage: 'Info and above' },
|
||||||
|
extrasLabel: {
|
||||||
|
id: 'app.settings.logs.export.modal.extras',
|
||||||
|
defaultMessage: 'Additional information',
|
||||||
|
},
|
||||||
|
systemInfo: {
|
||||||
|
id: 'app.settings.logs.export.modal.system-info',
|
||||||
|
defaultMessage: 'System and environment summary',
|
||||||
|
},
|
||||||
|
instanceLogs: {
|
||||||
|
id: 'app.settings.logs.export.modal.instance-logs',
|
||||||
|
defaultMessage: 'Most recent instance log',
|
||||||
|
},
|
||||||
|
crashAnalysis: {
|
||||||
|
id: 'app.settings.logs.export.modal.crash-analysis',
|
||||||
|
defaultMessage: 'Crash analysis (when a crash is detected)',
|
||||||
|
},
|
||||||
|
cancel: { id: 'app.settings.logs.export.modal.cancel', defaultMessage: 'Cancel' },
|
||||||
|
confirm: { id: 'app.settings.logs.export.modal.confirm', defaultMessage: 'Export' },
|
||||||
|
exportedTitle: {
|
||||||
|
id: 'app.settings.logs.export.notification-title',
|
||||||
|
defaultMessage: 'Logs exported',
|
||||||
|
},
|
||||||
|
exportedText: {
|
||||||
|
id: 'app.settings.logs.export.notification-text',
|
||||||
|
defaultMessage: 'The log archive was saved to {path}',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const rangeOptions = computed(() => [
|
||||||
|
{ value: 'last30Minutes', label: formatMessage(messages.rangeLast30Minutes) },
|
||||||
|
{ value: 'last2Hours', label: formatMessage(messages.rangeLast2Hours) },
|
||||||
|
{ value: 'all', label: formatMessage(messages.rangeAll) },
|
||||||
|
])
|
||||||
|
|
||||||
|
const levelOptions = computed(() => [
|
||||||
|
{ value: 'all', label: formatMessage(messages.levelAll) },
|
||||||
|
{ value: 'debug', label: formatMessage(messages.levelDebug) },
|
||||||
|
{ value: 'info', label: formatMessage(messages.levelInfo) },
|
||||||
|
])
|
||||||
|
|
||||||
|
async function exportLogs() {
|
||||||
|
exporting.value = true
|
||||||
|
try {
|
||||||
|
const path = await exportLauncherLogs({
|
||||||
|
range: selectedRange.value,
|
||||||
|
level: selectedLevel.value,
|
||||||
|
includeSystemInfo: includeSystemInfo.value,
|
||||||
|
includeInstanceLogs: includeInstanceLogs.value,
|
||||||
|
includeCrashAnalysis: includeCrashAnalysis.value,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (path) {
|
||||||
|
modal.value?.hide()
|
||||||
|
popupNotificationManager.addPopupNotification({
|
||||||
|
title: formatMessage(messages.exportedTitle),
|
||||||
|
text: formatMessage(messages.exportedText, { path }),
|
||||||
|
type: 'success',
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
label: formatMessage(commonMessages.openInFolderButton),
|
||||||
|
icon: FolderOpenIcon,
|
||||||
|
action: () => highlightInFolder(path).catch(handleError),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
exporting.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
show: () => modal.value?.show(),
|
||||||
|
hide: () => modal.value?.hide(),
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<NewModal
|
||||||
|
ref="modal"
|
||||||
|
:header="formatMessage(messages.title)"
|
||||||
|
:closable="true"
|
||||||
|
:close-on-click-outside="true"
|
||||||
|
width="40rem"
|
||||||
|
scrollable
|
||||||
|
>
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<p class="m-0">{{ formatMessage(messages.description) }}</p>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<span class="font-semibold text-[var(--color-text-primary)]">{{
|
||||||
|
formatMessage(messages.rangeLabel)
|
||||||
|
}}</span>
|
||||||
|
<Combobox
|
||||||
|
id="log-export-range"
|
||||||
|
v-model="selectedRange"
|
||||||
|
:name="formatMessage(messages.rangeLabel)"
|
||||||
|
:options="rangeOptions"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<span class="font-semibold text-[var(--color-text-primary)]">{{
|
||||||
|
formatMessage(messages.levelLabel)
|
||||||
|
}}</span>
|
||||||
|
<Combobox
|
||||||
|
id="log-export-level"
|
||||||
|
v-model="selectedLevel"
|
||||||
|
:name="formatMessage(messages.levelLabel)"
|
||||||
|
:options="levelOptions"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<span class="font-semibold text-[var(--color-text-primary)]">{{
|
||||||
|
formatMessage(messages.extrasLabel)
|
||||||
|
}}</span>
|
||||||
|
<Checkbox v-model="includeSystemInfo" :label="formatMessage(messages.systemInfo)" />
|
||||||
|
<Checkbox v-model="includeInstanceLogs" :label="formatMessage(messages.instanceLogs)" />
|
||||||
|
<Checkbox v-model="includeCrashAnalysis" :label="formatMessage(messages.crashAnalysis)" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template #actions>
|
||||||
|
<div class="flex justify-end gap-2">
|
||||||
|
<Button type="outlined" :disabled="exporting" @click="modal?.hide()"
|
||||||
|
><XIcon />
|
||||||
|
{{ formatMessage(messages.cancel) }}
|
||||||
|
</Button>
|
||||||
|
<Button type="colored" color="brand" :disabled="exporting" @click="exportLogs"
|
||||||
|
><DownloadIcon />
|
||||||
|
{{ formatMessage(messages.confirm) }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</NewModal>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,354 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { Combobox, defineMessages, injectNotificationManager, Toggle, useVIntl } from '@modrinth/ui'
|
||||||
|
import { computed, onMounted, ref } from 'vue'
|
||||||
|
|
||||||
|
import { type AIState, getAIState, sharedAIState } from '@/helpers/ai'
|
||||||
|
import {
|
||||||
|
get_crash_analysis_ai_settings,
|
||||||
|
get_log_share_settings,
|
||||||
|
update_crash_analysis_ai_settings,
|
||||||
|
update_log_share_settings,
|
||||||
|
} from '@/helpers/logs'
|
||||||
|
|
||||||
|
import SettingsRow from './SettingsRow.vue'
|
||||||
|
import SettingsSection from './SettingsSection.vue'
|
||||||
|
|
||||||
|
type CrashAISettings = {
|
||||||
|
enabled: boolean
|
||||||
|
provider_id: string
|
||||||
|
model_id: string
|
||||||
|
ai_source: 'logshare' | 'custom'
|
||||||
|
}
|
||||||
|
|
||||||
|
type LogShareSettings = {
|
||||||
|
share_provider: 'logshare' | 'mclogs'
|
||||||
|
ai_source: string
|
||||||
|
auto_upload: boolean
|
||||||
|
multi_file: boolean
|
||||||
|
no_storage: boolean
|
||||||
|
show_progress: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError } = injectNotificationManager()
|
||||||
|
const settings = ref<LogShareSettings>({
|
||||||
|
share_provider: 'logshare',
|
||||||
|
ai_source: 'logshare',
|
||||||
|
auto_upload: true,
|
||||||
|
multi_file: true,
|
||||||
|
no_storage: false,
|
||||||
|
show_progress: true,
|
||||||
|
})
|
||||||
|
const aiSettings = ref<CrashAISettings>({
|
||||||
|
enabled: false,
|
||||||
|
provider_id: '',
|
||||||
|
model_id: '',
|
||||||
|
ai_source: 'logshare',
|
||||||
|
})
|
||||||
|
const loading = ref(true)
|
||||||
|
const saving = ref(false)
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.log-share.settings.title', defaultMessage: 'Log sharing & AI analysis' },
|
||||||
|
description: {
|
||||||
|
id: 'app.log-share.settings.description',
|
||||||
|
defaultMessage:
|
||||||
|
'Share crash diagnostics with LogShare for a structured summary and optional AI analysis. LogShare is preferred; mclo.gs is used as a fallback.',
|
||||||
|
},
|
||||||
|
shareProvider: {
|
||||||
|
id: 'app.log-share.settings.share-provider',
|
||||||
|
defaultMessage: 'Log sharing service',
|
||||||
|
},
|
||||||
|
shareProviderDescription: {
|
||||||
|
id: 'app.log-share.settings.share-provider-description',
|
||||||
|
defaultMessage: 'Where the diagnostic link is uploaded when you share it.',
|
||||||
|
},
|
||||||
|
aiSource: { id: 'app.log-share.settings.ai-source', defaultMessage: 'AI analysis source' },
|
||||||
|
aiSourceLogShare: {
|
||||||
|
id: 'app.log-share.settings.ai-source-logshare',
|
||||||
|
defaultMessage: 'LogShare AI',
|
||||||
|
},
|
||||||
|
aiSourceCustom: {
|
||||||
|
id: 'app.log-share.settings.ai-source-custom',
|
||||||
|
defaultMessage: 'Custom AI provider',
|
||||||
|
},
|
||||||
|
aiSourceDescription: {
|
||||||
|
id: 'app.log-share.settings.ai-source-description',
|
||||||
|
defaultMessage:
|
||||||
|
'Both sources send a sanitized and shortened crash context. AI output may be inaccurate.',
|
||||||
|
},
|
||||||
|
enabled: {
|
||||||
|
id: 'app.crash-analysis.ai.settings.enabled',
|
||||||
|
defaultMessage: 'Enable AI explanations',
|
||||||
|
},
|
||||||
|
enabledDescription: {
|
||||||
|
id: 'app.crash-analysis.ai.settings.enabled-description',
|
||||||
|
defaultMessage: 'Local rule-based crash analysis remains available without AI.',
|
||||||
|
},
|
||||||
|
provider: { id: 'app.crash-analysis.ai.settings.provider', defaultMessage: 'AI provider' },
|
||||||
|
model: { id: 'app.crash-analysis.ai.settings.model', defaultMessage: 'Text model' },
|
||||||
|
noProviders: {
|
||||||
|
id: 'app.crash-analysis.ai.settings.no-providers',
|
||||||
|
defaultMessage: 'Enable a provider and a text model above before using AI crash explanations.',
|
||||||
|
},
|
||||||
|
autoUpload: {
|
||||||
|
id: 'app.log-share.settings.auto-upload',
|
||||||
|
defaultMessage: 'Upload to get a structured summary automatically',
|
||||||
|
},
|
||||||
|
autoUploadDescription: {
|
||||||
|
id: 'app.log-share.settings.auto-upload-description',
|
||||||
|
defaultMessage: 'Only effective in LogShare AI mode.',
|
||||||
|
},
|
||||||
|
multiFile: { id: 'app.log-share.settings.multi-file', defaultMessage: 'Multi-file upload' },
|
||||||
|
multiFileDescription: {
|
||||||
|
id: 'app.log-share.settings.multi-file-description',
|
||||||
|
defaultMessage: 'Upload latest.log, crash reports, hs_err and launcher logs together.',
|
||||||
|
},
|
||||||
|
noStorage: {
|
||||||
|
id: 'app.log-share.settings.no-storage',
|
||||||
|
defaultMessage: 'Analyze without storing logs',
|
||||||
|
},
|
||||||
|
noStorageDescription: {
|
||||||
|
id: 'app.log-share.settings.no-storage-description',
|
||||||
|
defaultMessage:
|
||||||
|
'Submit content directly for analysis and skip the stored upload. Disables the automatic summary.',
|
||||||
|
},
|
||||||
|
showProgress: {
|
||||||
|
id: 'app.log-share.settings.show-progress',
|
||||||
|
defaultMessage: 'Show AI analysis progress',
|
||||||
|
},
|
||||||
|
showProgressDescription: {
|
||||||
|
id: 'app.log-share.settings.show-progress-description',
|
||||||
|
defaultMessage: 'Display thinking, tool and limit status while LogShare AI is working.',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const emptyState: AIState = { settings: { enabled: false }, catalog_source: '', providers: [] }
|
||||||
|
const aiState = computed(() => sharedAIState.value ?? emptyState)
|
||||||
|
const providers = computed(() =>
|
||||||
|
aiState.value.providers.filter(
|
||||||
|
(provider) => provider.enabled && provider.models.some((model) => model.enabled),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
const providerOptions = computed(() =>
|
||||||
|
providers.value.map((provider) => ({
|
||||||
|
value: provider.provider_id,
|
||||||
|
label: provider.custom_name || provider.provider_id,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
const modelOptions = computed(
|
||||||
|
() =>
|
||||||
|
providers.value
|
||||||
|
.find((provider) => provider.provider_id === aiSettings.value.provider_id)
|
||||||
|
?.models.filter((model) => model.enabled)
|
||||||
|
.map((model) => ({ value: model.id, label: model.name || model.id })) ?? [],
|
||||||
|
)
|
||||||
|
|
||||||
|
const isCustom = computed(() => aiSettings.value.ai_source === 'custom')
|
||||||
|
const noStorageEnabled = computed(() => aiSettings.value.ai_source === 'logshare')
|
||||||
|
|
||||||
|
const shareProviderOptions = [
|
||||||
|
{ value: 'logshare', label: 'LogShare' },
|
||||||
|
{ value: 'mclogs', label: 'mclo.gs' },
|
||||||
|
]
|
||||||
|
const aiSourceOptions = [
|
||||||
|
{ value: 'logshare', label: formatMessage(messages.aiSourceLogShare) },
|
||||||
|
{ value: 'custom', label: formatMessage(messages.aiSourceCustom) },
|
||||||
|
]
|
||||||
|
|
||||||
|
async function saveShare(next: LogShareSettings): Promise<void> {
|
||||||
|
saving.value = true
|
||||||
|
try {
|
||||||
|
await update_log_share_settings(next)
|
||||||
|
settings.value = next
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
saving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveAI(next: CrashAISettings): Promise<void> {
|
||||||
|
saving.value = true
|
||||||
|
try {
|
||||||
|
await update_crash_analysis_ai_settings(next)
|
||||||
|
aiSettings.value = next
|
||||||
|
settings.value = { ...settings.value, ai_source: next.ai_source }
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
saving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateShare(patch: Partial<LogShareSettings>): void {
|
||||||
|
void saveShare({ ...settings.value, ...patch })
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectShareProvider(value: unknown): void {
|
||||||
|
const provider = value === 'mclogs' ? 'mclogs' : 'logshare'
|
||||||
|
updateShare({ share_provider: provider, ai_source: aiSettings.value.ai_source })
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectAiSource(value: unknown): void {
|
||||||
|
const source = value === 'custom' ? 'custom' : 'logshare'
|
||||||
|
void saveAI({ ...aiSettings.value, ai_source: source })
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateEnabled(enabled: boolean): void {
|
||||||
|
void saveAI({ ...aiSettings.value, enabled })
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateProvider(providerId: string): void {
|
||||||
|
const provider = providers.value.find((item) => item.provider_id === providerId)
|
||||||
|
const modelId = provider?.models.find((model) => model.enabled)?.id ?? ''
|
||||||
|
void saveAI({ ...aiSettings.value, provider_id: providerId, model_id: modelId })
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateModel(modelId: string): void {
|
||||||
|
void saveAI({ ...aiSettings.value, model_id: modelId })
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
try {
|
||||||
|
const [nextShare, nextAI] = await Promise.all([
|
||||||
|
get_log_share_settings(),
|
||||||
|
get_crash_analysis_ai_settings(),
|
||||||
|
getAIState(),
|
||||||
|
])
|
||||||
|
settings.value = { ...nextShare, ai_source: nextAI.ai_source }
|
||||||
|
aiSettings.value = nextAI
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<SettingsSection
|
||||||
|
v-if="!loading"
|
||||||
|
id="settings-target-log-share"
|
||||||
|
:title="formatMessage(messages.title)"
|
||||||
|
:description="formatMessage(messages.description)"
|
||||||
|
>
|
||||||
|
<SettingsRow>
|
||||||
|
<template #label>{{ formatMessage(messages.shareProvider) }}</template>
|
||||||
|
<template #description>{{ formatMessage(messages.shareProviderDescription) }}</template>
|
||||||
|
<template #control>
|
||||||
|
<Combobox
|
||||||
|
id="log-share-provider"
|
||||||
|
:model-value="settings.share_provider"
|
||||||
|
:options="shareProviderOptions"
|
||||||
|
:disabled="saving"
|
||||||
|
@update:model-value="selectShareProvider($event)"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</SettingsRow>
|
||||||
|
<SettingsRow>
|
||||||
|
<template #label>{{ formatMessage(messages.aiSource) }}</template>
|
||||||
|
<template #description>{{ formatMessage(messages.aiSourceDescription) }}</template>
|
||||||
|
<template #control>
|
||||||
|
<Combobox
|
||||||
|
id="log-share-ai-source"
|
||||||
|
:model-value="aiSettings.ai_source"
|
||||||
|
:options="aiSourceOptions"
|
||||||
|
:disabled="saving"
|
||||||
|
@update:model-value="selectAiSource($event)"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</SettingsRow>
|
||||||
|
<template v-if="isCustom">
|
||||||
|
<SettingsRow>
|
||||||
|
<template #label>{{ formatMessage(messages.enabled) }}</template>
|
||||||
|
<template #description>{{ formatMessage(messages.enabledDescription) }}</template>
|
||||||
|
<template #control>
|
||||||
|
<Toggle
|
||||||
|
id="crash-analysis-ai-enabled"
|
||||||
|
:model-value="aiSettings.enabled"
|
||||||
|
:disabled="saving || !aiState.settings.enabled || !providers.length"
|
||||||
|
@update:model-value="updateEnabled(!!$event)"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</SettingsRow>
|
||||||
|
<template v-if="providers.length">
|
||||||
|
<SettingsRow>
|
||||||
|
<template #label>{{ formatMessage(messages.provider) }}</template>
|
||||||
|
<template #control>
|
||||||
|
<Combobox
|
||||||
|
id="crash-analysis-ai-provider"
|
||||||
|
:model-value="aiSettings.provider_id"
|
||||||
|
:options="providerOptions"
|
||||||
|
:disabled="saving"
|
||||||
|
@update:model-value="updateProvider(String($event))"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</SettingsRow>
|
||||||
|
<SettingsRow>
|
||||||
|
<template #label>{{ formatMessage(messages.model) }}</template>
|
||||||
|
<template #control>
|
||||||
|
<Combobox
|
||||||
|
id="crash-analysis-ai-model"
|
||||||
|
:model-value="aiSettings.model_id"
|
||||||
|
:options="modelOptions"
|
||||||
|
:disabled="saving || !aiSettings.provider_id"
|
||||||
|
@update:model-value="updateModel(String($event))"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</SettingsRow>
|
||||||
|
</template>
|
||||||
|
<p v-else class="m-0 p-4 text-sm text-[var(--color-text-tertiary)]">
|
||||||
|
{{ formatMessage(messages.noProviders) }}
|
||||||
|
</p>
|
||||||
|
</template>
|
||||||
|
<SettingsRow>
|
||||||
|
<template #label>{{ formatMessage(messages.autoUpload) }}</template>
|
||||||
|
<template #description>{{ formatMessage(messages.autoUploadDescription) }}</template>
|
||||||
|
<template #control>
|
||||||
|
<Toggle
|
||||||
|
id="log-share-auto-upload"
|
||||||
|
:model-value="settings.auto_upload"
|
||||||
|
:disabled="saving || !noStorageEnabled || settings.no_storage"
|
||||||
|
@update:model-value="updateShare({ auto_upload: !!$event })"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</SettingsRow>
|
||||||
|
<SettingsRow>
|
||||||
|
<template #label>{{ formatMessage(messages.multiFile) }}</template>
|
||||||
|
<template #description>{{ formatMessage(messages.multiFileDescription) }}</template>
|
||||||
|
<template #control>
|
||||||
|
<Toggle
|
||||||
|
id="log-share-multi-file"
|
||||||
|
:model-value="settings.multi_file"
|
||||||
|
:disabled="saving"
|
||||||
|
@update:model-value="updateShare({ multi_file: !!$event })"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</SettingsRow>
|
||||||
|
<SettingsRow>
|
||||||
|
<template #label>{{ formatMessage(messages.noStorage) }}</template>
|
||||||
|
<template #description>{{ formatMessage(messages.noStorageDescription) }}</template>
|
||||||
|
<template #control>
|
||||||
|
<Toggle
|
||||||
|
id="log-share-no-storage"
|
||||||
|
:model-value="settings.no_storage"
|
||||||
|
:disabled="saving || !noStorageEnabled"
|
||||||
|
@update:model-value="updateShare({ no_storage: !!$event })"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</SettingsRow>
|
||||||
|
<SettingsRow>
|
||||||
|
<template #label>{{ formatMessage(messages.showProgress) }}</template>
|
||||||
|
<template #description>{{ formatMessage(messages.showProgressDescription) }}</template>
|
||||||
|
<template #control>
|
||||||
|
<Toggle
|
||||||
|
id="log-share-show-progress"
|
||||||
|
:model-value="settings.show_progress"
|
||||||
|
:disabled="saving"
|
||||||
|
@update:model-value="updateShare({ show_progress: !!$event })"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</SettingsRow>
|
||||||
|
</SettingsSection>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { FolderOpenIcon, UploadIcon } from '@modrinth/assets'
|
||||||
|
import { Button, defineMessages, injectNotificationManager, useVIntl } from '@modrinth/ui'
|
||||||
|
import { ref } from 'vue'
|
||||||
|
|
||||||
|
import { showLauncherLogsFolder } from '@/helpers/utils'
|
||||||
|
|
||||||
|
import LogExportModal from './LogExportModal.vue'
|
||||||
|
import SettingsRow from './SettingsRow.vue'
|
||||||
|
import SettingsSection from './SettingsSection.vue'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError } = injectNotificationManager()
|
||||||
|
|
||||||
|
const exportModal = ref<InstanceType<typeof LogExportModal>>()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
exportTitle: { id: 'app.settings.logs.export.title', defaultMessage: 'Export logs' },
|
||||||
|
exportDescription: {
|
||||||
|
id: 'app.settings.logs.export.description',
|
||||||
|
defaultMessage:
|
||||||
|
'Package launcher logs with an optional environment summary, instance log, and crash analysis.',
|
||||||
|
},
|
||||||
|
exportButton: { id: 'app.settings.logs.export.button', defaultMessage: 'Export logs…' },
|
||||||
|
openFolder: { id: 'app.settings.logs.open-folder', defaultMessage: 'Open logs folder' },
|
||||||
|
})
|
||||||
|
|
||||||
|
async function openLogsFolder() {
|
||||||
|
try {
|
||||||
|
await showLauncherLogsFolder()
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-6">
|
||||||
|
<SettingsSection
|
||||||
|
:title="formatMessage(messages.exportTitle)"
|
||||||
|
:description="formatMessage(messages.exportDescription)"
|
||||||
|
title-id="settings-target-logs-export"
|
||||||
|
>
|
||||||
|
<SettingsRow stacked>
|
||||||
|
<template #label>
|
||||||
|
<span>{{ formatMessage(messages.exportTitle) }}</span>
|
||||||
|
</template>
|
||||||
|
<template #description>{{ formatMessage(messages.exportDescription) }}</template>
|
||||||
|
<template #control>
|
||||||
|
<div class="flex flex-wrap gap-2">
|
||||||
|
<Button type="colored" color="brand" @click="exportModal?.show()"
|
||||||
|
><UploadIcon />
|
||||||
|
{{ formatMessage(messages.exportButton) }}
|
||||||
|
</Button>
|
||||||
|
<Button @click="openLogsFolder"
|
||||||
|
><FolderOpenIcon />
|
||||||
|
{{ formatMessage(messages.openFolder) }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</SettingsRow>
|
||||||
|
</SettingsSection>
|
||||||
|
|
||||||
|
<LogExportModal ref="exportModal" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -253,6 +253,15 @@ const messages = defineMessages({
|
|||||||
defaultMessage:
|
defaultMessage:
|
||||||
'When CurseForge does not provide a download address, derive its CDN address and try downloading the file automatically. Disable this to use the manual download workflow.',
|
'When CurseForge does not provide a download address, derive its CDN address and try downloading the file automatically. Disable this to use the manual download workflow.',
|
||||||
},
|
},
|
||||||
|
ignoreSslErrors: {
|
||||||
|
id: 'app.settings.resources.ignore-ssl-errors',
|
||||||
|
defaultMessage: 'Ignore SSL certificate errors',
|
||||||
|
},
|
||||||
|
ignoreSslErrorsDescription: {
|
||||||
|
id: 'app.settings.resources.ignore-ssl-errors-description',
|
||||||
|
defaultMessage:
|
||||||
|
'Skip TLS certificate validation for launcher network requests. Only enable this if you trust your network and understand the security risk.',
|
||||||
|
},
|
||||||
mojangAuthService: {
|
mojangAuthService: {
|
||||||
id: 'app.settings.resources.mojang-auth-service',
|
id: 'app.settings.resources.mojang-auth-service',
|
||||||
defaultMessage: 'Mojang authentication service',
|
defaultMessage: 'Mojang authentication service',
|
||||||
@@ -923,6 +932,15 @@ function validateMinecraftDirectory(value) {
|
|||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
</SettingsRow>
|
</SettingsRow>
|
||||||
|
<SettingsRow>
|
||||||
|
<template #label>{{ formatMessage(messages.ignoreSslErrors) }}</template>
|
||||||
|
<template #description>
|
||||||
|
{{ formatMessage(messages.ignoreSslErrorsDescription) }}
|
||||||
|
</template>
|
||||||
|
<template #control>
|
||||||
|
<Toggle id="ignore-ssl-errors" v-model="settings.ignore_ssl_errors" />
|
||||||
|
</template>
|
||||||
|
</SettingsRow>
|
||||||
</SettingsSection>
|
</SettingsSection>
|
||||||
|
|
||||||
<SettingsSection v-if="props.scope === 'content-downloads'">
|
<SettingsSection v-if="props.scope === 'content-downloads'">
|
||||||
|
|||||||
@@ -0,0 +1,129 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { Button, defineMessages, injectNotificationManager, useVIntl } from '@modrinth/ui'
|
||||||
|
import { onMounted, ref } from 'vue'
|
||||||
|
|
||||||
|
import { delete_shared_log, list_shared_logs } from '@/helpers/logs'
|
||||||
|
|
||||||
|
import SettingsRow from './SettingsRow.vue'
|
||||||
|
import SettingsSection from './SettingsSection.vue'
|
||||||
|
|
||||||
|
type SharedLog = {
|
||||||
|
id: string
|
||||||
|
url: string
|
||||||
|
raw: string
|
||||||
|
token: string
|
||||||
|
provider: string
|
||||||
|
instance_id: string | null
|
||||||
|
instance_name: string | null
|
||||||
|
truncated: boolean
|
||||||
|
created_at: number
|
||||||
|
}
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { addNotification, handleError } = injectNotificationManager()
|
||||||
|
const logs = ref<SharedLog[]>([])
|
||||||
|
const loading = ref(true)
|
||||||
|
const deletingId = ref<string | null>(null)
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.log-share.shared-logs.title', defaultMessage: 'Shared logs' },
|
||||||
|
description: {
|
||||||
|
id: 'app.log-share.shared-logs.description',
|
||||||
|
defaultMessage:
|
||||||
|
'Every diagnostic you have shared is listed here. Delete an entry to remove it from your history and request its removal from the sharing service.',
|
||||||
|
},
|
||||||
|
empty: { id: 'app.log-share.shared-logs.empty', defaultMessage: 'No shared logs yet.' },
|
||||||
|
delete: { id: 'app.log-share.shared-logs.delete', defaultMessage: 'Delete' },
|
||||||
|
deleting: { id: 'app.log-share.shared-logs.deleting', defaultMessage: 'Deleting…' },
|
||||||
|
deleted: {
|
||||||
|
id: 'app.log-share.shared-logs.deleted',
|
||||||
|
defaultMessage: 'Shared log removed.',
|
||||||
|
},
|
||||||
|
deleteFailed: {
|
||||||
|
id: 'app.log-share.shared-logs.delete-failed',
|
||||||
|
defaultMessage: 'Failed to delete the shared log.',
|
||||||
|
},
|
||||||
|
truncated: { id: 'app.log-share.shared-logs.truncated', defaultMessage: 'Truncated' },
|
||||||
|
})
|
||||||
|
|
||||||
|
async function refresh(): Promise<void> {
|
||||||
|
try {
|
||||||
|
logs.value = await list_shared_logs()
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function remove(log: SharedLog): Promise<void> {
|
||||||
|
if (deletingId.value) return
|
||||||
|
deletingId.value = log.id
|
||||||
|
try {
|
||||||
|
await delete_shared_log(log.id, log.token)
|
||||||
|
logs.value = logs.value.filter((item) => item.id !== log.id)
|
||||||
|
addNotification({ title: formatMessage(messages.deleted), type: 'success' })
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
addNotification({ title: formatMessage(messages.deleteFailed), type: 'error' })
|
||||||
|
} finally {
|
||||||
|
deletingId.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDate(timestamp: number): string {
|
||||||
|
return new Date(timestamp * 1000).toLocaleString()
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(refresh)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<SettingsSection
|
||||||
|
id="settings-target-shared-logs"
|
||||||
|
:title="formatMessage(messages.title)"
|
||||||
|
:description="formatMessage(messages.description)"
|
||||||
|
>
|
||||||
|
<SettingsRow stacked>
|
||||||
|
<template #control>
|
||||||
|
<div class="flex w-full min-w-0 flex-col gap-2">
|
||||||
|
<p v-if="loading" class="m-0 p-2 text-sm text-[var(--color-text-tertiary)]">…</p>
|
||||||
|
<p v-else-if="!logs.length" class="m-0 p-2 text-sm text-[var(--color-text-tertiary)]">
|
||||||
|
{{ formatMessage(messages.empty) }}
|
||||||
|
</p>
|
||||||
|
<ul v-else class="m-0 flex max-h-72 list-none flex-col gap-1 overflow-y-auto p-2">
|
||||||
|
<li
|
||||||
|
v-for="log in logs"
|
||||||
|
:key="log.id"
|
||||||
|
class="flex items-center gap-3 rounded-lg bg-surface-2 px-3 py-2"
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
:href="log.url || `https://logshare.cn/${log.id}`"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
class="min-w-0 flex-1 truncate text-[var(--color-text-default)] underline"
|
||||||
|
>
|
||||||
|
{{ log.url || log.id }}
|
||||||
|
</a>
|
||||||
|
<span class="shrink-0 text-xs text-[var(--color-text-tertiary)]">
|
||||||
|
{{ log.provider }}
|
||||||
|
<template v-if="log.truncated">
|
||||||
|
· {{ formatMessage(messages.truncated) }}
|
||||||
|
</template>
|
||||||
|
<template v-if="log.instance_name"> · {{ log.instance_name }} </template>
|
||||||
|
· {{ formatDate(log.created_at) }}
|
||||||
|
</span>
|
||||||
|
<Button type="outlined" :disabled="deletingId === log.id" @click="remove(log)"
|
||||||
|
>{{
|
||||||
|
deletingId === log.id
|
||||||
|
? formatMessage(messages.deleting)
|
||||||
|
: formatMessage(messages.delete)
|
||||||
|
}}
|
||||||
|
</Button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</SettingsRow>
|
||||||
|
</SettingsSection>
|
||||||
|
</template>
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import BackupRepositorySettings from './BackupRepositorySettings.vue'
|
||||||
import ResourceManagementSettings from './ResourceManagementSettings.vue'
|
import ResourceManagementSettings from './ResourceManagementSettings.vue'
|
||||||
import StorageSettings from './StorageSettings.vue'
|
import StorageSettings from './StorageSettings.vue'
|
||||||
</script>
|
</script>
|
||||||
@@ -6,6 +7,7 @@ import StorageSettings from './StorageSettings.vue'
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col gap-6">
|
<div class="flex flex-col gap-6">
|
||||||
<ResourceManagementSettings scope="storage-backups" />
|
<ResourceManagementSettings scope="storage-backups" />
|
||||||
|
<BackupRepositorySettings />
|
||||||
<StorageSettings />
|
<StorageSettings />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -0,0 +1,181 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { RefreshCwIcon, SearchIcon, SpinnerIcon, XIcon } from '@modrinth/assets'
|
||||||
|
import {
|
||||||
|
Avatar,
|
||||||
|
Button,
|
||||||
|
CheckCircleButton,
|
||||||
|
commonMessages,
|
||||||
|
defineMessages,
|
||||||
|
NewModal,
|
||||||
|
StyledInput,
|
||||||
|
useVIntl,
|
||||||
|
} from '@modrinth/ui'
|
||||||
|
import { computed, ref, useTemplateRef } from 'vue'
|
||||||
|
|
||||||
|
import { getInstanceIconUrl } from '@/helpers/instance'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
title: string
|
||||||
|
description: string
|
||||||
|
sources: {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
icon_path?: string | null
|
||||||
|
eligible: boolean
|
||||||
|
}[]
|
||||||
|
loading?: boolean
|
||||||
|
pending?: boolean
|
||||||
|
error?: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
confirm: []
|
||||||
|
close: []
|
||||||
|
retry: []
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const selectedInstanceId = defineModel<string>({ required: true })
|
||||||
|
const modal = useTemplateRef<InstanceType<typeof NewModal>>('modal')
|
||||||
|
const search = ref('')
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
ineligible: {
|
||||||
|
id: 'app.settings.synced-options.choose-sync-source.ineligible',
|
||||||
|
defaultMessage: 'You cannot choose this instance as a sync source',
|
||||||
|
},
|
||||||
|
search: {
|
||||||
|
id: 'app.settings.synced-options.choose-sync-source.search-placeholder',
|
||||||
|
defaultMessage: 'Search instance',
|
||||||
|
},
|
||||||
|
empty: {
|
||||||
|
id: 'app.settings.synced-options.choose-sync-source.no-instances-found',
|
||||||
|
defaultMessage: 'No instances found',
|
||||||
|
},
|
||||||
|
sync: {
|
||||||
|
id: 'app.settings.synced-options.choose-sync-source.sync',
|
||||||
|
defaultMessage: 'Sync',
|
||||||
|
},
|
||||||
|
loadError: {
|
||||||
|
id: 'app.settings.synced-options.choose-sync-source.load-error',
|
||||||
|
defaultMessage: 'Could not load sync sources. Please try again.',
|
||||||
|
},
|
||||||
|
retry: {
|
||||||
|
id: 'app.settings.synced-options.choose-sync-source.retry',
|
||||||
|
defaultMessage: 'Try again',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const filteredSources = computed(() => {
|
||||||
|
const query = search.value.trim().toLocaleLowerCase()
|
||||||
|
return props.sources.filter((source) => source.name.toLocaleLowerCase().includes(query))
|
||||||
|
})
|
||||||
|
const canConfirm = computed(
|
||||||
|
() =>
|
||||||
|
!props.loading &&
|
||||||
|
!props.pending &&
|
||||||
|
!props.error &&
|
||||||
|
props.sources.some((source) => source.id === selectedInstanceId.value && source.eligible),
|
||||||
|
)
|
||||||
|
|
||||||
|
function show() {
|
||||||
|
search.value = ''
|
||||||
|
modal.value?.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
function hide() {
|
||||||
|
return modal.value?.hide()
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ show, hide })
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<NewModal
|
||||||
|
ref="modal"
|
||||||
|
:header="title"
|
||||||
|
no-padding
|
||||||
|
actions-divider
|
||||||
|
max-width="560px"
|
||||||
|
width="560px"
|
||||||
|
:disable-close="pending"
|
||||||
|
:on-after-hide="() => emit('close')"
|
||||||
|
>
|
||||||
|
<p
|
||||||
|
class="m-0 border-0 border-b border-solid border-surface-5 p-6 text-[var(--color-text-default)]"
|
||||||
|
>
|
||||||
|
{{ description }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="flex h-[400px] flex-col gap-3 overflow-y-auto bg-surface-2 px-6 py-4">
|
||||||
|
<StyledInput
|
||||||
|
v-model="search"
|
||||||
|
:icon="SearchIcon"
|
||||||
|
type="search"
|
||||||
|
autocomplete="off"
|
||||||
|
:placeholder="formatMessage(messages.search)"
|
||||||
|
:aria-label="formatMessage(messages.search)"
|
||||||
|
class="shrink-0"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div v-if="loading" class="flex flex-1 items-center justify-center" aria-busy="true">
|
||||||
|
<SpinnerIcon class="size-5 animate-spin text-[var(--color-text-tertiary)]" />
|
||||||
|
</div>
|
||||||
|
<div v-else-if="error" class="flex flex-1 flex-col items-center justify-center gap-3">
|
||||||
|
<p role="alert" class="m-0 text-center text-[var(--color-text-default)]">
|
||||||
|
{{ formatMessage(messages.loadError) }}
|
||||||
|
</p>
|
||||||
|
<Button @click="emit('retry')">{{ formatMessage(messages.retry) }}</Button>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-else-if="filteredSources.length === 0"
|
||||||
|
class="flex flex-1 items-center justify-center text-[var(--color-text-tertiary)]"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.empty) }}
|
||||||
|
</div>
|
||||||
|
<div v-else role="radiogroup" :aria-label="title" class="flex flex-col gap-1">
|
||||||
|
<div
|
||||||
|
v-for="source in filteredSources"
|
||||||
|
:key="source.id"
|
||||||
|
v-tooltip="!source.eligible ? formatMessage(messages.ineligible) : undefined"
|
||||||
|
>
|
||||||
|
<CheckCircleButton
|
||||||
|
:checked="selectedInstanceId === source.id"
|
||||||
|
:disabled="pending || !source.eligible"
|
||||||
|
class="min-h-10"
|
||||||
|
@click="selectedInstanceId = source.id"
|
||||||
|
>
|
||||||
|
<span class="size-5 shrink-0 overflow-hidden rounded-[6px]">
|
||||||
|
<Avatar
|
||||||
|
:src="getInstanceIconUrl(source.icon_path)"
|
||||||
|
:alt="source.name"
|
||||||
|
:tint-by="source.id"
|
||||||
|
size="1.25rem"
|
||||||
|
no-shadow
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
<span class="min-w-0 flex-1 truncate">{{ source.name }}</span>
|
||||||
|
</CheckCircleButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<template #actions>
|
||||||
|
<div class="flex justify-end gap-2 p-2">
|
||||||
|
<Button type="outlined" :disabled="pending" @click="hide">
|
||||||
|
<XIcon aria-hidden="true" />
|
||||||
|
{{ formatMessage(commonMessages.cancelButton) }}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="colored"
|
||||||
|
color="brand"
|
||||||
|
:disabled="!canConfirm"
|
||||||
|
:loading="pending"
|
||||||
|
@click="canConfirm && emit('confirm')"
|
||||||
|
>
|
||||||
|
<RefreshCwIcon :class="{ 'animate-spin': pending }" aria-hidden="true" />
|
||||||
|
{{ formatMessage(messages.sync) }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</NewModal>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { Button, defineMessages, NewModal, useVIntl } from '@modrinth/ui'
|
||||||
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
|
|
||||||
|
import {
|
||||||
|
remove_synced_pack,
|
||||||
|
set_synced_pack_enabled,
|
||||||
|
syncedPackKeys,
|
||||||
|
syncedPackQueryOptions,
|
||||||
|
type SyncedPackType,
|
||||||
|
} from '@/helpers/synced-packs'
|
||||||
|
|
||||||
|
const modal = ref<InstanceType<typeof NewModal>>()
|
||||||
|
const type = ref<SyncedPackType>('resourcepack')
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const messages = defineMessages({
|
||||||
|
resourcePacks: {
|
||||||
|
id: 'app.settings.synced-packs.resource-packs',
|
||||||
|
defaultMessage: 'Resource packs',
|
||||||
|
},
|
||||||
|
dataPacks: { id: 'app.settings.synced-packs.data-packs', defaultMessage: 'Data packs' },
|
||||||
|
enable: { id: 'app.settings.synced-packs.enable', defaultMessage: 'Enable' },
|
||||||
|
disable: { id: 'app.settings.synced-packs.disable', defaultMessage: 'Disable' },
|
||||||
|
remove: { id: 'app.settings.synced-packs.remove', defaultMessage: 'Remove' },
|
||||||
|
empty: { id: 'app.settings.synced-packs.empty', defaultMessage: 'No synced packs' },
|
||||||
|
})
|
||||||
|
const query = useQuery(computed(() => syncedPackQueryOptions(type.value)))
|
||||||
|
const packs = computed(() => query.value.data.value ?? [])
|
||||||
|
const mutation = useMutation({
|
||||||
|
mutationFn: async (request: { id: string; enabled?: boolean; remove?: boolean }) => {
|
||||||
|
if (request.remove) await remove_synced_pack(request.id)
|
||||||
|
else await set_synced_pack_enabled(request.id, request.enabled ?? true)
|
||||||
|
},
|
||||||
|
onSuccess: () => queryClient.invalidateQueries({ queryKey: syncedPackKeys.all }),
|
||||||
|
})
|
||||||
|
|
||||||
|
async function show(nextType: SyncedPackType) {
|
||||||
|
type.value = nextType
|
||||||
|
modal.value?.show()
|
||||||
|
await queryClient.invalidateQueries({ queryKey: syncedPackKeys.list(nextType) })
|
||||||
|
}
|
||||||
|
|
||||||
|
function hide() {
|
||||||
|
modal.value?.hide()
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ show, hide })
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<NewModal
|
||||||
|
ref="modal"
|
||||||
|
:header="formatMessage(type === 'resourcepack' ? messages.resourcePacks : messages.dataPacks)"
|
||||||
|
max-width="42rem"
|
||||||
|
>
|
||||||
|
<div v-if="packs.length" class="flex flex-col gap-2">
|
||||||
|
<div
|
||||||
|
v-for="pack in packs"
|
||||||
|
:key="pack.id"
|
||||||
|
class="flex items-center gap-3 border-b border-solid border-surface-4 py-2"
|
||||||
|
>
|
||||||
|
<span class="min-w-0 flex-1 truncate">{{ pack.file_name }}</span>
|
||||||
|
<Button
|
||||||
|
:disabled="mutation.isPending.value"
|
||||||
|
@click="mutation.mutate({ id: pack.id, enabled: !pack.enabled })"
|
||||||
|
>{{ formatMessage(pack.enabled ? messages.disable : messages.enable) }}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="colored"
|
||||||
|
color="red"
|
||||||
|
:disabled="mutation.isPending.value"
|
||||||
|
@click="mutation.mutate({ id: pack.id, remove: true })"
|
||||||
|
>{{ formatMessage(messages.remove) }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p v-else class="m-0 text-[var(--color-text-tertiary)]">{{ formatMessage(messages.empty) }}</p>
|
||||||
|
</NewModal>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { SaveIcon, XIcon } from '@modrinth/assets'
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
commonMessages,
|
||||||
|
defineMessages,
|
||||||
|
injectNotificationManager,
|
||||||
|
NewModal,
|
||||||
|
useVIntl,
|
||||||
|
} from '@modrinth/ui'
|
||||||
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
|
||||||
|
import { nextTick, ref } from 'vue'
|
||||||
|
|
||||||
|
import StudioEditor from '@/components/instance/studio/StudioEditor.vue'
|
||||||
|
import { set_command_history } from '@/helpers/instance'
|
||||||
|
import { commandHistoryQueryOptions, syncedOptionsKeys } from '@/helpers/synced-options'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError } = injectNotificationManager()
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
const modal = ref<InstanceType<typeof NewModal> | null>(null)
|
||||||
|
const commandHistory = ref('')
|
||||||
|
const historyQuery = useQuery({ ...commandHistoryQueryOptions(), enabled: false })
|
||||||
|
const saveMutation = useMutation({
|
||||||
|
mutationFn: set_command_history,
|
||||||
|
onSuccess: (history) => {
|
||||||
|
queryClient.setQueryData(syncedOptionsKeys.commandHistory, history)
|
||||||
|
},
|
||||||
|
onError: handleError,
|
||||||
|
})
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
commandHistoryEditorTitle: {
|
||||||
|
id: 'app.settings.synced-options.command-history.editor-title',
|
||||||
|
defaultMessage: 'Edit command history',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
async function show() {
|
||||||
|
const result = await historyQuery.refetch()
|
||||||
|
if (result.isError) {
|
||||||
|
handleError(result.error)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!result.isSuccess) return
|
||||||
|
commandHistory.value = result.data
|
||||||
|
modal.value?.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveCommandHistory() {
|
||||||
|
if (saveMutation.isPending.value) return
|
||||||
|
try {
|
||||||
|
await saveMutation.mutateAsync(commandHistory.value)
|
||||||
|
await nextTick()
|
||||||
|
modal.value?.hide()
|
||||||
|
} catch {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ show })
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<NewModal
|
||||||
|
ref="modal"
|
||||||
|
:header="formatMessage(messages.commandHistoryEditorTitle)"
|
||||||
|
:disable-close="saveMutation.isPending.value"
|
||||||
|
no-padding
|
||||||
|
actions-divider
|
||||||
|
max-width="700px"
|
||||||
|
width="700px"
|
||||||
|
>
|
||||||
|
<StudioEditor
|
||||||
|
v-model:content="commandHistory"
|
||||||
|
file-path="command_history.txt"
|
||||||
|
language="plaintext"
|
||||||
|
class="h-[420px] text-sm"
|
||||||
|
/>
|
||||||
|
<template #actions>
|
||||||
|
<div class="flex justify-end gap-2">
|
||||||
|
<Button type="outlined" @click="modal?.hide()">
|
||||||
|
<XIcon aria-hidden="true" />
|
||||||
|
{{ formatMessage(commonMessages.cancelButton) }}
|
||||||
|
</Button>
|
||||||
|
<Button type="colored" :loading="saveMutation.isPending.value" @click="saveCommandHistory">
|
||||||
|
<SaveIcon aria-hidden="true" />
|
||||||
|
{{ formatMessage(commonMessages.saveButton) }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</NewModal>
|
||||||
|
</template>
|
||||||
+62
@@ -0,0 +1,62 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { Button } from '@modrinth/ui'
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
modelValue?: boolean
|
||||||
|
disabled?: boolean
|
||||||
|
label: string
|
||||||
|
onLabel: string
|
||||||
|
offLabel: string
|
||||||
|
placeholder?: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:model-value': [value: boolean]
|
||||||
|
}>()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div
|
||||||
|
v-tooltip="modelValue === undefined ? placeholder : undefined"
|
||||||
|
role="group"
|
||||||
|
:aria-label="label"
|
||||||
|
class="inline-flex h-9 items-center gap-0.5 rounded-xl border border-solid border-surface-5 p-px shadow-[0_1px_3px_rgba(0,0,0,0.15)]"
|
||||||
|
:class="{ 'opacity-50': disabled }"
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
type="quiet"
|
||||||
|
size="sm"
|
||||||
|
:interaction="modelValue === true ? 'none' : 'surface'"
|
||||||
|
class="boolean-control-on !rounded-[10px] !px-3 !font-medium disabled:!opacity-100"
|
||||||
|
:class="modelValue === true ? '!text-green' : '!text-[var(--color-text-primary)]'"
|
||||||
|
:aria-pressed="modelValue === true"
|
||||||
|
:disabled="disabled"
|
||||||
|
@click="emit('update:model-value', true)"
|
||||||
|
>
|
||||||
|
{{ onLabel }}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="quiet"
|
||||||
|
size="sm"
|
||||||
|
:interaction="modelValue === false ? 'none' : 'surface'"
|
||||||
|
class="boolean-control-off !rounded-[10px] !px-3 !font-medium !text-[var(--color-text-primary)] disabled:!opacity-100"
|
||||||
|
:aria-pressed="modelValue === false"
|
||||||
|
:disabled="disabled"
|
||||||
|
@click="emit('update:model-value', false)"
|
||||||
|
>
|
||||||
|
{{ offLabel }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.boolean-control-on[aria-pressed='true'] {
|
||||||
|
background-color: color-mix(in srgb, var(--color-green) 30%, var(--surface-3));
|
||||||
|
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--color-green) 60%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.boolean-control-off[aria-pressed='true'] {
|
||||||
|
background-color: var(--surface-4);
|
||||||
|
box-shadow: inset 0 0 0 1px var(--surface-5);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
+163
@@ -0,0 +1,163 @@
|
|||||||
|
import { toRaw } from 'vue'
|
||||||
|
|
||||||
|
import type {
|
||||||
|
EditableGameSetting,
|
||||||
|
GameOptionCanonicalValue,
|
||||||
|
GameSettingChange,
|
||||||
|
GameSettingsEditorState,
|
||||||
|
} from '@/helpers/game-options'
|
||||||
|
|
||||||
|
function clonePlainValue(value: unknown): unknown {
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
return toRaw(value).map(clonePlainValue)
|
||||||
|
}
|
||||||
|
if (value !== null && typeof value === 'object') {
|
||||||
|
return Object.fromEntries(
|
||||||
|
Object.entries(toRaw(value)).map(([key, nestedValue]) => [key, clonePlainValue(nestedValue)]),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
export function cloneGameSettingsState(state: GameSettingsEditorState): GameSettingsEditorState {
|
||||||
|
return clonePlainValue(state) as GameSettingsEditorState
|
||||||
|
}
|
||||||
|
|
||||||
|
export function canonicalValuesEqual(
|
||||||
|
left: GameOptionCanonicalValue | null | undefined,
|
||||||
|
right: GameOptionCanonicalValue | null | undefined,
|
||||||
|
): boolean {
|
||||||
|
return JSON.stringify(left ?? null) === JSON.stringify(right ?? null)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function gameSettingChanges(
|
||||||
|
base: GameSettingsEditorState | null,
|
||||||
|
draft: GameSettingsEditorState | null,
|
||||||
|
forcedValueOptionIds: ReadonlySet<string> = new Set(),
|
||||||
|
): GameSettingChange[] {
|
||||||
|
if (!base || !draft) return []
|
||||||
|
|
||||||
|
const baseSettings = new Map(base.settings.map((setting) => [setting.option_id, setting]))
|
||||||
|
return draft.settings.flatMap((setting) => {
|
||||||
|
const previous = baseSettings.get(setting.option_id)
|
||||||
|
if (!previous) return []
|
||||||
|
|
||||||
|
const syncChanged = previous.sync_enabled !== setting.sync_enabled
|
||||||
|
const valueChanged = !canonicalValuesEqual(previous.canonical_value, setting.canonical_value)
|
||||||
|
const promoteLocalValue =
|
||||||
|
forcedValueOptionIds.has(setting.option_id) &&
|
||||||
|
previous.value_state !== 'canonical' &&
|
||||||
|
setting.canonical_value !== null &&
|
||||||
|
setting.canonical_value !== undefined
|
||||||
|
if (!syncChanged && !valueChanged && !promoteLocalValue) return []
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
option_id: setting.option_id,
|
||||||
|
base_option_revision: previous.option_revision,
|
||||||
|
...(syncChanged ? { sync_enabled: setting.sync_enabled } : {}),
|
||||||
|
...(valueChanged || promoteLocalValue
|
||||||
|
? { canonical_value: setting.canonical_value ?? null }
|
||||||
|
: {}),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function gameSettingNumberScale(setting: EditableGameSetting): number {
|
||||||
|
if (setting.editor.unit !== 'percent') return 1
|
||||||
|
return setting.option_id === 'sensitivity' ? 200 : 100
|
||||||
|
}
|
||||||
|
|
||||||
|
export function canonicalValueText(setting: EditableGameSetting): string {
|
||||||
|
const value = setting.canonical_value
|
||||||
|
if (!value) return ''
|
||||||
|
|
||||||
|
switch (value.type) {
|
||||||
|
case 'bool':
|
||||||
|
return value.value ? 'true' : 'false'
|
||||||
|
case 'integer':
|
||||||
|
case 'decimal':
|
||||||
|
return setting.editor.unit === 'percent'
|
||||||
|
? String(Number((Number(value.value) * gameSettingNumberScale(setting)).toFixed(8)))
|
||||||
|
: String(value.value)
|
||||||
|
case 'string_list':
|
||||||
|
return value.value.join(', ')
|
||||||
|
default:
|
||||||
|
return value.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function canonicalBooleanValue(setting: EditableGameSetting): boolean | undefined {
|
||||||
|
return setting.canonical_value?.type === 'bool' ? setting.canonical_value.value : undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isKeybindSetting(setting: EditableGameSetting): boolean {
|
||||||
|
return (
|
||||||
|
setting.editor.type === 'key_binding' ||
|
||||||
|
(setting.editor.type === 'external_raw' && !!setting.raw_key?.startsWith('key_'))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function canonicalValueFromInput(
|
||||||
|
setting: EditableGameSetting,
|
||||||
|
value: string | number | boolean | undefined,
|
||||||
|
): GameOptionCanonicalValue | null {
|
||||||
|
if (value === undefined || value === '') return null
|
||||||
|
|
||||||
|
switch (setting.editor.type) {
|
||||||
|
case 'bool':
|
||||||
|
return { type: 'bool', value: Boolean(value) }
|
||||||
|
case 'integer': {
|
||||||
|
const parsed = Number(value)
|
||||||
|
return Number.isSafeInteger(parsed) ? { type: 'integer', value: parsed } : null
|
||||||
|
}
|
||||||
|
case 'decimal': {
|
||||||
|
const parsed = Number(value)
|
||||||
|
if (!Number.isFinite(parsed)) return null
|
||||||
|
return {
|
||||||
|
type: 'decimal',
|
||||||
|
value:
|
||||||
|
setting.editor.unit === 'percent'
|
||||||
|
? String(Number((parsed / gameSettingNumberScale(setting)).toFixed(8)))
|
||||||
|
: String(value),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 'enum':
|
||||||
|
return { type: 'enum', value: String(value) }
|
||||||
|
case 'string_list':
|
||||||
|
return {
|
||||||
|
type: 'string_list',
|
||||||
|
value: String(value)
|
||||||
|
.split(',')
|
||||||
|
.map((item) => item.trim())
|
||||||
|
.filter(Boolean),
|
||||||
|
}
|
||||||
|
case 'key_binding':
|
||||||
|
return { type: 'key_binding', value: String(value) }
|
||||||
|
case 'external_raw':
|
||||||
|
return { type: 'external_raw', value: String(value) }
|
||||||
|
default:
|
||||||
|
return { type: 'text', value: String(value) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function settingSearchText(
|
||||||
|
setting: EditableGameSetting,
|
||||||
|
label: string,
|
||||||
|
description: string,
|
||||||
|
): string {
|
||||||
|
return [label, description, setting.option_id, setting.raw_key]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(' ')
|
||||||
|
.toLocaleLowerCase()
|
||||||
|
}
|
||||||
|
|
||||||
|
export function settingCanBeEnabled(setting: EditableGameSetting): boolean {
|
||||||
|
return (
|
||||||
|
!setting.controlled &&
|
||||||
|
!setting.validation_error &&
|
||||||
|
!['mixed', 'unset', 'invalid'].includes(setting.value_state) &&
|
||||||
|
(setting.compatibility.total_participating === 0 || setting.compatibility.will_receive > 0)
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,483 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
EyeIcon,
|
||||||
|
LanguagesIcon,
|
||||||
|
LinkIcon,
|
||||||
|
MessageIcon,
|
||||||
|
MonitorIcon,
|
||||||
|
RefreshCwIcon,
|
||||||
|
SaveIcon,
|
||||||
|
SearchIcon,
|
||||||
|
SettingsIcon,
|
||||||
|
ShirtIcon,
|
||||||
|
TagCategoryAudioIcon,
|
||||||
|
TagCategoryGamepad2Icon,
|
||||||
|
UnlinkIcon,
|
||||||
|
WrenchIcon,
|
||||||
|
XIcon,
|
||||||
|
} from '@modrinth/assets'
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
commonMessages,
|
||||||
|
defineMessages,
|
||||||
|
FloatingActionBar,
|
||||||
|
StyledInput,
|
||||||
|
TabbedModal,
|
||||||
|
type TabbedModalTab,
|
||||||
|
useVIntl,
|
||||||
|
} from '@modrinth/ui'
|
||||||
|
import type { Component } from 'vue'
|
||||||
|
import { computed, inject, ref, watch } from 'vue'
|
||||||
|
import { type RouteLocationRaw, useRouter } from 'vue-router'
|
||||||
|
|
||||||
|
import type { EditableGameSetting, GameSettingCategory } from '@/helpers/game-options'
|
||||||
|
import { injectInstanceSettings } from '@/pages/instance/components/settings-modal/instance-settings-context'
|
||||||
|
import { appSettingsModalContextKey } from '@/providers/app-settings-modal'
|
||||||
|
|
||||||
|
import {
|
||||||
|
canonicalValueText,
|
||||||
|
isKeybindSetting,
|
||||||
|
settingCanBeEnabled,
|
||||||
|
settingSearchText,
|
||||||
|
} from './editors'
|
||||||
|
import { minecraftKeybindConflictKey } from './keybinds'
|
||||||
|
import {
|
||||||
|
formatGameSettingDescription,
|
||||||
|
formatGameSettingLabel,
|
||||||
|
gameSettingCategoryMessage,
|
||||||
|
} from './messages'
|
||||||
|
import GameSettingRow from './row.vue'
|
||||||
|
import { useGameSettingsEditor } from './use-editor'
|
||||||
|
import { useGameSettingLabels } from './use-labels'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
instanceId?: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
saved: []
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const router = useRouter()
|
||||||
|
const appSettingsModal = inject(appSettingsModalContextKey, null)
|
||||||
|
const instanceSettings = injectInstanceSettings(null)
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.title',
|
||||||
|
defaultMessage: 'Game settings',
|
||||||
|
},
|
||||||
|
syncTitle: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.sync-title',
|
||||||
|
defaultMessage: 'Sync game settings',
|
||||||
|
},
|
||||||
|
syncedOptionsDescription: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.sync-description',
|
||||||
|
defaultMessage:
|
||||||
|
'Synced options are applied to every instance and override the values included with a modpack.',
|
||||||
|
},
|
||||||
|
search: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.search',
|
||||||
|
defaultMessage: 'Search settings...',
|
||||||
|
},
|
||||||
|
enableAll: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.enable-all',
|
||||||
|
defaultMessage: 'Sync all',
|
||||||
|
},
|
||||||
|
disableAll: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.disable-all',
|
||||||
|
defaultMessage: 'Unsync all',
|
||||||
|
},
|
||||||
|
customEmpty: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.custom-empty',
|
||||||
|
defaultMessage:
|
||||||
|
'Settings added by mods will appear here after Modrinth finds them in one of your instances.',
|
||||||
|
},
|
||||||
|
empty: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.empty',
|
||||||
|
defaultMessage: 'No settings match your search or filter.',
|
||||||
|
},
|
||||||
|
loading: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.loading',
|
||||||
|
defaultMessage: 'Loading settings...',
|
||||||
|
},
|
||||||
|
loadFailed: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.load-failed',
|
||||||
|
defaultMessage: 'We couldn’t load your game settings.',
|
||||||
|
},
|
||||||
|
retry: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.retry',
|
||||||
|
defaultMessage: 'Retry',
|
||||||
|
},
|
||||||
|
saveSettings: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.save',
|
||||||
|
defaultMessage: 'Save settings',
|
||||||
|
},
|
||||||
|
unsavedChanges: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.unsaved-changes',
|
||||||
|
defaultMessage: 'You have unsaved changes.',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const modal = ref<InstanceType<typeof TabbedModal> | null>(null)
|
||||||
|
const activeCategoryId = ref('')
|
||||||
|
const search = ref('')
|
||||||
|
const opened = ref(false)
|
||||||
|
let allowClose = false
|
||||||
|
|
||||||
|
const {
|
||||||
|
draftState,
|
||||||
|
isLocalEditor,
|
||||||
|
isDirty,
|
||||||
|
hasBlockingDraft,
|
||||||
|
loading,
|
||||||
|
loadError,
|
||||||
|
saving,
|
||||||
|
load,
|
||||||
|
reset: resetEditor,
|
||||||
|
cancelChanges,
|
||||||
|
setSyncEnabled,
|
||||||
|
setCanonicalValue,
|
||||||
|
save,
|
||||||
|
saveAndWait,
|
||||||
|
} = useGameSettingsEditor(
|
||||||
|
() => props.instanceId,
|
||||||
|
() => emit('saved'),
|
||||||
|
)
|
||||||
|
|
||||||
|
const categoryIcons: Record<string, Component> = {
|
||||||
|
skin_customization: ShirtIcon,
|
||||||
|
video: MonitorIcon,
|
||||||
|
video_settings: MonitorIcon,
|
||||||
|
language: LanguagesIcon,
|
||||||
|
music_and_sound: TagCategoryAudioIcon,
|
||||||
|
controls: TagCategoryGamepad2Icon,
|
||||||
|
chat: MessageIcon,
|
||||||
|
chat_settings: MessageIcon,
|
||||||
|
accessibility: EyeIcon,
|
||||||
|
custom: WrenchIcon,
|
||||||
|
custom_settings: WrenchIcon,
|
||||||
|
}
|
||||||
|
|
||||||
|
const localeLabels = useGameSettingLabels(
|
||||||
|
opened,
|
||||||
|
() => props.instanceId,
|
||||||
|
() => draftState.value?.settings ?? [],
|
||||||
|
)
|
||||||
|
|
||||||
|
function settingLabel(setting: EditableGameSetting) {
|
||||||
|
if (setting.kind === 'external') {
|
||||||
|
return (
|
||||||
|
localeLabels.value[setting.option_id]?.label ?? formatGameSettingLabel(formatMessage, setting)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return formatGameSettingLabel(formatMessage, setting)
|
||||||
|
}
|
||||||
|
|
||||||
|
const categories = computed<GameSettingCategory[]>(() => {
|
||||||
|
if (!draftState.value) return []
|
||||||
|
|
||||||
|
const settings = draftState.value.settings
|
||||||
|
const visible = draftState.value.categories.filter(
|
||||||
|
(category) =>
|
||||||
|
category.is_custom || settings.some((setting) => setting.category_id === category.id),
|
||||||
|
)
|
||||||
|
if (!visible.some((category) => category.is_custom || category.id === 'custom_settings')) {
|
||||||
|
visible.push({
|
||||||
|
id: 'custom_settings',
|
||||||
|
is_custom: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return visible
|
||||||
|
})
|
||||||
|
|
||||||
|
const categoryTabs = computed<TabbedModalTab[]>(() =>
|
||||||
|
categories.value.map((category) => ({
|
||||||
|
name: gameSettingCategoryMessage(category),
|
||||||
|
icon: categoryIcon(category),
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
|
||||||
|
const activeCategory = computed(() =>
|
||||||
|
categories.value.find((category) => category.id === activeCategoryId.value),
|
||||||
|
)
|
||||||
|
|
||||||
|
const categorySettings = computed(() => {
|
||||||
|
if (!draftState.value) return []
|
||||||
|
|
||||||
|
const query = search.value.trim().toLocaleLowerCase()
|
||||||
|
return draftState.value.settings.filter((setting) => {
|
||||||
|
if (!query && setting.category_id !== activeCategoryId.value) return false
|
||||||
|
if (
|
||||||
|
query &&
|
||||||
|
!settingSearchText(
|
||||||
|
setting,
|
||||||
|
settingLabel(setting),
|
||||||
|
setting.kind === 'external'
|
||||||
|
? (localeLabels.value[setting.option_id]?.source?.project?.title ??
|
||||||
|
localeLabels.value[setting.option_id]?.source?.file_name ??
|
||||||
|
'')
|
||||||
|
: formatGameSettingDescription(formatMessage, setting),
|
||||||
|
).includes(query)
|
||||||
|
)
|
||||||
|
return false
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const keybindConflicts = computed(() => {
|
||||||
|
if (!draftState.value) return new Map<string, string[]>()
|
||||||
|
|
||||||
|
const bindings = new Map<string, EditableGameSetting[]>()
|
||||||
|
for (const setting of draftState.value.settings) {
|
||||||
|
if (!isKeybindSetting(setting)) continue
|
||||||
|
const key = minecraftKeybindConflictKey(setting.option_id, canonicalValueText(setting))
|
||||||
|
if (!key) continue
|
||||||
|
bindings.set(key, [...(bindings.get(key) ?? []), setting])
|
||||||
|
}
|
||||||
|
|
||||||
|
const conflicts = new Map<string, string[]>()
|
||||||
|
for (const settings of bindings.values()) {
|
||||||
|
if (settings.length < 2) continue
|
||||||
|
for (const setting of settings) {
|
||||||
|
conflicts.set(
|
||||||
|
setting.option_id,
|
||||||
|
settings
|
||||||
|
.filter((candidate) => candidate.option_id !== setting.option_id)
|
||||||
|
.map((candidate) => settingLabel(candidate)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return conflicts
|
||||||
|
})
|
||||||
|
|
||||||
|
const enableCandidates = computed(() =>
|
||||||
|
categorySettings.value.filter((setting) => !setting.sync_enabled && settingCanBeEnabled(setting)),
|
||||||
|
)
|
||||||
|
const disableCandidates = computed(() =>
|
||||||
|
categorySettings.value.filter((setting) => setting.sync_enabled && !setting.controlled),
|
||||||
|
)
|
||||||
|
const toggleableCategorySettings = computed(() =>
|
||||||
|
categorySettings.value.filter((setting) => !setting.controlled),
|
||||||
|
)
|
||||||
|
const allCategorySettingsSynced = computed(
|
||||||
|
() =>
|
||||||
|
toggleableCategorySettings.value.length > 0 &&
|
||||||
|
toggleableCategorySettings.value.every((setting) => setting.sync_enabled),
|
||||||
|
)
|
||||||
|
const modalTitle = computed(() =>
|
||||||
|
formatMessage(isLocalEditor.value ? messages.title : messages.syncTitle),
|
||||||
|
)
|
||||||
|
|
||||||
|
function categoryIcon(category: GameSettingCategory): Component {
|
||||||
|
return categoryIcons[category.id] ?? SettingsIcon
|
||||||
|
}
|
||||||
|
|
||||||
|
function changeCategory(_fromIndex: number, toIndex: number): boolean {
|
||||||
|
const category = categories.value[toIndex]
|
||||||
|
if (!category) return false
|
||||||
|
activeCategoryId.value = category.id
|
||||||
|
search.value = ''
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
categories,
|
||||||
|
() => {
|
||||||
|
if (!categories.value.some((category) => category.id === activeCategoryId.value)) {
|
||||||
|
activeCategoryId.value = categories.value[0]?.id ?? 'custom_settings'
|
||||||
|
}
|
||||||
|
const index = categories.value.findIndex((category) => category.id === activeCategoryId.value)
|
||||||
|
if (index >= 0) modal.value?.setTab(index)
|
||||||
|
},
|
||||||
|
{ flush: 'sync' },
|
||||||
|
)
|
||||||
|
|
||||||
|
function show() {
|
||||||
|
opened.value = true
|
||||||
|
allowClose = false
|
||||||
|
search.value = ''
|
||||||
|
void load()
|
||||||
|
modal.value?.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
function hide() {
|
||||||
|
modal.value?.hide()
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
opened.value = false
|
||||||
|
resetEditor()
|
||||||
|
allowClose = false
|
||||||
|
}
|
||||||
|
|
||||||
|
function beforeHide(): boolean {
|
||||||
|
if (allowClose || !isDirty.value) return true
|
||||||
|
void saveBeforeClose()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveBeforeClose() {
|
||||||
|
const saved = await saveAndWait()
|
||||||
|
if (!saved) return
|
||||||
|
allowClose = true
|
||||||
|
modal.value?.hide()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function openSource(location: RouteLocationRaw) {
|
||||||
|
if (isDirty.value || saving.value) return
|
||||||
|
if (appSettingsModal && !appSettingsModal.close()) return
|
||||||
|
allowClose = true
|
||||||
|
modal.value?.hide()
|
||||||
|
if (instanceSettings?.closeModal) {
|
||||||
|
instanceSettings.closeModal(() => void router.push(location))
|
||||||
|
} else {
|
||||||
|
await router.push(location)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleVisibleSync() {
|
||||||
|
const enabled = !allCategorySettingsSynced.value
|
||||||
|
const candidates = enabled ? enableCandidates.value : disableCandidates.value
|
||||||
|
setSyncEnabled(
|
||||||
|
candidates.map((setting) => setting.option_id),
|
||||||
|
enabled,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ show, hide })
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<TabbedModal
|
||||||
|
ref="modal"
|
||||||
|
:tabs="categoryTabs"
|
||||||
|
:header="modalTitle"
|
||||||
|
:before-hide="beforeHide"
|
||||||
|
:before-tab-change="changeCategory"
|
||||||
|
:hide-tab-selection="search.trim().length > 0"
|
||||||
|
:on-after-hide="reset"
|
||||||
|
:floating-action-bar-shown="isDirty"
|
||||||
|
max-width="min(1080px, calc(95vw - 2rem))"
|
||||||
|
width="min(1080px, calc(95vw - 2rem))"
|
||||||
|
>
|
||||||
|
<template #sidebar-header>
|
||||||
|
<div class="pb-4">
|
||||||
|
<StyledInput
|
||||||
|
v-model="search"
|
||||||
|
:icon="SearchIcon"
|
||||||
|
type="search"
|
||||||
|
autocomplete="off"
|
||||||
|
:placeholder="formatMessage(messages.search)"
|
||||||
|
:aria-label="formatMessage(messages.search)"
|
||||||
|
wrapper-class="w-full shrink-0"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template #content>
|
||||||
|
<div class="flex min-h-full min-w-0 flex-col">
|
||||||
|
<div
|
||||||
|
v-if="!isLocalEditor && (loading || loadError || categorySettings.length > 0)"
|
||||||
|
class="mb-4 flex shrink-0 flex-wrap items-start justify-between gap-4 border-0 border-b border-solid border-surface-4 pb-4"
|
||||||
|
>
|
||||||
|
<p class="m-0 min-w-60 flex-1 text-[var(--color-text-default)]">
|
||||||
|
{{ formatMessage(messages.syncedOptionsDescription) }}
|
||||||
|
</p>
|
||||||
|
<div class="ml-auto flex w-48 justify-end">
|
||||||
|
<Button
|
||||||
|
size="lg"
|
||||||
|
:disabled="
|
||||||
|
allCategorySettingsSynced
|
||||||
|
? disableCandidates.length === 0
|
||||||
|
: enableCandidates.length === 0
|
||||||
|
"
|
||||||
|
@click="toggleVisibleSync"
|
||||||
|
>
|
||||||
|
<LinkIcon v-if="allCategorySettingsSynced" aria-hidden="true" />
|
||||||
|
<UnlinkIcon v-else aria-hidden="true" />
|
||||||
|
{{
|
||||||
|
formatMessage(allCategorySettingsSynced ? messages.disableAll : messages.enableAll)
|
||||||
|
}}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="loading"
|
||||||
|
role="status"
|
||||||
|
:aria-label="formatMessage(messages.loading)"
|
||||||
|
class="flex flex-1 flex-col gap-4"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-for="row in 5"
|
||||||
|
:key="row"
|
||||||
|
class="h-20 animate-pulse rounded-xl bg-surface-3"
|
||||||
|
aria-hidden="true"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-else-if="loadError"
|
||||||
|
class="flex min-h-40 flex-1 flex-col items-center justify-center gap-3 text-[var(--color-text-tertiary)]"
|
||||||
|
>
|
||||||
|
<p class="m-0">{{ formatMessage(messages.loadFailed) }}</p>
|
||||||
|
<Button @click="load">
|
||||||
|
<RefreshCwIcon aria-hidden="true" />
|
||||||
|
{{ formatMessage(messages.retry) }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div v-else class="min-h-0 flex-1">
|
||||||
|
<div
|
||||||
|
v-if="categorySettings.length === 0"
|
||||||
|
class="flex h-full min-h-40 items-center justify-center px-8 text-center text-[var(--color-text-tertiary)]"
|
||||||
|
>
|
||||||
|
{{
|
||||||
|
activeCategory?.is_custom && !search
|
||||||
|
? formatMessage(messages.customEmpty)
|
||||||
|
: formatMessage(messages.empty)
|
||||||
|
}}
|
||||||
|
</div>
|
||||||
|
<div v-else class="flex flex-col gap-4">
|
||||||
|
<GameSettingRow
|
||||||
|
v-for="setting in categorySettings"
|
||||||
|
:key="setting.option_id"
|
||||||
|
:setting="setting"
|
||||||
|
:locale-label="localeLabels[setting.option_id]"
|
||||||
|
:keybind-conflicts="keybindConflicts.get(setting.option_id)"
|
||||||
|
:show-sync-toggle="!isLocalEditor"
|
||||||
|
:source-navigation-disabled="isDirty || saving"
|
||||||
|
@open-source="openSource"
|
||||||
|
@update:sync-enabled="setSyncEnabled([setting.option_id], $event)"
|
||||||
|
@update:canonical-value="setCanonicalValue(setting.option_id, $event)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template #floating-action-bar>
|
||||||
|
<FloatingActionBar v-if="isDirty" shown inline :aria-label="modalTitle">
|
||||||
|
<p class="m-0 text-sm font-semibold md:text-base">
|
||||||
|
{{ formatMessage(messages.unsavedChanges) }}
|
||||||
|
</p>
|
||||||
|
<div class="ml-auto flex gap-2">
|
||||||
|
<Button type="outlined" @click="cancelChanges">
|
||||||
|
<XIcon aria-hidden="true" />
|
||||||
|
{{ formatMessage(commonMessages.cancelButton) }}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="colored"
|
||||||
|
color="brand"
|
||||||
|
:disabled="!isDirty || loading || saving || hasBlockingDraft"
|
||||||
|
:loading="saving"
|
||||||
|
@click="save"
|
||||||
|
>
|
||||||
|
<SaveIcon aria-hidden="true" />
|
||||||
|
{{ formatMessage(messages.saveSettings) }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</FloatingActionBar>
|
||||||
|
</template>
|
||||||
|
</TabbedModal>
|
||||||
|
</template>
|
||||||
+235
@@ -0,0 +1,235 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { TriangleAlertIcon } from '@modrinth/assets'
|
||||||
|
import { Button, defineMessages, useVIntl } from '@modrinth/ui'
|
||||||
|
import { computed, onBeforeUnmount, ref, useId, watch } from 'vue'
|
||||||
|
|
||||||
|
import {
|
||||||
|
activateKeybindRecording,
|
||||||
|
deactivateKeybindRecording,
|
||||||
|
formatMinecraftKeybind,
|
||||||
|
minecraftKeyTokenFromKeyboardEvent,
|
||||||
|
minecraftMouseTokenFromButton,
|
||||||
|
} from './keybinds'
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
modelValue: string
|
||||||
|
settingLabel: string
|
||||||
|
conflicts?: string[]
|
||||||
|
mixed?: boolean
|
||||||
|
disabled?: boolean
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
conflicts: () => [],
|
||||||
|
mixed: false,
|
||||||
|
disabled: false,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:model-value': [value: string]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { formatMessage, locale } = useVIntl()
|
||||||
|
const statusId = useId()
|
||||||
|
const conflictId = useId()
|
||||||
|
const recording = ref(false)
|
||||||
|
const statusMessage = ref('')
|
||||||
|
const controlElement = ref<HTMLElement | null>(null)
|
||||||
|
let suppressNextClick = false
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
listen: {
|
||||||
|
id: 'app.settings.game-options.keybind.listen',
|
||||||
|
defaultMessage: 'Press a key…',
|
||||||
|
},
|
||||||
|
choose: {
|
||||||
|
id: 'app.settings.game-options.keybind.choose',
|
||||||
|
defaultMessage: 'Choose a key',
|
||||||
|
},
|
||||||
|
mixed: {
|
||||||
|
id: 'app.settings.game-options.keybind.mixed',
|
||||||
|
defaultMessage: 'Different across instances',
|
||||||
|
},
|
||||||
|
change: {
|
||||||
|
id: 'app.settings.game-options.keybind.change',
|
||||||
|
defaultMessage: '{setting}: {binding}. Activate to change the binding.',
|
||||||
|
},
|
||||||
|
listeningStatus: {
|
||||||
|
id: 'app.settings.game-options.keybind.listening-status',
|
||||||
|
defaultMessage: 'Listening for a key or mouse button. Press Escape to clear this binding.',
|
||||||
|
},
|
||||||
|
recordingLabel: {
|
||||||
|
id: 'app.settings.game-options.keybind.recording-label',
|
||||||
|
defaultMessage:
|
||||||
|
'{setting}: listening for a key or mouse button. Press Escape to clear this binding.',
|
||||||
|
},
|
||||||
|
unsupportedStatus: {
|
||||||
|
id: 'app.settings.game-options.keybind.unsupported-status',
|
||||||
|
defaultMessage: 'That input cannot be used by Minecraft. Press another key.',
|
||||||
|
},
|
||||||
|
cancelledStatus: {
|
||||||
|
id: 'app.settings.game-options.keybind.cancelled-status',
|
||||||
|
defaultMessage: 'Key binding change cancelled.',
|
||||||
|
},
|
||||||
|
assignedStatus: {
|
||||||
|
id: 'app.settings.game-options.keybind.assigned-status',
|
||||||
|
defaultMessage: '{setting} is now bound to {binding}.',
|
||||||
|
},
|
||||||
|
conflict: {
|
||||||
|
id: 'app.settings.game-options.keybind.conflict-description',
|
||||||
|
defaultMessage: 'This is already used by {settings}.',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const isMac = /Mac|iPhone|iPad|iPod/.test(navigator.platform)
|
||||||
|
const bindingLabel = computed(() => {
|
||||||
|
if (props.mixed) return formatMessage(messages.mixed)
|
||||||
|
if (!props.modelValue) return formatMessage(messages.choose)
|
||||||
|
return formatMinecraftKeybind(formatMessage, props.modelValue, isMac)
|
||||||
|
})
|
||||||
|
const visibleLabel = computed(() =>
|
||||||
|
recording.value ? formatMessage(messages.listen) : bindingLabel.value,
|
||||||
|
)
|
||||||
|
const conflictSettings = computed(() =>
|
||||||
|
new Intl.ListFormat(locale.value, { style: 'long', type: 'conjunction' }).format(
|
||||||
|
props.conflicts.map((setting) => `‘${setting}’`),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
const conflictMessage = computed(() =>
|
||||||
|
props.conflicts.length
|
||||||
|
? formatMessage(messages.conflict, { settings: conflictSettings.value })
|
||||||
|
: '',
|
||||||
|
)
|
||||||
|
const accessibleLabel = computed(() =>
|
||||||
|
formatMessage(recording.value ? messages.recordingLabel : messages.change, {
|
||||||
|
setting: props.settingLabel,
|
||||||
|
binding: bindingLabel.value,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
function startRecording() {
|
||||||
|
if (props.disabled || recording.value) return
|
||||||
|
activateKeybindRecording(cancelRecording)
|
||||||
|
recording.value = true
|
||||||
|
statusMessage.value = formatMessage(messages.listeningStatus)
|
||||||
|
window.addEventListener('keydown', handleKeydown, true)
|
||||||
|
window.addEventListener('pointerdown', handlePointerDown, true)
|
||||||
|
window.addEventListener('blur', cancelRecording)
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopRecording() {
|
||||||
|
recording.value = false
|
||||||
|
window.removeEventListener('keydown', handleKeydown, true)
|
||||||
|
window.removeEventListener('pointerdown', handlePointerDown, true)
|
||||||
|
window.removeEventListener('blur', cancelRecording)
|
||||||
|
deactivateKeybindRecording(cancelRecording)
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelRecording() {
|
||||||
|
if (!recording.value) return
|
||||||
|
stopRecording()
|
||||||
|
statusMessage.value = formatMessage(messages.cancelledStatus)
|
||||||
|
}
|
||||||
|
|
||||||
|
function assign(value: string) {
|
||||||
|
if (!recording.value) return
|
||||||
|
stopRecording()
|
||||||
|
emit('update:model-value', value)
|
||||||
|
statusMessage.value = formatMessage(messages.assignedStatus, {
|
||||||
|
setting: props.settingLabel,
|
||||||
|
binding: formatMinecraftKeybind(formatMessage, value, isMac),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleClick(event: MouseEvent) {
|
||||||
|
if (suppressNextClick) {
|
||||||
|
suppressNextClick = false
|
||||||
|
event.preventDefault()
|
||||||
|
event.stopPropagation()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
startRecording()
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleKeydown(event: KeyboardEvent) {
|
||||||
|
if (!recording.value) return
|
||||||
|
|
||||||
|
event.preventDefault()
|
||||||
|
event.stopPropagation()
|
||||||
|
if (event.code === 'Escape') {
|
||||||
|
assign('key.keyboard.unknown')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (event.repeat) return
|
||||||
|
|
||||||
|
const token = event.isComposing ? null : minecraftKeyTokenFromKeyboardEvent(event)
|
||||||
|
if (!token) {
|
||||||
|
statusMessage.value = formatMessage(messages.unsupportedStatus)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
assign(token)
|
||||||
|
}
|
||||||
|
|
||||||
|
function handlePointerDown(event: PointerEvent) {
|
||||||
|
if (!recording.value) return
|
||||||
|
if (event.pointerType !== 'mouse') return
|
||||||
|
const otherKeybindControl =
|
||||||
|
event.target instanceof Element
|
||||||
|
? event.target.closest<HTMLElement>('[data-game-keybind-control]')
|
||||||
|
: null
|
||||||
|
if (otherKeybindControl && otherKeybindControl !== controlElement.value) return
|
||||||
|
|
||||||
|
event.preventDefault()
|
||||||
|
event.stopPropagation()
|
||||||
|
const token = minecraftMouseTokenFromButton(event.button)
|
||||||
|
if (!token) {
|
||||||
|
statusMessage.value = formatMessage(messages.unsupportedStatus)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
suppressNextClick = event.button === 0 && otherKeybindControl === controlElement.value
|
||||||
|
assign(token)
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.disabled,
|
||||||
|
(disabled) => {
|
||||||
|
if (disabled) cancelRecording()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
onBeforeUnmount(cancelRecording)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex w-full min-w-0 items-center gap-1.5">
|
||||||
|
<span
|
||||||
|
ref="controlElement"
|
||||||
|
v-tooltip="!recording && conflictMessage ? conflictMessage : undefined"
|
||||||
|
data-game-keybind-control
|
||||||
|
class="flex min-w-0 flex-1"
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
:type="recording || conflicts.length ? 'outlined' : 'base'"
|
||||||
|
:color="recording ? 'brand' : conflicts.length ? 'orange' : undefined"
|
||||||
|
size="md"
|
||||||
|
:disabled="disabled"
|
||||||
|
:aria-label="accessibleLabel"
|
||||||
|
:aria-describedby="recording ? statusId : conflicts.length ? conflictId : undefined"
|
||||||
|
class="w-full overflow-hidden"
|
||||||
|
@click="handleClick"
|
||||||
|
@contextmenu.prevent.stop
|
||||||
|
@auxclick.prevent.stop
|
||||||
|
>
|
||||||
|
<TriangleAlertIcon v-if="!recording && conflicts.length" aria-hidden="true" />
|
||||||
|
<span class="min-w-0 truncate">{{ visibleLabel }}</span>
|
||||||
|
</Button>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<span :id="statusId" class="visually-hidden" role="status" aria-live="polite">
|
||||||
|
{{ statusMessage }}
|
||||||
|
</span>
|
||||||
|
<span v-if="conflicts.length" :id="conflictId" class="visually-hidden">
|
||||||
|
{{ conflictMessage }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
+426
@@ -0,0 +1,426 @@
|
|||||||
|
import { defineMessages, type MessageDescriptor, type VIntlFormatters } from '@modrinth/ui'
|
||||||
|
|
||||||
|
type FormatMessage = VIntlFormatters['formatMessage']
|
||||||
|
|
||||||
|
type StopKeybindRecording = () => void
|
||||||
|
let stopActiveKeybindRecording: StopKeybindRecording | null = null
|
||||||
|
|
||||||
|
export function activateKeybindRecording(stop: StopKeybindRecording) {
|
||||||
|
if (stopActiveKeybindRecording === stop) return
|
||||||
|
const stopPrevious = stopActiveKeybindRecording
|
||||||
|
stopActiveKeybindRecording = stop
|
||||||
|
stopPrevious?.()
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deactivateKeybindRecording(stop: StopKeybindRecording) {
|
||||||
|
if (stopActiveKeybindRecording === stop) {
|
||||||
|
stopActiveKeybindRecording = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const keyMessages = defineMessages({
|
||||||
|
unbound: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.unbound',
|
||||||
|
defaultMessage: 'Unbound',
|
||||||
|
},
|
||||||
|
escape: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.escape',
|
||||||
|
defaultMessage: 'Escape',
|
||||||
|
},
|
||||||
|
backspace: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.backspace',
|
||||||
|
defaultMessage: 'Backspace',
|
||||||
|
},
|
||||||
|
tab: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.tab',
|
||||||
|
defaultMessage: 'Tab',
|
||||||
|
},
|
||||||
|
enter: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.enter',
|
||||||
|
defaultMessage: 'Enter',
|
||||||
|
},
|
||||||
|
leftControl: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.left-control',
|
||||||
|
defaultMessage: 'Left Ctrl',
|
||||||
|
},
|
||||||
|
rightControl: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.right-control',
|
||||||
|
defaultMessage: 'Right Ctrl',
|
||||||
|
},
|
||||||
|
leftShift: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.left-shift',
|
||||||
|
defaultMessage: 'Left Shift',
|
||||||
|
},
|
||||||
|
rightShift: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.right-shift',
|
||||||
|
defaultMessage: 'Right Shift',
|
||||||
|
},
|
||||||
|
leftAlt: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.left-alt',
|
||||||
|
defaultMessage: 'Left Alt',
|
||||||
|
},
|
||||||
|
rightAlt: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.right-alt',
|
||||||
|
defaultMessage: 'Right Alt',
|
||||||
|
},
|
||||||
|
space: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.space',
|
||||||
|
defaultMessage: 'Space',
|
||||||
|
},
|
||||||
|
capsLock: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.caps-lock',
|
||||||
|
defaultMessage: 'Caps Lock',
|
||||||
|
},
|
||||||
|
numLock: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.num-lock',
|
||||||
|
defaultMessage: 'Num Lock',
|
||||||
|
},
|
||||||
|
scrollLock: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.scroll-lock',
|
||||||
|
defaultMessage: 'Scroll Lock',
|
||||||
|
},
|
||||||
|
printScreen: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.print-screen',
|
||||||
|
defaultMessage: 'Print Screen',
|
||||||
|
},
|
||||||
|
pause: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.pause',
|
||||||
|
defaultMessage: 'Pause',
|
||||||
|
},
|
||||||
|
home: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.home',
|
||||||
|
defaultMessage: 'Home',
|
||||||
|
},
|
||||||
|
end: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.end',
|
||||||
|
defaultMessage: 'End',
|
||||||
|
},
|
||||||
|
pageUp: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.page-up',
|
||||||
|
defaultMessage: 'Page Up',
|
||||||
|
},
|
||||||
|
pageDown: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.page-down',
|
||||||
|
defaultMessage: 'Page Down',
|
||||||
|
},
|
||||||
|
insert: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.insert',
|
||||||
|
defaultMessage: 'Insert',
|
||||||
|
},
|
||||||
|
delete: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.delete',
|
||||||
|
defaultMessage: 'Delete',
|
||||||
|
},
|
||||||
|
arrowUp: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.arrow-up',
|
||||||
|
defaultMessage: 'Up Arrow',
|
||||||
|
},
|
||||||
|
arrowDown: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.arrow-down',
|
||||||
|
defaultMessage: 'Down Arrow',
|
||||||
|
},
|
||||||
|
arrowLeft: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.arrow-left',
|
||||||
|
defaultMessage: 'Left Arrow',
|
||||||
|
},
|
||||||
|
arrowRight: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.arrow-right',
|
||||||
|
defaultMessage: 'Right Arrow',
|
||||||
|
},
|
||||||
|
leftSuper: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.left-super',
|
||||||
|
defaultMessage: 'Left Super',
|
||||||
|
},
|
||||||
|
rightSuper: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.right-super',
|
||||||
|
defaultMessage: 'Right Super',
|
||||||
|
},
|
||||||
|
leftCommand: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.left-command',
|
||||||
|
defaultMessage: 'Left Command',
|
||||||
|
},
|
||||||
|
rightCommand: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.right-command',
|
||||||
|
defaultMessage: 'Right Command',
|
||||||
|
},
|
||||||
|
menu: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.menu',
|
||||||
|
defaultMessage: 'Menu',
|
||||||
|
},
|
||||||
|
keypadKey: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.keypad-key',
|
||||||
|
defaultMessage: 'Numpad {key}',
|
||||||
|
},
|
||||||
|
leftMouse: {
|
||||||
|
id: 'app.settings.game-options.keybind.mouse.left',
|
||||||
|
defaultMessage: 'Left Mouse',
|
||||||
|
},
|
||||||
|
rightMouse: {
|
||||||
|
id: 'app.settings.game-options.keybind.mouse.right',
|
||||||
|
defaultMessage: 'Right Mouse',
|
||||||
|
},
|
||||||
|
middleMouse: {
|
||||||
|
id: 'app.settings.game-options.keybind.mouse.middle',
|
||||||
|
defaultMessage: 'Middle Mouse',
|
||||||
|
},
|
||||||
|
mouseButton: {
|
||||||
|
id: 'app.settings.game-options.keybind.mouse.button',
|
||||||
|
defaultMessage: 'Mouse {button}',
|
||||||
|
},
|
||||||
|
scancode: {
|
||||||
|
id: 'app.settings.game-options.keybind.scancode',
|
||||||
|
defaultMessage: 'Scancode {code}',
|
||||||
|
},
|
||||||
|
unknownKey: {
|
||||||
|
id: 'app.settings.game-options.keybind.key.unknown',
|
||||||
|
defaultMessage: 'Unknown key',
|
||||||
|
},
|
||||||
|
controlModifier: {
|
||||||
|
id: 'app.settings.game-options.keybind.modifier.control',
|
||||||
|
defaultMessage: 'Ctrl',
|
||||||
|
},
|
||||||
|
shiftModifier: {
|
||||||
|
id: 'app.settings.game-options.keybind.modifier.shift',
|
||||||
|
defaultMessage: 'Shift',
|
||||||
|
},
|
||||||
|
altModifier: {
|
||||||
|
id: 'app.settings.game-options.keybind.modifier.alt',
|
||||||
|
defaultMessage: 'Alt',
|
||||||
|
},
|
||||||
|
commandModifier: {
|
||||||
|
id: 'app.settings.game-options.keybind.modifier.command',
|
||||||
|
defaultMessage: 'Command',
|
||||||
|
},
|
||||||
|
superModifier: {
|
||||||
|
id: 'app.settings.game-options.keybind.modifier.super',
|
||||||
|
defaultMessage: 'Super',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const keyboardCodeTokens: Record<string, string> = {
|
||||||
|
Escape: 'escape',
|
||||||
|
Minus: 'minus',
|
||||||
|
Equal: 'equal',
|
||||||
|
Backspace: 'backspace',
|
||||||
|
Tab: 'tab',
|
||||||
|
BracketLeft: 'left.bracket',
|
||||||
|
BracketRight: 'right.bracket',
|
||||||
|
Enter: 'enter',
|
||||||
|
ControlLeft: 'left.control',
|
||||||
|
Semicolon: 'semicolon',
|
||||||
|
Quote: 'apostrophe',
|
||||||
|
Backquote: 'grave.accent',
|
||||||
|
ShiftLeft: 'left.shift',
|
||||||
|
Backslash: 'backslash',
|
||||||
|
Comma: 'comma',
|
||||||
|
Period: 'period',
|
||||||
|
Slash: 'slash',
|
||||||
|
ShiftRight: 'right.shift',
|
||||||
|
AltLeft: 'left.alt',
|
||||||
|
Space: 'space',
|
||||||
|
CapsLock: 'caps.lock',
|
||||||
|
NumLock: 'num.lock',
|
||||||
|
ScrollLock: 'scroll.lock',
|
||||||
|
NumpadSubtract: 'keypad.subtract',
|
||||||
|
NumpadAdd: 'keypad.add',
|
||||||
|
NumpadDecimal: 'keypad.decimal',
|
||||||
|
NumpadComma: 'keypad.decimal',
|
||||||
|
NumpadEqual: 'keypad.equal',
|
||||||
|
NumpadEnter: 'keypad.enter',
|
||||||
|
ControlRight: 'right.control',
|
||||||
|
NumpadDivide: 'keypad.divide',
|
||||||
|
NumpadMultiply: 'keypad.multiply',
|
||||||
|
PrintScreen: 'print.screen',
|
||||||
|
AltRight: 'right.alt',
|
||||||
|
Pause: 'pause',
|
||||||
|
Home: 'home',
|
||||||
|
ArrowUp: 'up',
|
||||||
|
PageUp: 'page.up',
|
||||||
|
ArrowLeft: 'left',
|
||||||
|
ArrowRight: 'right',
|
||||||
|
End: 'end',
|
||||||
|
ArrowDown: 'down',
|
||||||
|
PageDown: 'page.down',
|
||||||
|
Insert: 'insert',
|
||||||
|
Delete: 'delete',
|
||||||
|
MetaLeft: 'left.win',
|
||||||
|
MetaRight: 'right.win',
|
||||||
|
ContextMenu: 'menu',
|
||||||
|
}
|
||||||
|
|
||||||
|
const keyboardLabels: Record<string, MessageDescriptor | string> = {
|
||||||
|
escape: keyMessages.escape,
|
||||||
|
minus: '-',
|
||||||
|
equal: '=',
|
||||||
|
backspace: keyMessages.backspace,
|
||||||
|
tab: keyMessages.tab,
|
||||||
|
'left.bracket': '[',
|
||||||
|
'right.bracket': ']',
|
||||||
|
enter: keyMessages.enter,
|
||||||
|
'left.control': keyMessages.leftControl,
|
||||||
|
semicolon: ';',
|
||||||
|
apostrophe: "'",
|
||||||
|
'grave.accent': '`',
|
||||||
|
'left.shift': keyMessages.leftShift,
|
||||||
|
backslash: '\\',
|
||||||
|
comma: ',',
|
||||||
|
period: '.',
|
||||||
|
slash: '/',
|
||||||
|
'right.shift': keyMessages.rightShift,
|
||||||
|
'left.alt': keyMessages.leftAlt,
|
||||||
|
space: keyMessages.space,
|
||||||
|
'caps.lock': keyMessages.capsLock,
|
||||||
|
'num.lock': keyMessages.numLock,
|
||||||
|
'scroll.lock': keyMessages.scrollLock,
|
||||||
|
'keypad.subtract': '-',
|
||||||
|
'keypad.add': '+',
|
||||||
|
'keypad.decimal': '.',
|
||||||
|
'keypad.equal': '=',
|
||||||
|
'keypad.enter': keyMessages.enter,
|
||||||
|
'right.control': keyMessages.rightControl,
|
||||||
|
'keypad.divide': '/',
|
||||||
|
'keypad.multiply': '*',
|
||||||
|
'print.screen': keyMessages.printScreen,
|
||||||
|
'right.alt': keyMessages.rightAlt,
|
||||||
|
pause: keyMessages.pause,
|
||||||
|
home: keyMessages.home,
|
||||||
|
up: keyMessages.arrowUp,
|
||||||
|
'page.up': keyMessages.pageUp,
|
||||||
|
left: keyMessages.arrowLeft,
|
||||||
|
right: keyMessages.arrowRight,
|
||||||
|
end: keyMessages.end,
|
||||||
|
down: keyMessages.arrowDown,
|
||||||
|
'page.down': keyMessages.pageDown,
|
||||||
|
insert: keyMessages.insert,
|
||||||
|
delete: keyMessages.delete,
|
||||||
|
menu: keyMessages.menu,
|
||||||
|
}
|
||||||
|
|
||||||
|
function splitKeybind(value: string): [key: string, modifier?: string] {
|
||||||
|
const separator = value.indexOf(':')
|
||||||
|
return separator === -1 ? [value] : [value.slice(0, separator), value.slice(separator + 1)]
|
||||||
|
}
|
||||||
|
|
||||||
|
function keyboardIdentifierFromCode(code: string): string | null {
|
||||||
|
const letter = /^Key([A-Z])$/.exec(code)
|
||||||
|
if (letter) return letter[1].toLowerCase()
|
||||||
|
|
||||||
|
const digit = /^Digit([0-9])$/.exec(code)
|
||||||
|
if (digit) return digit[1]
|
||||||
|
|
||||||
|
const functionKey = /^F([1-9]|1[0-9]|2[0-5])$/.exec(code)
|
||||||
|
if (functionKey) return `f${functionKey[1]}`
|
||||||
|
|
||||||
|
const keypadDigit = /^Numpad([0-9])$/.exec(code)
|
||||||
|
if (keypadDigit) return `keypad.${keypadDigit[1]}`
|
||||||
|
|
||||||
|
return keyboardCodeTokens[code] ?? null
|
||||||
|
}
|
||||||
|
|
||||||
|
export function minecraftKeyTokenFromKeyboardEvent(event: KeyboardEvent): string | null {
|
||||||
|
const identifier = keyboardIdentifierFromCode(event.code)
|
||||||
|
return identifier ? `key.keyboard.${identifier}` : null
|
||||||
|
}
|
||||||
|
|
||||||
|
export function minecraftMouseTokenFromButton(button: number): string | null {
|
||||||
|
if (!Number.isInteger(button) || button < 0 || button > 15) return null
|
||||||
|
if (button === 0) return 'key.mouse.left'
|
||||||
|
if (button === 1) return 'key.mouse.middle'
|
||||||
|
if (button === 2) return 'key.mouse.right'
|
||||||
|
return `key.mouse.${button + 1}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatKeyboardLabel(
|
||||||
|
formatMessage: FormatMessage,
|
||||||
|
identifier: string,
|
||||||
|
isMac: boolean,
|
||||||
|
): string {
|
||||||
|
if (identifier === 'unknown') return formatMessage(keyMessages.unbound)
|
||||||
|
if (/^[a-z]$/.test(identifier)) return identifier.toUpperCase()
|
||||||
|
if (/^[0-9]$/.test(identifier)) return identifier
|
||||||
|
if (/^f([1-9]|1[0-9]|2[0-5])$/.test(identifier)) return identifier.toUpperCase()
|
||||||
|
|
||||||
|
const keypad = /^keypad\.(.+)$/.exec(identifier)
|
||||||
|
if (keypad) {
|
||||||
|
const label = keyboardLabels[identifier]
|
||||||
|
const key = typeof label === 'string' ? label : label ? formatMessage(label) : keypad[1]
|
||||||
|
return formatMessage(keyMessages.keypadKey, { key })
|
||||||
|
}
|
||||||
|
|
||||||
|
if (identifier === 'left.win') {
|
||||||
|
return formatMessage(isMac ? keyMessages.leftCommand : keyMessages.leftSuper)
|
||||||
|
}
|
||||||
|
if (identifier === 'right.win') {
|
||||||
|
return formatMessage(isMac ? keyMessages.rightCommand : keyMessages.rightSuper)
|
||||||
|
}
|
||||||
|
|
||||||
|
const label = keyboardLabels[identifier]
|
||||||
|
if (typeof label === 'string') return label
|
||||||
|
if (label) return formatMessage(label)
|
||||||
|
return identifier
|
||||||
|
.split('.')
|
||||||
|
.map((part) => `${part.charAt(0).toUpperCase()}${part.slice(1)}`)
|
||||||
|
.join(' ')
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatModifier(formatMessage: FormatMessage, modifier: string, isMac: boolean): string {
|
||||||
|
switch (modifier.toUpperCase()) {
|
||||||
|
case 'CONTROL':
|
||||||
|
case 'CTRL':
|
||||||
|
return formatMessage(keyMessages.controlModifier)
|
||||||
|
case 'SHIFT':
|
||||||
|
return formatMessage(keyMessages.shiftModifier)
|
||||||
|
case 'ALT':
|
||||||
|
return formatMessage(keyMessages.altModifier)
|
||||||
|
case 'META':
|
||||||
|
case 'SUPER':
|
||||||
|
return formatMessage(isMac ? keyMessages.commandModifier : keyMessages.superModifier)
|
||||||
|
default:
|
||||||
|
return modifier
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatMinecraftKeybind(
|
||||||
|
formatMessage: FormatMessage,
|
||||||
|
value: string,
|
||||||
|
isMac: boolean,
|
||||||
|
): string {
|
||||||
|
const [key, modifier] = splitKeybind(value)
|
||||||
|
let label: string
|
||||||
|
|
||||||
|
if (key.startsWith('key.keyboard.')) {
|
||||||
|
label = formatKeyboardLabel(formatMessage, key.slice('key.keyboard.'.length), isMac)
|
||||||
|
} else if (key === 'key.mouse.left') {
|
||||||
|
label = formatMessage(keyMessages.leftMouse)
|
||||||
|
} else if (key === 'key.mouse.right') {
|
||||||
|
label = formatMessage(keyMessages.rightMouse)
|
||||||
|
} else if (key === 'key.mouse.middle') {
|
||||||
|
label = formatMessage(keyMessages.middleMouse)
|
||||||
|
} else if (key.startsWith('key.mouse.')) {
|
||||||
|
label = formatMessage(keyMessages.mouseButton, {
|
||||||
|
button: key.slice('key.mouse.'.length),
|
||||||
|
})
|
||||||
|
} else if (key.startsWith('scancode.')) {
|
||||||
|
label = formatMessage(keyMessages.scancode, { code: key.slice('scancode.'.length) })
|
||||||
|
} else {
|
||||||
|
label = formatMessage(keyMessages.unknownKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!modifier || key === 'key.keyboard.unknown') return label
|
||||||
|
const modifiers = modifier
|
||||||
|
.split(/[+:]/)
|
||||||
|
.filter(Boolean)
|
||||||
|
.map((part) => formatModifier(formatMessage, part, isMac))
|
||||||
|
return [...modifiers, label].join(' + ')
|
||||||
|
}
|
||||||
|
|
||||||
|
export function minecraftKeybindConflictKey(optionId: string, value: string): string | null {
|
||||||
|
const normalized = value.trim().toLowerCase()
|
||||||
|
if (!normalized || normalized === 'key.keyboard.unknown') return null
|
||||||
|
|
||||||
|
if (optionId === 'key.debug.modifier') return null
|
||||||
|
if (optionId.startsWith('key.debug.') && optionId !== 'key.debug.overlay') {
|
||||||
|
return `debug:${normalized}`
|
||||||
|
}
|
||||||
|
return `direct:${normalized}`
|
||||||
|
}
|
||||||
+152
@@ -0,0 +1,152 @@
|
|||||||
|
import type { ComboboxOption } from '@modrinth/ui'
|
||||||
|
|
||||||
|
/** Java Edition language names and regions from https://github.com/misode/mcmeta/blob/assets/pack.mcmeta. */
|
||||||
|
const languageNames: Record<string, string> = {
|
||||||
|
en_us: 'English (US)',
|
||||||
|
af_za: 'Afrikaans (Suid-Afrika)',
|
||||||
|
esan: 'Andalûh (Andaluçía)',
|
||||||
|
enp: 'Anglish (Oned Riches)',
|
||||||
|
ast_es: 'Asturianu (Asturies)',
|
||||||
|
az_az: 'Azərbaycanca (Azərbaycan)',
|
||||||
|
id_id: 'Bahasa Indonesia (Indonesia)',
|
||||||
|
ms_my: 'Bahasa Melayu (Malaysia)',
|
||||||
|
tzo_mx: "Bats'i k'op (Jobel)",
|
||||||
|
qid: 'Bhs. Indonesia edjaän lama (Indonesia tempo doeloe)',
|
||||||
|
be_latn: 'Biełaruskaja (Biełaruś)',
|
||||||
|
bar: 'Boarisch (Bayern)',
|
||||||
|
bs_ba: 'Bosanski (Bosna i Hercegovina)',
|
||||||
|
brb: 'Braobans (Braobant)',
|
||||||
|
br_fr: 'Brezhoneg (Breizh)',
|
||||||
|
ca_es: 'Català (Catalunya)',
|
||||||
|
val_es: 'Català (Valencià) (País Valencià)',
|
||||||
|
cy_gb: 'Cymraeg (Cymru)',
|
||||||
|
qcb_es: 'Cántabru/Montañés (Cantabria)',
|
||||||
|
da_dk: 'Dansk (Danmark)',
|
||||||
|
se_no: 'Davvisámegiella (Sápmi)',
|
||||||
|
de_at: 'Deitsch (Österreich)',
|
||||||
|
de_de: 'Deutsch (Deutschland)',
|
||||||
|
et_ee: 'Eesti keel (Eesti)',
|
||||||
|
en_au: 'English (Australia)',
|
||||||
|
en_ca: 'English (Canada)',
|
||||||
|
en_nz: 'English (New Zealand)',
|
||||||
|
en_gb: 'English (United Kingdom)',
|
||||||
|
es_ar: 'Español (Argentina)',
|
||||||
|
es_cl: 'Español (Chile)',
|
||||||
|
es_ec: 'Español (Ecuador)',
|
||||||
|
es_es: 'Español (España)',
|
||||||
|
es_mx: 'Español (México)',
|
||||||
|
es_uy: 'Español (Uruguay)',
|
||||||
|
es_ve: 'Español (Venezuela)',
|
||||||
|
eo_uy: 'Esperanto (Esperantujo)',
|
||||||
|
eu_es: 'Euskara (Euskal Herria)',
|
||||||
|
fil_ph: 'Filipino (Pilipinas)',
|
||||||
|
fr_ca: 'Français (Canada)',
|
||||||
|
fr_fr: 'Français (France)',
|
||||||
|
fr_ch: 'Français (Suisse)',
|
||||||
|
fy_nl: 'Frysk (Fryslân)',
|
||||||
|
fra_de: 'Fränggisch (Franggn)',
|
||||||
|
fur_it: 'Furlan (Friûl)',
|
||||||
|
fo_fo: 'Føroyskt (Føroyar)',
|
||||||
|
ga_ie: 'Gaeilge (Éire)',
|
||||||
|
gl_es: 'Galego (Galicia / Galiza)',
|
||||||
|
go_fr: 'Galo (Bertègn)',
|
||||||
|
gd_gb: 'Gàidhlig (Alba)',
|
||||||
|
hr_hr: 'Hrvatski (Hrvatska)',
|
||||||
|
hn_no: 'Høgnorsk (Norig)',
|
||||||
|
io_en: 'Ido (Idia)',
|
||||||
|
ig_ng: 'Igbo (Naigeria)',
|
||||||
|
it_it: 'Italiano (Italia)',
|
||||||
|
kw_gb: 'Kernewek (Kernow)',
|
||||||
|
ksh: 'Kölsch/Ripoarisch (Rhingland)',
|
||||||
|
lol_us: 'LOLCAT (Kingdom of Cats)',
|
||||||
|
la_la: 'Latina (Latium)',
|
||||||
|
lv_lv: 'Latviešu (Latvija)',
|
||||||
|
lt_lt: 'Lietuvių (Lietuva)',
|
||||||
|
li_li: 'Limburgs (Limburg)',
|
||||||
|
lmo: 'Lombard (Lombardia)',
|
||||||
|
lb_lu: 'Lëtzebuergesch (Lëtzebuerg)',
|
||||||
|
hu_hu: 'Magyar (Magyarország)',
|
||||||
|
mt_mt: 'Malti (Malta)',
|
||||||
|
isv: 'Medžuslovjansky (Slovjanščina)',
|
||||||
|
nah: 'Mēxikatlahtōlli (Mēxiko)',
|
||||||
|
nl_nl: 'Nederlands (Nederland)',
|
||||||
|
pls: 'Ngiiwà (Ndanìꞌngà)',
|
||||||
|
no_no: 'Norsk bokmål (Norge)',
|
||||||
|
nn_no: 'Norsk nynorsk (Noreg)',
|
||||||
|
uz_uz: "O'zbekcha (O'zbekiston)",
|
||||||
|
oc_fr: 'Occitan (Occitània)',
|
||||||
|
en_pt: 'Pirate Speak (The Seven Seas)',
|
||||||
|
nds_de: 'Plattdüütsch (Düütschland)',
|
||||||
|
pl_pl: 'Polski (Polska)',
|
||||||
|
pt_br: 'Português (Brasil)',
|
||||||
|
pt_pt: 'Português (Portugal)',
|
||||||
|
qya_aa: 'Quenya (Arda)',
|
||||||
|
ro_ro: 'Română (România)',
|
||||||
|
de_ch: 'Schwiizerdütsch (Schwiiz)',
|
||||||
|
enws: 'Shakespearean English (Kingdom of England)',
|
||||||
|
sq_al: 'Shqip (Shqipëri)',
|
||||||
|
sk_sk: 'Slovenčina (Slovensko)',
|
||||||
|
sl_si: 'Slovenščina (Slovenija)',
|
||||||
|
so_so: 'Soomaali (Soomaaliya)',
|
||||||
|
sr_cs: 'Srpski (Srbija)',
|
||||||
|
fi_fi: 'Suomi (Suomi)',
|
||||||
|
sv_se: 'Svenska (Sverige)',
|
||||||
|
sxu: 'Säggs’sch (Saggsn)',
|
||||||
|
tl_ph: 'Tagalog (Pilipinas)',
|
||||||
|
vi_vn: 'Tiếng Việt (Việt Nam)',
|
||||||
|
tr_tr: 'Türkçe (Türkiye)',
|
||||||
|
vp_vl: 'Viossa (Vilant)',
|
||||||
|
nl_be: 'Vlaams (België)',
|
||||||
|
vec_it: 'Vèneto (Veneto)',
|
||||||
|
vro: 'Võro (Eesti)',
|
||||||
|
yo_ng: 'Yorùbá (Nàìjíríà)',
|
||||||
|
jbo_en: "la .lojban. (la jbogu'e)",
|
||||||
|
tlh_aa: "tlhIngan Hol (tlhIngan wo')",
|
||||||
|
tok: 'toki pona (kulupu pona)',
|
||||||
|
is_is: 'Íslenska (Ísland)',
|
||||||
|
ovd: 'Övdalska (Swerre)',
|
||||||
|
cs_cz: 'Čeština (Česko)',
|
||||||
|
szl: 'Ślōnski (Gōrny Ślōnsk)',
|
||||||
|
en_ud: 'ɥsᴉꞁᵷuƎ (uʍoᗡ ǝpᴉsd∩)',
|
||||||
|
haw_us: 'ʻŌlelo Hawaiʻi (Hawaiʻi)',
|
||||||
|
el_gr: 'Ελληνικά (Ελλάδα)',
|
||||||
|
ba_ru: 'Башҡортса (Башҡортостан, Рәсәй)',
|
||||||
|
be_by: 'Беларуская (Беларусь)',
|
||||||
|
bg_bg: 'Български (България)',
|
||||||
|
hal_ua: 'Галицка (Галичина, Вкраїна)',
|
||||||
|
ky_kg: 'Кыргызча (Кыргызстан)',
|
||||||
|
mk_mk: 'Македонски (Северна Македонија)',
|
||||||
|
mn_mn: 'Монгол (Монгол Улс)',
|
||||||
|
ry_ua: 'Руснацькый (Пудкарпатя, Украина)',
|
||||||
|
ru_ru: 'Русский (Россия)',
|
||||||
|
rpr: 'Русскій дореформенный (Россійская имперія)',
|
||||||
|
sah_sah: 'Сахалыы (Cаха Сирэ)',
|
||||||
|
sr_sp: 'Српски (Србија)',
|
||||||
|
tt_ru: 'Татарча (Татарстан, Рәсәй)',
|
||||||
|
uk_ua: 'Українська (Україна)',
|
||||||
|
cv_cu: 'Чӑвашла (Чӑваш Ен, Раҫҫей)',
|
||||||
|
kk_kz: 'Қазақша (Қазақстан)',
|
||||||
|
hy_am: 'Հայերեն (Հայաստան)',
|
||||||
|
yi_de: 'ייִדיש (אשכנזיש יידן)',
|
||||||
|
he_il: 'עברית (ישראל)',
|
||||||
|
ar_sa: 'العربية (العالم العربي)',
|
||||||
|
zlm_arab: 'بهاس ملايو (مليسيا)',
|
||||||
|
fa_ir: 'فارسی (ايران)',
|
||||||
|
hi_in: 'हिंदी (भारत)',
|
||||||
|
ta_in: 'தமிழ் (இந்தியா)',
|
||||||
|
kn_in: 'ಕನ್ನಡ (ಭಾರತ)',
|
||||||
|
th_th: 'ไทย (ประเทศไทย)',
|
||||||
|
lo_la: 'ລາວ (ປະເທດລາວ)',
|
||||||
|
ka_ge: 'ქართული (საქართველო)',
|
||||||
|
lzh: '文言 (華夏)',
|
||||||
|
ja_jp: '日本語 (日本)',
|
||||||
|
zh_cn: '简体中文 (中国大陆)',
|
||||||
|
zh_tw: '繁體中文 (台灣)',
|
||||||
|
zh_hk: '繁體中文 (香港特別行政區)',
|
||||||
|
ko_kr: '한국어 (대한민국)',
|
||||||
|
got_de: '𐌲𐌿𐍄𐍂𐌰𐌶𐌳𐌰 (𐌲𐌿𐍄𐌸𐌹𐌿𐌳𐌰)',
|
||||||
|
}
|
||||||
|
|
||||||
|
export const minecraftLanguageOptions: ComboboxOption<string>[] = Object.entries(languageNames)
|
||||||
|
.map(([value, label]) => ({ value, label, searchTerms: [value] }))
|
||||||
|
.sort((a, b) => a.label.localeCompare(b.label))
|
||||||
+1428
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,384 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { LinkIcon, UnknownIcon, UnlinkIcon } from '@modrinth/assets'
|
||||||
|
import {
|
||||||
|
Avatar,
|
||||||
|
Combobox,
|
||||||
|
type ComboboxOption,
|
||||||
|
defineMessages,
|
||||||
|
IconButton,
|
||||||
|
Slider,
|
||||||
|
StyledInput,
|
||||||
|
truncatedTooltip,
|
||||||
|
useVIntl,
|
||||||
|
} from '@modrinth/ui'
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
|
import { type RouteLocationRaw, RouterLink } from 'vue-router'
|
||||||
|
|
||||||
|
import type {
|
||||||
|
EditableGameSetting,
|
||||||
|
GameOptionCanonicalValue,
|
||||||
|
GameSettingLocaleLabel,
|
||||||
|
} from '@/helpers/game-options'
|
||||||
|
|
||||||
|
import GameSettingBooleanControl from './boolean-control.vue'
|
||||||
|
import {
|
||||||
|
canonicalBooleanValue,
|
||||||
|
canonicalValueFromInput,
|
||||||
|
canonicalValueText,
|
||||||
|
gameSettingNumberScale,
|
||||||
|
isKeybindSetting,
|
||||||
|
settingCanBeEnabled,
|
||||||
|
} from './editors'
|
||||||
|
import GameKeybindInput from './keybind-input.vue'
|
||||||
|
import { minecraftLanguageOptions } from './languages'
|
||||||
|
import {
|
||||||
|
formatGameSettingChoice,
|
||||||
|
formatGameSettingDescription,
|
||||||
|
formatGameSettingLabel,
|
||||||
|
formatGameSettingValidation,
|
||||||
|
presentationMessages,
|
||||||
|
} from './messages'
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
setting: EditableGameSetting
|
||||||
|
localeLabel?: GameSettingLocaleLabel
|
||||||
|
keybindConflicts?: string[]
|
||||||
|
disabled?: boolean
|
||||||
|
showSyncToggle?: boolean
|
||||||
|
sourceNavigationDisabled?: boolean
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
keybindConflicts: () => [],
|
||||||
|
disabled: false,
|
||||||
|
showSyncToggle: true,
|
||||||
|
sourceNavigationDisabled: false,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:sync-enabled': [enabled: boolean]
|
||||||
|
'update:canonical-value': [value: GameOptionCanonicalValue | null]
|
||||||
|
'open-source': [location: RouteLocationRaw]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const settingLabelRef = ref<HTMLElement | null>(null)
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
on: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.value-on',
|
||||||
|
defaultMessage: 'On',
|
||||||
|
},
|
||||||
|
off: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.value-off',
|
||||||
|
defaultMessage: 'Off',
|
||||||
|
},
|
||||||
|
mixed: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.value-mixed',
|
||||||
|
defaultMessage: 'Different across instances',
|
||||||
|
},
|
||||||
|
unset: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.value-unset',
|
||||||
|
defaultMessage: 'Choose a value',
|
||||||
|
},
|
||||||
|
syncSetting: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.sync-setting',
|
||||||
|
defaultMessage: 'Sync {setting} across instances',
|
||||||
|
},
|
||||||
|
unsyncSetting: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.unsync-setting',
|
||||||
|
defaultMessage: 'Stop syncing {setting} across instances',
|
||||||
|
},
|
||||||
|
syncedAcrossInstances: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.synced-across-instances',
|
||||||
|
defaultMessage: 'Synced across instances',
|
||||||
|
},
|
||||||
|
notBeingSynced: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.not-being-synced',
|
||||||
|
defaultMessage: 'Not being synced',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const settingLabel = computed(() => {
|
||||||
|
if (props.setting.kind === 'external') {
|
||||||
|
return props.localeLabel?.label ?? formatGameSettingLabel(formatMessage, props.setting)
|
||||||
|
}
|
||||||
|
return formatGameSettingLabel(formatMessage, props.setting)
|
||||||
|
})
|
||||||
|
const settingDescription = computed(() =>
|
||||||
|
formatGameSettingDescription(formatMessage, props.setting),
|
||||||
|
)
|
||||||
|
const settingSource = computed(() =>
|
||||||
|
props.setting.kind === 'external' ? props.localeLabel?.source : undefined,
|
||||||
|
)
|
||||||
|
const sourceLocation = computed<RouteLocationRaw>(() => {
|
||||||
|
const source = settingSource.value
|
||||||
|
if (source?.project) {
|
||||||
|
return { path: `/project/${source.project.id}` }
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
name: 'InstanceContent',
|
||||||
|
params: { id: source?.instance_id },
|
||||||
|
query: { highlight: source?.file_path },
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const valueText = computed(() => canonicalValueText(props.setting))
|
||||||
|
const languageOptions = computed<ComboboxOption<string>[]>(() => {
|
||||||
|
const value = valueText.value
|
||||||
|
if (value && !minecraftLanguageOptions.some((option) => option.value === value)) {
|
||||||
|
return [{ value, label: value }, ...minecraftLanguageOptions]
|
||||||
|
}
|
||||||
|
return minecraftLanguageOptions
|
||||||
|
})
|
||||||
|
const enumOptions = computed<ComboboxOption<string>[]>(() =>
|
||||||
|
(props.setting.editor.choices ?? []).map((choice) => ({
|
||||||
|
value: choice.value,
|
||||||
|
label:
|
||||||
|
props.setting.kind === 'external'
|
||||||
|
? (props.localeLabel?.choices[choice.value] ?? choice.value)
|
||||||
|
: formatGameSettingChoice(formatMessage, props.setting.option_id, choice.value),
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
const isNumber = computed(
|
||||||
|
() => props.setting.editor.type === 'integer' || props.setting.editor.type === 'decimal',
|
||||||
|
)
|
||||||
|
const isSlider = computed(
|
||||||
|
() => isNumber.value && props.setting.editor.min != null && props.setting.editor.max != null,
|
||||||
|
)
|
||||||
|
const booleanValue = computed(() => canonicalBooleanValue(props.setting))
|
||||||
|
const numberScale = computed(() => gameSettingNumberScale(props.setting))
|
||||||
|
const inputMin = computed(() =>
|
||||||
|
props.setting.editor.min === null || props.setting.editor.min === undefined
|
||||||
|
? undefined
|
||||||
|
: props.setting.editor.min * numberScale.value,
|
||||||
|
)
|
||||||
|
const inputMax = computed(() =>
|
||||||
|
props.setting.editor.max === null || props.setting.editor.max === undefined
|
||||||
|
? undefined
|
||||||
|
: props.setting.editor.max * numberScale.value,
|
||||||
|
)
|
||||||
|
const inputStep = computed(() =>
|
||||||
|
props.setting.editor.step === null || props.setting.editor.step === undefined
|
||||||
|
? undefined
|
||||||
|
: props.setting.editor.step * numberScale.value,
|
||||||
|
)
|
||||||
|
const sliderValue = computed(() => {
|
||||||
|
if (valueText.value === '') return null
|
||||||
|
const value = Number(valueText.value)
|
||||||
|
return Number.isFinite(value) ? value : null
|
||||||
|
})
|
||||||
|
const inputValue = computed(() =>
|
||||||
|
isNumber.value ? (sliderValue.value ?? undefined) : valueText.value,
|
||||||
|
)
|
||||||
|
const editorDisabled = computed(
|
||||||
|
() =>
|
||||||
|
props.disabled ||
|
||||||
|
props.setting.controlled ||
|
||||||
|
(props.showSyncToggle && !props.setting.sync_enabled),
|
||||||
|
)
|
||||||
|
const syncToggleDisabled = computed(
|
||||||
|
() =>
|
||||||
|
props.disabled ||
|
||||||
|
props.setting.controlled ||
|
||||||
|
(!props.setting.sync_enabled && !settingCanBeEnabled(props.setting)),
|
||||||
|
)
|
||||||
|
const placeholder = computed(() => {
|
||||||
|
if (props.setting.value_state === 'mixed') return formatMessage(messages.mixed)
|
||||||
|
if (props.setting.value_state === 'unset') return formatMessage(messages.unset)
|
||||||
|
if (props.setting.editor.type === 'external_raw') {
|
||||||
|
return formatMessage(presentationMessages.customValuePlaceholder)
|
||||||
|
}
|
||||||
|
return undefined
|
||||||
|
})
|
||||||
|
const validationMessage = computed(() =>
|
||||||
|
formatGameSettingValidation(formatMessage, props.setting.validation_error),
|
||||||
|
)
|
||||||
|
const syncDisabledReason = computed(() => {
|
||||||
|
if (validationMessage.value) return validationMessage.value
|
||||||
|
if (props.setting.value_state === 'invalid') {
|
||||||
|
return formatMessage(presentationMessages.validationInvalidValue)
|
||||||
|
}
|
||||||
|
if (props.setting.value_state === 'mixed' || props.setting.value_state === 'unset') {
|
||||||
|
return formatMessage(presentationMessages.validationMissingValue)
|
||||||
|
}
|
||||||
|
if (props.setting.controlled) {
|
||||||
|
return formatMessage(presentationMessages.bucketLauncherControlled, { count: 1 })
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
props.setting.compatibility.total_participating > 0 &&
|
||||||
|
props.setting.compatibility.will_receive === 0
|
||||||
|
) {
|
||||||
|
return formatMessage(presentationMessages.compatibilityNone)
|
||||||
|
}
|
||||||
|
return undefined
|
||||||
|
})
|
||||||
|
const syncActionLabel = computed(() =>
|
||||||
|
formatMessage(props.setting.sync_enabled ? messages.unsyncSetting : messages.syncSetting, {
|
||||||
|
setting: settingLabel.value,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
const syncStatusTooltip = computed(() =>
|
||||||
|
formatMessage(
|
||||||
|
props.setting.sync_enabled ? messages.syncedAcrossInstances : messages.notBeingSynced,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
function updateValue(value: string | number | boolean | undefined) {
|
||||||
|
emit('update:canonical-value', canonicalValueFromInput(props.setting, value))
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div
|
||||||
|
class="grid min-h-[54px] min-w-0 items-center gap-2"
|
||||||
|
:class="
|
||||||
|
isSlider
|
||||||
|
? showSyncToggle
|
||||||
|
? 'grid-cols-[minmax(10rem,0.65fr)_minmax(0,1.35fr)_2.25rem]'
|
||||||
|
: 'grid-cols-[minmax(10rem,0.65fr)_minmax(0,1.35fr)]'
|
||||||
|
: showSyncToggle
|
||||||
|
? 'grid-cols-[minmax(0,1fr)_12rem_2.25rem]'
|
||||||
|
: 'grid-cols-[minmax(0,1fr)_12rem]'
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<div class="min-w-0 pr-2">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<h3
|
||||||
|
ref="settingLabelRef"
|
||||||
|
v-tooltip="truncatedTooltip(settingLabelRef, settingLabel)"
|
||||||
|
class="m-0 truncate text-lg font-semibold text-[var(--color-text-primary)]"
|
||||||
|
>
|
||||||
|
{{ settingLabel }}
|
||||||
|
</h3>
|
||||||
|
<span
|
||||||
|
v-if="validationMessage"
|
||||||
|
v-tooltip="validationMessage"
|
||||||
|
tabindex="0"
|
||||||
|
role="img"
|
||||||
|
class="flex shrink-0 rounded-md text-orange outline-none focus-visible:ring-4 focus-visible:ring-brand-shadow"
|
||||||
|
>
|
||||||
|
<UnknownIcon class="size-4" aria-hidden="true" />
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<RouterLink v-if="settingSource" v-slot="{ href }" :to="sourceLocation" custom>
|
||||||
|
<a
|
||||||
|
:href="sourceNavigationDisabled ? undefined : href"
|
||||||
|
:aria-disabled="sourceNavigationDisabled || undefined"
|
||||||
|
class="mt-2 inline-flex max-w-full items-center gap-1.5 text-[var(--color-text-default)]"
|
||||||
|
:class="sourceNavigationDisabled ? 'cursor-default' : 'hover:underline'"
|
||||||
|
@click.prevent="!sourceNavigationDisabled && emit('open-source', sourceLocation)"
|
||||||
|
>
|
||||||
|
<Avatar
|
||||||
|
v-if="settingSource.project"
|
||||||
|
:src="settingSource.project.icon_url"
|
||||||
|
size="1.25rem"
|
||||||
|
no-shadow
|
||||||
|
/>
|
||||||
|
<span class="truncate">{{
|
||||||
|
settingSource.project?.title ?? settingSource.file_name
|
||||||
|
}}</span>
|
||||||
|
</a>
|
||||||
|
</RouterLink>
|
||||||
|
<p v-else-if="settingDescription" class="m-0 mt-0.5 text-[var(--color-text-default)]">
|
||||||
|
{{ settingDescription }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex min-w-0 items-center justify-end">
|
||||||
|
<Slider
|
||||||
|
v-if="isSlider"
|
||||||
|
size="standard"
|
||||||
|
:model-value="sliderValue"
|
||||||
|
:min="inputMin ?? 0"
|
||||||
|
:max="inputMax ?? 100"
|
||||||
|
:step="inputStep ?? 1"
|
||||||
|
:snap-points="setting.category_id === 'music_and_sound' ? [0, 50, 100] : []"
|
||||||
|
:snap-range="5"
|
||||||
|
:unit="setting.editor.unit === 'percent' ? '%' : undefined"
|
||||||
|
:placeholder="placeholder"
|
||||||
|
:aria-label="settingLabel"
|
||||||
|
:disabled="editorDisabled"
|
||||||
|
@update:model-value="updateValue"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<GameSettingBooleanControl
|
||||||
|
v-else-if="setting.editor.type === 'bool'"
|
||||||
|
:model-value="booleanValue"
|
||||||
|
:label="settingLabel"
|
||||||
|
:on-label="formatMessage(messages.on)"
|
||||||
|
:off-label="formatMessage(messages.off)"
|
||||||
|
:placeholder="placeholder"
|
||||||
|
:disabled="editorDisabled"
|
||||||
|
@update:model-value="updateValue"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Combobox
|
||||||
|
v-else-if="setting.option_id === 'language'"
|
||||||
|
:model-value="valueText"
|
||||||
|
:options="languageOptions"
|
||||||
|
:placeholder="placeholder"
|
||||||
|
:disabled="editorDisabled"
|
||||||
|
:aria-label="settingLabel"
|
||||||
|
:search-input-attrs="{ 'aria-label': settingLabel }"
|
||||||
|
searchable
|
||||||
|
select-search-text-on-focus
|
||||||
|
class="min-w-0"
|
||||||
|
@update:model-value="updateValue"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Combobox
|
||||||
|
v-else-if="setting.editor.type === 'enum'"
|
||||||
|
:model-value="valueText"
|
||||||
|
:options="enumOptions"
|
||||||
|
:placeholder="placeholder"
|
||||||
|
:disabled="editorDisabled"
|
||||||
|
:aria-label="settingLabel"
|
||||||
|
class="min-w-0"
|
||||||
|
@update:model-value="updateValue"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<GameKeybindInput
|
||||||
|
v-else-if="isKeybindSetting(setting)"
|
||||||
|
:model-value="valueText"
|
||||||
|
:setting-label="settingLabel"
|
||||||
|
:conflicts="keybindConflicts"
|
||||||
|
:mixed="setting.value_state === 'mixed'"
|
||||||
|
:disabled="editorDisabled"
|
||||||
|
@update:model-value="updateValue"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<StyledInput
|
||||||
|
v-else
|
||||||
|
:model-value="inputValue"
|
||||||
|
:type="isNumber ? 'number' : 'text'"
|
||||||
|
:min="inputMin"
|
||||||
|
:max="inputMax"
|
||||||
|
:step="inputStep"
|
||||||
|
:placeholder="placeholder"
|
||||||
|
:disabled="editorDisabled"
|
||||||
|
:aria-label="settingLabel"
|
||||||
|
wrapper-class="w-full"
|
||||||
|
@update:model-value="updateValue"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<span
|
||||||
|
v-if="showSyncToggle"
|
||||||
|
v-tooltip="syncToggleDisabled && syncDisabledReason ? syncDisabledReason : syncStatusTooltip"
|
||||||
|
class="flex justify-center"
|
||||||
|
>
|
||||||
|
<IconButton
|
||||||
|
:type="setting.sync_enabled ? 'chip' : 'base'"
|
||||||
|
:color="setting.sync_enabled ? 'blue' : undefined"
|
||||||
|
:label="syncActionLabel"
|
||||||
|
:disabled="syncToggleDisabled"
|
||||||
|
:aria-pressed="setting.sync_enabled"
|
||||||
|
@click="emit('update:sync-enabled', !setting.sync_enabled)"
|
||||||
|
>
|
||||||
|
<LinkIcon v-if="setting.sync_enabled" aria-hidden="true" />
|
||||||
|
<UnlinkIcon v-else aria-hidden="true" />
|
||||||
|
</IconButton>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
+448
@@ -0,0 +1,448 @@
|
|||||||
|
import { defineMessages, injectNotificationManager, useVIntl } from '@modrinth/ui'
|
||||||
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
|
||||||
|
import { computed, type MaybeRefOrGetter, nextTick, onScopeDispose, ref, toValue, watch } from 'vue'
|
||||||
|
|
||||||
|
import {
|
||||||
|
type EditableGameSetting,
|
||||||
|
type GameOptionCanonicalValue,
|
||||||
|
type GameSettingChange,
|
||||||
|
type GameSettingsEditorState,
|
||||||
|
gameSettingsKeys,
|
||||||
|
gameSettingsQueryOptions,
|
||||||
|
get_local_game_options_config,
|
||||||
|
get_synced_game_options_config,
|
||||||
|
preview_local_game_option_changes,
|
||||||
|
preview_synced_game_option_changes,
|
||||||
|
save_local_game_option_changes,
|
||||||
|
save_synced_game_option_changes,
|
||||||
|
type UpdateGameSettingsRequest,
|
||||||
|
} from '@/helpers/game-options'
|
||||||
|
|
||||||
|
import { canonicalValuesEqual, cloneGameSettingsState, gameSettingChanges } from './editors'
|
||||||
|
|
||||||
|
export function useGameSettingsEditor(
|
||||||
|
instanceId: MaybeRefOrGetter<string | undefined>,
|
||||||
|
onSaved: () => void,
|
||||||
|
) {
|
||||||
|
const { addNotification, handleError } = injectNotificationManager()
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
const messages = defineMessages({
|
||||||
|
conflictTitle: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.conflict-title',
|
||||||
|
defaultMessage: 'These settings changed elsewhere',
|
||||||
|
},
|
||||||
|
conflictText: {
|
||||||
|
id: 'app.settings.synced-options.game-settings.conflict-text',
|
||||||
|
defaultMessage: 'We loaded the latest settings. Check your changes, then save again.',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const baseState = ref<GameSettingsEditorState | null>(null)
|
||||||
|
const draftState = ref<GameSettingsEditorState | null>(null)
|
||||||
|
const touchedValueOptionIds = ref<Set<string>>(new Set())
|
||||||
|
let previewTimer: ReturnType<typeof setTimeout> | null = null
|
||||||
|
let previewGeneration = 0
|
||||||
|
let loadGeneration = 0
|
||||||
|
let saveGeneration = 0
|
||||||
|
|
||||||
|
const editorInstanceId = ref<string>()
|
||||||
|
const isLocalEditor = computed(() => !!editorInstanceId.value)
|
||||||
|
|
||||||
|
const dirtyChanges = computed(() =>
|
||||||
|
gameSettingChanges(baseState.value, draftState.value, touchedValueOptionIds.value),
|
||||||
|
)
|
||||||
|
const isDirty = computed(() => dirtyChanges.value.length > 0)
|
||||||
|
const dirtyOptionIds = computed(
|
||||||
|
() => new Set(dirtyChanges.value.map((change) => change.option_id)),
|
||||||
|
)
|
||||||
|
const hasBlockingDraft = computed(
|
||||||
|
() =>
|
||||||
|
draftState.value?.settings.some(
|
||||||
|
(setting) =>
|
||||||
|
dirtyOptionIds.value.has(setting.option_id) &&
|
||||||
|
(isLocalEditor.value || setting.sync_enabled) &&
|
||||||
|
(!!setting.validation_error ||
|
||||||
|
['mixed', 'unset', 'invalid'].includes(setting.value_state)),
|
||||||
|
) ?? false,
|
||||||
|
)
|
||||||
|
const stateQuery = useQuery(
|
||||||
|
computed(() => ({
|
||||||
|
...gameSettingsQueryOptions(editorInstanceId.value),
|
||||||
|
enabled: false,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
const loading = computed(
|
||||||
|
() => !draftState.value && (stateQuery.isPending.value || stateQuery.isFetching.value),
|
||||||
|
)
|
||||||
|
const loadError = computed(() => !draftState.value && stateQuery.isError.value)
|
||||||
|
const previewMutation = useMutation({
|
||||||
|
mutationFn: ({
|
||||||
|
instanceId,
|
||||||
|
request,
|
||||||
|
}: {
|
||||||
|
instanceId?: string
|
||||||
|
request: UpdateGameSettingsRequest
|
||||||
|
}) =>
|
||||||
|
instanceId
|
||||||
|
? preview_local_game_option_changes(instanceId, request)
|
||||||
|
: preview_synced_game_option_changes(request),
|
||||||
|
})
|
||||||
|
const saveMutation = useMutation({
|
||||||
|
mutationFn: saveDraft,
|
||||||
|
onError: handleError,
|
||||||
|
})
|
||||||
|
|
||||||
|
function applyState(state: GameSettingsEditorState) {
|
||||||
|
baseState.value = cloneGameSettingsState(state)
|
||||||
|
draftState.value = cloneGameSettingsState(state)
|
||||||
|
touchedValueOptionIds.value = new Set()
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(stateQuery.data, (state) => {
|
||||||
|
if (state && draftState.value && !isDirty.value && !saveMutation.isPending.value) {
|
||||||
|
applyState(state)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
async function load() {
|
||||||
|
const generation = ++loadGeneration
|
||||||
|
cancelPreview()
|
||||||
|
editorInstanceId.value = toValue(instanceId)
|
||||||
|
const options = gameSettingsQueryOptions(editorInstanceId.value)
|
||||||
|
const cached = !editorInstanceId.value && queryClient.getQueryData(options.queryKey)
|
||||||
|
if (cached) {
|
||||||
|
applyState(cached)
|
||||||
|
try {
|
||||||
|
// A previously cached empty state is common immediately after enabling
|
||||||
|
// sync. Refresh it before returning so the editor does not stay empty.
|
||||||
|
const refreshed = await queryClient.fetchQuery({ ...options, staleTime: 0 })
|
||||||
|
if (generation !== loadGeneration) return false
|
||||||
|
applyState(refreshed)
|
||||||
|
return true
|
||||||
|
} catch (error) {
|
||||||
|
if (generation !== loadGeneration) return false
|
||||||
|
handleError(error)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await nextTick()
|
||||||
|
const result = await queryClient
|
||||||
|
.fetchQuery({ ...options, staleTime: 0 })
|
||||||
|
.then((data) => ({ data, isError: false, error: null as unknown }))
|
||||||
|
.catch((error) => ({ data: undefined, isError: true, error }))
|
||||||
|
if (generation !== loadGeneration) return false
|
||||||
|
if (result.isError) {
|
||||||
|
handleError(result.error)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (!result.data) return false
|
||||||
|
applyState(result.data)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelPreview() {
|
||||||
|
if (previewTimer) clearTimeout(previewTimer)
|
||||||
|
previewTimer = null
|
||||||
|
previewGeneration++
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
cancelPreview()
|
||||||
|
loadGeneration++
|
||||||
|
saveGeneration++
|
||||||
|
baseState.value = null
|
||||||
|
draftState.value = null
|
||||||
|
touchedValueOptionIds.value = new Set()
|
||||||
|
saveMutation.reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelChanges() {
|
||||||
|
if (!baseState.value) return
|
||||||
|
cancelPreview()
|
||||||
|
draftState.value = cloneGameSettingsState(baseState.value)
|
||||||
|
touchedValueOptionIds.value = new Set()
|
||||||
|
}
|
||||||
|
|
||||||
|
function setSyncEnabled(optionIds: readonly string[], enabled: boolean) {
|
||||||
|
if (!draftState.value) return
|
||||||
|
const ids = new Set(optionIds)
|
||||||
|
draftState.value.settings = draftState.value.settings.map((setting) =>
|
||||||
|
ids.has(setting.option_id)
|
||||||
|
? { ...setting, sync_enabled: enabled, validation_error: null }
|
||||||
|
: setting,
|
||||||
|
)
|
||||||
|
schedulePreview()
|
||||||
|
}
|
||||||
|
|
||||||
|
function schedulePreview() {
|
||||||
|
cancelPreview()
|
||||||
|
previewTimer = setTimeout(() => void preview(), 350)
|
||||||
|
}
|
||||||
|
|
||||||
|
function save() {
|
||||||
|
if (saveMutation.isPending.value || loading.value || hasBlockingDraft.value || !isDirty.value)
|
||||||
|
return
|
||||||
|
saveMutation.mutate()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveAndWait(): Promise<boolean> {
|
||||||
|
if (loading.value || hasBlockingDraft.value || !isDirty.value) return !hasBlockingDraft.value
|
||||||
|
try {
|
||||||
|
await saveMutation.mutateAsync()
|
||||||
|
return true
|
||||||
|
} catch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function editorRequest(): UpdateGameSettingsRequest | null {
|
||||||
|
if (!baseState.value || !draftState.value) return null
|
||||||
|
return {
|
||||||
|
expected_summary_revision: draftState.value.summary_revision,
|
||||||
|
expected_canonical_revision: draftState.value.canonical_revision,
|
||||||
|
expected_catalog_revision: draftState.value.catalog_revision,
|
||||||
|
changes: dirtyChanges.value,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setCanonicalValue(optionId: string, value: GameOptionCanonicalValue | null) {
|
||||||
|
if (!draftState.value) return
|
||||||
|
const currentSetting = draftState.value.settings.find(
|
||||||
|
(setting) => setting.option_id === optionId,
|
||||||
|
)
|
||||||
|
const baseSetting = baseState.value?.settings.find((setting) => setting.option_id === optionId)
|
||||||
|
if (!currentSetting) return
|
||||||
|
|
||||||
|
const revertedToBase =
|
||||||
|
!!baseSetting &&
|
||||||
|
!canonicalValuesEqual(currentSetting.canonical_value, baseSetting.canonical_value) &&
|
||||||
|
canonicalValuesEqual(value, baseSetting.canonical_value)
|
||||||
|
const touchedOptionIds = new Set(touchedValueOptionIds.value)
|
||||||
|
if (revertedToBase) {
|
||||||
|
touchedOptionIds.delete(optionId)
|
||||||
|
} else {
|
||||||
|
touchedOptionIds.add(optionId)
|
||||||
|
}
|
||||||
|
touchedValueOptionIds.value = touchedOptionIds
|
||||||
|
draftState.value.settings = draftState.value.settings.map((setting) =>
|
||||||
|
setting.option_id === optionId
|
||||||
|
? {
|
||||||
|
...setting,
|
||||||
|
canonical_value: value,
|
||||||
|
value_state: revertedToBase ? baseSetting.value_state : value ? 'canonical' : 'unset',
|
||||||
|
validation_error: revertedToBase ? baseSetting.validation_error : null,
|
||||||
|
}
|
||||||
|
: setting,
|
||||||
|
)
|
||||||
|
schedulePreview()
|
||||||
|
}
|
||||||
|
|
||||||
|
function mergePreview(preview: GameSettingsEditorState) {
|
||||||
|
if (!baseState.value || !draftState.value) return
|
||||||
|
const previousBase = cloneGameSettingsState(baseState.value)
|
||||||
|
const previousDraft = cloneGameSettingsState(draftState.value)
|
||||||
|
const dirtyIds = new Set(
|
||||||
|
gameSettingChanges(previousBase, previousDraft, touchedValueOptionIds.value).map(
|
||||||
|
(change) => change.option_id,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
const stagedSettings = new Map(
|
||||||
|
previousDraft.settings
|
||||||
|
.filter((setting) => dirtyIds.has(setting.option_id))
|
||||||
|
.map((setting) => [setting.option_id, setting]),
|
||||||
|
)
|
||||||
|
const previousBaseSettings = new Map(
|
||||||
|
previousBase.settings.map((setting) => [setting.option_id, setting]),
|
||||||
|
)
|
||||||
|
const nextBase = cloneGameSettingsState(preview)
|
||||||
|
const nextDraft = cloneGameSettingsState(preview)
|
||||||
|
nextBase.settings = nextBase.settings.map((setting) =>
|
||||||
|
dirtyIds.has(setting.option_id)
|
||||||
|
? { ...(previousBaseSettings.get(setting.option_id) ?? setting) }
|
||||||
|
: setting,
|
||||||
|
)
|
||||||
|
nextDraft.settings = nextDraft.settings.map((setting): EditableGameSetting => {
|
||||||
|
const staged = stagedSettings.get(setting.option_id)
|
||||||
|
if (!staged) return setting
|
||||||
|
return {
|
||||||
|
...setting,
|
||||||
|
sync_enabled: staged.sync_enabled,
|
||||||
|
canonical_value: staged.canonical_value,
|
||||||
|
option_revision: staged.option_revision,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
baseState.value = nextBase
|
||||||
|
draftState.value = nextDraft
|
||||||
|
}
|
||||||
|
|
||||||
|
async function preview() {
|
||||||
|
const request = editorRequest()
|
||||||
|
if (!request || request.changes.length === 0) {
|
||||||
|
previewGeneration++
|
||||||
|
if (baseState.value) draftState.value = cloneGameSettingsState(baseState.value)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const generation = ++previewGeneration
|
||||||
|
try {
|
||||||
|
const previewState = await previewMutation.mutateAsync({
|
||||||
|
instanceId: editorInstanceId.value,
|
||||||
|
request,
|
||||||
|
})
|
||||||
|
if (generation !== previewGeneration) return
|
||||||
|
mergePreview(previewState)
|
||||||
|
} catch {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyChangesToRefreshedState(
|
||||||
|
refreshed: GameSettingsEditorState,
|
||||||
|
stagedDraft: GameSettingsEditorState,
|
||||||
|
changes: GameSettingChange[],
|
||||||
|
touchedOptionIds: ReadonlySet<string>,
|
||||||
|
conflictOptionIds: ReadonlySet<string> = new Set(),
|
||||||
|
) {
|
||||||
|
const changesById = new Map(changes.map((change) => [change.option_id, change]))
|
||||||
|
const stagedSettings = new Map(
|
||||||
|
stagedDraft.settings.map((setting) => [setting.option_id, setting]),
|
||||||
|
)
|
||||||
|
const nextBase = cloneGameSettingsState(refreshed)
|
||||||
|
const nextDraft = cloneGameSettingsState(refreshed)
|
||||||
|
|
||||||
|
nextDraft.settings = nextDraft.settings.map((setting) => {
|
||||||
|
const change = changesById.get(setting.option_id)
|
||||||
|
const staged = stagedSettings.get(setting.option_id)
|
||||||
|
if (!change || !staged) return setting
|
||||||
|
|
||||||
|
return {
|
||||||
|
...setting,
|
||||||
|
...(change.sync_enabled !== undefined ? { sync_enabled: staged.sync_enabled } : {}),
|
||||||
|
...(change.canonical_value !== undefined
|
||||||
|
? {
|
||||||
|
canonical_value: staged.canonical_value,
|
||||||
|
value_state: staged.value_state,
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
validation_error: conflictOptionIds.has(setting.option_id)
|
||||||
|
? 'changed_since_opened'
|
||||||
|
: staged.validation_error,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
baseState.value = nextBase
|
||||||
|
draftState.value = nextDraft
|
||||||
|
touchedValueOptionIds.value = new Set(
|
||||||
|
[...touchedOptionIds].filter(
|
||||||
|
(optionId) => changesById.get(optionId)?.canonical_value !== undefined,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveDraft() {
|
||||||
|
const request = editorRequest()
|
||||||
|
if (!request || request.changes.length === 0 || !baseState.value || !draftState.value) return
|
||||||
|
|
||||||
|
cancelPreview()
|
||||||
|
const targetInstanceId = editorInstanceId.value
|
||||||
|
const generation = ++saveGeneration
|
||||||
|
const previousBase = cloneGameSettingsState(baseState.value)
|
||||||
|
const optimisticState = cloneGameSettingsState(draftState.value)
|
||||||
|
const previouslyTouchedOptionIds = new Set(touchedValueOptionIds.value)
|
||||||
|
baseState.value = cloneGameSettingsState(optimisticState)
|
||||||
|
touchedValueOptionIds.value = new Set()
|
||||||
|
try {
|
||||||
|
await queryClient.cancelQueries({
|
||||||
|
queryKey: gameSettingsQueryOptions(targetInstanceId).queryKey,
|
||||||
|
})
|
||||||
|
const result = targetInstanceId
|
||||||
|
? await save_local_game_option_changes(targetInstanceId, request)
|
||||||
|
: await save_synced_game_option_changes(request)
|
||||||
|
const refreshed =
|
||||||
|
result.state ??
|
||||||
|
(targetInstanceId
|
||||||
|
? await get_local_game_options_config(targetInstanceId)
|
||||||
|
: await get_synced_game_options_config())
|
||||||
|
queryClient.setQueryData(gameSettingsQueryOptions(targetInstanceId).queryKey, refreshed)
|
||||||
|
if (targetInstanceId) {
|
||||||
|
void queryClient.invalidateQueries({ queryKey: gameSettingsKeys.synced })
|
||||||
|
}
|
||||||
|
if (result.conflicts?.length) {
|
||||||
|
if (generation !== saveGeneration || !draftState.value) return
|
||||||
|
previewGeneration++
|
||||||
|
const stagedDraft = cloneGameSettingsState(draftState.value)
|
||||||
|
const retainedTouchedOptionIds = new Set([
|
||||||
|
...previouslyTouchedOptionIds,
|
||||||
|
...touchedValueOptionIds.value,
|
||||||
|
])
|
||||||
|
const stagedChanges = gameSettingChanges(
|
||||||
|
previousBase,
|
||||||
|
stagedDraft,
|
||||||
|
retainedTouchedOptionIds,
|
||||||
|
)
|
||||||
|
const conflicts = new Set(result.conflicts)
|
||||||
|
applyChangesToRefreshedState(
|
||||||
|
refreshed,
|
||||||
|
stagedDraft,
|
||||||
|
stagedChanges,
|
||||||
|
retainedTouchedOptionIds,
|
||||||
|
conflicts,
|
||||||
|
)
|
||||||
|
|
||||||
|
addNotification({
|
||||||
|
type: 'warning',
|
||||||
|
title: formatMessage(messages.conflictTitle),
|
||||||
|
text: formatMessage(messages.conflictText),
|
||||||
|
})
|
||||||
|
if (isDirty.value) {
|
||||||
|
schedulePreview()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (generation !== saveGeneration) {
|
||||||
|
onSaved()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!baseState.value || !draftState.value) return
|
||||||
|
previewGeneration++
|
||||||
|
const stagedDraft = cloneGameSettingsState(draftState.value)
|
||||||
|
const touchedSinceSave = new Set(touchedValueOptionIds.value)
|
||||||
|
const changesSinceSave = gameSettingChanges(optimisticState, stagedDraft, touchedSinceSave)
|
||||||
|
applyChangesToRefreshedState(refreshed, stagedDraft, changesSinceSave, touchedSinceSave)
|
||||||
|
if (changesSinceSave.length > 0) schedulePreview()
|
||||||
|
onSaved()
|
||||||
|
} catch (error) {
|
||||||
|
if (generation === saveGeneration && draftState.value) {
|
||||||
|
previewGeneration++
|
||||||
|
baseState.value = previousBase
|
||||||
|
touchedValueOptionIds.value = new Set([
|
||||||
|
...previouslyTouchedOptionIds,
|
||||||
|
...touchedValueOptionIds.value,
|
||||||
|
])
|
||||||
|
if (dirtyChanges.value.length > 0) schedulePreview()
|
||||||
|
}
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onScopeDispose(reset)
|
||||||
|
|
||||||
|
return {
|
||||||
|
draftState,
|
||||||
|
isLocalEditor,
|
||||||
|
isDirty,
|
||||||
|
hasBlockingDraft,
|
||||||
|
loading,
|
||||||
|
loadError,
|
||||||
|
saving: saveMutation.isPending,
|
||||||
|
load,
|
||||||
|
reset,
|
||||||
|
cancelChanges,
|
||||||
|
setSyncEnabled,
|
||||||
|
setCanonicalValue,
|
||||||
|
save,
|
||||||
|
saveAndWait,
|
||||||
|
}
|
||||||
|
}
|
||||||
+138
@@ -0,0 +1,138 @@
|
|||||||
|
import { useDebugLogger, useVIntl } from '@modrinth/ui'
|
||||||
|
import { listen, type UnlistenFn } from '@tauri-apps/api/event'
|
||||||
|
import { computed, type MaybeRefOrGetter, onScopeDispose, shallowRef, toValue, watch } from 'vue'
|
||||||
|
|
||||||
|
import {
|
||||||
|
type EditableGameSetting,
|
||||||
|
type GameSettingLocaleLabel,
|
||||||
|
get_game_setting_locale_labels,
|
||||||
|
} from '@/helpers/game-options'
|
||||||
|
|
||||||
|
export function useGameSettingLabels(
|
||||||
|
opened: MaybeRefOrGetter<boolean>,
|
||||||
|
instanceId: MaybeRefOrGetter<string | undefined>,
|
||||||
|
settings: MaybeRefOrGetter<EditableGameSetting[]>,
|
||||||
|
) {
|
||||||
|
const debug = useDebugLogger('GameSettingLabels')
|
||||||
|
const { locale } = useVIntl()
|
||||||
|
const labels = shallowRef<Record<string, GameSettingLocaleLabel>>({})
|
||||||
|
const optionIds = computed(() =>
|
||||||
|
toValue(settings)
|
||||||
|
.filter((setting) => setting.kind === 'external')
|
||||||
|
.map((setting) => setting.option_id)
|
||||||
|
.sort(),
|
||||||
|
)
|
||||||
|
let generation = 0
|
||||||
|
let stopListening: UnlistenFn | undefined
|
||||||
|
let refreshSources = false
|
||||||
|
|
||||||
|
debug('setup', { opened: toValue(opened), instanceId: toValue(instanceId), locale: locale.value })
|
||||||
|
|
||||||
|
async function refresh(reason: string) {
|
||||||
|
if (!toValue(opened) || !optionIds.value.length) {
|
||||||
|
debug('refresh skipped', {
|
||||||
|
reason,
|
||||||
|
opened: toValue(opened),
|
||||||
|
optionCount: optionIds.value.length,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const request = ++generation
|
||||||
|
const reindex = refreshSources
|
||||||
|
const requestedIds = [...optionIds.value]
|
||||||
|
const started = performance.now()
|
||||||
|
refreshSources = false
|
||||||
|
debug('request started', {
|
||||||
|
request,
|
||||||
|
reason,
|
||||||
|
instanceId: toValue(instanceId),
|
||||||
|
locale: locale.value,
|
||||||
|
reindex,
|
||||||
|
optionIds: requestedIds,
|
||||||
|
})
|
||||||
|
try {
|
||||||
|
const result = await get_game_setting_locale_labels(
|
||||||
|
toValue(instanceId),
|
||||||
|
locale.value,
|
||||||
|
requestedIds,
|
||||||
|
reindex,
|
||||||
|
)
|
||||||
|
const applied = request === generation && toValue(opened)
|
||||||
|
debug('request completed', {
|
||||||
|
request,
|
||||||
|
generation,
|
||||||
|
applied,
|
||||||
|
opened: toValue(opened),
|
||||||
|
elapsedMs: Math.round(performance.now() - started),
|
||||||
|
returnedCount: Object.keys(result.settings).length,
|
||||||
|
missingOptionIds: requestedIds.filter((id) => !result.settings[id]),
|
||||||
|
labelSample: Object.entries(result.settings).slice(0, 8),
|
||||||
|
})
|
||||||
|
if (applied) labels.value = result.settings
|
||||||
|
} catch (error) {
|
||||||
|
debug('request failed', {
|
||||||
|
request,
|
||||||
|
reason,
|
||||||
|
elapsedMs: Math.round(performance.now() - started),
|
||||||
|
error,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => toValue(opened),
|
||||||
|
(active, _, onCleanup) => {
|
||||||
|
debug('modal state changed', { active, generation, optionCount: optionIds.value.length })
|
||||||
|
let cancelled = false
|
||||||
|
onCleanup(() => {
|
||||||
|
cancelled = true
|
||||||
|
stopListening?.()
|
||||||
|
stopListening = undefined
|
||||||
|
generation++
|
||||||
|
labels.value = {}
|
||||||
|
debug('modal cleanup: listener removed and labels cleared', { generation })
|
||||||
|
})
|
||||||
|
if (!active) return
|
||||||
|
refreshSources = true
|
||||||
|
debug('registering locale update listener')
|
||||||
|
void listen('game-option-locales-updated', () => {
|
||||||
|
debug('received game-option-locales-updated')
|
||||||
|
void refresh('locale update event')
|
||||||
|
})
|
||||||
|
.then((unlisten) => {
|
||||||
|
debug('locale update listener registered', { cancelled })
|
||||||
|
if (cancelled) unlisten()
|
||||||
|
else {
|
||||||
|
stopListening = unlisten
|
||||||
|
void refresh('listener registered')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
debug('locale update listener failed', { cancelled, error })
|
||||||
|
if (!cancelled) void refresh('listener failed')
|
||||||
|
})
|
||||||
|
},
|
||||||
|
{ flush: 'sync' },
|
||||||
|
)
|
||||||
|
|
||||||
|
watch([locale, () => toValue(instanceId), () => optionIds.value.join('\n')], () => {
|
||||||
|
generation++
|
||||||
|
labels.value = {}
|
||||||
|
debug('locale, instance or option IDs changed: labels cleared', {
|
||||||
|
generation,
|
||||||
|
locale: locale.value,
|
||||||
|
instanceId: toValue(instanceId),
|
||||||
|
optionCount: optionIds.value.length,
|
||||||
|
})
|
||||||
|
void refresh('request inputs changed')
|
||||||
|
})
|
||||||
|
|
||||||
|
onScopeDispose(() => {
|
||||||
|
generation++
|
||||||
|
stopListening?.()
|
||||||
|
labels.value = {}
|
||||||
|
debug('scope disposed', { generation })
|
||||||
|
})
|
||||||
|
|
||||||
|
return labels
|
||||||
|
}
|
||||||
@@ -0,0 +1,476 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
ClipboardCopyIcon,
|
||||||
|
EditIcon,
|
||||||
|
MoreVerticalIcon,
|
||||||
|
NoSignalIcon,
|
||||||
|
RefreshCwIcon,
|
||||||
|
SaveIcon,
|
||||||
|
SearchIcon,
|
||||||
|
SignalIcon,
|
||||||
|
TrashIcon,
|
||||||
|
XIcon,
|
||||||
|
} from '@modrinth/assets'
|
||||||
|
import {
|
||||||
|
Avatar,
|
||||||
|
Button,
|
||||||
|
type ButtonMenuOption,
|
||||||
|
commonMessages,
|
||||||
|
defineMessages,
|
||||||
|
FilterPills,
|
||||||
|
injectNotificationManager,
|
||||||
|
NewModal,
|
||||||
|
StyledInput,
|
||||||
|
Table,
|
||||||
|
type TableColumn,
|
||||||
|
TeleportOverflowMenu,
|
||||||
|
useVIntl,
|
||||||
|
} from '@modrinth/ui'
|
||||||
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
|
||||||
|
import { computed, nextTick, ref } from 'vue'
|
||||||
|
|
||||||
|
import { remove_synced_server, type SyncedServer, update_synced_server } from '@/helpers/instance'
|
||||||
|
import { syncedOptionsKeys, syncedServersQueryOptions } from '@/helpers/synced-options'
|
||||||
|
import { copyToClipboard } from '@/helpers/utils'
|
||||||
|
import {
|
||||||
|
refreshServerData,
|
||||||
|
refreshServers,
|
||||||
|
type ServerData,
|
||||||
|
type ServerWorld,
|
||||||
|
} from '@/helpers/worlds'
|
||||||
|
|
||||||
|
const { handleError } = injectNotificationManager()
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const queryClient = useQueryClient()
|
||||||
|
const serverEditorModal = ref<InstanceType<typeof NewModal> | null>(null)
|
||||||
|
const editServerModal = ref<InstanceType<typeof NewModal> | null>(null)
|
||||||
|
const editedServer = ref<SyncedServer | null>(null)
|
||||||
|
const serversQuery = useQuery(syncedServersQueryOptions())
|
||||||
|
const syncedServers = computed(() => serversQuery.data.value ?? [])
|
||||||
|
const serverData = ref<Record<string, ServerData>>({})
|
||||||
|
const serverSearch = ref('')
|
||||||
|
const selectedServerFilters = ref<string[]>([])
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
serverEditorTitle: {
|
||||||
|
id: 'app.settings.synced-options.multiplayer-servers.editor-title',
|
||||||
|
defaultMessage: 'Edit synced servers',
|
||||||
|
},
|
||||||
|
editServerTitle: {
|
||||||
|
id: 'instance.edit-server.title',
|
||||||
|
defaultMessage: 'Edit server',
|
||||||
|
},
|
||||||
|
serverName: {
|
||||||
|
id: 'app.settings.synced-options.multiplayer-servers.name',
|
||||||
|
defaultMessage: 'Server name',
|
||||||
|
},
|
||||||
|
serverAddress: {
|
||||||
|
id: 'app.settings.synced-options.multiplayer-servers.address',
|
||||||
|
defaultMessage: 'Server address',
|
||||||
|
},
|
||||||
|
searchServers: {
|
||||||
|
id: 'app.settings.synced-options.multiplayer-servers.search',
|
||||||
|
defaultMessage:
|
||||||
|
'Search {count, number} {count, plural, one {synced server} other {synced servers}}...',
|
||||||
|
},
|
||||||
|
serverStatus: {
|
||||||
|
id: 'app.settings.synced-options.multiplayer-servers.status',
|
||||||
|
defaultMessage: 'Status',
|
||||||
|
},
|
||||||
|
onlineFilter: {
|
||||||
|
id: 'app.settings.synced-options.multiplayer-servers.filter-online',
|
||||||
|
defaultMessage: 'Online',
|
||||||
|
},
|
||||||
|
offlineFilter: {
|
||||||
|
id: 'app.settings.synced-options.multiplayer-servers.filter-offline',
|
||||||
|
defaultMessage: 'Offline',
|
||||||
|
},
|
||||||
|
playersOnline: {
|
||||||
|
id: 'app.settings.synced-options.multiplayer-servers.players-online',
|
||||||
|
defaultMessage: '{count, number} online',
|
||||||
|
},
|
||||||
|
noMatchingServers: {
|
||||||
|
id: 'app.settings.synced-options.multiplayer-servers.no-results',
|
||||||
|
defaultMessage: 'No synced servers match your search or filters.',
|
||||||
|
},
|
||||||
|
serverCount: {
|
||||||
|
id: 'app.settings.synced-options.multiplayer-servers.count',
|
||||||
|
defaultMessage: '{count, plural, one {# server} other {# servers}}',
|
||||||
|
},
|
||||||
|
moreServerOptions: {
|
||||||
|
id: 'app.settings.synced-options.multiplayer-servers.more-options',
|
||||||
|
defaultMessage: 'More server options',
|
||||||
|
},
|
||||||
|
copyServerAddress: {
|
||||||
|
id: 'app.settings.synced-options.multiplayer-servers.copy-address',
|
||||||
|
defaultMessage: 'Copy address',
|
||||||
|
},
|
||||||
|
noSyncedServers: {
|
||||||
|
id: 'app.settings.synced-options.multiplayer-servers.empty',
|
||||||
|
defaultMessage: 'No user-added servers are currently synced.',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const serverWorlds = computed<ServerWorld[]>(() =>
|
||||||
|
syncedServers.value.map((server, index) => ({
|
||||||
|
name: server.name,
|
||||||
|
type: 'server',
|
||||||
|
index,
|
||||||
|
server_id: server.id,
|
||||||
|
address: server.address,
|
||||||
|
pack_status:
|
||||||
|
server.accept_textures === true
|
||||||
|
? 'enabled'
|
||||||
|
: server.accept_textures === false
|
||||||
|
? 'disabled'
|
||||||
|
: 'prompt',
|
||||||
|
display_status: 'normal',
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
|
||||||
|
type SyncedServerTableColumn = 'server' | 'status' | 'version' | 'actions'
|
||||||
|
type SyncedServerTableRow = SyncedServer & {
|
||||||
|
server: string
|
||||||
|
status: 'online' | 'offline'
|
||||||
|
version: string
|
||||||
|
actions: null
|
||||||
|
}
|
||||||
|
|
||||||
|
const syncedServerColumns = computed<TableColumn<SyncedServerTableColumn>[]>(() => [
|
||||||
|
{
|
||||||
|
key: 'server',
|
||||||
|
label: formatMessage(commonMessages.serverLabel),
|
||||||
|
width: '45%',
|
||||||
|
cellClass: '!h-16',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'status',
|
||||||
|
label: formatMessage(messages.serverStatus),
|
||||||
|
width: '25%',
|
||||||
|
cellClass: '!h-16',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'version',
|
||||||
|
label: formatMessage(commonMessages.versionLabel),
|
||||||
|
width: '22%',
|
||||||
|
cellClass: '!h-16',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'actions',
|
||||||
|
label: formatMessage(commonMessages.actionsLabel),
|
||||||
|
align: 'right',
|
||||||
|
width: '6rem',
|
||||||
|
cellClass: '!h-16',
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const syncedServerFilterOptions = computed(() => [
|
||||||
|
{ id: 'online', label: formatMessage(messages.onlineFilter) },
|
||||||
|
{ id: 'offline', label: formatMessage(messages.offlineFilter) },
|
||||||
|
])
|
||||||
|
|
||||||
|
const syncedServerRows = computed<SyncedServerTableRow[]>(() =>
|
||||||
|
syncedServers.value.map((server) => ({
|
||||||
|
...server,
|
||||||
|
server: server.name,
|
||||||
|
status: serverData.value[server.address]?.status ? 'online' : 'offline',
|
||||||
|
version: serverData.value[server.address]?.status?.version?.name ?? '',
|
||||||
|
actions: null,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
|
||||||
|
const statusFilteredSyncedServerRows = computed(() => {
|
||||||
|
if (selectedServerFilters.value.length === 0) return syncedServerRows.value
|
||||||
|
return syncedServerRows.value.filter((server) =>
|
||||||
|
selectedServerFilters.value.includes(server.status),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
const filteredSyncedServerRows = computed(() => {
|
||||||
|
const search = serverSearch.value.trim().toLocaleLowerCase()
|
||||||
|
if (!search) return statusFilteredSyncedServerRows.value
|
||||||
|
return statusFilteredSyncedServerRows.value.filter(
|
||||||
|
(server) =>
|
||||||
|
server.name.toLocaleLowerCase().includes(search) ||
|
||||||
|
server.address.toLocaleLowerCase().includes(search),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
const refreshMutation = useMutation({
|
||||||
|
mutationFn: () => refreshServers(serverWorlds.value, serverData.value, null),
|
||||||
|
onError: handleError,
|
||||||
|
})
|
||||||
|
const refreshingAllSyncedServers = refreshMutation.isPending
|
||||||
|
const saveMutation = useMutation({
|
||||||
|
mutationFn: update_synced_server,
|
||||||
|
onSuccess: async (_, server) => {
|
||||||
|
queryClient.setQueryData<SyncedServer[]>(syncedOptionsKeys.servers, (servers) =>
|
||||||
|
servers?.map((current) => (current.id === server.id ? { ...server } : current)),
|
||||||
|
)
|
||||||
|
await queryClient.invalidateQueries({ queryKey: ['worlds'] })
|
||||||
|
void refreshSyncedServer(server.address).catch(handleError)
|
||||||
|
},
|
||||||
|
onError: handleError,
|
||||||
|
})
|
||||||
|
const removeMutation = useMutation({
|
||||||
|
mutationFn: remove_synced_server,
|
||||||
|
onSuccess: async (_, serverId) => {
|
||||||
|
queryClient.setQueryData<SyncedServer[]>(syncedOptionsKeys.servers, (servers) =>
|
||||||
|
servers?.filter((server) => server.id !== serverId),
|
||||||
|
)
|
||||||
|
await queryClient.invalidateQueries({ queryKey: ['worlds'] })
|
||||||
|
},
|
||||||
|
onError: handleError,
|
||||||
|
})
|
||||||
|
|
||||||
|
async function show() {
|
||||||
|
const result = await serversQuery.refetch()
|
||||||
|
if (result.isError) {
|
||||||
|
handleError(result.error)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
serverSearch.value = ''
|
||||||
|
selectedServerFilters.value = []
|
||||||
|
serverData.value = {}
|
||||||
|
serverEditorModal.value?.show()
|
||||||
|
refreshAllSyncedServers()
|
||||||
|
}
|
||||||
|
|
||||||
|
function openSyncedServerEditor(server: SyncedServer) {
|
||||||
|
editedServer.value = { ...server }
|
||||||
|
editServerModal.value?.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveSyncedServer() {
|
||||||
|
if (!editedServer.value || saveMutation.isPending.value) return
|
||||||
|
try {
|
||||||
|
await saveMutation.mutateAsync({ ...editedServer.value })
|
||||||
|
await nextTick()
|
||||||
|
editServerModal.value?.hide()
|
||||||
|
} catch {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshSyncedServer(address: string) {
|
||||||
|
serverData.value[address] ??= { refreshing: true }
|
||||||
|
await refreshServerData(serverData.value[address], null, address)
|
||||||
|
}
|
||||||
|
|
||||||
|
function refreshAllSyncedServers() {
|
||||||
|
if (!refreshingAllSyncedServers.value) refreshMutation.mutate()
|
||||||
|
}
|
||||||
|
|
||||||
|
function syncedServerMenuOptions(server: SyncedServer): ButtonMenuOption[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
id: 'refresh',
|
||||||
|
label: formatMessage(commonMessages.refreshButton),
|
||||||
|
icon: RefreshCwIcon,
|
||||||
|
action: () => refreshSyncedServer(server.address).catch(handleError),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'copy-address',
|
||||||
|
label: formatMessage(messages.copyServerAddress),
|
||||||
|
icon: ClipboardCopyIcon,
|
||||||
|
action: () => copyToClipboard(server.address),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'edit',
|
||||||
|
label: formatMessage(commonMessages.editButton),
|
||||||
|
icon: EditIcon,
|
||||||
|
action: () => openSyncedServerEditor(server),
|
||||||
|
},
|
||||||
|
{ type: 'divider' },
|
||||||
|
{
|
||||||
|
id: 'remove',
|
||||||
|
label: formatMessage(commonMessages.removeButton),
|
||||||
|
icon: TrashIcon,
|
||||||
|
tone: 'red',
|
||||||
|
disabled: removeMutation.isPending.value,
|
||||||
|
action: () => removeMutation.mutate(server.id),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ show })
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<NewModal
|
||||||
|
ref="serverEditorModal"
|
||||||
|
:header="formatMessage(messages.serverEditorTitle)"
|
||||||
|
no-padding
|
||||||
|
max-width="min(928px, calc(100vw - 2rem))"
|
||||||
|
width="min(928px, calc(100vw - 2rem))"
|
||||||
|
>
|
||||||
|
<div class="flex max-h-[min(600px,calc(95vh-10rem))] flex-col">
|
||||||
|
<div
|
||||||
|
class="flex shrink-0 flex-col gap-4 border-0 border-b border-solid border-surface-4 px-6 py-4"
|
||||||
|
>
|
||||||
|
<StyledInput
|
||||||
|
v-model="serverSearch"
|
||||||
|
:icon="SearchIcon"
|
||||||
|
type="search"
|
||||||
|
autocomplete="off"
|
||||||
|
:spellcheck="false"
|
||||||
|
:placeholder="formatMessage(messages.searchServers, { count: syncedServers.length })"
|
||||||
|
size="medium"
|
||||||
|
:aria-label="formatMessage(messages.searchServers, { count: syncedServers.length })"
|
||||||
|
:clear-label="formatMessage(commonMessages.clearButton)"
|
||||||
|
clearable
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||||
|
<FilterPills v-model="selectedServerFilters" :options="syncedServerFilterOptions">
|
||||||
|
<template #all>
|
||||||
|
{{ formatMessage(commonMessages.allProjectType) }}
|
||||||
|
</template>
|
||||||
|
</FilterPills>
|
||||||
|
<Button
|
||||||
|
type="quiet"
|
||||||
|
:disabled="refreshingAllSyncedServers || syncedServers.length === 0"
|
||||||
|
interaction="none"
|
||||||
|
@click="refreshAllSyncedServers"
|
||||||
|
>
|
||||||
|
<RefreshCwIcon
|
||||||
|
:class="{ 'animate-spin': refreshingAllSyncedServers }"
|
||||||
|
aria-hidden="true"
|
||||||
|
/>
|
||||||
|
{{ formatMessage(commonMessages.refreshButton) }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex min-h-0 flex-1 flex-col overflow-hidden">
|
||||||
|
<div
|
||||||
|
v-if="syncedServers.length === 0"
|
||||||
|
class="flex flex-1 items-center justify-center p-8 text-center text-[var(--color-text-tertiary)]"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.noSyncedServers) }}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-else-if="filteredSyncedServerRows.length === 0"
|
||||||
|
class="flex flex-1 items-center justify-center p-8 text-center text-[var(--color-text-tertiary)]"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.noMatchingServers) }}
|
||||||
|
</div>
|
||||||
|
<div v-else class="min-h-0 flex-1 overflow-y-auto">
|
||||||
|
<Table
|
||||||
|
:columns="syncedServerColumns"
|
||||||
|
:data="filteredSyncedServerRows"
|
||||||
|
row-key="id"
|
||||||
|
table-min-width="44rem"
|
||||||
|
class="!rounded-none !border-0"
|
||||||
|
>
|
||||||
|
<template #cell-server="{ row }">
|
||||||
|
<div class="flex min-w-0 items-center gap-3">
|
||||||
|
<Avatar
|
||||||
|
:src="serverData[row.address]?.status?.favicon"
|
||||||
|
:alt="row.name"
|
||||||
|
:tint-by="row.address"
|
||||||
|
size="32px"
|
||||||
|
no-shadow
|
||||||
|
class="shrink-0 !rounded-lg"
|
||||||
|
/>
|
||||||
|
<div class="flex min-w-0 flex-col">
|
||||||
|
<span class="truncate font-semibold text-[var(--color-text-primary)]">{{
|
||||||
|
row.name
|
||||||
|
}}</span>
|
||||||
|
<span class="truncate text-sm text-[var(--color-text-tertiary)]">{{
|
||||||
|
row.address
|
||||||
|
}}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<template #cell-status="{ row }">
|
||||||
|
<span class="inline-flex items-center gap-1.5 font-medium">
|
||||||
|
<RefreshCwIcon
|
||||||
|
v-if="serverData[row.address]?.refreshing"
|
||||||
|
class="size-4 shrink-0 animate-spin"
|
||||||
|
aria-hidden="true"
|
||||||
|
/>
|
||||||
|
<SignalIcon
|
||||||
|
v-else-if="serverData[row.address]?.status"
|
||||||
|
class="size-4 shrink-0 text-green"
|
||||||
|
aria-hidden="true"
|
||||||
|
/>
|
||||||
|
<NoSignalIcon v-else class="size-4 shrink-0" aria-hidden="true" />
|
||||||
|
<template v-if="serverData[row.address]?.refreshing">
|
||||||
|
{{ formatMessage(commonMessages.loadingLabel) }}
|
||||||
|
</template>
|
||||||
|
<template v-else-if="serverData[row.address]?.status">
|
||||||
|
{{
|
||||||
|
formatMessage(messages.playersOnline, {
|
||||||
|
count: serverData[row.address]?.status?.players?.online ?? 0,
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
</template>
|
||||||
|
<template v-else>{{ formatMessage(messages.offlineFilter) }}</template>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
<template #cell-version="{ row }">
|
||||||
|
<span class="block truncate">{{ row.version || '—' }}</span>
|
||||||
|
</template>
|
||||||
|
<template #cell-actions="{ row }">
|
||||||
|
<div class="flex justify-end">
|
||||||
|
<TeleportOverflowMenu
|
||||||
|
type="quiet"
|
||||||
|
:label="formatMessage(messages.moreServerOptions)"
|
||||||
|
:options="syncedServerMenuOptions(row)"
|
||||||
|
>
|
||||||
|
<MoreVerticalIcon aria-hidden="true" />
|
||||||
|
</TeleportOverflowMenu>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="flex shrink-0 items-center border-0 border-t border-solid border-surface-4 px-6 py-4"
|
||||||
|
>
|
||||||
|
<span class="font-medium text-[var(--color-text-default)]">
|
||||||
|
{{ formatMessage(messages.serverCount, { count: syncedServers.length }) }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</NewModal>
|
||||||
|
|
||||||
|
<NewModal
|
||||||
|
ref="editServerModal"
|
||||||
|
:header="formatMessage(messages.editServerTitle)"
|
||||||
|
:disable-close="saveMutation.isPending.value"
|
||||||
|
max-width="500px"
|
||||||
|
width="500px"
|
||||||
|
>
|
||||||
|
<div v-if="editedServer" class="flex flex-col gap-4">
|
||||||
|
<label class="flex flex-col gap-2 font-semibold text-[var(--color-text-primary)]">
|
||||||
|
{{ formatMessage(messages.serverName) }}
|
||||||
|
<StyledInput v-model="editedServer.name" autocomplete="off" wrapper-class="w-full" />
|
||||||
|
</label>
|
||||||
|
<label class="flex flex-col gap-2 font-semibold text-[var(--color-text-primary)]">
|
||||||
|
{{ formatMessage(messages.serverAddress) }}
|
||||||
|
<StyledInput v-model="editedServer.address" autocomplete="off" wrapper-class="w-full" />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<template #actions>
|
||||||
|
<div class="flex justify-end gap-2">
|
||||||
|
<Button type="outlined" @click="editServerModal?.hide()">
|
||||||
|
<XIcon aria-hidden="true" />
|
||||||
|
{{ formatMessage(commonMessages.cancelButton) }}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="colored"
|
||||||
|
color="brand"
|
||||||
|
:disabled="!editedServer?.address"
|
||||||
|
:loading="saveMutation.isPending.value"
|
||||||
|
@click="saveSyncedServer"
|
||||||
|
>
|
||||||
|
<SaveIcon aria-hidden="true" />
|
||||||
|
{{ formatMessage(commonMessages.saveChangesButton) }}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</NewModal>
|
||||||
|
</template>
|
||||||
@@ -3,6 +3,7 @@ import type { MessageDescriptor } from '@modrinth/ui'
|
|||||||
export type SettingsCategoryId =
|
export type SettingsCategoryId =
|
||||||
| 'interface'
|
| 'interface'
|
||||||
| 'home-navigation'
|
| 'home-navigation'
|
||||||
|
| 'shortcut-settings'
|
||||||
| 'language-translation'
|
| 'language-translation'
|
||||||
| 'ai'
|
| 'ai'
|
||||||
| 'java-performance'
|
| 'java-performance'
|
||||||
@@ -13,6 +14,7 @@ export type SettingsCategoryId =
|
|||||||
| 'updates'
|
| 'updates'
|
||||||
| 'about'
|
| 'about'
|
||||||
| 'feature-flags'
|
| 'feature-flags'
|
||||||
|
| 'logs'
|
||||||
|
|
||||||
export type SettingsGroupId = 'launcher' | 'game' | 'data-privacy' | 'support' | 'developer'
|
export type SettingsGroupId = 'launcher' | 'game' | 'data-privacy' | 'support' | 'developer'
|
||||||
|
|
||||||
@@ -44,6 +46,15 @@ export const settingsCategoryDefinitions: SettingsCategoryDefinition[] = [
|
|||||||
group: 'launcher',
|
group: 'launcher',
|
||||||
onboardingId: 'settings-tab-home-navigation',
|
onboardingId: 'settings-tab-home-navigation',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: 'shortcut-settings',
|
||||||
|
name: {
|
||||||
|
id: 'app.settings.tabs.shortcut-settings',
|
||||||
|
defaultMessage: 'Keyboard shortcuts',
|
||||||
|
},
|
||||||
|
group: 'launcher',
|
||||||
|
onboardingId: 'settings-tab-shortcut-settings',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: 'language-translation',
|
id: 'language-translation',
|
||||||
name: {
|
name: {
|
||||||
@@ -116,6 +127,11 @@ export const settingsCategoryDefinitions: SettingsCategoryDefinition[] = [
|
|||||||
name: { id: 'app.settings.tabs.about', defaultMessage: 'About' },
|
name: { id: 'app.settings.tabs.about', defaultMessage: 'About' },
|
||||||
group: 'support',
|
group: 'support',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: 'logs',
|
||||||
|
name: { id: 'app.settings.tabs.logs', defaultMessage: 'Logs' },
|
||||||
|
group: 'support',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: 'feature-flags',
|
id: 'feature-flags',
|
||||||
name: {
|
name: {
|
||||||
|
|||||||
@@ -3,9 +3,11 @@ import {
|
|||||||
BotIcon,
|
BotIcon,
|
||||||
CoffeeIcon,
|
CoffeeIcon,
|
||||||
CpuIcon,
|
CpuIcon,
|
||||||
|
FileTextIcon,
|
||||||
GameIcon,
|
GameIcon,
|
||||||
GaugeIcon,
|
GaugeIcon,
|
||||||
InfoIcon,
|
InfoIcon,
|
||||||
|
KeyboardIcon,
|
||||||
LanguagesIcon,
|
LanguagesIcon,
|
||||||
LayoutTemplateIcon,
|
LayoutTemplateIcon,
|
||||||
PaintbrushIcon,
|
PaintbrushIcon,
|
||||||
@@ -48,6 +50,10 @@ const categoryContent: Record<SettingsCategoryId, Pick<SettingsCategory, 'icon'
|
|||||||
icon: LayoutTemplateIcon,
|
icon: LayoutTemplateIcon,
|
||||||
content: defineAsyncComponent(() => import('./HomeNavigationSettings.vue')),
|
content: defineAsyncComponent(() => import('./HomeNavigationSettings.vue')),
|
||||||
},
|
},
|
||||||
|
'shortcut-settings': {
|
||||||
|
icon: KeyboardIcon,
|
||||||
|
content: defineAsyncComponent(() => import('./KeybindSettings.vue')),
|
||||||
|
},
|
||||||
'language-translation': {
|
'language-translation': {
|
||||||
icon: LanguagesIcon,
|
icon: LanguagesIcon,
|
||||||
content: defineAsyncComponent(() => import('./LanguageTranslationSettings.vue')),
|
content: defineAsyncComponent(() => import('./LanguageTranslationSettings.vue')),
|
||||||
@@ -78,6 +84,10 @@ const categoryContent: Record<SettingsCategoryId, Pick<SettingsCategory, 'icon'
|
|||||||
content: defineAsyncComponent(() => import('./UpdateSettings.vue')),
|
content: defineAsyncComponent(() => import('./UpdateSettings.vue')),
|
||||||
},
|
},
|
||||||
about: { icon: InfoIcon, content: defineAsyncComponent(() => import('./AboutSettings.vue')) },
|
about: { icon: InfoIcon, content: defineAsyncComponent(() => import('./AboutSettings.vue')) },
|
||||||
|
logs: {
|
||||||
|
icon: FileTextIcon,
|
||||||
|
content: defineAsyncComponent(() => import('./LogsSettings.vue')),
|
||||||
|
},
|
||||||
'feature-flags': {
|
'feature-flags': {
|
||||||
icon: ToggleRightIcon,
|
icon: ToggleRightIcon,
|
||||||
content: defineAsyncComponent(() => import('./FeatureFlagSettings.vue')),
|
content: defineAsyncComponent(() => import('./FeatureFlagSettings.vue')),
|
||||||
|
|||||||
@@ -384,6 +384,16 @@ export const settingsSearchEntries: SettingsSearchEntry[] = [
|
|||||||
categoryId: 'feature-flags',
|
categoryId: 'feature-flags',
|
||||||
label: message('settings.feature-flags.title', 'Feature flags'),
|
label: message('settings.feature-flags.title', 'Feature flags'),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: 'logs-export',
|
||||||
|
categoryId: 'logs',
|
||||||
|
targetId: 'settings-target-logs-export',
|
||||||
|
label: message('app.settings.logs.export.title', 'Export logs'),
|
||||||
|
description: message(
|
||||||
|
'app.settings.logs.export.description',
|
||||||
|
'Package launcher logs with an optional environment summary, instance log, and crash analysis.',
|
||||||
|
),
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
export function validateSettingsSearchEntries(entries = settingsSearchEntries): string[] {
|
export function validateSettingsSearchEntries(entries = settingsSearchEntries): string[] {
|
||||||
|
|||||||
@@ -0,0 +1,171 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { SparklesIcon, SpinnerIcon } from '@modrinth/assets'
|
||||||
|
import { Avatar, ButtonStyled, defineMessages, useVIntl } from '@modrinth/ui'
|
||||||
|
import { computed, onMounted, ref, watch } from 'vue'
|
||||||
|
|
||||||
|
import {
|
||||||
|
requestSkinSiteLuck,
|
||||||
|
skinSitePlayers,
|
||||||
|
skinSitePlayersStatus,
|
||||||
|
skinSiteStatus,
|
||||||
|
skinSiteUser,
|
||||||
|
} from '@/composables/skin-site-session'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
signedOutTitle: { id: 'app.skin-site.home.signed-out-title', defaultMessage: 'Not signed in' },
|
||||||
|
signedOutBody: {
|
||||||
|
id: 'app.skin-site.home.signed-out-body',
|
||||||
|
defaultMessage: 'Sign in to the StarLight skin site to manage players and download packs.',
|
||||||
|
},
|
||||||
|
players: { id: 'app.skin-site.home.players', defaultMessage: 'Your players' },
|
||||||
|
noPlayers: {
|
||||||
|
id: 'app.skin-site.home.no-players',
|
||||||
|
defaultMessage: 'No players yet. Add one on the skin site.',
|
||||||
|
},
|
||||||
|
luck: { id: 'app.skin-site.home.luck', defaultMessage: "Today's luck" },
|
||||||
|
luckUnavailable: { id: 'app.skin-site.home.luck-unavailable', defaultMessage: 'Unavailable' },
|
||||||
|
loading: { id: 'app.skin-site.home.loading', defaultMessage: 'Loading…' },
|
||||||
|
error: { id: 'app.skin-site.home.error', defaultMessage: 'Could not load players.' },
|
||||||
|
signIn: { id: 'app.skin-site.home.sign-in', defaultMessage: 'Sign in' },
|
||||||
|
settings: { id: 'app.skin-site.home.settings', defaultMessage: 'Account' },
|
||||||
|
admin: { id: 'app.skin-site.home.admin', defaultMessage: 'Admin' },
|
||||||
|
myPlayers: { id: 'app.skin-site.home.my-players', defaultMessage: 'My players' },
|
||||||
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'sign-in' | 'open-settings' | 'open-players' | 'open-admin'): void
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const luck = ref<number | null>(null)
|
||||||
|
const luckLoading = ref(false)
|
||||||
|
|
||||||
|
const signedIn = computed(() => skinSiteStatus.value === 'signed-in' && !!skinSiteUser.value)
|
||||||
|
|
||||||
|
const isAdmin = computed(() => {
|
||||||
|
const permissions = skinSiteUser.value?.permissions ?? []
|
||||||
|
return permissions.includes('WEB_ADMIN') || permissions.includes('SERVER_ADMIN')
|
||||||
|
})
|
||||||
|
const players = computed(() => skinSitePlayers.value)
|
||||||
|
const playersLoading = computed(
|
||||||
|
() => skinSitePlayersStatus.value === 'checking' || skinSitePlayersStatus.value === 'idle',
|
||||||
|
)
|
||||||
|
const playersError = computed(() => skinSitePlayersStatus.value === 'error')
|
||||||
|
|
||||||
|
async function loadLuck() {
|
||||||
|
if (!signedIn.value) {
|
||||||
|
luck.value = null
|
||||||
|
return
|
||||||
|
}
|
||||||
|
luckLoading.value = true
|
||||||
|
try {
|
||||||
|
luck.value = await requestSkinSiteLuck()
|
||||||
|
} catch {
|
||||||
|
luck.value = null
|
||||||
|
} finally {
|
||||||
|
luckLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(loadLuck)
|
||||||
|
watch(signedIn, loadLuck)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div
|
||||||
|
class="flex flex-col gap-4 rounded-2xl border border-solid border-surface-5 bg-bg-raised p-4"
|
||||||
|
>
|
||||||
|
<div v-if="!signedIn" class="flex flex-col items-start gap-2">
|
||||||
|
<h3 class="m-0 text-base font-semibold text-contrast">
|
||||||
|
{{ formatMessage(messages.signedOutTitle) }}
|
||||||
|
</h3>
|
||||||
|
<p class="m-0 text-sm text-secondary">{{ formatMessage(messages.signedOutBody) }}</p>
|
||||||
|
<ButtonStyled color="brand">
|
||||||
|
<button type="button" @click="emit('sign-in')">
|
||||||
|
{{ formatMessage(messages.signIn) }}
|
||||||
|
</button>
|
||||||
|
</ButtonStyled>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template v-else>
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<div
|
||||||
|
class="flex size-10 shrink-0 items-center justify-center rounded-full bg-brand-highlight text-lg font-bold text-contrast"
|
||||||
|
>
|
||||||
|
{{ skinSiteUser!.username.slice(0, 1).toUpperCase() }}
|
||||||
|
</div>
|
||||||
|
<div class="flex min-w-0 flex-col">
|
||||||
|
<span class="truncate font-semibold text-contrast">{{ skinSiteUser!.username }}</span>
|
||||||
|
<span class="truncate text-xs text-secondary">{{ skinSiteUser!.uuid }}</span>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="shrink-0 rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="emit('open-settings')"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.settings) }}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
v-if="isAdmin"
|
||||||
|
type="button"
|
||||||
|
class="shrink-0 rounded-full bg-brand px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="emit('open-admin')"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.admin) }}
|
||||||
|
</button>
|
||||||
|
<div
|
||||||
|
class="ml-auto flex shrink-0 items-center gap-1 rounded-full bg-button-bg px-3 py-1 text-sm"
|
||||||
|
:title="formatMessage(messages.luck)"
|
||||||
|
>
|
||||||
|
<SpinnerIcon v-if="luckLoading" class="size-4 animate-spin" />
|
||||||
|
<template v-else-if="luck !== null">
|
||||||
|
<SparklesIcon class="size-4 text-brand" />
|
||||||
|
<span class="font-semibold text-contrast">{{ luck }}</span>
|
||||||
|
</template>
|
||||||
|
<span v-else class="text-xs text-secondary">{{
|
||||||
|
formatMessage(messages.luckUnavailable)
|
||||||
|
}}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<span class="text-sm font-semibold text-contrast">{{
|
||||||
|
formatMessage(messages.players)
|
||||||
|
}}</span>
|
||||||
|
|
||||||
|
<div v-if="playersLoading" class="flex items-center gap-2 text-sm text-secondary">
|
||||||
|
<SpinnerIcon class="size-4 animate-spin" />
|
||||||
|
{{ formatMessage(messages.loading) }}
|
||||||
|
</div>
|
||||||
|
<p v-else-if="playersError" class="m-0 text-sm text-red">
|
||||||
|
{{ formatMessage(messages.error) }}
|
||||||
|
</p>
|
||||||
|
<p v-else-if="!players.length" class="m-0 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.noPlayers) }}
|
||||||
|
</p>
|
||||||
|
<div v-else class="flex flex-wrap gap-3">
|
||||||
|
<div
|
||||||
|
v-for="player in players"
|
||||||
|
:key="player.uuid"
|
||||||
|
class="flex items-center gap-2 rounded-xl bg-button-bg px-2 py-1.5"
|
||||||
|
>
|
||||||
|
<Avatar
|
||||||
|
:src="player.headDataUrl"
|
||||||
|
:alt="player.name"
|
||||||
|
size="2rem"
|
||||||
|
pixelated
|
||||||
|
class="!rounded-md"
|
||||||
|
/>
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<span class="text-sm font-medium text-contrast">{{ player.name }}</span>
|
||||||
|
<span v-if="player.isMojang" class="text-[10px] uppercase text-secondary"
|
||||||
|
>Mojang</span
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,171 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { defineMessages, useVIntl } from '@modrinth/ui'
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
|
|
||||||
|
import { skinSiteUser } from '@/composables/skin-site-session'
|
||||||
|
|
||||||
|
import AdminBroadcastPage from './admin/AdminBroadcastPage.vue'
|
||||||
|
import AdminLauncherPage from './admin/AdminLauncherPage.vue'
|
||||||
|
import AdminPlayersPage from './admin/AdminPlayersPage.vue'
|
||||||
|
import AdminReviewPage from './admin/AdminReviewPage.vue'
|
||||||
|
import AdminSummaryPage from './admin/AdminSummaryPage.vue'
|
||||||
|
import AdminUsersPage from './admin/AdminUsersPage.vue'
|
||||||
|
|
||||||
|
const emit = defineEmits<{ (e: 'back'): void }>()
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.skin-site.admin.title', defaultMessage: 'Admin console' },
|
||||||
|
back: { id: 'app.skin-site.admin.back', defaultMessage: 'Back to home' },
|
||||||
|
noAccess: { id: 'app.skin-site.admin.no-access', defaultMessage: 'You do not have access.' },
|
||||||
|
noAccessHint: {
|
||||||
|
id: 'app.skin-site.admin.no-access-hint',
|
||||||
|
defaultMessage: 'Sign in with an administrator account to use this console.',
|
||||||
|
},
|
||||||
|
groupSecurity: { id: 'app.skin-site.admin.group.security', defaultMessage: 'Security' },
|
||||||
|
groupUsers: { id: 'app.skin-site.admin.group.users', defaultMessage: 'Users' },
|
||||||
|
groupCommunity: { id: 'app.skin-site.admin.group.community', defaultMessage: 'Community' },
|
||||||
|
groupResources: { id: 'app.skin-site.admin.group.resources', defaultMessage: 'Resources' },
|
||||||
|
itemServers: { id: 'app.skin-site.admin.item.servers', defaultMessage: 'Servers' },
|
||||||
|
itemSummary: { id: 'app.skin-site.admin.item.summary', defaultMessage: 'Summary' },
|
||||||
|
itemAccessAudit: { id: 'app.skin-site.admin.item.access-audit', defaultMessage: 'Access audit' },
|
||||||
|
itemUsers: { id: 'app.skin-site.admin.item.users', defaultMessage: 'Users' },
|
||||||
|
itemPlayers: { id: 'app.skin-site.admin.item.players', defaultMessage: 'Players' },
|
||||||
|
itemReview: { id: 'app.skin-site.admin.item.review', defaultMessage: 'Player review' },
|
||||||
|
itemBroadcast: { id: 'app.skin-site.admin.item.broadcast', defaultMessage: 'Broadcast' },
|
||||||
|
itemChat: { id: 'app.skin-site.admin.item.chat', defaultMessage: 'Chat rooms' },
|
||||||
|
itemWiki: { id: 'app.skin-site.admin.item.wiki', defaultMessage: 'Wiki' },
|
||||||
|
itemDonations: { id: 'app.skin-site.admin.item.donations', defaultMessage: 'Donations' },
|
||||||
|
itemMods: { id: 'app.skin-site.admin.item.mods', defaultMessage: 'Mods' },
|
||||||
|
itemLauncher: { id: 'app.skin-site.admin.item.launcher', defaultMessage: 'Launcher' },
|
||||||
|
itemDownloads: { id: 'app.skin-site.admin.item.downloads', defaultMessage: 'Downloads' },
|
||||||
|
})
|
||||||
|
|
||||||
|
type AdminKey =
|
||||||
|
| 'servers'
|
||||||
|
| 'summary'
|
||||||
|
| 'access-audit'
|
||||||
|
| 'users'
|
||||||
|
| 'players'
|
||||||
|
| 'review'
|
||||||
|
| 'broadcast'
|
||||||
|
| 'chat'
|
||||||
|
| 'wiki'
|
||||||
|
| 'donations'
|
||||||
|
| 'mods'
|
||||||
|
| 'launcher'
|
||||||
|
| 'downloads'
|
||||||
|
|
||||||
|
interface NavItem {
|
||||||
|
key: AdminKey
|
||||||
|
label: string
|
||||||
|
}
|
||||||
|
interface NavGroup {
|
||||||
|
id: string
|
||||||
|
label: string
|
||||||
|
items: NavItem[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const navGroups = computed<NavGroup[]>(() => [
|
||||||
|
{
|
||||||
|
id: 'security',
|
||||||
|
label: formatMessage(messages.groupSecurity),
|
||||||
|
items: [
|
||||||
|
{ key: 'servers', label: formatMessage(messages.itemServers) },
|
||||||
|
{ key: 'summary', label: formatMessage(messages.itemSummary) },
|
||||||
|
{ key: 'access-audit', label: formatMessage(messages.itemAccessAudit) },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'users',
|
||||||
|
label: formatMessage(messages.groupUsers),
|
||||||
|
items: [
|
||||||
|
{ key: 'users', label: formatMessage(messages.itemUsers) },
|
||||||
|
{ key: 'players', label: formatMessage(messages.itemPlayers) },
|
||||||
|
{ key: 'review', label: formatMessage(messages.itemReview) },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'community',
|
||||||
|
label: formatMessage(messages.groupCommunity),
|
||||||
|
items: [
|
||||||
|
{ key: 'broadcast', label: formatMessage(messages.itemBroadcast) },
|
||||||
|
{ key: 'chat', label: formatMessage(messages.itemChat) },
|
||||||
|
{ key: 'wiki', label: formatMessage(messages.itemWiki) },
|
||||||
|
{ key: 'donations', label: formatMessage(messages.itemDonations) },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'resources',
|
||||||
|
label: formatMessage(messages.groupResources),
|
||||||
|
items: [
|
||||||
|
{ key: 'mods', label: formatMessage(messages.itemMods) },
|
||||||
|
{ key: 'launcher', label: formatMessage(messages.itemLauncher) },
|
||||||
|
{ key: 'downloads', label: formatMessage(messages.itemDownloads) },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const hasAdminAccess = computed(() => {
|
||||||
|
const permissions = skinSiteUser.value?.permissions ?? []
|
||||||
|
return permissions.includes('WEB_ADMIN') || permissions.includes('SERVER_ADMIN')
|
||||||
|
})
|
||||||
|
|
||||||
|
const current = ref<AdminKey>('summary')
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex h-full min-h-0 flex-col gap-4">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex w-fit items-center gap-1 rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="emit('back')"
|
||||||
|
>
|
||||||
|
← {{ formatMessage(messages.back) }}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="!hasAdminAccess"
|
||||||
|
class="flex flex-col gap-1 rounded-xl border border-solid border-surface-5 bg-bg-raised p-6"
|
||||||
|
>
|
||||||
|
<h2 class="m-0 text-lg font-bold text-contrast">{{ formatMessage(messages.noAccess) }}</h2>
|
||||||
|
<p class="m-0 text-sm text-secondary">{{ formatMessage(messages.noAccessHint) }}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else class="flex min-h-0 flex-1 gap-4">
|
||||||
|
<nav class="flex w-48 shrink-0 flex-col gap-3 overflow-y-auto">
|
||||||
|
<div v-for="group in navGroups" :key="group.id" class="flex flex-col gap-1">
|
||||||
|
<span class="px-2 text-[10px] font-bold tracking-wide text-secondary uppercase">
|
||||||
|
{{ group.label }}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
v-for="item in group.items"
|
||||||
|
:key="item.key"
|
||||||
|
type="button"
|
||||||
|
class="rounded-lg px-2 py-1.5 text-left text-xs font-semibold transition-colors"
|
||||||
|
:class="
|
||||||
|
current === item.key
|
||||||
|
? 'bg-brand text-contrast'
|
||||||
|
: 'text-secondary hover:bg-button-bg hover:text-contrast'
|
||||||
|
"
|
||||||
|
@click="current = item.key"
|
||||||
|
>
|
||||||
|
{{ item.label }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<section
|
||||||
|
class="min-w-0 flex-1 overflow-y-auto rounded-xl border border-solid border-surface-5 bg-bg-raised p-4"
|
||||||
|
>
|
||||||
|
<AdminSummaryPage v-if="current === 'summary'" />
|
||||||
|
<AdminBroadcastPage v-else-if="current === 'broadcast'" />
|
||||||
|
<AdminUsersPage v-else-if="current === 'users'" />
|
||||||
|
<AdminPlayersPage v-else-if="current === 'players'" />
|
||||||
|
<AdminReviewPage v-else-if="current === 'review'" />
|
||||||
|
<AdminLauncherPage v-else-if="current === 'launcher'" />
|
||||||
|
<p v-else class="m-0 text-sm text-secondary">{{ current }}</p>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { SpinnerIcon } from '@modrinth/assets'
|
||||||
|
import { defineMessages, useVIntl } from '@modrinth/ui'
|
||||||
|
import { onMounted, ref } from 'vue'
|
||||||
|
|
||||||
|
import { type SkinSiteAnnouncement, skinSiteAnnouncements } from '@/helpers/skin-site-api'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.skin-site.home.announcements.title', defaultMessage: 'Announcements' },
|
||||||
|
empty: {
|
||||||
|
id: 'app.skin-site.home.announcements.empty',
|
||||||
|
defaultMessage: 'No announcements right now.',
|
||||||
|
},
|
||||||
|
loading: { id: 'app.skin-site.home.announcements.loading', defaultMessage: 'Loading…' },
|
||||||
|
failed: {
|
||||||
|
id: 'app.skin-site.home.announcements.failed',
|
||||||
|
defaultMessage: 'Could not load announcements.',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const announcements = ref<SkinSiteAnnouncement[]>([])
|
||||||
|
const loading = ref(true)
|
||||||
|
const failed = ref(false)
|
||||||
|
|
||||||
|
function formatDate(ts: number): string {
|
||||||
|
try {
|
||||||
|
return new Date(ts).toLocaleDateString()
|
||||||
|
} catch {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
try {
|
||||||
|
const result = await skinSiteAnnouncements()
|
||||||
|
if (result.success) {
|
||||||
|
announcements.value = [...(result.payload ?? [])]
|
||||||
|
.sort((a, b) => {
|
||||||
|
if (a.star !== b.star) return a.star ? -1 : 1
|
||||||
|
return b.updateAt - a.updateAt
|
||||||
|
})
|
||||||
|
.slice(0, 5)
|
||||||
|
} else {
|
||||||
|
failed.value = true
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
failed.value = true
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<h3 class="m-0 text-base font-semibold text-contrast">
|
||||||
|
{{ formatMessage(messages.title) }}
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<div v-if="loading" class="flex items-center gap-2 text-sm text-secondary">
|
||||||
|
<SpinnerIcon class="size-4 animate-spin" />
|
||||||
|
{{ formatMessage(messages.loading) }}
|
||||||
|
</div>
|
||||||
|
<p v-else-if="failed" class="m-0 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.failed) }}
|
||||||
|
</p>
|
||||||
|
<p v-else-if="!announcements.length" class="m-0 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.empty) }}
|
||||||
|
</p>
|
||||||
|
<div v-else class="flex flex-col gap-2">
|
||||||
|
<div
|
||||||
|
v-for="item in announcements"
|
||||||
|
:key="item.id"
|
||||||
|
class="flex flex-col gap-1 rounded-xl border border-solid border-surface-5 bg-bg-raised p-3"
|
||||||
|
>
|
||||||
|
<div class="flex items-start gap-2">
|
||||||
|
<span class="min-w-0 flex-1 truncate text-sm font-semibold text-contrast">
|
||||||
|
{{ item.title }}
|
||||||
|
</span>
|
||||||
|
<span class="shrink-0 text-xs text-secondary">{{ formatDate(item.updateAt) }}</span>
|
||||||
|
</div>
|
||||||
|
<span v-if="item.subtitle" class="truncate text-xs text-secondary">{{
|
||||||
|
item.subtitle
|
||||||
|
}}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,187 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
defineMessages,
|
||||||
|
injectNotificationManager,
|
||||||
|
NewModal,
|
||||||
|
StyledInput,
|
||||||
|
useVIntl,
|
||||||
|
} from '@modrinth/ui'
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
|
|
||||||
|
import { type SkinSiteBugIssueType, skinSiteCreateBugIssue } from '@/helpers/skin-site-api'
|
||||||
|
|
||||||
|
const emit = defineEmits<{ (e: 'created', id: number): void }>()
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError, addNotification } = injectNotificationManager()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.skin-site.bug-create.title', defaultMessage: 'New issue' },
|
||||||
|
type: { id: 'app.skin-site.bug-create.type', defaultMessage: 'Type' },
|
||||||
|
titleField: { id: 'app.skin-site.bug-create.title-field', defaultMessage: 'Title' },
|
||||||
|
titlePlaceholder: {
|
||||||
|
id: 'app.skin-site.bug-create.title-placeholder',
|
||||||
|
defaultMessage: 'A short summary of the problem',
|
||||||
|
},
|
||||||
|
description: { id: 'app.skin-site.bug-create.description', defaultMessage: 'Description' },
|
||||||
|
descriptionPlaceholder: {
|
||||||
|
id: 'app.skin-site.bug-create.description-placeholder',
|
||||||
|
defaultMessage: 'What happened, and how can it be reproduced?',
|
||||||
|
},
|
||||||
|
privateLabel: { id: 'app.skin-site.bug-create.private', defaultMessage: 'Private issue' },
|
||||||
|
privateHint: {
|
||||||
|
id: 'app.skin-site.bug-create.private-hint',
|
||||||
|
defaultMessage: 'Only you and the maintainers can see it.',
|
||||||
|
},
|
||||||
|
images: { id: 'app.skin-site.bug-create.images', defaultMessage: 'Images' },
|
||||||
|
imagesHint: {
|
||||||
|
id: 'app.skin-site.bug-create.images-hint',
|
||||||
|
defaultMessage: 'Optional, up to 5 images.',
|
||||||
|
},
|
||||||
|
submit: { id: 'app.skin-site.bug-create.submit', defaultMessage: 'Create issue' },
|
||||||
|
submitting: { id: 'app.skin-site.bug-create.submitting', defaultMessage: 'Creating…' },
|
||||||
|
created: { id: 'app.skin-site.bug-create.created', defaultMessage: 'Issue created.' },
|
||||||
|
cancel: { id: 'app.skin-site.bug-create.cancel', defaultMessage: 'Cancel' },
|
||||||
|
typeBug: { id: 'app.skin-site.bugs.type.bug', defaultMessage: 'Bug' },
|
||||||
|
typeFeature: { id: 'app.skin-site.bugs.type.feature', defaultMessage: 'Feature' },
|
||||||
|
typeImprovement: { id: 'app.skin-site.bugs.type.improvement', defaultMessage: 'Improvement' },
|
||||||
|
})
|
||||||
|
|
||||||
|
const modal = ref<InstanceType<typeof NewModal>>()
|
||||||
|
const type = ref<SkinSiteBugIssueType>('BUG')
|
||||||
|
const title = ref('')
|
||||||
|
const description = ref('')
|
||||||
|
const isPrivate = ref(false)
|
||||||
|
const images = ref<File[]>([])
|
||||||
|
const working = ref(false)
|
||||||
|
|
||||||
|
const TYPE_OPTIONS: SkinSiteBugIssueType[] = ['BUG', 'FEATURE', 'IMPROVEMENT']
|
||||||
|
|
||||||
|
function typeLabel(t: SkinSiteBugIssueType): string {
|
||||||
|
if (t === 'FEATURE') return formatMessage(messages.typeFeature)
|
||||||
|
if (t === 'IMPROVEMENT') return formatMessage(messages.typeImprovement)
|
||||||
|
return formatMessage(messages.typeBug)
|
||||||
|
}
|
||||||
|
|
||||||
|
const canSubmit = computed(
|
||||||
|
() => title.value.trim().length > 0 && description.value.trim().length > 0 && !working.value,
|
||||||
|
)
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
type.value = 'BUG'
|
||||||
|
title.value = ''
|
||||||
|
description.value = ''
|
||||||
|
isPrivate.value = false
|
||||||
|
images.value = []
|
||||||
|
working.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
function show() {
|
||||||
|
reset()
|
||||||
|
modal.value?.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
function onFiles(event: Event) {
|
||||||
|
const input = event.target as HTMLInputElement
|
||||||
|
images.value = Array.from(input.files ?? []).slice(0, 5)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submit() {
|
||||||
|
if (!canSubmit.value) return
|
||||||
|
working.value = true
|
||||||
|
try {
|
||||||
|
const result = await skinSiteCreateBugIssue(
|
||||||
|
{
|
||||||
|
type: type.value,
|
||||||
|
title: title.value.trim(),
|
||||||
|
description: description.value.trim(),
|
||||||
|
private: isPrivate.value,
|
||||||
|
},
|
||||||
|
images.value,
|
||||||
|
)
|
||||||
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
|
addNotification({ type: 'success', title: formatMessage(messages.created) })
|
||||||
|
modal.value?.hide()
|
||||||
|
emit('created', result.payload.id)
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
working.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancel() {
|
||||||
|
modal.value?.hide()
|
||||||
|
reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ show })
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<NewModal ref="modal" :header="formatMessage(messages.title)" @hide="reset">
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="font-semibold text-contrast">{{ formatMessage(messages.type) }}</span>
|
||||||
|
<select
|
||||||
|
v-model="type"
|
||||||
|
class="rounded-lg border border-solid border-surface-5 bg-bg-raised px-3 py-2 text-sm text-contrast"
|
||||||
|
>
|
||||||
|
<option v-for="t in TYPE_OPTIONS" :key="t" :value="t">{{ typeLabel(t) }}</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="font-semibold text-contrast">{{ formatMessage(messages.titleField) }}</span>
|
||||||
|
<StyledInput
|
||||||
|
v-model="title"
|
||||||
|
type="text"
|
||||||
|
:placeholder="formatMessage(messages.titlePlaceholder)"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="font-semibold text-contrast">{{ formatMessage(messages.description) }}</span>
|
||||||
|
<textarea
|
||||||
|
v-model="description"
|
||||||
|
rows="5"
|
||||||
|
class="w-full resize-y rounded-lg border border-solid border-surface-5 bg-bg-raised px-3 py-2 text-sm text-contrast outline-none focus:border-brand"
|
||||||
|
:placeholder="formatMessage(messages.descriptionPlaceholder)"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label class="flex items-start gap-2">
|
||||||
|
<input v-model="isPrivate" type="checkbox" class="mt-1" />
|
||||||
|
<span class="flex flex-col">
|
||||||
|
<span class="text-sm font-semibold text-contrast">
|
||||||
|
{{ formatMessage(messages.privateLabel) }}
|
||||||
|
</span>
|
||||||
|
<span class="text-xs text-secondary">{{ formatMessage(messages.privateHint) }}</span>
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="font-semibold text-contrast">{{ formatMessage(messages.images) }}</span>
|
||||||
|
<input type="file" accept="image/*" multiple @change="onFiles" />
|
||||||
|
<span class="text-xs text-secondary">{{ formatMessage(messages.imagesHint) }}</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div class="flex justify-end gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-button-bg px-4 py-2 text-sm font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="cancel"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.cancel) }}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-brand px-4 py-2 text-sm font-semibold text-contrast disabled:opacity-50"
|
||||||
|
:disabled="!canSubmit"
|
||||||
|
@click="submit"
|
||||||
|
>
|
||||||
|
{{ working ? formatMessage(messages.submitting) : formatMessage(messages.submit) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</NewModal>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,425 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { SpinnerIcon } from '@modrinth/assets'
|
||||||
|
import { defineMessages, injectNotificationManager, useVIntl } from '@modrinth/ui'
|
||||||
|
import { computed, onMounted, ref } from 'vue'
|
||||||
|
|
||||||
|
import {
|
||||||
|
type SkinSiteBugComment,
|
||||||
|
skinSiteBugComments,
|
||||||
|
type SkinSiteBugIssue,
|
||||||
|
skinSiteBugIssue,
|
||||||
|
type SkinSiteBugIssueType,
|
||||||
|
type SkinSiteBugPriority,
|
||||||
|
type SkinSiteBugResolution,
|
||||||
|
type SkinSiteBugStatus,
|
||||||
|
skinSiteCreateBugComment,
|
||||||
|
skinSiteDeleteBugComment,
|
||||||
|
} from '@/helpers/skin-site-api'
|
||||||
|
|
||||||
|
const props = defineProps<{ issueId: number }>()
|
||||||
|
const emit = defineEmits<{ (e: 'back'): void }>()
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError, addNotification } = injectNotificationManager()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
back: { id: 'app.skin-site.bug-detail.back', defaultMessage: 'Back to list' },
|
||||||
|
loading: { id: 'app.skin-site.bug-detail.loading', defaultMessage: 'Loading…' },
|
||||||
|
failed: { id: 'app.skin-site.bug-detail.failed', defaultMessage: 'Could not load this issue.' },
|
||||||
|
issueNo: { id: 'app.skin-site.bug-detail.issue-no', defaultMessage: 'Issue #{id}' },
|
||||||
|
by: { id: 'app.skin-site.bug-detail.by', defaultMessage: 'by {name}' },
|
||||||
|
assignee: { id: 'app.skin-site.bug-detail.assignee', defaultMessage: 'Assignee: {name}' },
|
||||||
|
unassigned: { id: 'app.skin-site.bug-detail.unassigned', defaultMessage: 'Unassigned' },
|
||||||
|
descriptionEmpty: {
|
||||||
|
id: 'app.skin-site.bug-detail.description-empty',
|
||||||
|
defaultMessage: 'No description provided.',
|
||||||
|
},
|
||||||
|
resolution: { id: 'app.skin-site.bug-detail.resolution', defaultMessage: 'Resolution: {name}' },
|
||||||
|
commentsTitle: { id: 'app.skin-site.bug-detail.comments-title', defaultMessage: 'Comments' },
|
||||||
|
commentsEmpty: {
|
||||||
|
id: 'app.skin-site.bug-detail.comments-empty',
|
||||||
|
defaultMessage: 'No comments yet. Be the first to reply.',
|
||||||
|
},
|
||||||
|
commentsLoading: {
|
||||||
|
id: 'app.skin-site.bug-detail.comments-loading',
|
||||||
|
defaultMessage: 'Loading comments…',
|
||||||
|
},
|
||||||
|
commentPlaceholder: {
|
||||||
|
id: 'app.skin-site.bug-detail.comment-placeholder',
|
||||||
|
defaultMessage: 'Write a comment…',
|
||||||
|
},
|
||||||
|
commentSubmit: { id: 'app.skin-site.bug-detail.comment-submit', defaultMessage: 'Comment' },
|
||||||
|
commentSending: { id: 'app.skin-site.bug-detail.comment-sending', defaultMessage: 'Sending…' },
|
||||||
|
commentEmptyError: {
|
||||||
|
id: 'app.skin-site.bug-detail.comment-empty-error',
|
||||||
|
defaultMessage: 'Comment cannot be empty.',
|
||||||
|
},
|
||||||
|
commentPosted: {
|
||||||
|
id: 'app.skin-site.bug-detail.comment-posted',
|
||||||
|
defaultMessage: 'Comment posted.',
|
||||||
|
},
|
||||||
|
commentDeleted: {
|
||||||
|
id: 'app.skin-site.bug-detail.comment-deleted',
|
||||||
|
defaultMessage: 'Comment deleted.',
|
||||||
|
},
|
||||||
|
delete: { id: 'app.skin-site.bug-detail.delete', defaultMessage: 'Delete' },
|
||||||
|
deleting: { id: 'app.skin-site.bug-detail.deleting', defaultMessage: 'Deleting…' },
|
||||||
|
system: { id: 'app.skin-site.bug-detail.system', defaultMessage: 'System' },
|
||||||
|
typeBug: { id: 'app.skin-site.bugs.type.bug', defaultMessage: 'Bug' },
|
||||||
|
typeFeature: { id: 'app.skin-site.bugs.type.feature', defaultMessage: 'Feature' },
|
||||||
|
typeImprovement: { id: 'app.skin-site.bugs.type.improvement', defaultMessage: 'Improvement' },
|
||||||
|
statusPending: { id: 'app.skin-site.bugs.status.pending', defaultMessage: 'Pending' },
|
||||||
|
statusConfirmed: { id: 'app.skin-site.bugs.status.confirmed', defaultMessage: 'Confirmed' },
|
||||||
|
statusNeedsInfo: { id: 'app.skin-site.bugs.status.needs-info', defaultMessage: 'Needs info' },
|
||||||
|
statusInProgress: { id: 'app.skin-site.bugs.status.in-progress', defaultMessage: 'In progress' },
|
||||||
|
statusVerifying: { id: 'app.skin-site.bugs.status.verifying', defaultMessage: 'Verifying' },
|
||||||
|
statusClosed: { id: 'app.skin-site.bugs.status.closed', defaultMessage: 'Closed' },
|
||||||
|
priorityCritical: { id: 'app.skin-site.bugs.priority.critical', defaultMessage: 'Critical' },
|
||||||
|
priorityHigh: { id: 'app.skin-site.bugs.priority.high', defaultMessage: 'High' },
|
||||||
|
priorityNormal: { id: 'app.skin-site.bugs.priority.normal', defaultMessage: 'Normal' },
|
||||||
|
priorityLow: { id: 'app.skin-site.bugs.priority.low', defaultMessage: 'Low' },
|
||||||
|
resFixed: { id: 'app.skin-site.bugs.resolution.fixed', defaultMessage: 'Fixed' },
|
||||||
|
resWontFix: { id: 'app.skin-site.bugs.resolution.wont-fix', defaultMessage: 'Won’t fix' },
|
||||||
|
resByDesign: { id: 'app.skin-site.bugs.resolution.by-design', defaultMessage: 'By design' },
|
||||||
|
resDuplicate: { id: 'app.skin-site.bugs.resolution.duplicate', defaultMessage: 'Duplicate' },
|
||||||
|
resCannotReproduce: {
|
||||||
|
id: 'app.skin-site.bugs.resolution.cannot-reproduce',
|
||||||
|
defaultMessage: 'Cannot reproduce',
|
||||||
|
},
|
||||||
|
resInvalid: { id: 'app.skin-site.bugs.resolution.invalid', defaultMessage: 'Invalid' },
|
||||||
|
})
|
||||||
|
|
||||||
|
const issue = ref<SkinSiteBugIssue | null>(null)
|
||||||
|
const loading = ref(true)
|
||||||
|
const failed = ref(false)
|
||||||
|
|
||||||
|
const comments = ref<SkinSiteBugComment[]>([])
|
||||||
|
const commentsLoading = ref(true)
|
||||||
|
const commentsHasMore = ref(false)
|
||||||
|
const commentsLoadingMore = ref(false)
|
||||||
|
const commentDraft = ref('')
|
||||||
|
const commentSending = ref(false)
|
||||||
|
const deletingId = ref<number | null>(null)
|
||||||
|
|
||||||
|
function typeLabel(type: SkinSiteBugIssueType): string {
|
||||||
|
switch (type) {
|
||||||
|
case 'FEATURE':
|
||||||
|
return formatMessage(messages.typeFeature)
|
||||||
|
case 'IMPROVEMENT':
|
||||||
|
return formatMessage(messages.typeImprovement)
|
||||||
|
default:
|
||||||
|
return formatMessage(messages.typeBug)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function statusLabel(status: SkinSiteBugStatus): string {
|
||||||
|
switch (status) {
|
||||||
|
case 'CONFIRMED':
|
||||||
|
return formatMessage(messages.statusConfirmed)
|
||||||
|
case 'NEEDS_INFO':
|
||||||
|
return formatMessage(messages.statusNeedsInfo)
|
||||||
|
case 'IN_PROGRESS':
|
||||||
|
return formatMessage(messages.statusInProgress)
|
||||||
|
case 'VERIFYING':
|
||||||
|
return formatMessage(messages.statusVerifying)
|
||||||
|
case 'CLOSED':
|
||||||
|
return formatMessage(messages.statusClosed)
|
||||||
|
default:
|
||||||
|
return formatMessage(messages.statusPending)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function priorityLabel(priority: SkinSiteBugPriority): string {
|
||||||
|
switch (priority) {
|
||||||
|
case 'CRITICAL':
|
||||||
|
return formatMessage(messages.priorityCritical)
|
||||||
|
case 'HIGH':
|
||||||
|
return formatMessage(messages.priorityHigh)
|
||||||
|
case 'LOW':
|
||||||
|
return formatMessage(messages.priorityLow)
|
||||||
|
default:
|
||||||
|
return formatMessage(messages.priorityNormal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolutionLabel(resolution: SkinSiteBugResolution): string {
|
||||||
|
switch (resolution) {
|
||||||
|
case 'WONT_FIX':
|
||||||
|
return formatMessage(messages.resWontFix)
|
||||||
|
case 'BY_DESIGN':
|
||||||
|
return formatMessage(messages.resByDesign)
|
||||||
|
case 'DUPLICATE':
|
||||||
|
return formatMessage(messages.resDuplicate)
|
||||||
|
case 'CANNOT_REPRODUCE':
|
||||||
|
return formatMessage(messages.resCannotReproduce)
|
||||||
|
case 'INVALID':
|
||||||
|
return formatMessage(messages.resInvalid)
|
||||||
|
default:
|
||||||
|
return formatMessage(messages.resFixed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDateTime(ts: number): string {
|
||||||
|
try {
|
||||||
|
return new Date(ts).toLocaleString()
|
||||||
|
} catch {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const canSubmit = computed(() => !commentSending.value && commentDraft.value.trim().length > 0)
|
||||||
|
|
||||||
|
async function loadIssue() {
|
||||||
|
loading.value = true
|
||||||
|
failed.value = false
|
||||||
|
try {
|
||||||
|
const result = await skinSiteBugIssue(props.issueId)
|
||||||
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
|
issue.value = result.payload
|
||||||
|
} catch (error) {
|
||||||
|
failed.value = true
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadComments(reset = true) {
|
||||||
|
if (reset) {
|
||||||
|
commentsLoading.value = true
|
||||||
|
comments.value = []
|
||||||
|
} else {
|
||||||
|
commentsLoadingMore.value = true
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const result = await skinSiteBugComments(props.issueId, reset ? 0 : comments.value.length, 50)
|
||||||
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
|
const page = result.payload
|
||||||
|
comments.value = reset ? page.items : [...comments.value, ...page.items]
|
||||||
|
commentsHasMore.value = page.hasMore
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
commentsLoading.value = false
|
||||||
|
commentsLoadingMore.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submitComment() {
|
||||||
|
const content = commentDraft.value.trim()
|
||||||
|
if (!content || commentSending.value) return
|
||||||
|
commentSending.value = true
|
||||||
|
try {
|
||||||
|
const result = await skinSiteCreateBugComment(props.issueId, content)
|
||||||
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
|
comments.value = [...comments.value, result.payload]
|
||||||
|
commentDraft.value = ''
|
||||||
|
addNotification({ type: 'success', title: formatMessage(messages.commentPosted) })
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
commentSending.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteComment(comment: SkinSiteBugComment) {
|
||||||
|
if (deletingId.value !== null) return
|
||||||
|
deletingId.value = comment.id
|
||||||
|
try {
|
||||||
|
const result = await skinSiteDeleteBugComment(comment.id)
|
||||||
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
|
comments.value = comments.value.filter((c) => c.id !== comment.id)
|
||||||
|
addNotification({ type: 'success', title: formatMessage(messages.commentDeleted) })
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
deletingId.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
void loadIssue()
|
||||||
|
void loadComments(true)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex w-fit items-center gap-1 rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="emit('back')"
|
||||||
|
>
|
||||||
|
← {{ formatMessage(messages.back) }}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div v-if="loading" class="flex items-center gap-2 text-sm text-secondary">
|
||||||
|
<SpinnerIcon class="size-4 animate-spin" />
|
||||||
|
{{ formatMessage(messages.loading) }}
|
||||||
|
</div>
|
||||||
|
<p v-else-if="failed" class="m-0 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.failed) }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<template v-else-if="issue">
|
||||||
|
<header
|
||||||
|
class="flex flex-col gap-2 rounded-xl border border-solid border-surface-5 bg-bg-raised p-4"
|
||||||
|
>
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<span
|
||||||
|
class="shrink-0 rounded-full bg-button-bg px-2 py-0.5 text-[10px] font-semibold text-secondary"
|
||||||
|
>
|
||||||
|
{{ typeLabel(issue.type) }}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
class="shrink-0 rounded-full px-2 py-0.5 text-[10px] font-semibold"
|
||||||
|
:class="{
|
||||||
|
'bg-green text-contrast':
|
||||||
|
issue.status === 'CONFIRMED' || issue.status === 'VERIFYING',
|
||||||
|
'bg-yellow text-contrast':
|
||||||
|
issue.status === 'NEEDS_INFO' || issue.status === 'IN_PROGRESS',
|
||||||
|
'bg-button-bg text-secondary': issue.status === 'PENDING',
|
||||||
|
'bg-surface-5 text-secondary': issue.status === 'CLOSED',
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
{{ statusLabel(issue.status) }}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
class="shrink-0 rounded-full px-2 py-0.5 text-[10px] font-semibold"
|
||||||
|
:class="{
|
||||||
|
'bg-red text-contrast': issue.priority === 'CRITICAL',
|
||||||
|
'bg-orange text-contrast': issue.priority === 'HIGH',
|
||||||
|
'bg-button-bg text-secondary':
|
||||||
|
issue.priority === 'NORMAL' || issue.priority === 'LOW',
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
{{ priorityLabel(issue.priority) }}
|
||||||
|
</span>
|
||||||
|
<span v-if="issue.private" class="shrink-0 text-[10px] font-semibold text-secondary">
|
||||||
|
🔒
|
||||||
|
</span>
|
||||||
|
<span class="min-w-0 flex-1 truncate text-xs text-secondary">
|
||||||
|
{{ formatMessage(messages.issueNo, { id: issue.id }) }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h1 class="m-0 text-xl font-bold text-contrast">{{ issue.title }}</h1>
|
||||||
|
|
||||||
|
<div class="flex flex-wrap items-center gap-3 text-xs text-secondary">
|
||||||
|
<span>{{ formatMessage(messages.by, { name: issue.authorName }) }}</span>
|
||||||
|
<span>{{ formatDateTime(issue.createdAt) }}</span>
|
||||||
|
<span v-if="issue.assigneeName">
|
||||||
|
{{ formatMessage(messages.assignee, { name: issue.assigneeName }) }}
|
||||||
|
</span>
|
||||||
|
<span v-else>{{ formatMessage(messages.unassigned) }}</span>
|
||||||
|
</div>
|
||||||
|
<span v-if="issue.resolution" class="text-xs font-semibold text-secondary">
|
||||||
|
{{ formatMessage(messages.resolution, { name: resolutionLabel(issue.resolution) }) }}
|
||||||
|
</span>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="rounded-xl border border-solid border-surface-5 bg-bg-raised p-4">
|
||||||
|
<p
|
||||||
|
v-if="issue.description"
|
||||||
|
class="m-0 whitespace-pre-wrap break-words text-sm text-contrast"
|
||||||
|
>
|
||||||
|
{{ issue.description }}
|
||||||
|
</p>
|
||||||
|
<p v-else class="m-0 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.descriptionEmpty) }}
|
||||||
|
</p>
|
||||||
|
<div v-if="issue.images.length" class="mt-3 flex flex-wrap gap-2">
|
||||||
|
<span
|
||||||
|
v-for="image in issue.images"
|
||||||
|
:key="image.hash"
|
||||||
|
class="rounded-lg bg-surface-5 px-2 py-1 text-[10px] font-mono text-secondary"
|
||||||
|
>
|
||||||
|
{{ image.hash }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<section class="flex flex-col gap-3">
|
||||||
|
<h2 class="m-0 text-base font-bold text-contrast">
|
||||||
|
{{ formatMessage(messages.commentsTitle) }}
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<div v-if="commentsLoading" class="flex items-center gap-2 text-sm text-secondary">
|
||||||
|
<SpinnerIcon class="size-4 animate-spin" />
|
||||||
|
{{ formatMessage(messages.commentsLoading) }}
|
||||||
|
</div>
|
||||||
|
<p
|
||||||
|
v-else-if="!comments.length"
|
||||||
|
class="m-0 rounded-xl border border-solid border-surface-5 bg-bg-raised p-4 text-sm text-secondary"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.commentsEmpty) }}
|
||||||
|
</p>
|
||||||
|
<div
|
||||||
|
v-for="comment in comments"
|
||||||
|
v-else
|
||||||
|
:key="comment.id"
|
||||||
|
class="flex flex-col gap-1.5 rounded-xl border border-solid border-surface-5 bg-bg-raised p-3"
|
||||||
|
>
|
||||||
|
<div class="flex flex-wrap items-center gap-2 text-xs text-secondary">
|
||||||
|
<span class="font-semibold text-contrast">{{ comment.authorName }}</span>
|
||||||
|
<span
|
||||||
|
v-if="comment.system"
|
||||||
|
class="rounded-full bg-button-bg px-2 py-0.5 text-[10px] font-semibold"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.system) }}
|
||||||
|
</span>
|
||||||
|
<span>{{ formatDateTime(comment.createdAt) }}</span>
|
||||||
|
<span v-if="comment.editedAt">(edited)</span>
|
||||||
|
<button
|
||||||
|
v-if="comment.canDelete"
|
||||||
|
type="button"
|
||||||
|
class="ml-auto rounded-full bg-button-bg px-2 py-0.5 text-[10px] font-semibold text-secondary hover:brightness-110 disabled:opacity-50"
|
||||||
|
:disabled="deletingId !== null"
|
||||||
|
@click="deleteComment(comment)"
|
||||||
|
>
|
||||||
|
{{
|
||||||
|
deletingId === comment.id
|
||||||
|
? formatMessage(messages.deleting)
|
||||||
|
: formatMessage(messages.delete)
|
||||||
|
}}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p class="m-0 whitespace-pre-wrap break-words text-sm text-contrast">
|
||||||
|
{{ comment.content }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
v-if="commentsHasMore"
|
||||||
|
type="button"
|
||||||
|
class="w-fit self-center rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110 disabled:opacity-50"
|
||||||
|
:disabled="commentsLoadingMore"
|
||||||
|
@click="loadComments(false)"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.commentsTitle) }}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<form class="flex flex-col gap-2" @submit.prevent="submitComment">
|
||||||
|
<textarea
|
||||||
|
v-model="commentDraft"
|
||||||
|
rows="3"
|
||||||
|
class="w-full resize-y rounded-xl border border-solid border-surface-5 bg-bg-raised p-3 text-sm text-contrast outline-none focus:border-brand"
|
||||||
|
:placeholder="formatMessage(messages.commentPlaceholder)"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
class="w-fit self-end rounded-full bg-brand px-4 py-2 text-sm font-semibold text-contrast disabled:opacity-50"
|
||||||
|
:disabled="!canSubmit"
|
||||||
|
>
|
||||||
|
{{
|
||||||
|
commentSending
|
||||||
|
? formatMessage(messages.commentSending)
|
||||||
|
: formatMessage(messages.commentSubmit)
|
||||||
|
}}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,306 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { SpinnerIcon } from '@modrinth/assets'
|
||||||
|
import { defineMessages, injectNotificationManager, useVIntl } from '@modrinth/ui'
|
||||||
|
import { onMounted, ref } from 'vue'
|
||||||
|
|
||||||
|
import {
|
||||||
|
type SkinSiteBugIssue,
|
||||||
|
skinSiteBugIssues,
|
||||||
|
type SkinSiteBugIssueType,
|
||||||
|
type SkinSiteBugPriority,
|
||||||
|
type SkinSiteBugStatus,
|
||||||
|
} from '@/helpers/skin-site-api'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError } = injectNotificationManager()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.skin-site.bugs.title', defaultMessage: 'Bugs & suggestions' },
|
||||||
|
back: { id: 'app.skin-site.bugs.back', defaultMessage: 'Back to home' },
|
||||||
|
subtitle: {
|
||||||
|
id: 'app.skin-site.bugs.subtitle',
|
||||||
|
defaultMessage: 'Report issues and follow their progress.',
|
||||||
|
},
|
||||||
|
loading: { id: 'app.skin-site.bugs.loading', defaultMessage: 'Loading…' },
|
||||||
|
failed: { id: 'app.skin-site.bugs.failed', defaultMessage: 'Could not load issues.' },
|
||||||
|
empty: { id: 'app.skin-site.bugs.empty', defaultMessage: 'No issues match these filters.' },
|
||||||
|
all: { id: 'app.skin-site.bugs.all', defaultMessage: 'All' },
|
||||||
|
more: { id: 'app.skin-site.bugs.more', defaultMessage: 'Load more' },
|
||||||
|
openOnly: { id: 'app.skin-site.bugs.open-only', defaultMessage: 'Open only' },
|
||||||
|
create: { id: 'app.skin-site.bugs.create', defaultMessage: 'New issue' },
|
||||||
|
notifications: {
|
||||||
|
id: 'app.skin-site.bugs.notifications',
|
||||||
|
defaultMessage: 'Notifications',
|
||||||
|
},
|
||||||
|
comments: { id: 'app.skin-site.bugs.comments', defaultMessage: '{count} comments' },
|
||||||
|
typeBug: { id: 'app.skin-site.bugs.type.bug', defaultMessage: 'Bug' },
|
||||||
|
typeFeature: { id: 'app.skin-site.bugs.type.feature', defaultMessage: 'Feature' },
|
||||||
|
typeImprovement: { id: 'app.skin-site.bugs.type.improvement', defaultMessage: 'Improvement' },
|
||||||
|
statusPending: { id: 'app.skin-site.bugs.status.pending', defaultMessage: 'Pending' },
|
||||||
|
statusConfirmed: { id: 'app.skin-site.bugs.status.confirmed', defaultMessage: 'Confirmed' },
|
||||||
|
statusNeedsInfo: { id: 'app.skin-site.bugs.status.needs-info', defaultMessage: 'Needs info' },
|
||||||
|
statusInProgress: { id: 'app.skin-site.bugs.status.in-progress', defaultMessage: 'In progress' },
|
||||||
|
statusVerifying: { id: 'app.skin-site.bugs.status.verifying', defaultMessage: 'Verifying' },
|
||||||
|
statusClosed: { id: 'app.skin-site.bugs.status.closed', defaultMessage: 'Closed' },
|
||||||
|
priorityCritical: { id: 'app.skin-site.bugs.priority.critical', defaultMessage: 'Critical' },
|
||||||
|
priorityHigh: { id: 'app.skin-site.bugs.priority.high', defaultMessage: 'High' },
|
||||||
|
priorityNormal: { id: 'app.skin-site.bugs.priority.normal', defaultMessage: 'Normal' },
|
||||||
|
priorityLow: { id: 'app.skin-site.bugs.priority.low', defaultMessage: 'Low' },
|
||||||
|
})
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'back' | 'create' | 'notifications'): void
|
||||||
|
(e: 'open', id: number): void
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const items = ref<SkinSiteBugIssue[]>([])
|
||||||
|
const hasMore = ref(false)
|
||||||
|
const loading = ref(true)
|
||||||
|
const loadingMore = ref(false)
|
||||||
|
const failed = ref(false)
|
||||||
|
|
||||||
|
const typeFilter = ref<SkinSiteBugIssueType | ''>('')
|
||||||
|
const statusFilter = ref<SkinSiteBugStatus | ''>('')
|
||||||
|
const priorityFilter = ref<SkinSiteBugPriority | ''>('')
|
||||||
|
const openOnly = ref(true)
|
||||||
|
|
||||||
|
const TYPE_OPTIONS: SkinSiteBugIssueType[] = ['BUG', 'FEATURE', 'IMPROVEMENT']
|
||||||
|
const STATUS_OPTIONS: SkinSiteBugStatus[] = [
|
||||||
|
'PENDING',
|
||||||
|
'CONFIRMED',
|
||||||
|
'NEEDS_INFO',
|
||||||
|
'IN_PROGRESS',
|
||||||
|
'VERIFYING',
|
||||||
|
'CLOSED',
|
||||||
|
]
|
||||||
|
const PRIORITY_OPTIONS: SkinSiteBugPriority[] = ['CRITICAL', 'HIGH', 'NORMAL', 'LOW']
|
||||||
|
|
||||||
|
function typeLabel(type: SkinSiteBugIssueType): string {
|
||||||
|
switch (type) {
|
||||||
|
case 'FEATURE':
|
||||||
|
return formatMessage(messages.typeFeature)
|
||||||
|
case 'IMPROVEMENT':
|
||||||
|
return formatMessage(messages.typeImprovement)
|
||||||
|
default:
|
||||||
|
return formatMessage(messages.typeBug)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function statusLabel(status: SkinSiteBugStatus): string {
|
||||||
|
switch (status) {
|
||||||
|
case 'CONFIRMED':
|
||||||
|
return formatMessage(messages.statusConfirmed)
|
||||||
|
case 'NEEDS_INFO':
|
||||||
|
return formatMessage(messages.statusNeedsInfo)
|
||||||
|
case 'IN_PROGRESS':
|
||||||
|
return formatMessage(messages.statusInProgress)
|
||||||
|
case 'VERIFYING':
|
||||||
|
return formatMessage(messages.statusVerifying)
|
||||||
|
case 'CLOSED':
|
||||||
|
return formatMessage(messages.statusClosed)
|
||||||
|
default:
|
||||||
|
return formatMessage(messages.statusPending)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function priorityLabel(priority: SkinSiteBugPriority): string {
|
||||||
|
switch (priority) {
|
||||||
|
case 'CRITICAL':
|
||||||
|
return formatMessage(messages.priorityCritical)
|
||||||
|
case 'HIGH':
|
||||||
|
return formatMessage(messages.priorityHigh)
|
||||||
|
case 'LOW':
|
||||||
|
return formatMessage(messages.priorityLow)
|
||||||
|
default:
|
||||||
|
return formatMessage(messages.priorityNormal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDate(ts: number): string {
|
||||||
|
try {
|
||||||
|
return new Date(ts).toLocaleDateString()
|
||||||
|
} catch {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function load(reset = true) {
|
||||||
|
if (reset) {
|
||||||
|
loading.value = true
|
||||||
|
items.value = []
|
||||||
|
} else {
|
||||||
|
loadingMore.value = true
|
||||||
|
}
|
||||||
|
failed.value = false
|
||||||
|
try {
|
||||||
|
const result = await skinSiteBugIssues({
|
||||||
|
offset: reset ? 0 : items.value.length,
|
||||||
|
limit: 20,
|
||||||
|
type: typeFilter.value || undefined,
|
||||||
|
status: statusFilter.value || undefined,
|
||||||
|
priority: priorityFilter.value || undefined,
|
||||||
|
openOnly: openOnly.value,
|
||||||
|
})
|
||||||
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
|
const page = result.payload
|
||||||
|
items.value = reset ? page.items : [...items.value, ...page.items]
|
||||||
|
hasMore.value = page.hasMore
|
||||||
|
} catch (error) {
|
||||||
|
failed.value = true
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
loadingMore.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearFilters() {
|
||||||
|
typeFilter.value = ''
|
||||||
|
statusFilter.value = ''
|
||||||
|
priorityFilter.value = ''
|
||||||
|
void load(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => load(true))
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex w-fit items-center gap-1 rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="emit('back')"
|
||||||
|
>
|
||||||
|
← {{ formatMessage(messages.back) }}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<header class="flex flex-wrap items-start gap-3">
|
||||||
|
<div class="flex flex-col gap-1">
|
||||||
|
<h1 class="m-0 text-xl font-bold text-contrast">{{ formatMessage(messages.title) }}</h1>
|
||||||
|
<p class="m-0 text-sm text-secondary">{{ formatMessage(messages.subtitle) }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="ml-auto flex items-center gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-secondary hover:brightness-110"
|
||||||
|
@click="emit('notifications')"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.notifications) }}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-brand px-4 py-2 text-sm font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="emit('create')"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.create) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<select
|
||||||
|
v-model="typeFilter"
|
||||||
|
class="rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast"
|
||||||
|
@change="load(true)"
|
||||||
|
>
|
||||||
|
<option value="">{{ formatMessage(messages.all) }}</option>
|
||||||
|
<option v-for="t in TYPE_OPTIONS" :key="t" :value="t">{{ typeLabel(t) }}</option>
|
||||||
|
</select>
|
||||||
|
<select
|
||||||
|
v-model="statusFilter"
|
||||||
|
class="rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast"
|
||||||
|
@change="load(true)"
|
||||||
|
>
|
||||||
|
<option value="">{{ formatMessage(messages.all) }}</option>
|
||||||
|
<option v-for="s in STATUS_OPTIONS" :key="s" :value="s">{{ statusLabel(s) }}</option>
|
||||||
|
</select>
|
||||||
|
<select
|
||||||
|
v-model="priorityFilter"
|
||||||
|
class="rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast"
|
||||||
|
@change="load(true)"
|
||||||
|
>
|
||||||
|
<option value="">{{ formatMessage(messages.all) }}</option>
|
||||||
|
<option v-for="p in PRIORITY_OPTIONS" :key="p" :value="p">{{ priorityLabel(p) }}</option>
|
||||||
|
</select>
|
||||||
|
<label class="flex items-center gap-1.5 text-xs text-secondary">
|
||||||
|
<input v-model="openOnly" type="checkbox" @change="load(true)" />
|
||||||
|
{{ formatMessage(messages.openOnly) }}
|
||||||
|
</label>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="ml-auto rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-secondary hover:brightness-110"
|
||||||
|
@click="clearFilters"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.all) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="loading" class="flex items-center gap-2 text-sm text-secondary">
|
||||||
|
<SpinnerIcon class="size-4 animate-spin" />
|
||||||
|
{{ formatMessage(messages.loading) }}
|
||||||
|
</div>
|
||||||
|
<p v-else-if="failed" class="m-0 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.failed) }}
|
||||||
|
</p>
|
||||||
|
<p v-else-if="!items.length" class="m-0 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.empty) }}
|
||||||
|
</p>
|
||||||
|
<div v-else class="flex flex-col gap-2">
|
||||||
|
<div
|
||||||
|
v-for="issue in items"
|
||||||
|
:key="issue.id"
|
||||||
|
class="flex cursor-pointer flex-col gap-1.5 rounded-xl border border-solid border-surface-5 bg-bg-raised p-3 hover:border-brand"
|
||||||
|
@click="emit('open', issue.id)"
|
||||||
|
>
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<span
|
||||||
|
class="shrink-0 rounded-full bg-button-bg px-2 py-0.5 text-[10px] font-semibold text-secondary"
|
||||||
|
>
|
||||||
|
{{ typeLabel(issue.type) }}
|
||||||
|
</span>
|
||||||
|
<span class="min-w-0 flex-1 truncate text-sm font-semibold text-contrast">
|
||||||
|
#{{ issue.id }} {{ issue.title }}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
class="shrink-0 rounded-full px-2 py-0.5 text-[10px] font-semibold"
|
||||||
|
:class="{
|
||||||
|
'bg-green text-contrast':
|
||||||
|
issue.status === 'CONFIRMED' || issue.status === 'VERIFYING',
|
||||||
|
'bg-yellow text-contrast':
|
||||||
|
issue.status === 'NEEDS_INFO' || issue.status === 'IN_PROGRESS',
|
||||||
|
'bg-button-bg text-secondary': issue.status === 'PENDING',
|
||||||
|
'bg-surface-5 text-secondary': issue.status === 'CLOSED',
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
{{ statusLabel(issue.status) }}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
class="shrink-0 rounded-full px-2 py-0.5 text-[10px] font-semibold"
|
||||||
|
:class="{
|
||||||
|
'bg-red text-contrast': issue.priority === 'CRITICAL',
|
||||||
|
'bg-orange text-contrast': issue.priority === 'HIGH',
|
||||||
|
'bg-button-bg text-secondary':
|
||||||
|
issue.priority === 'NORMAL' || issue.priority === 'LOW',
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
{{ priorityLabel(issue.priority) }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-wrap items-center gap-3 text-xs text-secondary">
|
||||||
|
<span>{{ issue.authorName }}</span>
|
||||||
|
<span>{{ formatDate(issue.createdAt) }}</span>
|
||||||
|
<span>{{ formatMessage(messages.comments, { count: issue.commentCount }) }}</span>
|
||||||
|
<span v-if="issue.assigneeName">→ {{ issue.assigneeName }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
v-if="hasMore"
|
||||||
|
type="button"
|
||||||
|
class="w-fit self-center rounded-full bg-brand px-4 py-2 text-sm font-semibold text-contrast disabled:opacity-50"
|
||||||
|
:disabled="loadingMore"
|
||||||
|
@click="load(false)"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.more) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { SpinnerIcon } from '@modrinth/assets'
|
||||||
|
import { defineMessages, injectNotificationManager, useVIntl } from '@modrinth/ui'
|
||||||
|
import { onMounted, ref } from 'vue'
|
||||||
|
|
||||||
|
import {
|
||||||
|
type SkinSiteBugNotification,
|
||||||
|
skinSiteBugNotifications,
|
||||||
|
skinSiteMarkBugNotificationRead,
|
||||||
|
} from '@/helpers/skin-site-api'
|
||||||
|
|
||||||
|
const emit = defineEmits<{ (e: 'back'): void; (e: 'open', id: number): void }>()
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError } = injectNotificationManager()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.skin-site.bug-notifications.title', defaultMessage: 'Notifications' },
|
||||||
|
back: { id: 'app.skin-site.bug-notifications.back', defaultMessage: 'Back to home' },
|
||||||
|
subtitle: {
|
||||||
|
id: 'app.skin-site.bug-notifications.subtitle',
|
||||||
|
defaultMessage: 'Activity on issues you reported or follow.',
|
||||||
|
},
|
||||||
|
loading: { id: 'app.skin-site.bug-notifications.loading', defaultMessage: 'Loading…' },
|
||||||
|
failed: {
|
||||||
|
id: 'app.skin-site.bug-notifications.failed',
|
||||||
|
defaultMessage: 'Could not load notifications.',
|
||||||
|
},
|
||||||
|
empty: { id: 'app.skin-site.bug-notifications.empty', defaultMessage: 'No new notifications.' },
|
||||||
|
item: {
|
||||||
|
id: 'app.skin-site.bug-notifications.item',
|
||||||
|
defaultMessage: '{name} updated issue #{id}',
|
||||||
|
},
|
||||||
|
markAll: {
|
||||||
|
id: 'app.skin-site.bug-notifications.mark-all',
|
||||||
|
defaultMessage: 'Mark all as read',
|
||||||
|
},
|
||||||
|
markedAll: {
|
||||||
|
id: 'app.skin-site.bug-notifications.marked-all',
|
||||||
|
defaultMessage: 'All notifications marked as read.',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const items = ref<SkinSiteBugNotification[]>([])
|
||||||
|
const loading = ref(true)
|
||||||
|
const failed = ref(false)
|
||||||
|
const marking = ref(false)
|
||||||
|
|
||||||
|
function formatDateTime(ts: number): string {
|
||||||
|
try {
|
||||||
|
return new Date(ts).toLocaleString()
|
||||||
|
} catch {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function load() {
|
||||||
|
loading.value = true
|
||||||
|
failed.value = false
|
||||||
|
try {
|
||||||
|
const result = await skinSiteBugNotifications()
|
||||||
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
|
items.value = result.payload ?? []
|
||||||
|
} catch (error) {
|
||||||
|
failed.value = true
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function markAllRead() {
|
||||||
|
if (marking.value || !items.value.length) return
|
||||||
|
marking.value = true
|
||||||
|
try {
|
||||||
|
await skinSiteMarkBugNotificationRead()
|
||||||
|
items.value = []
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
marking.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => void load())
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex w-fit items-center gap-1 rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="emit('back')"
|
||||||
|
>
|
||||||
|
← {{ formatMessage(messages.back) }}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<header class="flex flex-wrap items-center gap-3">
|
||||||
|
<div class="flex flex-col gap-1">
|
||||||
|
<h1 class="m-0 text-xl font-bold text-contrast">{{ formatMessage(messages.title) }}</h1>
|
||||||
|
<p class="m-0 text-sm text-secondary">{{ formatMessage(messages.subtitle) }}</p>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
v-if="items.length"
|
||||||
|
type="button"
|
||||||
|
class="ml-auto rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-secondary hover:brightness-110 disabled:opacity-50"
|
||||||
|
:disabled="marking"
|
||||||
|
@click="markAllRead"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.markAll) }}
|
||||||
|
</button>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div v-if="loading" class="flex items-center gap-2 text-sm text-secondary">
|
||||||
|
<SpinnerIcon class="size-4 animate-spin" />
|
||||||
|
{{ formatMessage(messages.loading) }}
|
||||||
|
</div>
|
||||||
|
<p v-else-if="failed" class="m-0 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.failed) }}
|
||||||
|
</p>
|
||||||
|
<p
|
||||||
|
v-else-if="!items.length"
|
||||||
|
class="m-0 rounded-xl border border-solid border-surface-5 bg-bg-raised p-4 text-sm text-secondary"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.empty) }}
|
||||||
|
</p>
|
||||||
|
<div v-else class="flex flex-col gap-2">
|
||||||
|
<div
|
||||||
|
v-for="item in items"
|
||||||
|
:key="item.id"
|
||||||
|
class="flex cursor-pointer flex-wrap items-center gap-3 rounded-xl border border-solid border-surface-5 bg-bg-raised p-3 hover:border-brand"
|
||||||
|
@click="emit('open', item.issueId)"
|
||||||
|
>
|
||||||
|
<span class="min-w-0 flex-1 truncate text-sm text-contrast">
|
||||||
|
{{ formatMessage(messages.item, { name: item.actorName, id: item.issueId }) }}
|
||||||
|
</span>
|
||||||
|
<span class="shrink-0 text-xs text-secondary">{{ formatDateTime(item.createdAt) }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,155 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
commonMessages,
|
||||||
|
defineMessages,
|
||||||
|
injectNotificationManager,
|
||||||
|
NewModal,
|
||||||
|
useVIntl,
|
||||||
|
} from '@modrinth/ui'
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
|
|
||||||
|
import { requestCaptcha, verifyCaptcha } from '@/helpers/skin-site-api'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError } = injectNotificationManager()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.skin-site.captcha.title', defaultMessage: 'Let us check you are human' },
|
||||||
|
subtitle: {
|
||||||
|
id: 'app.skin-site.captcha.subtitle',
|
||||||
|
defaultMessage: 'Drag the slider to rotate the image upright.',
|
||||||
|
},
|
||||||
|
submit: { id: 'app.skin-site.captcha.submit', defaultMessage: 'Submit' },
|
||||||
|
loading: { id: 'app.skin-site.captcha.loading', defaultMessage: 'Loading captcha…' },
|
||||||
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits<{ (e: 'verified', clientId: string): void; (e: 'cancel'): void }>()
|
||||||
|
|
||||||
|
const modal = ref<InstanceType<typeof NewModal>>()
|
||||||
|
const loading = ref(false)
|
||||||
|
const submitting = ref(false)
|
||||||
|
const image = ref('')
|
||||||
|
const challengeClientId = ref('')
|
||||||
|
const degree = ref(0)
|
||||||
|
|
||||||
|
/** The image is rotated by the server; the slider counter-rotates the preview. */
|
||||||
|
const previewRotation = computed(() => `${degree.value}deg`)
|
||||||
|
|
||||||
|
function resetState() {
|
||||||
|
degree.value = 0
|
||||||
|
image.value = ''
|
||||||
|
challengeClientId.value = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadCaptcha() {
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const result = await requestCaptcha()
|
||||||
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
|
image.value = result.payload.image ?? ''
|
||||||
|
challengeClientId.value = result.payload.clientId
|
||||||
|
degree.value = 0
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
modal.value?.hide()
|
||||||
|
emit('cancel')
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function show() {
|
||||||
|
resetState()
|
||||||
|
modal.value?.show()
|
||||||
|
await loadCaptcha()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submit() {
|
||||||
|
if (submitting.value || !challengeClientId.value) return
|
||||||
|
submitting.value = true
|
||||||
|
try {
|
||||||
|
const result = await verifyCaptcha({
|
||||||
|
clientId: challengeClientId.value,
|
||||||
|
degree: degree.value,
|
||||||
|
})
|
||||||
|
if (!result.success) {
|
||||||
|
handleError(new Error(result.errorMessage))
|
||||||
|
await loadCaptcha()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
modal.value?.hide()
|
||||||
|
emit('verified', result.payload)
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
submitting.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancel() {
|
||||||
|
modal.value?.hide()
|
||||||
|
emit('cancel')
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ show })
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<NewModal ref="modal" :header="formatMessage(messages.title)" @hide="resetState">
|
||||||
|
<div class="flex flex-col items-center gap-6">
|
||||||
|
<p class="m-0 text-secondary">{{ formatMessage(messages.subtitle) }}</p>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="size-44 overflow-hidden rounded-full border-4 border-solid border-bg-raised bg-button-bg"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
v-if="image"
|
||||||
|
:src="image"
|
||||||
|
alt=""
|
||||||
|
class="size-full object-cover transition-transform duration-75"
|
||||||
|
:style="{ transform: `rotate(${previewRotation})` }"
|
||||||
|
draggable="false"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="w-full max-w-sm">
|
||||||
|
<input
|
||||||
|
v-model.number="degree"
|
||||||
|
type="range"
|
||||||
|
min="0"
|
||||||
|
max="360"
|
||||||
|
step="1"
|
||||||
|
class="w-full accent-brand"
|
||||||
|
:disabled="loading || submitting"
|
||||||
|
/>
|
||||||
|
<div class="mt-1 flex justify-between text-xs text-secondary">
|
||||||
|
<span>0°</span>
|
||||||
|
<span>90°</span>
|
||||||
|
<span>180°</span>
|
||||||
|
<span>270°</span>
|
||||||
|
<span>360°</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template #actions>
|
||||||
|
<div class="flex justify-end gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full px-4 py-2 text-secondary hover:bg-button-bg"
|
||||||
|
@click="cancel"
|
||||||
|
>
|
||||||
|
{{ formatMessage(commonMessages.cancelButton) }}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-brand px-4 py-2 font-semibold text-contrast"
|
||||||
|
:disabled="loading || submitting || !image"
|
||||||
|
@click="submit"
|
||||||
|
>
|
||||||
|
{{ formatMessage(loading ? messages.loading : messages.submit) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</NewModal>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { HeartIcon, SpinnerIcon } from '@modrinth/assets'
|
||||||
|
import { defineMessages, useVIntl } from '@modrinth/ui'
|
||||||
|
import { onMounted, ref } from 'vue'
|
||||||
|
|
||||||
|
import { type SkinSiteDonationSummary, skinSiteDonationSummary } from '@/helpers/skin-site-api'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.skin-site.home.donation.title', defaultMessage: 'Donation thanks' },
|
||||||
|
total: { id: 'app.skin-site.home.donation.total', defaultMessage: 'Total raised' },
|
||||||
|
donors: { id: 'app.skin-site.home.donation.donors', defaultMessage: '{count} donors' },
|
||||||
|
unavailable: {
|
||||||
|
id: 'app.skin-site.home.donation.unavailable',
|
||||||
|
defaultMessage: 'Donation summary unavailable.',
|
||||||
|
},
|
||||||
|
loading: { id: 'app.skin-site.home.donation.loading', defaultMessage: 'Loading…' },
|
||||||
|
})
|
||||||
|
|
||||||
|
const summary = ref<SkinSiteDonationSummary | null>(null)
|
||||||
|
const loading = ref(true)
|
||||||
|
const failed = ref(false)
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
try {
|
||||||
|
const result = await skinSiteDonationSummary()
|
||||||
|
if (result.success) summary.value = result.payload
|
||||||
|
else failed.value = true
|
||||||
|
} catch {
|
||||||
|
failed.value = true
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div
|
||||||
|
class="flex items-center gap-3 rounded-xl border border-solid border-surface-5 bg-bg-raised px-4 py-3"
|
||||||
|
>
|
||||||
|
<HeartIcon class="size-5 shrink-0 text-brand" />
|
||||||
|
<div class="flex min-w-0 flex-1 flex-col">
|
||||||
|
<span class="text-sm font-semibold text-contrast">{{ formatMessage(messages.title) }}</span>
|
||||||
|
<span v-if="loading" class="flex items-center gap-1 text-xs text-secondary">
|
||||||
|
<SpinnerIcon class="size-3 animate-spin" />
|
||||||
|
{{ formatMessage(messages.loading) }}
|
||||||
|
</span>
|
||||||
|
<span v-else-if="failed" class="text-xs text-secondary">
|
||||||
|
{{ formatMessage(messages.unavailable) }}
|
||||||
|
</span>
|
||||||
|
<span v-else-if="summary" class="text-xs text-secondary">
|
||||||
|
{{ formatMessage(messages.total) }}: {{ summary.totalAmount }} ·
|
||||||
|
{{ formatMessage(messages.donors, { count: summary.donorCount }) }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,198 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { DownloadIcon, SpinnerIcon } from '@modrinth/assets'
|
||||||
|
import { defineMessages, injectNotificationManager, useVIntl } from '@modrinth/ui'
|
||||||
|
import { computed, onMounted, ref } from 'vue'
|
||||||
|
|
||||||
|
import {
|
||||||
|
skinSiteDownloadCategories,
|
||||||
|
type SkinSiteDownloadCategory,
|
||||||
|
type SkinSiteDownloadItem,
|
||||||
|
skinSiteDownloadList,
|
||||||
|
type SkinSiteDownloadStatus,
|
||||||
|
} from '@/helpers/skin-site-api'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError } = injectNotificationManager()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.skin-site.downloads.title', defaultMessage: 'Downloads' },
|
||||||
|
subtitle: {
|
||||||
|
id: 'app.skin-site.downloads.subtitle',
|
||||||
|
defaultMessage: 'Files shared by the server. Pick a category to narrow the list.',
|
||||||
|
},
|
||||||
|
back: { id: 'app.skin-site.downloads.back', defaultMessage: 'Back to home' },
|
||||||
|
all: { id: 'app.skin-site.downloads.all', defaultMessage: 'All' },
|
||||||
|
empty: { id: 'app.skin-site.downloads.empty', defaultMessage: 'Nothing to download yet.' },
|
||||||
|
loading: { id: 'app.skin-site.downloads.loading', defaultMessage: 'Loading…' },
|
||||||
|
failed: { id: 'app.skin-site.downloads.failed', defaultMessage: 'Could not load downloads.' },
|
||||||
|
goDownload: { id: 'app.skin-site.downloads.go', defaultMessage: 'Download' },
|
||||||
|
uploader: { id: 'app.skin-site.downloads.uploader', defaultMessage: 'by {name}' },
|
||||||
|
statusOk: { id: 'app.skin-site.downloads.status.ok', defaultMessage: 'OK' },
|
||||||
|
statusNew: { id: 'app.skin-site.downloads.status.new', defaultMessage: 'New' },
|
||||||
|
statusLegacy: { id: 'app.skin-site.downloads.status.legacy', defaultMessage: 'Legacy' },
|
||||||
|
statusOutdated: { id: 'app.skin-site.downloads.status.outdated', defaultMessage: 'Outdated' },
|
||||||
|
statusRemoval: { id: 'app.skin-site.downloads.status.removal', defaultMessage: 'Removal' },
|
||||||
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits<{ (e: 'back'): void }>()
|
||||||
|
|
||||||
|
const items = ref<SkinSiteDownloadItem[]>([])
|
||||||
|
const categories = ref<SkinSiteDownloadCategory[]>([])
|
||||||
|
const selectedCategory = ref<string | null>(null)
|
||||||
|
const loading = ref(true)
|
||||||
|
const failed = ref(false)
|
||||||
|
|
||||||
|
const filtered = computed(() =>
|
||||||
|
selectedCategory.value
|
||||||
|
? items.value.filter((item) => item.category.includes(selectedCategory.value!))
|
||||||
|
: items.value,
|
||||||
|
)
|
||||||
|
|
||||||
|
function statusLabel(status: SkinSiteDownloadStatus): string {
|
||||||
|
switch (status) {
|
||||||
|
case 'NEW':
|
||||||
|
return formatMessage(messages.statusNew)
|
||||||
|
case 'LEGACY':
|
||||||
|
return formatMessage(messages.statusLegacy)
|
||||||
|
case 'OUTDATED':
|
||||||
|
return formatMessage(messages.statusOutdated)
|
||||||
|
case 'REMOVAL':
|
||||||
|
return formatMessage(messages.statusRemoval)
|
||||||
|
default:
|
||||||
|
return formatMessage(messages.statusOk)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function openUrl(url: string) {
|
||||||
|
const { openUrl: open } = await import('@tauri-apps/plugin-opener')
|
||||||
|
await open(url)
|
||||||
|
}
|
||||||
|
|
||||||
|
function download(item: SkinSiteDownloadItem) {
|
||||||
|
const route = item.routes?.[0]
|
||||||
|
void openUrl(route?.url ?? item.url)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function load() {
|
||||||
|
loading.value = true
|
||||||
|
failed.value = false
|
||||||
|
try {
|
||||||
|
const [listResult, categoryResult] = await Promise.all([
|
||||||
|
skinSiteDownloadList(),
|
||||||
|
skinSiteDownloadCategories(),
|
||||||
|
])
|
||||||
|
if (!listResult.success) throw new Error(listResult.errorMessage)
|
||||||
|
items.value = listResult.payload ?? []
|
||||||
|
if (categoryResult.success) categories.value = categoryResult.payload ?? []
|
||||||
|
} catch (error) {
|
||||||
|
failed.value = true
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(load)
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex w-fit items-center gap-1 rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="emit('back')"
|
||||||
|
>
|
||||||
|
← {{ formatMessage(messages.back) }}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<header class="flex flex-col gap-1">
|
||||||
|
<h1 class="m-0 text-xl font-bold text-contrast">{{ formatMessage(messages.title) }}</h1>
|
||||||
|
<p class="m-0 text-sm text-secondary">{{ formatMessage(messages.subtitle) }}</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div v-if="categories.length" class="flex flex-wrap gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full px-3 py-1 text-xs font-semibold transition-colors"
|
||||||
|
:class="
|
||||||
|
selectedCategory === null
|
||||||
|
? 'bg-brand text-contrast'
|
||||||
|
: 'bg-button-bg text-secondary hover:brightness-110'
|
||||||
|
"
|
||||||
|
@click="selectedCategory = null"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.all) }}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
v-for="category in categories"
|
||||||
|
:key="category.id"
|
||||||
|
type="button"
|
||||||
|
class="rounded-full px-3 py-1 text-xs font-semibold transition-colors"
|
||||||
|
:class="
|
||||||
|
selectedCategory === category.name
|
||||||
|
? 'bg-brand text-contrast'
|
||||||
|
: 'bg-button-bg text-secondary hover:brightness-110'
|
||||||
|
"
|
||||||
|
@click="selectedCategory = category.name"
|
||||||
|
>
|
||||||
|
{{ category.name }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="loading" class="flex items-center gap-2 text-sm text-secondary">
|
||||||
|
<SpinnerIcon class="size-4 animate-spin" />
|
||||||
|
{{ formatMessage(messages.loading) }}
|
||||||
|
</div>
|
||||||
|
<p v-else-if="failed" class="m-0 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.failed) }}
|
||||||
|
</p>
|
||||||
|
<p v-else-if="!filtered.length" class="m-0 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.empty) }}
|
||||||
|
</p>
|
||||||
|
<div v-else class="flex flex-col gap-2">
|
||||||
|
<div
|
||||||
|
v-for="item in filtered"
|
||||||
|
:key="item.id"
|
||||||
|
class="flex flex-wrap items-center gap-3 rounded-xl border border-solid border-surface-5 bg-bg-raised p-3"
|
||||||
|
>
|
||||||
|
<div class="flex min-w-0 flex-1 flex-col gap-1">
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<span class="min-w-0 truncate text-sm font-semibold text-contrast">
|
||||||
|
{{ item.filename }}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-for="status in item.status"
|
||||||
|
:key="status"
|
||||||
|
class="shrink-0 rounded-full px-2 py-0.5 text-[10px] font-semibold"
|
||||||
|
:class="{
|
||||||
|
'bg-green text-contrast': status === 'NEW',
|
||||||
|
'bg-yellow text-contrast': status === 'LEGACY',
|
||||||
|
'bg-red text-contrast': status === 'OUTDATED' || status === 'REMOVAL',
|
||||||
|
'bg-button-bg text-secondary':
|
||||||
|
status !== 'NEW' &&
|
||||||
|
status !== 'LEGACY' &&
|
||||||
|
status !== 'OUTDATED' &&
|
||||||
|
status !== 'REMOVAL',
|
||||||
|
}"
|
||||||
|
>
|
||||||
|
{{ statusLabel(status) }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<span v-if="item.description" class="truncate text-xs text-secondary">
|
||||||
|
{{ item.description }}
|
||||||
|
</span>
|
||||||
|
<span v-if="item.uploader" class="text-xs text-secondary">
|
||||||
|
{{ formatMessage(messages.uploader, { name: item.uploader }) }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex shrink-0 items-center gap-1 rounded-full bg-brand px-3 py-1.5 text-xs font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="download(item)"
|
||||||
|
>
|
||||||
|
<DownloadIcon class="size-3.5" />
|
||||||
|
{{ formatMessage(messages.goDownload) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,150 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { CopyIcon } from '@modrinth/assets'
|
||||||
|
import { defineMessages, injectNotificationManager, useVIntl } from '@modrinth/ui'
|
||||||
|
import { ref } from 'vue'
|
||||||
|
|
||||||
|
import SkinSiteAccountCard from './SkinSiteAccountCard.vue'
|
||||||
|
import SkinSiteAdminView from './SkinSiteAdminView.vue'
|
||||||
|
import SkinSiteAnnouncements from './SkinSiteAnnouncements.vue'
|
||||||
|
import SkinSiteBugCreateModal from './SkinSiteBugCreateModal.vue'
|
||||||
|
import SkinSiteBugDetailView from './SkinSiteBugDetailView.vue'
|
||||||
|
import SkinSiteBugListView from './SkinSiteBugListView.vue'
|
||||||
|
import SkinSiteBugNotificationsView from './SkinSiteBugNotificationsView.vue'
|
||||||
|
import SkinSiteDonationCard from './SkinSiteDonationCard.vue'
|
||||||
|
import SkinSiteDownloadsView from './SkinSiteDownloadsView.vue'
|
||||||
|
import SkinSiteLoginModal from './SkinSiteLoginModal.vue'
|
||||||
|
import SkinSiteMapView from './SkinSiteMapView.vue'
|
||||||
|
import SkinSiteNavCards from './SkinSiteNavCards.vue'
|
||||||
|
import SkinSiteProfileModal from './SkinSiteProfileModal.vue'
|
||||||
|
import SkinSiteProfileView from './SkinSiteProfileView.vue'
|
||||||
|
import SkinSiteReviewView from './SkinSiteReviewView.vue'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { addNotification } = injectNotificationManager()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.skin-site.home.title', defaultMessage: 'StarLight Skin Site' },
|
||||||
|
subtitle: {
|
||||||
|
id: 'app.skin-site.home.subtitle',
|
||||||
|
defaultMessage: 'The wardrobe for StarLight Server players.',
|
||||||
|
},
|
||||||
|
address: { id: 'app.skin-site.home.address', defaultMessage: 'Skin site address' },
|
||||||
|
copied: { id: 'app.skin-site.home.copied', defaultMessage: 'Address copied.' },
|
||||||
|
})
|
||||||
|
|
||||||
|
const YGGDRASIL_URL = 'https://skin.starlight.cool/yggdrasil'
|
||||||
|
const loginModal = ref<InstanceType<typeof SkinSiteLoginModal>>()
|
||||||
|
const profileModal = ref<InstanceType<typeof SkinSiteProfileModal>>()
|
||||||
|
const view = ref<
|
||||||
|
| 'home'
|
||||||
|
| 'players'
|
||||||
|
| 'downloads'
|
||||||
|
| 'map'
|
||||||
|
| 'review'
|
||||||
|
| 'bugs'
|
||||||
|
| 'bug-detail'
|
||||||
|
| 'bug-notifications'
|
||||||
|
| 'admin'
|
||||||
|
>('home')
|
||||||
|
const selectedBugId = ref<number | null>(null)
|
||||||
|
|
||||||
|
function openBug(id: number) {
|
||||||
|
selectedBugId.value = id
|
||||||
|
view.value = 'bug-detail'
|
||||||
|
}
|
||||||
|
|
||||||
|
function backToBugList() {
|
||||||
|
selectedBugId.value = null
|
||||||
|
view.value = 'bugs'
|
||||||
|
}
|
||||||
|
|
||||||
|
const bugCreateModal = ref<InstanceType<typeof SkinSiteBugCreateModal>>()
|
||||||
|
|
||||||
|
function openBugNotifications() {
|
||||||
|
view.value = 'bug-notifications'
|
||||||
|
}
|
||||||
|
|
||||||
|
function onBugCreated(id: number) {
|
||||||
|
openBug(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function copyAddress() {
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(YGGDRASIL_URL)
|
||||||
|
addNotification({ type: 'success', title: formatMessage(messages.copied) })
|
||||||
|
} catch {
|
||||||
|
// Clipboard may be unavailable; the address stays selectable.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex h-full min-h-0 w-full flex-col overflow-y-auto">
|
||||||
|
<div class="mx-auto flex w-full max-w-5xl flex-col gap-6 p-6">
|
||||||
|
<SkinSiteProfileView v-if="view === 'players'" @back="view = 'home'" />
|
||||||
|
<SkinSiteDownloadsView v-else-if="view === 'downloads'" @back="view = 'home'" />
|
||||||
|
<SkinSiteMapView v-else-if="view === 'map'" @back="view = 'home'" />
|
||||||
|
<SkinSiteReviewView v-else-if="view === 'review'" @back="view = 'home'" />
|
||||||
|
<SkinSiteBugListView
|
||||||
|
v-else-if="view === 'bugs'"
|
||||||
|
@back="view = 'home'"
|
||||||
|
@open="openBug"
|
||||||
|
@create="bugCreateModal?.show()"
|
||||||
|
@notifications="openBugNotifications"
|
||||||
|
/>
|
||||||
|
<SkinSiteBugNotificationsView
|
||||||
|
v-else-if="view === 'bug-notifications'"
|
||||||
|
@back="view = 'bugs'"
|
||||||
|
@open="openBug"
|
||||||
|
/>
|
||||||
|
<SkinSiteAdminView v-else-if="view === 'admin'" @back="view = 'home'" />
|
||||||
|
<SkinSiteBugDetailView
|
||||||
|
v-else-if="view === 'bug-detail' && selectedBugId !== null"
|
||||||
|
:issue-id="selectedBugId"
|
||||||
|
@back="backToBugList"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<template v-else>
|
||||||
|
<header class="flex flex-col items-center gap-1 text-center">
|
||||||
|
<h1 class="m-0 text-2xl font-bold text-contrast">{{ formatMessage(messages.title) }}</h1>
|
||||||
|
<p class="m-0 text-sm text-secondary">{{ formatMessage(messages.subtitle) }}</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<SkinSiteAccountCard
|
||||||
|
@sign-in="loginModal?.show()"
|
||||||
|
@open-settings="profileModal?.show()"
|
||||||
|
@open-players="view = 'players'"
|
||||||
|
@open-admin="view = 'admin'"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-1 gap-6 lg:grid-cols-2">
|
||||||
|
<SkinSiteNavCards @navigate="(v) => (view = v)" />
|
||||||
|
<SkinSiteAnnouncements />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<SkinSiteDonationCard />
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="flex flex-wrap items-center gap-2 rounded-xl border border-solid border-surface-5 bg-bg-raised px-4 py-3"
|
||||||
|
>
|
||||||
|
<span class="text-sm font-semibold text-contrast">{{
|
||||||
|
formatMessage(messages.address)
|
||||||
|
}}</span>
|
||||||
|
<code class="min-w-0 flex-1 truncate text-xs text-secondary">{{ YGGDRASIL_URL }}</code>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex shrink-0 items-center gap-1 rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="copyAddress"
|
||||||
|
>
|
||||||
|
<CopyIcon class="size-3.5" />
|
||||||
|
{{ formatMessage({ id: 'app.skin-site.home.copy', defaultMessage: 'Copy' }) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<SkinSiteLoginModal ref="loginModal" />
|
||||||
|
<SkinSiteProfileModal ref="profileModal" />
|
||||||
|
<SkinSiteBugCreateModal ref="bugCreateModal" @created="onBugCreated" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,185 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
commonMessages,
|
||||||
|
defineMessages,
|
||||||
|
injectNotificationManager,
|
||||||
|
NewModal,
|
||||||
|
StyledInput,
|
||||||
|
useVIntl,
|
||||||
|
} from '@modrinth/ui'
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
|
|
||||||
|
import { reloadSkinSiteSession, signInSkinSite } from '@/composables/skin-site-session'
|
||||||
|
|
||||||
|
import SkinSiteCaptchaModal from './SkinSiteCaptchaModal.vue'
|
||||||
|
import SkinSitePasswordResetModal from './SkinSitePasswordResetModal.vue'
|
||||||
|
import SkinSiteRegisterModal from './SkinSiteRegisterModal.vue'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError, addNotification } = injectNotificationManager()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.skin-site.login.title', defaultMessage: 'Sign in to StarLight' },
|
||||||
|
username: { id: 'app.skin-site.login.username', defaultMessage: 'Username or email' },
|
||||||
|
password: { id: 'app.skin-site.login.password', defaultMessage: 'Password' },
|
||||||
|
signIn: { id: 'app.skin-site.login.sign-in', defaultMessage: 'Sign in' },
|
||||||
|
signingIn: { id: 'app.skin-site.login.signing-in', defaultMessage: 'Signing in…' },
|
||||||
|
register: { id: 'app.skin-site.login.register', defaultMessage: 'Create account' },
|
||||||
|
forgotPassword: { id: 'app.skin-site.login.forgot', defaultMessage: 'Forgot password?' },
|
||||||
|
usernameHint: {
|
||||||
|
id: 'app.skin-site.login.username-hint',
|
||||||
|
defaultMessage: '3–16 characters, or a registered email address.',
|
||||||
|
},
|
||||||
|
passwordHint: {
|
||||||
|
id: 'app.skin-site.login.password-hint',
|
||||||
|
defaultMessage: '6–50 characters with upper case, lower case and a digit.',
|
||||||
|
},
|
||||||
|
success: { id: 'app.skin-site.login.success', defaultMessage: 'Signed in to StarLight.' },
|
||||||
|
})
|
||||||
|
|
||||||
|
const PASSWORD_RE = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,50}$/
|
||||||
|
|
||||||
|
const modal = ref<InstanceType<typeof NewModal>>()
|
||||||
|
const captchaModal = ref<InstanceType<typeof SkinSiteCaptchaModal>>()
|
||||||
|
const registerModal = ref<InstanceType<typeof SkinSiteRegisterModal>>()
|
||||||
|
const passwordResetModal = ref<InstanceType<typeof SkinSitePasswordResetModal>>()
|
||||||
|
|
||||||
|
function openRegister() {
|
||||||
|
modal.value?.hide()
|
||||||
|
registerModal.value?.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
function openPasswordReset() {
|
||||||
|
modal.value?.hide()
|
||||||
|
passwordResetModal.value?.show()
|
||||||
|
}
|
||||||
|
const username = ref('')
|
||||||
|
const password = ref('')
|
||||||
|
const working = ref(false)
|
||||||
|
|
||||||
|
const emit = defineEmits<{ (e: 'signed-in' | 'cancel'): void }>()
|
||||||
|
|
||||||
|
const usernameValid = computed(() => {
|
||||||
|
const value = username.value.trim()
|
||||||
|
if (!value) return false
|
||||||
|
if (value.includes('@')) return value.length < 64
|
||||||
|
return value.length >= 3 && value.length <= 16
|
||||||
|
})
|
||||||
|
|
||||||
|
const passwordValid = computed(() => PASSWORD_RE.test(password.value))
|
||||||
|
const canSubmit = computed(() => usernameValid.value && passwordValid.value && !working.value)
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
username.value = ''
|
||||||
|
password.value = ''
|
||||||
|
working.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
function show() {
|
||||||
|
reset()
|
||||||
|
modal.value?.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function beginSignIn() {
|
||||||
|
if (!canSubmit.value) return
|
||||||
|
captchaModal.value?.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onCaptchaVerified(clientId: string) {
|
||||||
|
working.value = true
|
||||||
|
try {
|
||||||
|
const result = await signInSkinSite({
|
||||||
|
username: username.value.trim(),
|
||||||
|
password: password.value,
|
||||||
|
clientId,
|
||||||
|
})
|
||||||
|
if (!result.success) {
|
||||||
|
handleError(new Error(result.errorMessage))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await reloadSkinSiteSession()
|
||||||
|
addNotification({ type: 'success', title: formatMessage(messages.success) })
|
||||||
|
modal.value?.hide()
|
||||||
|
reset()
|
||||||
|
emit('signed-in')
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
working.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancel() {
|
||||||
|
modal.value?.hide()
|
||||||
|
emit('cancel')
|
||||||
|
}
|
||||||
|
|
||||||
|
function onRegisterSignedIn() {
|
||||||
|
emit('signed-in')
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({ show })
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<NewModal ref="modal" :header="formatMessage(messages.title)" @hide="reset">
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="font-semibold text-contrast">{{ formatMessage(messages.username) }}</span>
|
||||||
|
<StyledInput v-model="username" type="text" autocomplete="username" />
|
||||||
|
<span class="text-xs text-secondary">{{ formatMessage(messages.usernameHint) }}</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="font-semibold text-contrast">{{ formatMessage(messages.password) }}</span>
|
||||||
|
<StyledInput v-model="password" type="password" autocomplete="current-password" />
|
||||||
|
<span class="text-xs text-secondary">{{ formatMessage(messages.passwordHint) }}</span>
|
||||||
|
</label>
|
||||||
|
<div class="flex justify-between text-sm">
|
||||||
|
<button type="button" class="text-brand hover:underline" @click="openRegister">
|
||||||
|
{{ formatMessage(messages.register) }}
|
||||||
|
</button>
|
||||||
|
<button type="button" class="text-brand hover:underline" @click="openPasswordReset">
|
||||||
|
{{ formatMessage(messages.forgotPassword) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template #actions>
|
||||||
|
<div class="flex justify-end gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full px-4 py-2 text-secondary hover:bg-button-bg"
|
||||||
|
@click="cancel"
|
||||||
|
>
|
||||||
|
{{ formatMessage(commonMessages.cancelButton) }}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-brand px-4 py-2 font-semibold text-contrast disabled:opacity-50"
|
||||||
|
:disabled="!canSubmit"
|
||||||
|
@click="beginSignIn"
|
||||||
|
>
|
||||||
|
{{ formatMessage(working ? messages.signingIn : messages.signIn) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</NewModal>
|
||||||
|
|
||||||
|
<SkinSiteRegisterModal
|
||||||
|
ref="registerModal"
|
||||||
|
@signed-in="onRegisterSignedIn"
|
||||||
|
@cancel="modal?.show()"
|
||||||
|
/>
|
||||||
|
<SkinSitePasswordResetModal
|
||||||
|
ref="passwordResetModal"
|
||||||
|
@done="modal?.show()"
|
||||||
|
@cancel="modal?.show()"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<SkinSiteCaptchaModal
|
||||||
|
ref="captchaModal"
|
||||||
|
@verified="onCaptchaVerified"
|
||||||
|
@cancel="working = false"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { ExternalIcon, SpinnerIcon } from '@modrinth/assets'
|
||||||
|
import { defineMessages, injectNotificationManager, useVIntl } from '@modrinth/ui'
|
||||||
|
import { computed, onMounted, ref, watch } from 'vue'
|
||||||
|
|
||||||
|
import { type SkinSiteMapServer, skinSiteMapServers } from '@/helpers/skin-site-api'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError } = injectNotificationManager()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.skin-site.map.title', defaultMessage: 'Server map' },
|
||||||
|
back: { id: 'app.skin-site.map.back', defaultMessage: 'Back to home' },
|
||||||
|
internal: { id: 'app.skin-site.map.internal', defaultMessage: 'Internal' },
|
||||||
|
external: { id: 'app.skin-site.map.external', defaultMessage: 'External' },
|
||||||
|
server: { id: 'app.skin-site.map.server', defaultMessage: 'Server' },
|
||||||
|
map: { id: 'app.skin-site.map.map', defaultMessage: 'Map' },
|
||||||
|
openExternal: { id: 'app.skin-site.map.open', defaultMessage: 'Open in browser' },
|
||||||
|
loading: { id: 'app.skin-site.map.loading', defaultMessage: 'Loading maps…' },
|
||||||
|
empty: { id: 'app.skin-site.map.empty', defaultMessage: 'No maps available.' },
|
||||||
|
failed: { id: 'app.skin-site.map.failed', defaultMessage: 'Could not load maps.' },
|
||||||
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits<{ (e: 'back'): void }>()
|
||||||
|
|
||||||
|
const servers = ref<SkinSiteMapServer[]>([])
|
||||||
|
const internal = ref(false)
|
||||||
|
const serverIndex = ref(0)
|
||||||
|
const mapIndex = ref(0)
|
||||||
|
const loading = ref(true)
|
||||||
|
const failed = ref(false)
|
||||||
|
|
||||||
|
const filteredServers = computed(() => servers.value.filter((s) => s.internal === internal.value))
|
||||||
|
const selectedServer = computed(() => filteredServers.value[serverIndex.value])
|
||||||
|
const selectedMap = computed(() => selectedServer.value?.maps[mapIndex.value])
|
||||||
|
|
||||||
|
watch(internal, () => {
|
||||||
|
serverIndex.value = 0
|
||||||
|
mapIndex.value = 0
|
||||||
|
})
|
||||||
|
watch(serverIndex, () => {
|
||||||
|
mapIndex.value = 0
|
||||||
|
})
|
||||||
|
|
||||||
|
async function openExternal() {
|
||||||
|
if (!selectedMap.value) return
|
||||||
|
const { openUrl } = await import('@tauri-apps/plugin-opener')
|
||||||
|
await openUrl(selectedMap.value.url)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function load() {
|
||||||
|
loading.value = true
|
||||||
|
failed.value = false
|
||||||
|
try {
|
||||||
|
const result = await skinSiteMapServers()
|
||||||
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
|
servers.value = result.payload ?? []
|
||||||
|
if (!servers.value.some((s) => !s.internal)) internal.value = true
|
||||||
|
} catch (error) {
|
||||||
|
failed.value = true
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(load)
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex h-full min-h-0 flex-col gap-3">
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex items-center gap-1 rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="emit('back')"
|
||||||
|
>
|
||||||
|
← {{ formatMessage(messages.back) }}
|
||||||
|
</button>
|
||||||
|
<h1 class="m-0 text-lg font-bold text-contrast">{{ formatMessage(messages.title) }}</h1>
|
||||||
|
|
||||||
|
<select
|
||||||
|
v-model="internal"
|
||||||
|
class="rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast"
|
||||||
|
>
|
||||||
|
<option :value="false">{{ formatMessage(messages.external) }}</option>
|
||||||
|
<option :value="true">{{ formatMessage(messages.internal) }}</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select
|
||||||
|
v-if="filteredServers.length"
|
||||||
|
v-model.number="serverIndex"
|
||||||
|
class="rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast"
|
||||||
|
>
|
||||||
|
<option v-for="(server, index) in filteredServers" :key="index" :value="index">
|
||||||
|
{{ server.name }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select
|
||||||
|
v-if="selectedServer?.maps.length"
|
||||||
|
v-model.number="mapIndex"
|
||||||
|
class="rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast"
|
||||||
|
>
|
||||||
|
<option v-for="(map, index) in selectedServer.maps" :key="index" :value="index">
|
||||||
|
{{ map.name }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<button
|
||||||
|
v-if="selectedMap"
|
||||||
|
type="button"
|
||||||
|
class="ml-auto flex items-center gap-1 rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="openExternal"
|
||||||
|
>
|
||||||
|
<ExternalIcon class="size-3.5" />
|
||||||
|
{{ formatMessage(messages.openExternal) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="loading"
|
||||||
|
class="flex flex-1 items-center justify-center gap-2 text-sm text-secondary"
|
||||||
|
>
|
||||||
|
<SpinnerIcon class="size-4 animate-spin" />
|
||||||
|
{{ formatMessage(messages.loading) }}
|
||||||
|
</div>
|
||||||
|
<p v-else-if="failed" class="m-0 flex-1 text-center text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.failed) }}
|
||||||
|
</p>
|
||||||
|
<p v-else-if="!selectedMap" class="m-0 flex-1 text-center text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.empty) }}
|
||||||
|
</p>
|
||||||
|
<iframe
|
||||||
|
v-else
|
||||||
|
:key="selectedMap.url"
|
||||||
|
:src="selectedMap.url"
|
||||||
|
:title="`${selectedServer?.name} · ${selectedMap.name}`"
|
||||||
|
class="min-h-0 w-full flex-1 rounded-lg border border-solid border-surface-5"
|
||||||
|
allow="fullscreen"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
BookIcon,
|
||||||
|
BugIcon,
|
||||||
|
DownloadIcon,
|
||||||
|
MapIcon,
|
||||||
|
ShieldCheckIcon,
|
||||||
|
UserIcon,
|
||||||
|
} from '@modrinth/assets'
|
||||||
|
import { defineMessages, useVIntl } from '@modrinth/ui'
|
||||||
|
import type { Component } from 'vue'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
|
||||||
|
const emit = defineEmits<{ (e: 'navigate', view: 'downloads' | 'review' | 'bugs' | 'map'): void }>()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.skin-site.home.nav.title', defaultMessage: 'Skin site' },
|
||||||
|
download: { id: 'app.skin-site.home.nav.download', defaultMessage: 'Downloads' },
|
||||||
|
downloadDesc: {
|
||||||
|
id: 'app.skin-site.home.nav.download-desc',
|
||||||
|
defaultMessage: 'Browse files shared by the server.',
|
||||||
|
},
|
||||||
|
review: { id: 'app.skin-site.home.nav.review', defaultMessage: 'Player review' },
|
||||||
|
reviewDesc: {
|
||||||
|
id: 'app.skin-site.home.nav.review-desc',
|
||||||
|
defaultMessage: 'Submit and review player applications.',
|
||||||
|
},
|
||||||
|
wiki: { id: 'app.skin-site.home.nav.wiki', defaultMessage: 'Server wiki' },
|
||||||
|
wikiDesc: {
|
||||||
|
id: 'app.skin-site.home.nav.wiki-desc',
|
||||||
|
defaultMessage: 'Guides and documentation for the server.',
|
||||||
|
},
|
||||||
|
bugs: { id: 'app.skin-site.home.nav.bugs', defaultMessage: 'Bug tracker' },
|
||||||
|
bugsDesc: {
|
||||||
|
id: 'app.skin-site.home.nav.bugs-desc',
|
||||||
|
defaultMessage: 'Report issues and follow their progress.',
|
||||||
|
},
|
||||||
|
map: { id: 'app.skin-site.home.nav.map', defaultMessage: 'Server map' },
|
||||||
|
mapDesc: {
|
||||||
|
id: 'app.skin-site.home.nav.map-desc',
|
||||||
|
defaultMessage: 'Explore the live world map.',
|
||||||
|
},
|
||||||
|
profile: { id: 'app.skin-site.home.nav.profile', defaultMessage: 'Profile' },
|
||||||
|
profileDesc: {
|
||||||
|
id: 'app.skin-site.home.nav.profile-desc',
|
||||||
|
defaultMessage: 'Manage your account and textures.',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
interface NavItem {
|
||||||
|
id: string
|
||||||
|
title: string
|
||||||
|
description: string
|
||||||
|
icon: Component
|
||||||
|
href: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const SKIN_SITE = 'https://skin.starlight.cool'
|
||||||
|
|
||||||
|
const items: NavItem[] = [
|
||||||
|
{
|
||||||
|
id: 'download',
|
||||||
|
title: formatMessage(messages.download),
|
||||||
|
description: formatMessage(messages.downloadDesc),
|
||||||
|
icon: DownloadIcon,
|
||||||
|
href: `${SKIN_SITE}/download`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'review',
|
||||||
|
title: formatMessage(messages.review),
|
||||||
|
description: formatMessage(messages.reviewDesc),
|
||||||
|
icon: ShieldCheckIcon,
|
||||||
|
href: `${SKIN_SITE}/review`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'wiki',
|
||||||
|
title: formatMessage(messages.wiki),
|
||||||
|
description: formatMessage(messages.wikiDesc),
|
||||||
|
icon: BookIcon,
|
||||||
|
href: `${SKIN_SITE}/wiki`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'bugs',
|
||||||
|
title: formatMessage(messages.bugs),
|
||||||
|
description: formatMessage(messages.bugsDesc),
|
||||||
|
icon: BugIcon,
|
||||||
|
href: `${SKIN_SITE}/bugs`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'map',
|
||||||
|
title: formatMessage(messages.map),
|
||||||
|
description: formatMessage(messages.mapDesc),
|
||||||
|
icon: MapIcon,
|
||||||
|
href: `${SKIN_SITE}/map`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'profile',
|
||||||
|
title: formatMessage(messages.profile),
|
||||||
|
description: formatMessage(messages.profileDesc),
|
||||||
|
icon: UserIcon,
|
||||||
|
href: `${SKIN_SITE}/profile`,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
function open(item: NavItem) {
|
||||||
|
if (item.id === 'download' || item.id === 'review' || item.id === 'bugs' || item.id === 'map') {
|
||||||
|
emit('navigate', item.id === 'download' ? 'downloads' : item.id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
void import('@tauri-apps/plugin-opener').then(({ openUrl }) => openUrl(item.href))
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-3">
|
||||||
|
<h3 class="m-0 text-base font-semibold text-contrast">{{ formatMessage(messages.title) }}</h3>
|
||||||
|
<div class="grid grid-cols-2 gap-3 sm:grid-cols-3">
|
||||||
|
<button
|
||||||
|
v-for="item in items"
|
||||||
|
:key="item.id"
|
||||||
|
type="button"
|
||||||
|
class="flex flex-col items-start gap-1 rounded-xl border border-solid border-surface-5 bg-bg-raised p-3 text-left transition-colors hover:bg-button-bg"
|
||||||
|
@click="open(item)"
|
||||||
|
>
|
||||||
|
<component :is="item.icon" class="size-5 text-brand" />
|
||||||
|
<span class="text-sm font-semibold text-contrast">{{ item.title }}</span>
|
||||||
|
<span class="text-xs text-secondary">{{ item.description }}</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,238 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
commonMessages,
|
||||||
|
defineMessages,
|
||||||
|
injectNotificationManager,
|
||||||
|
NewModal,
|
||||||
|
StyledInput,
|
||||||
|
useVIntl,
|
||||||
|
} from '@modrinth/ui'
|
||||||
|
import { computed, onUnmounted, ref } from 'vue'
|
||||||
|
|
||||||
|
import { skinSitePasswordReset, skinSitePasswordResetEmailVerify } from '@/helpers/skin-site-api'
|
||||||
|
|
||||||
|
import SkinSiteCaptchaModal from './SkinSiteCaptchaModal.vue'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError, addNotification } = injectNotificationManager()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.skin-site.reset.title', defaultMessage: 'Reset password' },
|
||||||
|
email: { id: 'app.skin-site.reset.email', defaultMessage: 'Email' },
|
||||||
|
emailHint: {
|
||||||
|
id: 'app.skin-site.reset.email-hint',
|
||||||
|
defaultMessage: 'Use the address you registered with.',
|
||||||
|
},
|
||||||
|
code: { id: 'app.skin-site.reset.code', defaultMessage: 'Verification code' },
|
||||||
|
sendCode: { id: 'app.skin-site.reset.send-code', defaultMessage: 'Send code' },
|
||||||
|
sending: { id: 'app.skin-site.reset.sending', defaultMessage: 'Sending…' },
|
||||||
|
resendIn: { id: 'app.skin-site.reset.resend-in', defaultMessage: 'Sent ({seconds}s)' },
|
||||||
|
newPassword: { id: 'app.skin-site.reset.new-password', defaultMessage: 'New password' },
|
||||||
|
repeatPassword: { id: 'app.skin-site.reset.repeat-password', defaultMessage: 'Repeat password' },
|
||||||
|
passwordHint: {
|
||||||
|
id: 'app.skin-site.reset.password-hint',
|
||||||
|
defaultMessage: '6–50 characters with upper case, lower case and a digit.',
|
||||||
|
},
|
||||||
|
mismatch: { id: 'app.skin-site.reset.mismatch', defaultMessage: 'Passwords do not match.' },
|
||||||
|
submit: { id: 'app.skin-site.reset.submit', defaultMessage: 'Reset password' },
|
||||||
|
success: {
|
||||||
|
id: 'app.skin-site.reset.success',
|
||||||
|
defaultMessage: 'Password updated. You can sign in now.',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const PASSWORD_RE = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,50}$/
|
||||||
|
const COUNTDOWN_SECONDS = 60
|
||||||
|
|
||||||
|
const modal = ref<InstanceType<typeof NewModal>>()
|
||||||
|
const captchaModal = ref<InstanceType<typeof SkinSiteCaptchaModal>>()
|
||||||
|
const email = ref('')
|
||||||
|
const code = ref('')
|
||||||
|
const newPassword = ref('')
|
||||||
|
const repeatPassword = ref('')
|
||||||
|
const sending = ref(false)
|
||||||
|
const working = ref(false)
|
||||||
|
const countdown = ref(0)
|
||||||
|
let timer: ReturnType<typeof setInterval> | undefined
|
||||||
|
|
||||||
|
const emit = defineEmits<{ (e: 'done' | 'cancel'): void }>()
|
||||||
|
|
||||||
|
function stopTimer() {
|
||||||
|
if (timer) clearInterval(timer)
|
||||||
|
timer = undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
function startCountdown() {
|
||||||
|
countdown.value = COUNTDOWN_SECONDS
|
||||||
|
stopTimer()
|
||||||
|
timer = setInterval(() => {
|
||||||
|
countdown.value -= 1
|
||||||
|
if (countdown.value <= 0) stopTimer()
|
||||||
|
}, 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
const canSendCode = computed(
|
||||||
|
() => email.value.trim().length > 0 && !sending.value && countdown.value <= 0,
|
||||||
|
)
|
||||||
|
|
||||||
|
const passwordValid = computed(() => PASSWORD_RE.test(newPassword.value))
|
||||||
|
const passwordsMatch = computed(() => newPassword.value === repeatPassword.value)
|
||||||
|
const canSubmit = computed(
|
||||||
|
() =>
|
||||||
|
email.value.trim().length > 0 &&
|
||||||
|
code.value.trim().length === 6 &&
|
||||||
|
passwordValid.value &&
|
||||||
|
passwordsMatch.value &&
|
||||||
|
!working.value,
|
||||||
|
)
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
stopTimer()
|
||||||
|
email.value = ''
|
||||||
|
code.value = ''
|
||||||
|
newPassword.value = ''
|
||||||
|
repeatPassword.value = ''
|
||||||
|
sending.value = false
|
||||||
|
working.value = false
|
||||||
|
countdown.value = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function show() {
|
||||||
|
reset()
|
||||||
|
modal.value?.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function sendCode() {
|
||||||
|
if (!canSendCode.value) return
|
||||||
|
sending.value = true
|
||||||
|
try {
|
||||||
|
const result = await skinSitePasswordResetEmailVerify(email.value.trim())
|
||||||
|
if (!result.success) {
|
||||||
|
handleError(new Error(result.errorMessage))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
addNotification({ type: 'success', title: result.payload })
|
||||||
|
startCountdown()
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
sending.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function beginReset() {
|
||||||
|
if (!canSubmit.value) return
|
||||||
|
if (!passwordsMatch.value) {
|
||||||
|
handleError(new Error(formatMessage(messages.mismatch)))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
captchaModal.value?.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onCaptchaVerified(clientId: string) {
|
||||||
|
working.value = true
|
||||||
|
try {
|
||||||
|
const result = await skinSitePasswordReset({
|
||||||
|
clientId,
|
||||||
|
email: email.value.trim(),
|
||||||
|
emailVerifyCode: code.value.trim(),
|
||||||
|
newPassword: newPassword.value,
|
||||||
|
})
|
||||||
|
if (!result.success) {
|
||||||
|
handleError(new Error(result.errorMessage))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
addNotification({ type: 'success', title: formatMessage(messages.success) })
|
||||||
|
modal.value?.hide()
|
||||||
|
emit('done')
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
working.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancel() {
|
||||||
|
modal.value?.hide()
|
||||||
|
emit('cancel')
|
||||||
|
}
|
||||||
|
|
||||||
|
onUnmounted(stopTimer)
|
||||||
|
|
||||||
|
defineExpose({ show })
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<NewModal ref="modal" :header="formatMessage(messages.title)" @hide="reset">
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="font-semibold text-contrast">{{ formatMessage(messages.email) }}</span>
|
||||||
|
<StyledInput v-model="email" type="email" autocomplete="email" />
|
||||||
|
<span class="text-xs text-secondary">{{ formatMessage(messages.emailHint) }}</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="font-semibold text-contrast">{{ formatMessage(messages.code) }}</span>
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<StyledInput v-model="code" type="text" class="flex-1" maxlength="6" />
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="shrink-0 rounded-full bg-button-bg px-4 text-sm font-semibold text-contrast disabled:opacity-50"
|
||||||
|
:disabled="!canSendCode"
|
||||||
|
@click="sendCode"
|
||||||
|
>
|
||||||
|
{{
|
||||||
|
sending
|
||||||
|
? formatMessage(messages.sending)
|
||||||
|
: countdown > 0
|
||||||
|
? formatMessage(messages.resendIn, { seconds: countdown })
|
||||||
|
: formatMessage(messages.sendCode)
|
||||||
|
}}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="font-semibold text-contrast">{{ formatMessage(messages.newPassword) }}</span>
|
||||||
|
<StyledInput v-model="newPassword" type="password" autocomplete="new-password" />
|
||||||
|
<span class="text-xs text-secondary">{{ formatMessage(messages.passwordHint) }}</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="font-semibold text-contrast">{{
|
||||||
|
formatMessage(messages.repeatPassword)
|
||||||
|
}}</span>
|
||||||
|
<StyledInput v-model="repeatPassword" type="password" autocomplete="new-password" />
|
||||||
|
<span v-if="repeatPassword && !passwordsMatch" class="text-xs text-red">
|
||||||
|
{{ formatMessage(messages.mismatch) }}
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template #actions>
|
||||||
|
<div class="flex justify-end gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full px-4 py-2 text-secondary hover:bg-button-bg"
|
||||||
|
@click="cancel"
|
||||||
|
>
|
||||||
|
{{ formatMessage(commonMessages.cancelButton) }}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-brand px-4 py-2 font-semibold text-contrast disabled:opacity-50"
|
||||||
|
:disabled="!canSubmit"
|
||||||
|
@click="beginReset"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.submit) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</NewModal>
|
||||||
|
|
||||||
|
<SkinSiteCaptchaModal
|
||||||
|
ref="captchaModal"
|
||||||
|
@verified="onCaptchaVerified"
|
||||||
|
@cancel="working = false"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,402 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
commonMessages,
|
||||||
|
defineMessages,
|
||||||
|
injectNotificationManager,
|
||||||
|
NewModal,
|
||||||
|
StyledInput,
|
||||||
|
useVIntl,
|
||||||
|
} from '@modrinth/ui'
|
||||||
|
import { computed, onUnmounted, ref } from 'vue'
|
||||||
|
|
||||||
|
import { reloadSkinSiteSession, skinSiteUser } from '@/composables/skin-site-session'
|
||||||
|
import {
|
||||||
|
skinSiteChangePassword,
|
||||||
|
skinSiteChangeUsername,
|
||||||
|
skinSiteChangeYggdrasilPassword,
|
||||||
|
skinSiteUploadAvatar,
|
||||||
|
} from '@/helpers/skin-site-api'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError, addNotification } = injectNotificationManager()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.skin-site.profile.title', defaultMessage: 'Account settings' },
|
||||||
|
basic: { id: 'app.skin-site.profile.basic', defaultMessage: 'Profile' },
|
||||||
|
username: { id: 'app.skin-site.profile.username', defaultMessage: 'Username' },
|
||||||
|
usernameHint: {
|
||||||
|
id: 'app.skin-site.profile.username-hint',
|
||||||
|
defaultMessage: '3–16 characters.',
|
||||||
|
},
|
||||||
|
save: { id: 'app.skin-site.profile.save', defaultMessage: 'Save' },
|
||||||
|
avatar: { id: 'app.skin-site.profile.avatar', defaultMessage: 'Avatar' },
|
||||||
|
chooseAvatar: { id: 'app.skin-site.profile.choose-avatar', defaultMessage: 'Choose image' },
|
||||||
|
avatarHint: {
|
||||||
|
id: 'app.skin-site.profile.avatar-hint',
|
||||||
|
defaultMessage: 'Square images work best; the centre is cropped to 256×256.',
|
||||||
|
},
|
||||||
|
security: { id: 'app.skin-site.profile.security', defaultMessage: 'Security' },
|
||||||
|
sitePasswordHint: {
|
||||||
|
id: 'app.skin-site.profile.site-password-hint',
|
||||||
|
defaultMessage: 'This is the password used to sign in to the skin site.',
|
||||||
|
},
|
||||||
|
oldPassword: { id: 'app.skin-site.profile.old-password', defaultMessage: 'Current password' },
|
||||||
|
newPassword: { id: 'app.skin-site.profile.new-password', defaultMessage: 'New password' },
|
||||||
|
repeatPassword: {
|
||||||
|
id: 'app.skin-site.profile.repeat-password',
|
||||||
|
defaultMessage: 'Repeat new password',
|
||||||
|
},
|
||||||
|
mismatch: { id: 'app.skin-site.profile.mismatch', defaultMessage: 'Passwords do not match.' },
|
||||||
|
passwordHint: {
|
||||||
|
id: 'app.skin-site.profile.password-hint',
|
||||||
|
defaultMessage: '6–50 characters with upper case, lower case and a digit.',
|
||||||
|
},
|
||||||
|
submitPassword: {
|
||||||
|
id: 'app.skin-site.profile.submit-password',
|
||||||
|
defaultMessage: 'Update password',
|
||||||
|
},
|
||||||
|
minecraftPassword: {
|
||||||
|
id: 'app.skin-site.profile.minecraft-password',
|
||||||
|
defaultMessage: 'Minecraft password',
|
||||||
|
},
|
||||||
|
minecraftPasswordHint: {
|
||||||
|
id: 'app.skin-site.profile.minecraft-password-hint',
|
||||||
|
defaultMessage: 'Used by the launcher; defaults to the website password.',
|
||||||
|
},
|
||||||
|
resetDefault: {
|
||||||
|
id: 'app.skin-site.profile.reset-default',
|
||||||
|
defaultMessage: 'Reset to website password',
|
||||||
|
},
|
||||||
|
saved: { id: 'app.skin-site.profile.saved', defaultMessage: 'Saved.' },
|
||||||
|
avatarUploaded: {
|
||||||
|
id: 'app.skin-site.profile.avatar-uploaded',
|
||||||
|
defaultMessage: 'Avatar updated.',
|
||||||
|
},
|
||||||
|
passwordChanged: {
|
||||||
|
id: 'app.skin-site.profile.password-changed',
|
||||||
|
defaultMessage: 'Password updated.',
|
||||||
|
},
|
||||||
|
minecraftPasswordChanged: {
|
||||||
|
id: 'app.skin-site.profile.minecraft-password-changed',
|
||||||
|
defaultMessage: 'Minecraft password updated.',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const PASSWORD_RE = /^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)\S{6,50}$/
|
||||||
|
|
||||||
|
const modal = ref<InstanceType<typeof NewModal>>()
|
||||||
|
const username = ref('')
|
||||||
|
const savingUsername = ref(false)
|
||||||
|
const avatarPreview = ref('')
|
||||||
|
const uploadingAvatar = ref(false)
|
||||||
|
|
||||||
|
const oldPassword = ref('')
|
||||||
|
const newPassword = ref('')
|
||||||
|
const repeatPassword = ref('')
|
||||||
|
const savingPassword = ref(false)
|
||||||
|
|
||||||
|
const newMinecraftPassword = ref('')
|
||||||
|
const repeatMinecraftPassword = ref('')
|
||||||
|
const savingMinecraftPassword = ref(false)
|
||||||
|
|
||||||
|
const usernameValid = computed(() => {
|
||||||
|
const value = username.value.trim()
|
||||||
|
return value.length >= 3 && value.length <= 16
|
||||||
|
})
|
||||||
|
const usernameChanged = computed(
|
||||||
|
() => !!skinSiteUser.value && username.value.trim() !== skinSiteUser.value.username,
|
||||||
|
)
|
||||||
|
|
||||||
|
const passwordValid = computed(() => PASSWORD_RE.test(newPassword.value))
|
||||||
|
const passwordsMatch = computed(() => newPassword.value === repeatPassword.value)
|
||||||
|
const canSavePassword = computed(
|
||||||
|
() => !!oldPassword.value && passwordValid.value && passwordsMatch.value && !savingPassword.value,
|
||||||
|
)
|
||||||
|
|
||||||
|
const minecraftPasswordValid = computed(() => PASSWORD_RE.test(newMinecraftPassword.value))
|
||||||
|
const minecraftPasswordsMatch = computed(
|
||||||
|
() => newMinecraftPassword.value === repeatMinecraftPassword.value,
|
||||||
|
)
|
||||||
|
const canSaveMinecraftPassword = computed(
|
||||||
|
() =>
|
||||||
|
minecraftPasswordValid.value && minecraftPasswordsMatch.value && !savingMinecraftPassword.value,
|
||||||
|
)
|
||||||
|
|
||||||
|
function show() {
|
||||||
|
username.value = skinSiteUser.value?.username ?? ''
|
||||||
|
avatarPreview.value = ''
|
||||||
|
oldPassword.value = ''
|
||||||
|
newPassword.value = ''
|
||||||
|
repeatPassword.value = ''
|
||||||
|
newMinecraftPassword.value = ''
|
||||||
|
repeatMinecraftPassword.value = ''
|
||||||
|
modal.value?.show()
|
||||||
|
}
|
||||||
|
async function saveUsername() {
|
||||||
|
if (!usernameChanged.value || !usernameValid.value) return
|
||||||
|
savingUsername.value = true
|
||||||
|
try {
|
||||||
|
const result = await skinSiteChangeUsername(username.value.trim())
|
||||||
|
if (!result.success) {
|
||||||
|
handleError(new Error(result.errorMessage))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await reloadSkinSiteSession()
|
||||||
|
addNotification({ type: 'success', title: formatMessage(messages.saved) })
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
savingUsername.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Centre-crop the picked image to a square and scale it to 256×256. */
|
||||||
|
async function cropToSquare(file: File): Promise<Blob> {
|
||||||
|
const bitmap = await createImageBitmap(file)
|
||||||
|
const side = Math.min(bitmap.width, bitmap.height)
|
||||||
|
const sx = (bitmap.width - side) / 2
|
||||||
|
const sy = (bitmap.height - side) / 2
|
||||||
|
|
||||||
|
const canvas = document.createElement('canvas')
|
||||||
|
canvas.width = 256
|
||||||
|
canvas.height = 256
|
||||||
|
const ctx = canvas.getContext('2d')
|
||||||
|
if (!ctx) throw new Error('无法创建画布')
|
||||||
|
ctx.imageSmoothingQuality = 'high'
|
||||||
|
ctx.drawImage(bitmap, sx, sy, side, side, 0, 0, 256, 256)
|
||||||
|
bitmap.close?.()
|
||||||
|
|
||||||
|
return await new Promise<Blob>((resolve, reject) => {
|
||||||
|
canvas.toBlob((blob) => (blob ? resolve(blob) : reject(new Error('无法处理图片'))), 'image/png')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onAvatarPicked(event: Event) {
|
||||||
|
const input = event.target as HTMLInputElement
|
||||||
|
const file = input.files?.[0]
|
||||||
|
input.value = ''
|
||||||
|
if (!file) return
|
||||||
|
uploadingAvatar.value = true
|
||||||
|
try {
|
||||||
|
const blob = await cropToSquare(file)
|
||||||
|
avatarPreview.value = URL.createObjectURL(blob)
|
||||||
|
const result = await skinSiteUploadAvatar(blob)
|
||||||
|
if (!result.success) {
|
||||||
|
handleError(new Error(result.errorMessage))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await reloadSkinSiteSession()
|
||||||
|
addNotification({ type: 'success', title: formatMessage(messages.avatarUploaded) })
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
uploadingAvatar.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function savePassword() {
|
||||||
|
if (!canSavePassword.value) return
|
||||||
|
savingPassword.value = true
|
||||||
|
try {
|
||||||
|
const result = await skinSiteChangePassword(oldPassword.value, newPassword.value)
|
||||||
|
if (!result.success) {
|
||||||
|
handleError(new Error(result.errorMessage))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
oldPassword.value = ''
|
||||||
|
newPassword.value = ''
|
||||||
|
repeatPassword.value = ''
|
||||||
|
addNotification({ type: 'success', title: formatMessage(messages.passwordChanged) })
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
savingPassword.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveMinecraftPassword(resetToDefault: boolean) {
|
||||||
|
if (!resetToDefault && !canSaveMinecraftPassword.value) return
|
||||||
|
savingMinecraftPassword.value = true
|
||||||
|
try {
|
||||||
|
const result = await skinSiteChangeYggdrasilPassword(
|
||||||
|
resetToDefault ? null : newMinecraftPassword.value,
|
||||||
|
)
|
||||||
|
if (!result.success) {
|
||||||
|
handleError(new Error(result.errorMessage))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
newMinecraftPassword.value = ''
|
||||||
|
repeatMinecraftPassword.value = ''
|
||||||
|
addNotification({ type: 'success', title: formatMessage(messages.minecraftPasswordChanged) })
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
savingMinecraftPassword.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function close() {
|
||||||
|
modal.value?.hide()
|
||||||
|
}
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
if (avatarPreview.value) URL.revokeObjectURL(avatarPreview.value)
|
||||||
|
})
|
||||||
|
|
||||||
|
defineExpose({ show })
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<NewModal ref="modal" :header="formatMessage(messages.title)">
|
||||||
|
<div class="flex flex-col gap-6">
|
||||||
|
<section class="flex flex-col gap-3">
|
||||||
|
<h3 class="m-0 text-base font-semibold text-contrast">
|
||||||
|
{{ formatMessage(messages.basic) }}
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="text-sm font-semibold text-contrast">{{
|
||||||
|
formatMessage(messages.username)
|
||||||
|
}}</span>
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<StyledInput v-model="username" type="text" class="flex-1" maxlength="16" />
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="shrink-0 rounded-full bg-brand px-4 text-sm font-semibold text-contrast disabled:opacity-50"
|
||||||
|
:disabled="!usernameChanged || !usernameValid || savingUsername"
|
||||||
|
@click="saveUsername"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.save) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<span class="text-xs text-secondary">{{ formatMessage(messages.usernameHint) }}</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-1">
|
||||||
|
<span class="text-sm font-semibold text-contrast">{{
|
||||||
|
formatMessage(messages.avatar)
|
||||||
|
}}</span>
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<img
|
||||||
|
v-if="avatarPreview"
|
||||||
|
:src="avatarPreview"
|
||||||
|
alt=""
|
||||||
|
class="size-12 rounded-lg object-cover"
|
||||||
|
/>
|
||||||
|
<label
|
||||||
|
class="cursor-pointer rounded-full bg-button-bg px-4 py-2 text-sm font-semibold text-contrast hover:brightness-110"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.chooseAvatar) }}
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
accept="image/*"
|
||||||
|
class="hidden"
|
||||||
|
:disabled="uploadingAvatar"
|
||||||
|
@change="onAvatarPicked"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<span class="text-xs text-secondary">{{ formatMessage(messages.avatarHint) }}</span>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="flex flex-col gap-3">
|
||||||
|
<h3 class="m-0 text-base font-semibold text-contrast">
|
||||||
|
{{ formatMessage(messages.security) }}
|
||||||
|
</h3>
|
||||||
|
<span class="text-sm text-secondary">{{ formatMessage(messages.sitePasswordHint) }}</span>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-1 gap-2 sm:grid-cols-3">
|
||||||
|
<StyledInput
|
||||||
|
v-model="oldPassword"
|
||||||
|
type="password"
|
||||||
|
:placeholder="formatMessage(messages.oldPassword)"
|
||||||
|
autocomplete="current-password"
|
||||||
|
/>
|
||||||
|
<StyledInput
|
||||||
|
v-model="newPassword"
|
||||||
|
type="password"
|
||||||
|
:placeholder="formatMessage(messages.newPassword)"
|
||||||
|
autocomplete="new-password"
|
||||||
|
/>
|
||||||
|
<StyledInput
|
||||||
|
v-model="repeatPassword"
|
||||||
|
type="password"
|
||||||
|
:placeholder="formatMessage(messages.repeatPassword)"
|
||||||
|
autocomplete="new-password"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<span class="text-xs text-secondary">{{ formatMessage(messages.passwordHint) }}</span>
|
||||||
|
<span v-if="repeatPassword && !passwordsMatch" class="text-xs text-red">
|
||||||
|
{{ formatMessage(messages.mismatch) }}
|
||||||
|
</span>
|
||||||
|
<div class="flex justify-end">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-brand px-4 py-2 text-sm font-semibold text-contrast disabled:opacity-50"
|
||||||
|
:disabled="!canSavePassword"
|
||||||
|
@click="savePassword"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.submitPassword) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="flex flex-col gap-3">
|
||||||
|
<span class="text-sm font-semibold text-contrast">{{
|
||||||
|
formatMessage(messages.minecraftPassword)
|
||||||
|
}}</span>
|
||||||
|
<span class="text-xs text-secondary">{{
|
||||||
|
formatMessage(messages.minecraftPasswordHint)
|
||||||
|
}}</span>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-1 gap-2 sm:grid-cols-2">
|
||||||
|
<StyledInput
|
||||||
|
v-model="newMinecraftPassword"
|
||||||
|
type="password"
|
||||||
|
:placeholder="formatMessage(messages.newPassword)"
|
||||||
|
autocomplete="new-password"
|
||||||
|
/>
|
||||||
|
<StyledInput
|
||||||
|
v-model="repeatMinecraftPassword"
|
||||||
|
type="password"
|
||||||
|
:placeholder="formatMessage(messages.repeatPassword)"
|
||||||
|
autocomplete="new-password"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<span v-if="repeatMinecraftPassword && !minecraftPasswordsMatch" class="text-xs text-red">
|
||||||
|
{{ formatMessage(messages.mismatch) }}
|
||||||
|
</span>
|
||||||
|
<div class="flex flex-wrap justify-end gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-button-bg px-4 py-2 text-sm font-semibold text-contrast"
|
||||||
|
:disabled="savingMinecraftPassword"
|
||||||
|
@click="saveMinecraftPassword(true)"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.resetDefault) }}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-brand px-4 py-2 text-sm font-semibold text-contrast disabled:opacity-50"
|
||||||
|
:disabled="!canSaveMinecraftPassword"
|
||||||
|
@click="saveMinecraftPassword(false)"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.submitPassword) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template #actions>
|
||||||
|
<div class="flex justify-end">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full px-4 py-2 text-secondary hover:bg-button-bg"
|
||||||
|
@click="close"
|
||||||
|
>
|
||||||
|
{{ formatMessage(commonMessages.closeButton) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</NewModal>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,283 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { SpinnerIcon, TrashIcon, UploadIcon } from '@modrinth/assets'
|
||||||
|
import { Avatar, defineMessages, injectNotificationManager, useVIntl } from '@modrinth/ui'
|
||||||
|
import SkinPreviewRenderer from '@modrinth/ui/src/components/skin/SkinPreviewRenderer.vue'
|
||||||
|
import { computed, onMounted, ref, watch } from 'vue'
|
||||||
|
|
||||||
|
import {
|
||||||
|
requestSkinSitePlayers,
|
||||||
|
skinSitePlayers,
|
||||||
|
skinSitePlayersStatus,
|
||||||
|
skinSiteStatus,
|
||||||
|
skinSiteUser,
|
||||||
|
} from '@/composables/skin-site-session'
|
||||||
|
import {
|
||||||
|
skinSiteDeleteTexture,
|
||||||
|
type SkinSitePlayerSkin,
|
||||||
|
skinSitePlayerSkin,
|
||||||
|
skinSiteUploadTexture,
|
||||||
|
type SkinTextureType,
|
||||||
|
} from '@/helpers/skin-site-api'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError, addNotification } = injectNotificationManager()
|
||||||
|
|
||||||
|
const emit = defineEmits<{ (e: 'back'): void }>()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.skin-site.profile-view.title', defaultMessage: 'Your players' },
|
||||||
|
signedOut: {
|
||||||
|
id: 'app.skin-site.profile-view.signed-out',
|
||||||
|
defaultMessage: 'Sign in to manage your players.',
|
||||||
|
},
|
||||||
|
loading: { id: 'app.skin-site.profile-view.loading', defaultMessage: 'Loading players…' },
|
||||||
|
noPlayers: {
|
||||||
|
id: 'app.skin-site.profile-view.no-players',
|
||||||
|
defaultMessage: 'No players yet.',
|
||||||
|
},
|
||||||
|
selectHint: {
|
||||||
|
id: 'app.skin-site.profile-view.select-hint',
|
||||||
|
defaultMessage: 'Select a player to preview and edit its textures.',
|
||||||
|
},
|
||||||
|
skin: { id: 'app.skin-site.profile-view.skin', defaultMessage: 'Skin' },
|
||||||
|
cape: { id: 'app.skin-site.profile-view.cape', defaultMessage: 'Cape' },
|
||||||
|
elytra: { id: 'app.skin-site.profile-view.elytra', defaultMessage: 'Elytra' },
|
||||||
|
upload: { id: 'app.skin-site.profile-view.upload', defaultMessage: 'Upload' },
|
||||||
|
remove: { id: 'app.skin-site.profile-view.remove', defaultMessage: 'Remove' },
|
||||||
|
readonly: {
|
||||||
|
id: 'app.skin-site.profile-view.readonly',
|
||||||
|
defaultMessage: 'Mojang accounts are managed by Mojang; textures cannot be edited here.',
|
||||||
|
},
|
||||||
|
uploaded: { id: 'app.skin-site.profile-view.uploaded', defaultMessage: 'Texture updated.' },
|
||||||
|
removed: { id: 'app.skin-site.profile-view.removed', defaultMessage: 'Texture removed.' },
|
||||||
|
back: { id: 'app.skin-site.profile-view.back', defaultMessage: 'Back to home' },
|
||||||
|
})
|
||||||
|
const selectedId = ref<string | null>(null)
|
||||||
|
const texture = ref<SkinSitePlayerSkin>({})
|
||||||
|
const loadingTexture = ref(false)
|
||||||
|
const uploading = ref<SkinTextureType | null>(null)
|
||||||
|
|
||||||
|
const signedIn = computed(() => skinSiteStatus.value === 'signed-in' && !!skinSiteUser.value)
|
||||||
|
const players = computed(() => skinSitePlayers.value)
|
||||||
|
const playersLoading = computed(
|
||||||
|
() => skinSitePlayersStatus.value === 'checking' || skinSitePlayersStatus.value === 'idle',
|
||||||
|
)
|
||||||
|
const selectedPlayer = computed(
|
||||||
|
() => players.value.find((p) => p.uuid === selectedId.value) ?? null,
|
||||||
|
)
|
||||||
|
const editable = computed(() => !!selectedPlayer.value && !selectedPlayer.value.isMojang)
|
||||||
|
|
||||||
|
const skinVariant = computed<'CLASSIC' | 'SLIM'>(() =>
|
||||||
|
texture.value.model === 'slim' ? 'SLIM' : 'CLASSIC',
|
||||||
|
)
|
||||||
|
|
||||||
|
function selectPlayer(id: string) {
|
||||||
|
selectedId.value = id
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadTexture(uuid: string) {
|
||||||
|
loadingTexture.value = true
|
||||||
|
texture.value = {}
|
||||||
|
try {
|
||||||
|
const result = await skinSitePlayerSkin(uuid)
|
||||||
|
if (result.success && result.payload) texture.value = result.payload
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
loadingTexture.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(selectedId, (id) => {
|
||||||
|
if (id) void loadTexture(id)
|
||||||
|
else texture.value = {}
|
||||||
|
})
|
||||||
|
|
||||||
|
async function onUpload(type: SkinTextureType, event: Event) {
|
||||||
|
const input = event.target as HTMLInputElement
|
||||||
|
const file = input.files?.[0]
|
||||||
|
input.value = ''
|
||||||
|
if (!file || !selectedId.value) return
|
||||||
|
uploading.value = type
|
||||||
|
try {
|
||||||
|
const metadata: Record<string, string> = {}
|
||||||
|
if (type === 'SKIN') metadata.model = texture.value.model ?? 'default'
|
||||||
|
const result = await skinSiteUploadTexture(selectedId.value, file, type, metadata)
|
||||||
|
if (!result.success) {
|
||||||
|
handleError(new Error(result.errorMessage))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
addNotification({ type: 'success', title: formatMessage(messages.uploaded) })
|
||||||
|
await loadTexture(selectedId.value)
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
uploading.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function removeTexture(type: SkinTextureType) {
|
||||||
|
if (!selectedId.value) return
|
||||||
|
uploading.value = type
|
||||||
|
try {
|
||||||
|
const result = await skinSiteDeleteTexture(selectedId.value, type)
|
||||||
|
if (!result.success) {
|
||||||
|
handleError(new Error(result.errorMessage))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
addNotification({ type: 'success', title: formatMessage(messages.removed) })
|
||||||
|
await loadTexture(selectedId.value)
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
uploading.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
if (signedIn.value) void requestSkinSitePlayers().catch(() => {})
|
||||||
|
})
|
||||||
|
|
||||||
|
watch(signedIn, (value) => {
|
||||||
|
if (value) void requestSkinSitePlayers().catch(() => {})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex w-fit items-center gap-1 rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="emit('back')"
|
||||||
|
>
|
||||||
|
← {{ formatMessage(messages.back) }}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div v-if="!signedIn" class="rounded-2xl border border-solid border-surface-5 bg-bg-raised p-4">
|
||||||
|
<p class="m-0 text-sm text-secondary">{{ formatMessage(messages.signedOut) }}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else class="grid grid-cols-1 gap-4 lg:grid-cols-[18rem_minmax(0,1fr)]">
|
||||||
|
<!-- Player list -->
|
||||||
|
<div
|
||||||
|
class="flex flex-col gap-2 rounded-2xl border border-solid border-surface-5 bg-bg-raised p-3"
|
||||||
|
>
|
||||||
|
<h3 class="m-0 text-base font-semibold text-contrast">
|
||||||
|
{{ formatMessage(messages.title) }}
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<div v-if="playersLoading" class="flex items-center gap-2 text-sm text-secondary">
|
||||||
|
<SpinnerIcon class="size-4 animate-spin" />
|
||||||
|
{{ formatMessage(messages.loading) }}
|
||||||
|
</div>
|
||||||
|
<p v-else-if="!players.length" class="m-0 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.noPlayers) }}
|
||||||
|
</p>
|
||||||
|
<button
|
||||||
|
v-for="player in players"
|
||||||
|
:key="player.uuid"
|
||||||
|
type="button"
|
||||||
|
class="flex items-center gap-2 rounded-xl px-2 py-1.5 text-left transition-colors"
|
||||||
|
:class="
|
||||||
|
player.uuid === selectedId
|
||||||
|
? 'bg-brand-highlight text-contrast'
|
||||||
|
: 'bg-button-bg hover:brightness-110'
|
||||||
|
"
|
||||||
|
@click="selectPlayer(player.uuid)"
|
||||||
|
>
|
||||||
|
<Avatar
|
||||||
|
:src="player.headDataUrl"
|
||||||
|
:alt="player.name"
|
||||||
|
size="1.75rem"
|
||||||
|
pixelated
|
||||||
|
class="!rounded-md"
|
||||||
|
/>
|
||||||
|
<span class="min-w-0 flex-1 truncate text-sm font-medium">{{ player.name }}</span>
|
||||||
|
<span v-if="player.isMojang" class="shrink-0 text-[10px] uppercase text-secondary"
|
||||||
|
>Mojang</span
|
||||||
|
>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Preview + texture actions -->
|
||||||
|
<div
|
||||||
|
class="flex flex-col gap-4 rounded-2xl border border-solid border-surface-5 bg-bg-raised p-4"
|
||||||
|
>
|
||||||
|
<p v-if="!selectedPlayer" class="m-0 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.selectHint) }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<template v-else>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<h3 class="m-0 text-base font-semibold text-contrast">{{ selectedPlayer.name }}</h3>
|
||||||
|
<span v-if="selectedPlayer.isMojang" class="text-xs text-secondary">Mojang</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="relative h-80 w-full overflow-hidden rounded-xl bg-button-bg">
|
||||||
|
<div v-if="loadingTexture" class="absolute inset-0 flex items-center justify-center">
|
||||||
|
<SpinnerIcon class="size-6 animate-spin text-secondary" />
|
||||||
|
</div>
|
||||||
|
<SkinPreviewRenderer
|
||||||
|
v-else
|
||||||
|
:texture-src="texture.skin ?? ''"
|
||||||
|
:cape-src="texture.cape"
|
||||||
|
:variant="skinVariant"
|
||||||
|
:nametag="selectedPlayer.name"
|
||||||
|
:initial-rotation="Math.PI / 8"
|
||||||
|
class="size-full"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p v-if="!editable" class="m-0 text-xs text-secondary">
|
||||||
|
{{ formatMessage(messages.readonly) }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div v-else class="flex flex-col gap-2">
|
||||||
|
<div
|
||||||
|
v-for="entry in [
|
||||||
|
{ type: 'SKIN' as SkinTextureType, label: messages.skin, value: texture.skin },
|
||||||
|
{ type: 'CAPE' as SkinTextureType, label: messages.cape, value: texture.cape },
|
||||||
|
{
|
||||||
|
type: 'ELYTRA' as SkinTextureType,
|
||||||
|
label: messages.elytra,
|
||||||
|
value: texture.elytra,
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
:key="entry.type"
|
||||||
|
class="flex items-center gap-2 rounded-xl bg-button-bg px-3 py-2"
|
||||||
|
>
|
||||||
|
<span class="min-w-0 flex-1 text-sm font-medium text-contrast">
|
||||||
|
{{ formatMessage(entry.label) }}
|
||||||
|
</span>
|
||||||
|
<span class="shrink-0 text-xs text-secondary">
|
||||||
|
{{ entry.value ? '✓' : '—' }}
|
||||||
|
</span>
|
||||||
|
<label
|
||||||
|
class="flex shrink-0 cursor-pointer items-center gap-1 rounded-full bg-brand px-3 py-1 text-xs font-semibold text-contrast"
|
||||||
|
>
|
||||||
|
<UploadIcon class="size-3" />
|
||||||
|
{{ formatMessage(messages.upload) }}
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
accept="image/png"
|
||||||
|
class="hidden"
|
||||||
|
:disabled="uploading !== null"
|
||||||
|
@change="(e) => onUpload(entry.type, e)"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<button
|
||||||
|
v-if="entry.value"
|
||||||
|
type="button"
|
||||||
|
class="flex shrink-0 items-center gap-1 rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-red"
|
||||||
|
:disabled="uploading !== null"
|
||||||
|
@click="removeTexture(entry.type)"
|
||||||
|
>
|
||||||
|
<TrashIcon class="size-3" />
|
||||||
|
{{ formatMessage(messages.remove) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,299 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import {
|
||||||
|
commonMessages,
|
||||||
|
defineMessages,
|
||||||
|
injectNotificationManager,
|
||||||
|
NewModal,
|
||||||
|
StyledInput,
|
||||||
|
useVIntl,
|
||||||
|
} from '@modrinth/ui'
|
||||||
|
import { computed, onUnmounted, ref } from 'vue'
|
||||||
|
|
||||||
|
import { reloadSkinSiteSession, signInSkinSite } from '@/composables/skin-site-session'
|
||||||
|
import {
|
||||||
|
skinSiteRegister,
|
||||||
|
skinSiteRegisterCondition,
|
||||||
|
skinSiteRegisterEmailVerify,
|
||||||
|
} from '@/helpers/skin-site-api'
|
||||||
|
|
||||||
|
import SkinSiteCaptchaModal from './SkinSiteCaptchaModal.vue'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError, addNotification } = injectNotificationManager()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.skin-site.register.title', defaultMessage: 'Create a StarLight account' },
|
||||||
|
email: { id: 'app.skin-site.register.email', defaultMessage: 'Email' },
|
||||||
|
code: { id: 'app.skin-site.register.code', defaultMessage: 'Verification code' },
|
||||||
|
sendCode: { id: 'app.skin-site.register.send-code', defaultMessage: 'Send code' },
|
||||||
|
sending: { id: 'app.skin-site.register.sending', defaultMessage: 'Sending…' },
|
||||||
|
resendIn: { id: 'app.skin-site.register.resend-in', defaultMessage: 'Sent ({seconds}s)' },
|
||||||
|
password: { id: 'app.skin-site.register.password', defaultMessage: 'Password' },
|
||||||
|
repeatPassword: {
|
||||||
|
id: 'app.skin-site.register.repeat-password',
|
||||||
|
defaultMessage: 'Repeat password',
|
||||||
|
},
|
||||||
|
passwordHint: {
|
||||||
|
id: 'app.skin-site.register.password-hint',
|
||||||
|
defaultMessage: '6–50 characters with upper case, lower case and a digit.',
|
||||||
|
},
|
||||||
|
mismatch: { id: 'app.skin-site.register.mismatch', defaultMessage: 'Passwords do not match.' },
|
||||||
|
qq: { id: 'app.skin-site.register.qq', defaultMessage: 'QQ (optional)' },
|
||||||
|
inviteCode: { id: 'app.skin-site.register.invite-code', defaultMessage: 'Invite code' },
|
||||||
|
inviteRequired: {
|
||||||
|
id: 'app.skin-site.register.invite-required',
|
||||||
|
defaultMessage: 'This server requires an invite code.',
|
||||||
|
},
|
||||||
|
submit: { id: 'app.skin-site.register.submit', defaultMessage: 'Create account' },
|
||||||
|
success: {
|
||||||
|
id: 'app.skin-site.register.success',
|
||||||
|
defaultMessage: 'Account created and signed in.',
|
||||||
|
},
|
||||||
|
closed: {
|
||||||
|
id: 'app.skin-site.register.closed',
|
||||||
|
defaultMessage: 'Registration is currently closed on this server.',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const PASSWORD_RE = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,50}$/
|
||||||
|
const COUNTDOWN_SECONDS = 60
|
||||||
|
|
||||||
|
const modal = ref<InstanceType<typeof NewModal>>()
|
||||||
|
const captchaModal = ref<InstanceType<typeof SkinSiteCaptchaModal>>()
|
||||||
|
const email = ref('')
|
||||||
|
const code = ref('')
|
||||||
|
const password = ref('')
|
||||||
|
const repeatPassword = ref('')
|
||||||
|
const qq = ref('')
|
||||||
|
const inviteCode = ref('')
|
||||||
|
const inviteRequired = ref(false)
|
||||||
|
const registerAllowed = ref(true)
|
||||||
|
const sending = ref(false)
|
||||||
|
const working = ref(false)
|
||||||
|
const countdown = ref(0)
|
||||||
|
const loadingCondition = ref(false)
|
||||||
|
let timer: ReturnType<typeof setInterval> | undefined
|
||||||
|
|
||||||
|
const emit = defineEmits<{ (e: 'signed-in' | 'cancel'): void }>()
|
||||||
|
|
||||||
|
function stopTimer() {
|
||||||
|
if (timer) clearInterval(timer)
|
||||||
|
timer = undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
function startCountdown() {
|
||||||
|
countdown.value = COUNTDOWN_SECONDS
|
||||||
|
stopTimer()
|
||||||
|
timer = setInterval(() => {
|
||||||
|
countdown.value -= 1
|
||||||
|
if (countdown.value <= 0) stopTimer()
|
||||||
|
}, 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
const canSendCode = computed(
|
||||||
|
() => email.value.trim().length > 0 && !sending.value && countdown.value <= 0,
|
||||||
|
)
|
||||||
|
|
||||||
|
const passwordValid = computed(() => PASSWORD_RE.test(password.value))
|
||||||
|
const passwordsMatch = computed(() => password.value === repeatPassword.value)
|
||||||
|
const qqValid = computed(() => qq.value.trim() === '' || /^\d{5,}$/.test(qq.value.trim()))
|
||||||
|
const inviteValid = computed(() => !inviteRequired.value || inviteCode.value.trim().length > 0)
|
||||||
|
const canSubmit = computed(
|
||||||
|
() =>
|
||||||
|
registerAllowed.value &&
|
||||||
|
email.value.trim().length > 0 &&
|
||||||
|
code.value.trim().length === 6 &&
|
||||||
|
passwordValid.value &&
|
||||||
|
passwordsMatch.value &&
|
||||||
|
qqValid.value &&
|
||||||
|
inviteValid.value &&
|
||||||
|
!working.value,
|
||||||
|
)
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
stopTimer()
|
||||||
|
email.value = ''
|
||||||
|
code.value = ''
|
||||||
|
password.value = ''
|
||||||
|
repeatPassword.value = ''
|
||||||
|
qq.value = ''
|
||||||
|
inviteCode.value = ''
|
||||||
|
sending.value = false
|
||||||
|
working.value = false
|
||||||
|
countdown.value = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadCondition() {
|
||||||
|
loadingCondition.value = true
|
||||||
|
try {
|
||||||
|
const result = await skinSiteRegisterCondition()
|
||||||
|
if (result.success) {
|
||||||
|
registerAllowed.value = result.payload.registerAllowed
|
||||||
|
inviteRequired.value = result.payload.inviteCodeRequired
|
||||||
|
} else {
|
||||||
|
registerAllowed.value = false
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
loadingCondition.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function show() {
|
||||||
|
reset()
|
||||||
|
modal.value?.show()
|
||||||
|
await loadCondition()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function sendCode() {
|
||||||
|
if (!canSendCode.value) return
|
||||||
|
sending.value = true
|
||||||
|
try {
|
||||||
|
const result = await skinSiteRegisterEmailVerify(email.value.trim())
|
||||||
|
if (!result.success) {
|
||||||
|
handleError(new Error(result.errorMessage))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
addNotification({ type: 'success', title: result.payload })
|
||||||
|
startCountdown()
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
sending.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function beginRegister() {
|
||||||
|
if (!canSubmit.value) return
|
||||||
|
if (!passwordsMatch.value) {
|
||||||
|
handleError(new Error(formatMessage(messages.mismatch)))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
captchaModal.value?.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onCaptchaVerified(clientId: string) {
|
||||||
|
working.value = true
|
||||||
|
try {
|
||||||
|
const result = await skinSiteRegister({
|
||||||
|
email: email.value.trim(),
|
||||||
|
emailVerifyCode: code.value.trim(),
|
||||||
|
password: password.value,
|
||||||
|
qq: qq.value.trim() ? Number(qq.value.trim()) : undefined,
|
||||||
|
inviteCode: inviteCode.value.trim() || undefined,
|
||||||
|
clientId,
|
||||||
|
})
|
||||||
|
if (!result.success) {
|
||||||
|
handleError(new Error(result.errorMessage))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Registration returns a JWT; persist it through the normal sign-in path.
|
||||||
|
await signInSkinSite({ username: result.payload.username, password: password.value, clientId })
|
||||||
|
await reloadSkinSiteSession()
|
||||||
|
addNotification({ type: 'success', title: formatMessage(messages.success) })
|
||||||
|
modal.value?.hide()
|
||||||
|
emit('signed-in')
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
working.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancel() {
|
||||||
|
modal.value?.hide()
|
||||||
|
emit('cancel')
|
||||||
|
}
|
||||||
|
|
||||||
|
onUnmounted(stopTimer)
|
||||||
|
|
||||||
|
defineExpose({ show })
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<NewModal ref="modal" :header="formatMessage(messages.title)" @hide="reset">
|
||||||
|
<div v-if="!loadingCondition && !registerAllowed" class="text-secondary">
|
||||||
|
{{ formatMessage(messages.closed) }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else class="flex flex-col gap-4">
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="font-semibold text-contrast">{{ formatMessage(messages.email) }}</span>
|
||||||
|
<StyledInput v-model="email" type="email" autocomplete="email" />
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="font-semibold text-contrast">{{ formatMessage(messages.code) }}</span>
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<StyledInput v-model="code" type="text" class="flex-1" maxlength="6" />
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="shrink-0 rounded-full bg-button-bg px-4 text-sm font-semibold text-contrast disabled:opacity-50"
|
||||||
|
:disabled="!canSendCode"
|
||||||
|
@click="sendCode"
|
||||||
|
>
|
||||||
|
{{
|
||||||
|
sending
|
||||||
|
? formatMessage(messages.sending)
|
||||||
|
: countdown > 0
|
||||||
|
? formatMessage(messages.resendIn, { seconds: countdown })
|
||||||
|
: formatMessage(messages.sendCode)
|
||||||
|
}}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="font-semibold text-contrast">{{ formatMessage(messages.password) }}</span>
|
||||||
|
<StyledInput v-model="password" type="password" autocomplete="new-password" />
|
||||||
|
<span class="text-xs text-secondary">{{ formatMessage(messages.passwordHint) }}</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="font-semibold text-contrast">{{
|
||||||
|
formatMessage(messages.repeatPassword)
|
||||||
|
}}</span>
|
||||||
|
<StyledInput v-model="repeatPassword" type="password" autocomplete="new-password" />
|
||||||
|
<span v-if="repeatPassword && !passwordsMatch" class="text-xs text-red">
|
||||||
|
{{ formatMessage(messages.mismatch) }}
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="font-semibold text-contrast">{{ formatMessage(messages.qq) }}</span>
|
||||||
|
<StyledInput v-model="qq" type="text" inputmode="numeric" />
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label v-if="inviteRequired" class="flex flex-col gap-1">
|
||||||
|
<span class="font-semibold text-contrast">{{ formatMessage(messages.inviteCode) }}</span>
|
||||||
|
<StyledInput v-model="inviteCode" type="text" />
|
||||||
|
<span class="text-xs text-secondary">{{ formatMessage(messages.inviteRequired) }}</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template #actions>
|
||||||
|
<div class="flex justify-end gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full px-4 py-2 text-secondary hover:bg-button-bg"
|
||||||
|
@click="cancel"
|
||||||
|
>
|
||||||
|
{{ formatMessage(commonMessages.cancelButton) }}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-brand px-4 py-2 font-semibold text-contrast disabled:opacity-50"
|
||||||
|
:disabled="!canSubmit"
|
||||||
|
@click="beginRegister"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.submit) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</NewModal>
|
||||||
|
|
||||||
|
<SkinSiteCaptchaModal
|
||||||
|
ref="captchaModal"
|
||||||
|
@verified="onCaptchaVerified"
|
||||||
|
@cancel="working = false"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,313 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { CheckCircleIcon, SpinnerIcon } from '@modrinth/assets'
|
||||||
|
import { defineMessages, injectNotificationManager, StyledInput, useVIntl } from '@modrinth/ui'
|
||||||
|
import { computed, onMounted, ref } from 'vue'
|
||||||
|
|
||||||
|
import {
|
||||||
|
skinSiteReviewCatalog,
|
||||||
|
type SkinSiteReviewPaper,
|
||||||
|
type SkinSiteReviewQuestion,
|
||||||
|
type SkinSiteReviewReceipt,
|
||||||
|
skinSiteSubmitReview,
|
||||||
|
} from '@/helpers/skin-site-api'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError, addNotification } = injectNotificationManager()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.skin-site.review.title', defaultMessage: 'Player review' },
|
||||||
|
back: { id: 'app.skin-site.review.back', defaultMessage: 'Back to home' },
|
||||||
|
subtitle: {
|
||||||
|
id: 'app.skin-site.review.subtitle',
|
||||||
|
defaultMessage: 'Pick an application form and answer its questions.',
|
||||||
|
},
|
||||||
|
loading: { id: 'app.skin-site.review.loading', defaultMessage: 'Loading…' },
|
||||||
|
failed: { id: 'app.skin-site.review.failed', defaultMessage: 'Could not load the review forms.' },
|
||||||
|
empty: {
|
||||||
|
id: 'app.skin-site.review.empty',
|
||||||
|
defaultMessage: 'No application forms are available right now.',
|
||||||
|
},
|
||||||
|
email: { id: 'app.skin-site.review.email', defaultMessage: 'Your email' },
|
||||||
|
emailHint: {
|
||||||
|
id: 'app.skin-site.review.email-hint',
|
||||||
|
defaultMessage: 'Results are sent to this address.',
|
||||||
|
},
|
||||||
|
inviteCode: { id: 'app.skin-site.review.invite-code', defaultMessage: 'Invite code' },
|
||||||
|
submit: { id: 'app.skin-site.review.submit', defaultMessage: 'Submit application' },
|
||||||
|
submitting: { id: 'app.skin-site.review.submitting', defaultMessage: 'Submitting…' },
|
||||||
|
backToList: { id: 'app.skin-site.review.back-to-list', defaultMessage: 'Back to forms' },
|
||||||
|
required: { id: 'app.skin-site.review.required', defaultMessage: 'Required' },
|
||||||
|
optional: { id: 'app.skin-site.review.optional', defaultMessage: 'Optional' },
|
||||||
|
submitted: { id: 'app.skin-site.review.submitted', defaultMessage: 'Application submitted.' },
|
||||||
|
resultPending: { id: 'app.skin-site.review.result.pending', defaultMessage: 'Under review' },
|
||||||
|
resultPassed: { id: 'app.skin-site.review.result.passed', defaultMessage: 'Approved' },
|
||||||
|
resultRejected: { id: 'app.skin-site.review.result.rejected', defaultMessage: 'Rejected' },
|
||||||
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits<{ (e: 'back'): void }>()
|
||||||
|
|
||||||
|
const papers = ref<SkinSiteReviewPaper[]>([])
|
||||||
|
const loading = ref(true)
|
||||||
|
const failed = ref(false)
|
||||||
|
const activePaper = ref<SkinSiteReviewPaper | null>(null)
|
||||||
|
const email = ref('')
|
||||||
|
const inviteCode = ref('')
|
||||||
|
const answers = ref<Record<string, string | string[]>>({})
|
||||||
|
const submitting = ref(false)
|
||||||
|
const receipt = ref<SkinSiteReviewReceipt | null>(null)
|
||||||
|
|
||||||
|
const emailValid = computed(() => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email.value.trim()))
|
||||||
|
|
||||||
|
const requiredAnswered = computed(() => {
|
||||||
|
if (!activePaper.value) return false
|
||||||
|
return activePaper.value.questions.every((q) => {
|
||||||
|
if (q.informationQuestion || q.optional) return true
|
||||||
|
const value = answers.value[q.id]
|
||||||
|
if (Array.isArray(value)) return value.length > 0
|
||||||
|
return typeof value === 'string' ? value.trim().length > 0 : false
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const canSubmit = computed(() => emailValid.value && requiredAnswered.value && !submitting.value)
|
||||||
|
|
||||||
|
function defaultAnswer(q: SkinSiteReviewQuestion): string | string[] {
|
||||||
|
if (q.type === 'MULTIPLE' || q.type === 'SINGLE') {
|
||||||
|
const preset = (q.options ?? []).filter((o) => o.defaultSelected).map((o) => o.id)
|
||||||
|
return q.type === 'MULTIPLE' ? preset : (preset[0] ?? '')
|
||||||
|
}
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
function openPaper(paper: SkinSiteReviewPaper) {
|
||||||
|
activePaper.value = paper
|
||||||
|
answers.value = {}
|
||||||
|
for (const q of paper.questions) answers.value[q.id] = defaultAnswer(q)
|
||||||
|
email.value = ''
|
||||||
|
inviteCode.value = ''
|
||||||
|
receipt.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
function closePaper() {
|
||||||
|
activePaper.value = null
|
||||||
|
answers.value = {}
|
||||||
|
receipt.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleMultiple(q: SkinSiteReviewQuestion, optionId: string, checked: boolean) {
|
||||||
|
const current = Array.isArray(answers.value[q.id]) ? (answers.value[q.id] as string[]) : []
|
||||||
|
answers.value[q.id] = checked
|
||||||
|
? [...current.filter((id) => id !== optionId), optionId]
|
||||||
|
: current.filter((id) => id !== optionId)
|
||||||
|
}
|
||||||
|
async function loadCatalog() {
|
||||||
|
loading.value = true
|
||||||
|
failed.value = false
|
||||||
|
try {
|
||||||
|
const result = await skinSiteReviewCatalog()
|
||||||
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
|
papers.value = result.payload?.papers ?? []
|
||||||
|
} catch (error) {
|
||||||
|
failed.value = true
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function submitApplication() {
|
||||||
|
if (!activePaper.value || !canSubmit.value) return
|
||||||
|
submitting.value = true
|
||||||
|
try {
|
||||||
|
const payloadAnswers: Record<string, unknown> = {}
|
||||||
|
for (const q of activePaper.value.questions) {
|
||||||
|
if (q.informationQuestion) continue
|
||||||
|
payloadAnswers[q.id] = answers.value[q.id] ?? ''
|
||||||
|
}
|
||||||
|
const result = await skinSiteSubmitReview({
|
||||||
|
paperId: activePaper.value.id,
|
||||||
|
email: email.value.trim(),
|
||||||
|
answers: payloadAnswers,
|
||||||
|
...(inviteCode.value.trim() ? { inviteCode: inviteCode.value.trim() } : {}),
|
||||||
|
})
|
||||||
|
if (!result.success) {
|
||||||
|
handleError(new Error(result.errorMessage))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
receipt.value = result.payload
|
||||||
|
addNotification({ type: 'success', title: formatMessage(messages.submitted) })
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
submitting.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function resultLabel(result?: string): string {
|
||||||
|
switch (result) {
|
||||||
|
case 'PASSED':
|
||||||
|
return formatMessage(messages.resultPassed)
|
||||||
|
case 'REJECTED':
|
||||||
|
return formatMessage(messages.resultRejected)
|
||||||
|
default:
|
||||||
|
return formatMessage(messages.resultPending)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(loadCatalog)
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="flex w-fit items-center gap-1 rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="activePaper ? closePaper() : emit('back')"
|
||||||
|
>
|
||||||
|
← {{ activePaper ? formatMessage(messages.backToList) : formatMessage(messages.back) }}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<template v-if="!activePaper">
|
||||||
|
<header class="flex flex-col gap-1">
|
||||||
|
<h1 class="m-0 text-xl font-bold text-contrast">{{ formatMessage(messages.title) }}</h1>
|
||||||
|
<p class="m-0 text-sm text-secondary">{{ formatMessage(messages.subtitle) }}</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div v-if="loading" class="flex items-center gap-2 text-sm text-secondary">
|
||||||
|
<SpinnerIcon class="size-4 animate-spin" />
|
||||||
|
{{ formatMessage(messages.loading) }}
|
||||||
|
</div>
|
||||||
|
<p v-else-if="failed" class="m-0 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.failed) }}
|
||||||
|
</p>
|
||||||
|
<p v-else-if="!papers.length" class="m-0 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.empty) }}
|
||||||
|
</p>
|
||||||
|
<button
|
||||||
|
v-for="paper in papers"
|
||||||
|
:key="paper.id"
|
||||||
|
type="button"
|
||||||
|
class="flex flex-col items-start gap-1 rounded-xl border border-solid border-surface-5 bg-bg-raised p-3 text-left transition-colors hover:bg-button-bg"
|
||||||
|
@click="openPaper(paper)"
|
||||||
|
>
|
||||||
|
<span class="text-sm font-semibold text-contrast">{{ paper.title }}</span>
|
||||||
|
<span v-if="paper.description" class="text-xs text-secondary">{{ paper.description }}</span>
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-else-if="receipt"
|
||||||
|
class="flex flex-col items-center gap-3 rounded-2xl border border-solid border-surface-5 bg-bg-raised p-6 text-center"
|
||||||
|
>
|
||||||
|
<CheckCircleIcon class="size-10 text-brand" />
|
||||||
|
<h2 class="m-0 text-lg font-bold text-contrast">{{ formatMessage(messages.submitted) }}</h2>
|
||||||
|
<p class="m-0 text-sm text-secondary">{{ resultLabel(receipt.result) }}</p>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-brand px-4 py-2 text-sm font-semibold text-contrast"
|
||||||
|
@click="closePaper"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.backToList) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template v-else>
|
||||||
|
<h1 class="m-0 text-xl font-bold text-contrast">{{ activePaper.title }}</h1>
|
||||||
|
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="text-sm font-semibold text-contrast">{{ formatMessage(messages.email) }}</span>
|
||||||
|
<StyledInput v-model="email" type="email" autocomplete="email" />
|
||||||
|
<span class="text-xs text-secondary">{{ formatMessage(messages.emailHint) }}</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="text-sm font-semibold text-contrast">{{
|
||||||
|
formatMessage(messages.inviteCode)
|
||||||
|
}}</span>
|
||||||
|
<StyledInput v-model="inviteCode" type="text" />
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-for="question in activePaper.questions"
|
||||||
|
:key="question.id"
|
||||||
|
class="flex flex-col gap-2 rounded-xl border border-solid border-surface-5 bg-bg-raised p-3"
|
||||||
|
>
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<span class="text-sm font-semibold text-contrast">{{ question.title }}</span>
|
||||||
|
<span
|
||||||
|
v-if="!question.optional && !question.informationQuestion"
|
||||||
|
class="rounded-full bg-brand-highlight px-2 py-0.5 text-[10px] font-semibold text-contrast"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.required) }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<span v-if="question.annotation" class="text-xs text-secondary">{{
|
||||||
|
question.annotation
|
||||||
|
}}</span>
|
||||||
|
|
||||||
|
<span v-if="question.informationQuestion" class="text-xs text-secondary">
|
||||||
|
{{ question.answer }}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<template v-else-if="question.type === 'SINGLE' || question.type === 'TRUE_FALSE'">
|
||||||
|
<label
|
||||||
|
v-for="option in question.options ?? []"
|
||||||
|
:key="option.id"
|
||||||
|
class="flex items-center gap-2 text-sm"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
:name="question.id"
|
||||||
|
:value="option.id"
|
||||||
|
:checked="answers[question.id] === option.id"
|
||||||
|
@change="answers[question.id] = option.id"
|
||||||
|
/>
|
||||||
|
<span class="text-contrast">{{ option.description }}</span>
|
||||||
|
</label>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-else-if="question.type === 'MULTIPLE'">
|
||||||
|
<label
|
||||||
|
v-for="option in question.options ?? []"
|
||||||
|
:key="option.id"
|
||||||
|
class="flex items-center gap-2 text-sm"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
:checked="
|
||||||
|
Array.isArray(answers[question.id]) &&
|
||||||
|
(answers[question.id] as string[]).includes(option.id)
|
||||||
|
"
|
||||||
|
@change="
|
||||||
|
toggleMultiple(question, option.id, ($event.target as HTMLInputElement).checked)
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
<span class="text-contrast">{{ option.description }}</span>
|
||||||
|
</label>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<StyledInput
|
||||||
|
v-else-if="question.type === 'FILL'"
|
||||||
|
v-model="answers[question.id] as string"
|
||||||
|
type="text"
|
||||||
|
:maxlength="question.maxLength ?? 50"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<textarea
|
||||||
|
v-else
|
||||||
|
v-model="answers[question.id] as string"
|
||||||
|
rows="4"
|
||||||
|
class="w-full rounded-lg border border-solid border-surface-5 bg-button-bg p-2 text-sm text-contrast"
|
||||||
|
:maxlength="question.maxLength ?? 300"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="w-fit self-end rounded-full bg-brand px-5 py-2 text-sm font-semibold text-contrast disabled:opacity-50"
|
||||||
|
:disabled="!canSubmit"
|
||||||
|
@click="submitApplication"
|
||||||
|
>
|
||||||
|
{{ formatMessage(submitting ? messages.submitting : messages.submit) }}
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,366 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { SpinnerIcon } from '@modrinth/assets'
|
||||||
|
import { defineMessages, injectNotificationManager, useVIntl } from '@modrinth/ui'
|
||||||
|
import { computed, onMounted, ref } from 'vue'
|
||||||
|
|
||||||
|
import {
|
||||||
|
type SkinSiteBroadcast,
|
||||||
|
type SkinSiteBroadcastInput,
|
||||||
|
skinSiteBroadcasts,
|
||||||
|
skinSiteCreateBroadcast,
|
||||||
|
skinSiteDeleteBroadcast,
|
||||||
|
skinSiteUpdateBroadcast,
|
||||||
|
} from '@/helpers/skin-site-api'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError, addNotification } = injectNotificationManager()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.skin-site.admin.broadcast.title', defaultMessage: 'Announcements' },
|
||||||
|
loading: { id: 'app.skin-site.admin.broadcast.loading', defaultMessage: 'Loading…' },
|
||||||
|
failed: { id: 'app.skin-site.admin.broadcast.failed', defaultMessage: 'Could not load.' },
|
||||||
|
empty: { id: 'app.skin-site.admin.broadcast.empty', defaultMessage: 'No announcements yet.' },
|
||||||
|
create: { id: 'app.skin-site.admin.broadcast.create', defaultMessage: 'New announcement' },
|
||||||
|
save: { id: 'app.skin-site.admin.broadcast.save', defaultMessage: 'Save' },
|
||||||
|
cancel: { id: 'app.skin-site.admin.broadcast.cancel', defaultMessage: 'Cancel' },
|
||||||
|
edit: { id: 'app.skin-site.admin.broadcast.edit', defaultMessage: 'Edit' },
|
||||||
|
remove: { id: 'app.skin-site.admin.broadcast.remove', defaultMessage: 'Delete' },
|
||||||
|
titleField: { id: 'app.skin-site.admin.broadcast.title-field', defaultMessage: 'Title' },
|
||||||
|
subtitleField: { id: 'app.skin-site.admin.broadcast.subtitle-field', defaultMessage: 'Subtitle' },
|
||||||
|
contentField: { id: 'app.skin-site.admin.broadcast.content-field', defaultMessage: 'Content' },
|
||||||
|
expireAt: { id: 'app.skin-site.admin.broadcast.expire-at', defaultMessage: 'Expires at' },
|
||||||
|
star: { id: 'app.skin-site.admin.broadcast.star', defaultMessage: 'Highlight' },
|
||||||
|
level: { id: 'app.skin-site.admin.broadcast.level', defaultMessage: 'Importance' },
|
||||||
|
image: { id: 'app.skin-site.admin.broadcast.image', defaultMessage: 'Image' },
|
||||||
|
removeImage: { id: 'app.skin-site.admin.broadcast.remove-image', defaultMessage: 'Remove image' },
|
||||||
|
created: { id: 'app.skin-site.admin.broadcast.created', defaultMessage: 'Announcement created.' },
|
||||||
|
updated: { id: 'app.skin-site.admin.broadcast.updated', defaultMessage: 'Announcement updated.' },
|
||||||
|
deleted: { id: 'app.skin-site.admin.broadcast.deleted', defaultMessage: 'Announcement deleted.' },
|
||||||
|
confirmDelete: {
|
||||||
|
id: 'app.skin-site.admin.broadcast.confirm-delete',
|
||||||
|
defaultMessage: 'Delete “{title}”? This cannot be undone.',
|
||||||
|
},
|
||||||
|
uploader: { id: 'app.skin-site.admin.broadcast.uploader', defaultMessage: 'by {name}' },
|
||||||
|
})
|
||||||
|
|
||||||
|
const items = ref<SkinSiteBroadcast[]>([])
|
||||||
|
const loading = ref(true)
|
||||||
|
const failed = ref(false)
|
||||||
|
const saving = ref(false)
|
||||||
|
const deletingId = ref<number | null>(null)
|
||||||
|
|
||||||
|
const editorOpen = ref(false)
|
||||||
|
const editingId = ref<number | null>(null)
|
||||||
|
const form = ref({
|
||||||
|
title: '',
|
||||||
|
subtitle: '',
|
||||||
|
content: '',
|
||||||
|
expireAt: '',
|
||||||
|
star: false,
|
||||||
|
importantLevel: 0,
|
||||||
|
})
|
||||||
|
const imageFile = ref<File | null>(null)
|
||||||
|
const removeImage = ref(false)
|
||||||
|
|
||||||
|
const sorted = computed(() => [...items.value].sort((a, b) => b.id - a.id))
|
||||||
|
|
||||||
|
function formatDate(ts: number): string {
|
||||||
|
try {
|
||||||
|
return new Date(ts).toLocaleString()
|
||||||
|
} catch {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toDateInput(ts: number): string {
|
||||||
|
try {
|
||||||
|
const d = new Date(ts)
|
||||||
|
const pad = (n: number) => String(n).padStart(2, '0')
|
||||||
|
return (
|
||||||
|
d.getFullYear() +
|
||||||
|
'-' +
|
||||||
|
pad(d.getMonth() + 1) +
|
||||||
|
'-' +
|
||||||
|
pad(d.getDate()) +
|
||||||
|
'T' +
|
||||||
|
pad(d.getHours()) +
|
||||||
|
':' +
|
||||||
|
pad(d.getMinutes())
|
||||||
|
)
|
||||||
|
} catch {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetForm() {
|
||||||
|
form.value = {
|
||||||
|
title: '',
|
||||||
|
subtitle: '',
|
||||||
|
content: '',
|
||||||
|
expireAt: '',
|
||||||
|
star: false,
|
||||||
|
importantLevel: 0,
|
||||||
|
}
|
||||||
|
imageFile.value = null
|
||||||
|
removeImage.value = false
|
||||||
|
editingId.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
function openCreate() {
|
||||||
|
resetForm()
|
||||||
|
editorOpen.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function openEdit(item: SkinSiteBroadcast) {
|
||||||
|
form.value = {
|
||||||
|
title: item.title,
|
||||||
|
subtitle: item.subtitle,
|
||||||
|
content: item.content,
|
||||||
|
expireAt: toDateInput(item.expireAt),
|
||||||
|
star: item.star,
|
||||||
|
importantLevel: item.importantLevel,
|
||||||
|
}
|
||||||
|
imageFile.value = null
|
||||||
|
removeImage.value = false
|
||||||
|
editingId.value = item.id
|
||||||
|
editorOpen.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeEditor() {
|
||||||
|
editorOpen.value = false
|
||||||
|
resetForm()
|
||||||
|
}
|
||||||
|
|
||||||
|
function onImageChange(event: Event) {
|
||||||
|
const input = event.target as HTMLInputElement
|
||||||
|
imageFile.value = input.files?.[0] ?? null
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildInput(): SkinSiteBroadcastInput {
|
||||||
|
const ts = form.value.expireAt ? new Date(form.value.expireAt).getTime() : 0
|
||||||
|
return {
|
||||||
|
title: form.value.title.trim(),
|
||||||
|
subtitle: form.value.subtitle.trim(),
|
||||||
|
content: form.value.content,
|
||||||
|
expireAt: Number.isFinite(ts) ? ts : 0,
|
||||||
|
star: form.value.star,
|
||||||
|
importantLevel: Number(form.value.importantLevel) || 0,
|
||||||
|
imageFile: imageFile.value,
|
||||||
|
removeImage: removeImage.value,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const canSave = computed(
|
||||||
|
() => form.value.title.trim().length > 0 && form.value.content.length > 0 && !saving.value,
|
||||||
|
)
|
||||||
|
|
||||||
|
async function load() {
|
||||||
|
loading.value = true
|
||||||
|
failed.value = false
|
||||||
|
try {
|
||||||
|
const result = await skinSiteBroadcasts()
|
||||||
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
|
items.value = result.payload ?? []
|
||||||
|
} catch (error) {
|
||||||
|
failed.value = true
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
if (!canSave.value) return
|
||||||
|
saving.value = true
|
||||||
|
try {
|
||||||
|
const input = buildInput()
|
||||||
|
const result =
|
||||||
|
editingId.value === null
|
||||||
|
? await skinSiteCreateBroadcast(input)
|
||||||
|
: await skinSiteUpdateBroadcast(editingId.value, input)
|
||||||
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
|
addNotification({
|
||||||
|
type: 'success',
|
||||||
|
title: formatMessage(editingId.value === null ? messages.created : messages.updated),
|
||||||
|
})
|
||||||
|
closeEditor()
|
||||||
|
await load()
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
saving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function remove(item: SkinSiteBroadcast) {
|
||||||
|
if (deletingId.value !== null) return
|
||||||
|
if (!window.confirm(formatMessage(messages.confirmDelete, { title: item.title }))) return
|
||||||
|
deletingId.value = item.id
|
||||||
|
try {
|
||||||
|
const result = await skinSiteDeleteBroadcast(item.id)
|
||||||
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
|
addNotification({ type: 'success', title: formatMessage(messages.deleted) })
|
||||||
|
await load()
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
deletingId.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => void load())
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<div class="flex flex-wrap items-center gap-3">
|
||||||
|
<h2 class="m-0 text-lg font-bold text-contrast">{{ formatMessage(messages.title) }}</h2>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="ml-auto rounded-full bg-brand px-4 py-2 text-sm font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="openCreate"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.create) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="loading" class="flex items-center gap-2 text-sm text-secondary">
|
||||||
|
<SpinnerIcon class="size-4 animate-spin" />
|
||||||
|
{{ formatMessage(messages.loading) }}
|
||||||
|
</div>
|
||||||
|
<p v-else-if="failed" class="m-0 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.failed) }}
|
||||||
|
</p>
|
||||||
|
<p v-else-if="!sorted.length" class="m-0 rounded-xl bg-bg-raised p-4 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.empty) }}
|
||||||
|
</p>
|
||||||
|
<div v-else class="flex flex-col gap-2">
|
||||||
|
<div
|
||||||
|
v-for="item in sorted"
|
||||||
|
:key="item.id"
|
||||||
|
class="flex flex-wrap items-center gap-3 rounded-xl bg-bg-raised p-3"
|
||||||
|
>
|
||||||
|
<span class="shrink-0 text-xs text-secondary">#{{ item.id }}</span>
|
||||||
|
<div class="flex min-w-0 flex-1 flex-col">
|
||||||
|
<span class="truncate text-sm font-semibold text-contrast">{{ item.title }}</span>
|
||||||
|
<span v-if="item.subtitle" class="truncate text-xs text-secondary">
|
||||||
|
{{ item.subtitle }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<span class="shrink-0 text-xs text-secondary">{{ formatDate(item.updateAt) }}</span>
|
||||||
|
<span v-if="item.uploader" class="shrink-0 text-xs text-secondary">
|
||||||
|
{{ formatMessage(messages.uploader, { name: item.uploader }) }}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="shrink-0 rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="openEdit(item)"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.edit) }}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="shrink-0 rounded-full bg-red px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110 disabled:opacity-50"
|
||||||
|
:disabled="deletingId !== null"
|
||||||
|
@click="remove(item)"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.remove) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="editorOpen"
|
||||||
|
class="flex flex-col gap-3 rounded-xl border border-solid border-surface-5 bg-bg-raised p-4"
|
||||||
|
>
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="text-sm font-semibold text-contrast">
|
||||||
|
{{ formatMessage(messages.titleField) }}
|
||||||
|
</span>
|
||||||
|
<input
|
||||||
|
v-model="form.title"
|
||||||
|
type="text"
|
||||||
|
class="rounded-lg border border-solid border-surface-5 bg-bg px-3 py-2 text-sm text-contrast outline-none focus:border-brand"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="text-sm font-semibold text-contrast">
|
||||||
|
{{ formatMessage(messages.subtitleField) }}
|
||||||
|
</span>
|
||||||
|
<input
|
||||||
|
v-model="form.subtitle"
|
||||||
|
type="text"
|
||||||
|
class="rounded-lg border border-solid border-surface-5 bg-bg px-3 py-2 text-sm text-contrast outline-none focus:border-brand"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="text-sm font-semibold text-contrast">
|
||||||
|
{{ formatMessage(messages.contentField) }}
|
||||||
|
</span>
|
||||||
|
<textarea
|
||||||
|
v-model="form.content"
|
||||||
|
rows="5"
|
||||||
|
class="w-full resize-y rounded-lg border border-solid border-surface-5 bg-bg px-3 py-2 text-sm text-contrast outline-none focus:border-brand"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div class="flex flex-wrap items-end gap-3">
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="text-sm font-semibold text-contrast">
|
||||||
|
{{ formatMessage(messages.expireAt) }}
|
||||||
|
</span>
|
||||||
|
<input
|
||||||
|
v-model="form.expireAt"
|
||||||
|
type="datetime-local"
|
||||||
|
class="rounded-lg border border-solid border-surface-5 bg-bg px-3 py-2 text-sm text-contrast outline-none focus:border-brand"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="text-sm font-semibold text-contrast">
|
||||||
|
{{ formatMessage(messages.level) }}
|
||||||
|
</span>
|
||||||
|
<input
|
||||||
|
v-model.number="form.importantLevel"
|
||||||
|
type="number"
|
||||||
|
min="0"
|
||||||
|
max="9"
|
||||||
|
class="w-20 rounded-lg border border-solid border-surface-5 bg-bg px-3 py-2 text-sm text-contrast outline-none focus:border-brand"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label class="flex items-center gap-2 pb-2">
|
||||||
|
<input v-model="form.star" type="checkbox" />
|
||||||
|
<span class="text-sm text-contrast">{{ formatMessage(messages.star) }}</span>
|
||||||
|
</label>
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="text-sm font-semibold text-contrast">
|
||||||
|
{{ formatMessage(messages.image) }}
|
||||||
|
</span>
|
||||||
|
<input type="file" accept="image/*" @change="onImageChange" />
|
||||||
|
</label>
|
||||||
|
<label v-if="editingId !== null" class="flex items-center gap-2 pb-2">
|
||||||
|
<input v-model="removeImage" type="checkbox" />
|
||||||
|
<span class="text-sm text-contrast">{{ formatMessage(messages.removeImage) }}</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex justify-end gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-button-bg px-4 py-2 text-sm font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="closeEditor"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.cancel) }}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-brand px-4 py-2 text-sm font-semibold text-contrast disabled:opacity-50"
|
||||||
|
:disabled="!canSave"
|
||||||
|
@click="save"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.save) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,277 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { SpinnerIcon } from '@modrinth/assets'
|
||||||
|
import { defineMessages, injectNotificationManager, useVIntl } from '@modrinth/ui'
|
||||||
|
import { computed, onMounted, ref } from 'vue'
|
||||||
|
|
||||||
|
import {
|
||||||
|
skinSiteActivateLauncherRelease,
|
||||||
|
type SkinSiteLauncherAdminState,
|
||||||
|
skinSiteLauncherAdminState,
|
||||||
|
type SkinSiteLauncherRelease,
|
||||||
|
skinSiteUploadLauncherRelease,
|
||||||
|
} from '@/helpers/skin-site-api'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError, addNotification } = injectNotificationManager()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.skin-site.admin.launcher.title', defaultMessage: 'Launcher releases' },
|
||||||
|
loading: { id: 'app.skin-site.admin.launcher.loading', defaultMessage: 'Loading…' },
|
||||||
|
failed: {
|
||||||
|
id: 'app.skin-site.admin.launcher.failed',
|
||||||
|
defaultMessage: 'Could not load releases.',
|
||||||
|
},
|
||||||
|
empty: { id: 'app.skin-site.admin.launcher.empty', defaultMessage: 'No releases uploaded yet.' },
|
||||||
|
latestUrl: { id: 'app.skin-site.admin.launcher.latest-url', defaultMessage: 'Latest URL' },
|
||||||
|
version: { id: 'app.skin-site.admin.launcher.version', defaultMessage: 'Version' },
|
||||||
|
channel: { id: 'app.skin-site.admin.launcher.channel', defaultMessage: 'Channel' },
|
||||||
|
uploader: { id: 'app.skin-site.admin.launcher.uploader', defaultMessage: 'Uploaded by' },
|
||||||
|
uploadedAt: { id: 'app.skin-site.admin.launcher.uploaded-at', defaultMessage: 'Uploaded' },
|
||||||
|
publishedAt: { id: 'app.skin-site.admin.launcher.published-at', defaultMessage: 'Published' },
|
||||||
|
forceUpdate: { id: 'app.skin-site.admin.launcher.force-update', defaultMessage: 'Forced' },
|
||||||
|
active: { id: 'app.skin-site.admin.launcher.active', defaultMessage: 'Active' },
|
||||||
|
activate: { id: 'app.skin-site.admin.launcher.activate', defaultMessage: 'Activate' },
|
||||||
|
activated: { id: 'app.skin-site.admin.launcher.activated', defaultMessage: 'Release activated.' },
|
||||||
|
upload: { id: 'app.skin-site.admin.launcher.upload', defaultMessage: 'Upload release' },
|
||||||
|
uploadHint: {
|
||||||
|
id: 'app.skin-site.admin.launcher.upload-hint',
|
||||||
|
defaultMessage: 'Choose a release ZIP (max 4 GiB).',
|
||||||
|
},
|
||||||
|
uploading: { id: 'app.skin-site.admin.launcher.uploading', defaultMessage: 'Uploading…' },
|
||||||
|
uploadDone: {
|
||||||
|
id: 'app.skin-site.admin.launcher.upload-done',
|
||||||
|
defaultMessage: 'Release uploaded.',
|
||||||
|
},
|
||||||
|
forceFlag: {
|
||||||
|
id: 'app.skin-site.admin.launcher.force-flag',
|
||||||
|
defaultMessage: 'Force update',
|
||||||
|
},
|
||||||
|
prev: { id: 'app.skin-site.admin.launcher.prev', defaultMessage: 'Previous' },
|
||||||
|
next: { id: 'app.skin-site.admin.launcher.next', defaultMessage: 'Next' },
|
||||||
|
page: { id: 'app.skin-site.admin.launcher.page', defaultMessage: 'Page {page}' },
|
||||||
|
total: { id: 'app.skin-site.admin.launcher.total', defaultMessage: '{count} releases' },
|
||||||
|
})
|
||||||
|
|
||||||
|
const PAGE_SIZE = 10
|
||||||
|
|
||||||
|
const state = ref<SkinSiteLauncherAdminState | null>(null)
|
||||||
|
const loading = ref(true)
|
||||||
|
const failed = ref(false)
|
||||||
|
const offset = ref(0)
|
||||||
|
|
||||||
|
const uploading = ref(false)
|
||||||
|
const uploadPercent = ref(0)
|
||||||
|
const forceUpdate = ref(false)
|
||||||
|
const fileInput = ref<HTMLInputElement | null>(null)
|
||||||
|
const activatingId = ref<number | null>(null)
|
||||||
|
|
||||||
|
const releases = computed(() => state.value?.releases ?? [])
|
||||||
|
const total = computed(() => releases.value.length)
|
||||||
|
const page = computed(() => Math.floor(offset.value / PAGE_SIZE) + 1)
|
||||||
|
const pageCount = computed(() => Math.max(1, Math.ceil(total.value / PAGE_SIZE)))
|
||||||
|
const hasPrev = computed(() => offset.value > 0)
|
||||||
|
const hasNext = computed(() => offset.value + PAGE_SIZE < total.value)
|
||||||
|
const visible = computed(() => releases.value.slice(offset.value, offset.value + PAGE_SIZE))
|
||||||
|
|
||||||
|
function formatDateTime(ts?: number | null): string {
|
||||||
|
if (!ts) return '—'
|
||||||
|
try {
|
||||||
|
return new Date(ts).toLocaleString()
|
||||||
|
} catch {
|
||||||
|
return '—'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function load() {
|
||||||
|
loading.value = true
|
||||||
|
failed.value = false
|
||||||
|
try {
|
||||||
|
const result = await skinSiteLauncherAdminState()
|
||||||
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
|
state.value = result.payload
|
||||||
|
} catch (error) {
|
||||||
|
failed.value = true
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function prevPage() {
|
||||||
|
if (hasPrev.value) offset.value = Math.max(0, offset.value - PAGE_SIZE)
|
||||||
|
}
|
||||||
|
function nextPage() {
|
||||||
|
if (hasNext.value) offset.value += PAGE_SIZE
|
||||||
|
}
|
||||||
|
|
||||||
|
async function activate(release: SkinSiteLauncherRelease) {
|
||||||
|
if (activatingId.value !== null) return
|
||||||
|
activatingId.value = release.id
|
||||||
|
try {
|
||||||
|
const result = await skinSiteActivateLauncherRelease(release.id)
|
||||||
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
|
addNotification({ type: 'success', title: formatMessage(messages.activated) })
|
||||||
|
await load()
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
activatingId.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function pickFile() {
|
||||||
|
fileInput.value?.click()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onFileChosen(event: Event) {
|
||||||
|
const input = event.target as HTMLInputElement
|
||||||
|
const file = input.files?.[0]
|
||||||
|
input.value = ''
|
||||||
|
if (!file || uploading.value) return
|
||||||
|
uploading.value = true
|
||||||
|
uploadPercent.value = 0
|
||||||
|
try {
|
||||||
|
const result = await skinSiteUploadLauncherRelease(
|
||||||
|
file,
|
||||||
|
forceUpdate.value,
|
||||||
|
(p) => (uploadPercent.value = Math.round(p)),
|
||||||
|
)
|
||||||
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
|
addNotification({ type: 'success', title: formatMessage(messages.uploadDone) })
|
||||||
|
offset.value = 0
|
||||||
|
await load()
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
uploading.value = false
|
||||||
|
uploadPercent.value = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => void load())
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<h2 class="m-0 text-lg font-bold text-contrast">{{ formatMessage(messages.title) }}</h2>
|
||||||
|
<span class="text-xs text-secondary">
|
||||||
|
{{ formatMessage(messages.total, { count: total }) }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="state && state.latestUrl"
|
||||||
|
class="flex flex-wrap items-center gap-2 rounded-xl bg-bg-raised p-3"
|
||||||
|
>
|
||||||
|
<span class="text-xs font-semibold text-contrast">
|
||||||
|
{{ formatMessage(messages.latestUrl) }}
|
||||||
|
</span>
|
||||||
|
<code class="min-w-0 flex-1 truncate text-xs text-secondary">{{ state.latestUrl }}</code>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<input
|
||||||
|
ref="fileInput"
|
||||||
|
type="file"
|
||||||
|
accept=".zip,application/zip"
|
||||||
|
class="hidden"
|
||||||
|
@change="onFileChosen"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-brand px-4 py-2 text-sm font-semibold text-contrast hover:brightness-110 disabled:opacity-50"
|
||||||
|
:disabled="uploading"
|
||||||
|
@click="pickFile"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.upload) }}
|
||||||
|
</button>
|
||||||
|
<label class="flex items-center gap-2 text-xs text-contrast">
|
||||||
|
<input v-model="forceUpdate" type="checkbox" :disabled="uploading" />
|
||||||
|
{{ formatMessage(messages.forceFlag) }}
|
||||||
|
</label>
|
||||||
|
<span class="text-xs text-secondary">{{ formatMessage(messages.uploadHint) }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="uploading" class="flex items-center gap-2 text-sm text-secondary">
|
||||||
|
<SpinnerIcon class="size-4 animate-spin" />
|
||||||
|
{{ formatMessage(messages.uploading) }} {{ uploadPercent }}%
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="loading" class="flex items-center gap-2 text-sm text-secondary">
|
||||||
|
<SpinnerIcon class="size-4 animate-spin" />
|
||||||
|
{{ formatMessage(messages.loading) }}
|
||||||
|
</div>
|
||||||
|
<p v-else-if="failed" class="m-0 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.failed) }}
|
||||||
|
</p>
|
||||||
|
<p v-else-if="!total" class="m-0 rounded-xl bg-bg-raised p-4 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.empty) }}
|
||||||
|
</p>
|
||||||
|
<div v-else class="flex flex-col gap-2">
|
||||||
|
<div
|
||||||
|
v-for="release in visible"
|
||||||
|
:key="release.id"
|
||||||
|
class="flex flex-wrap items-center gap-3 rounded-xl bg-bg-raised p-3"
|
||||||
|
>
|
||||||
|
<div class="flex min-w-0 flex-1 flex-col">
|
||||||
|
<span class="truncate text-sm font-semibold text-contrast">
|
||||||
|
{{ release.version }}
|
||||||
|
<span class="text-xs font-normal text-secondary">#{{ release.id }}</span>
|
||||||
|
</span>
|
||||||
|
<span class="truncate text-xs text-secondary">
|
||||||
|
{{ formatMessage(messages.uploader) }}: {{ release.uploadedBy }} ·
|
||||||
|
{{ formatDateTime(release.uploadedAt) }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<span
|
||||||
|
class="shrink-0 rounded-full bg-button-bg px-2 py-0.5 text-[10px] font-semibold text-secondary"
|
||||||
|
>
|
||||||
|
{{ release.channel }}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-if="release.forceUpdate"
|
||||||
|
class="shrink-0 rounded-full bg-orange px-2 py-0.5 text-[10px] font-semibold text-contrast"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.forceUpdate) }}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-if="release.active"
|
||||||
|
class="shrink-0 rounded-full bg-green px-2 py-0.5 text-[10px] font-semibold text-contrast"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.active) }}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
v-if="!release.active"
|
||||||
|
type="button"
|
||||||
|
class="shrink-0 rounded-full bg-brand px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110 disabled:opacity-50"
|
||||||
|
:disabled="activatingId !== null"
|
||||||
|
@click="activate(release)"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.activate) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-center justify-center gap-3 pt-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110 disabled:opacity-50"
|
||||||
|
:disabled="!hasPrev"
|
||||||
|
@click="prevPage"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.prev) }}
|
||||||
|
</button>
|
||||||
|
<span class="text-xs text-secondary">
|
||||||
|
{{ formatMessage(messages.page, { page }) }} / {{ pageCount }}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110 disabled:opacity-50"
|
||||||
|
:disabled="!hasNext"
|
||||||
|
@click="nextPage"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.next) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,315 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { SpinnerIcon } from '@modrinth/assets'
|
||||||
|
import { defineMessages, injectNotificationManager, useVIntl } from '@modrinth/ui'
|
||||||
|
import { computed, onMounted, ref } from 'vue'
|
||||||
|
|
||||||
|
import {
|
||||||
|
skinSiteAdminDeletePlayer,
|
||||||
|
type SkinSiteAdminPlayer,
|
||||||
|
skinSiteAdminPlayerCount,
|
||||||
|
skinSiteAdminPlayerList,
|
||||||
|
skinSiteAdminUpdatePlayer,
|
||||||
|
} from '@/helpers/skin-site-api'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError, addNotification } = injectNotificationManager()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.skin-site.admin.players.title', defaultMessage: 'Players' },
|
||||||
|
loading: { id: 'app.skin-site.admin.players.loading', defaultMessage: 'Loading…' },
|
||||||
|
failed: { id: 'app.skin-site.admin.players.failed', defaultMessage: 'Could not load players.' },
|
||||||
|
empty: { id: 'app.skin-site.admin.players.empty', defaultMessage: 'No players found.' },
|
||||||
|
search: { id: 'app.skin-site.admin.players.search', defaultMessage: 'Search' },
|
||||||
|
searchName: { id: 'app.skin-site.admin.players.search-name', defaultMessage: 'Name' },
|
||||||
|
searchOwner: { id: 'app.skin-site.admin.players.search-owner', defaultMessage: 'Owner' },
|
||||||
|
searchUuid: { id: 'app.skin-site.admin.players.search-uuid', defaultMessage: 'UUID' },
|
||||||
|
total: { id: 'app.skin-site.admin.players.total', defaultMessage: '{count} players' },
|
||||||
|
prev: { id: 'app.skin-site.admin.players.prev', defaultMessage: 'Previous' },
|
||||||
|
next: { id: 'app.skin-site.admin.players.next', defaultMessage: 'Next' },
|
||||||
|
page: { id: 'app.skin-site.admin.players.page', defaultMessage: 'Page {page}' },
|
||||||
|
name: { id: 'app.skin-site.admin.players.name', defaultMessage: 'Name' },
|
||||||
|
owner: { id: 'app.skin-site.admin.players.owner', defaultMessage: 'Owner' },
|
||||||
|
source: { id: 'app.skin-site.admin.players.source', defaultMessage: 'Source' },
|
||||||
|
legacy: { id: 'app.skin-site.admin.players.legacy', defaultMessage: 'Legacy adapted' },
|
||||||
|
actions: { id: 'app.skin-site.admin.players.actions', defaultMessage: 'Actions' },
|
||||||
|
edit: { id: 'app.skin-site.admin.players.edit', defaultMessage: 'Edit' },
|
||||||
|
save: { id: 'app.skin-site.admin.players.save', defaultMessage: 'Save' },
|
||||||
|
cancel: { id: 'app.skin-site.admin.players.cancel', defaultMessage: 'Cancel' },
|
||||||
|
remove: { id: 'app.skin-site.admin.players.remove', defaultMessage: 'Delete' },
|
||||||
|
updated: { id: 'app.skin-site.admin.players.updated', defaultMessage: 'Player updated.' },
|
||||||
|
deleted: { id: 'app.skin-site.admin.players.deleted', defaultMessage: 'Player deleted.' },
|
||||||
|
confirmDelete: {
|
||||||
|
id: 'app.skin-site.admin.players.confirm-delete',
|
||||||
|
defaultMessage: 'Delete player “{name}”? This cannot be undone.',
|
||||||
|
},
|
||||||
|
mojang: { id: 'app.skin-site.admin.players.mojang', defaultMessage: 'Mojang' },
|
||||||
|
custom: { id: 'app.skin-site.admin.players.custom', defaultMessage: 'Skin site' },
|
||||||
|
})
|
||||||
|
|
||||||
|
const PAGE_SIZE = 20
|
||||||
|
|
||||||
|
const items = ref<SkinSiteAdminPlayer[]>([])
|
||||||
|
const total = ref(0)
|
||||||
|
const offset = ref(0)
|
||||||
|
const loading = ref(true)
|
||||||
|
const failed = ref(false)
|
||||||
|
|
||||||
|
const keyword = ref('')
|
||||||
|
const searchField = ref<'name' | 'ownerUsername' | 'uuid'>('name')
|
||||||
|
|
||||||
|
const editingUuid = ref<string | null>(null)
|
||||||
|
const editName = ref('')
|
||||||
|
const editIsMojang = ref(false)
|
||||||
|
const saving = ref(false)
|
||||||
|
const deletingUuid = ref<string | null>(null)
|
||||||
|
|
||||||
|
const page = computed(() => Math.floor(offset.value / PAGE_SIZE) + 1)
|
||||||
|
const pageCount = computed(() => Math.max(1, Math.ceil(total.value / PAGE_SIZE)))
|
||||||
|
const hasPrev = computed(() => offset.value > 0)
|
||||||
|
const hasNext = computed(() => offset.value + PAGE_SIZE < total.value)
|
||||||
|
|
||||||
|
const SEARCH_FIELDS: Array<'name' | 'ownerUsername' | 'uuid'> = ['name', 'ownerUsername', 'uuid']
|
||||||
|
|
||||||
|
function searchFieldLabel(field: string): string {
|
||||||
|
if (field === 'ownerUsername') return formatMessage(messages.searchOwner)
|
||||||
|
if (field === 'uuid') return formatMessage(messages.searchUuid)
|
||||||
|
return formatMessage(messages.searchName)
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildQuery() {
|
||||||
|
const kw = keyword.value.trim()
|
||||||
|
return {
|
||||||
|
limit: PAGE_SIZE,
|
||||||
|
offset: offset.value,
|
||||||
|
searchField: kw ? searchField.value : undefined,
|
||||||
|
keyword: kw || undefined,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function load(reset = false) {
|
||||||
|
if (reset) offset.value = 0
|
||||||
|
loading.value = true
|
||||||
|
failed.value = false
|
||||||
|
try {
|
||||||
|
const query = buildQuery()
|
||||||
|
const [listResult, countResult] = await Promise.all([
|
||||||
|
skinSiteAdminPlayerList(query),
|
||||||
|
skinSiteAdminPlayerCount(
|
||||||
|
query.keyword ? { searchField: query.searchField, keyword: query.keyword } : undefined,
|
||||||
|
),
|
||||||
|
])
|
||||||
|
if (!listResult.success) throw new Error(listResult.errorMessage)
|
||||||
|
items.value = listResult.payload ?? []
|
||||||
|
if (countResult.success && typeof countResult.payload === 'number') {
|
||||||
|
total.value = countResult.payload
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
failed.value = true
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function prevPage() {
|
||||||
|
if (!hasPrev.value) return
|
||||||
|
offset.value = Math.max(0, offset.value - PAGE_SIZE)
|
||||||
|
await load()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function nextPage() {
|
||||||
|
if (!hasNext.value) return
|
||||||
|
offset.value += PAGE_SIZE
|
||||||
|
await load()
|
||||||
|
}
|
||||||
|
|
||||||
|
function startEdit(player: SkinSiteAdminPlayer) {
|
||||||
|
editingUuid.value = player.uuid
|
||||||
|
editName.value = player.name
|
||||||
|
editIsMojang.value = player.isMojang
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelEdit() {
|
||||||
|
editingUuid.value = null
|
||||||
|
editName.value = ''
|
||||||
|
editIsMojang.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveEdit() {
|
||||||
|
if (!editingUuid.value || saving.value) return
|
||||||
|
saving.value = true
|
||||||
|
try {
|
||||||
|
const result = await skinSiteAdminUpdatePlayer({
|
||||||
|
uuid: editingUuid.value,
|
||||||
|
name: editName.value.trim(),
|
||||||
|
isMojang: editIsMojang.value,
|
||||||
|
})
|
||||||
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
|
addNotification({ type: 'success', title: formatMessage(messages.updated) })
|
||||||
|
cancelEdit()
|
||||||
|
await load()
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
saving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function remove(player: SkinSiteAdminPlayer) {
|
||||||
|
if (deletingUuid.value !== null) return
|
||||||
|
if (!window.confirm(formatMessage(messages.confirmDelete, { name: player.name }))) return
|
||||||
|
deletingUuid.value = player.uuid
|
||||||
|
try {
|
||||||
|
const result = await skinSiteAdminDeletePlayer(player.uuid)
|
||||||
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
|
addNotification({ type: 'success', title: formatMessage(messages.deleted) })
|
||||||
|
await load()
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
deletingUuid.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => void load())
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<h2 class="m-0 text-lg font-bold text-contrast">{{ formatMessage(messages.title) }}</h2>
|
||||||
|
<span class="text-xs text-secondary">
|
||||||
|
{{ formatMessage(messages.total, { count: total }) }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<select
|
||||||
|
v-model="searchField"
|
||||||
|
class="rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast"
|
||||||
|
>
|
||||||
|
<option v-for="f in SEARCH_FIELDS" :key="f" :value="f">
|
||||||
|
{{ searchFieldLabel(f) }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
<input
|
||||||
|
v-model="keyword"
|
||||||
|
type="text"
|
||||||
|
:placeholder="formatMessage(messages.search)"
|
||||||
|
class="min-w-0 flex-1 rounded-full border border-solid border-surface-5 bg-bg px-3 py-1 text-xs text-contrast outline-none focus:border-brand"
|
||||||
|
@keyup.enter="load(true)"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-brand px-4 py-1 text-xs font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="load(true)"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.search) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="loading" class="flex items-center gap-2 text-sm text-secondary">
|
||||||
|
<SpinnerIcon class="size-4 animate-spin" />
|
||||||
|
{{ formatMessage(messages.loading) }}
|
||||||
|
</div>
|
||||||
|
<p v-else-if="failed" class="m-0 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.failed) }}
|
||||||
|
</p>
|
||||||
|
<p v-else-if="!items.length" class="m-0 rounded-xl bg-bg-raised p-4 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.empty) }}
|
||||||
|
</p>
|
||||||
|
<div v-else class="flex flex-col gap-2">
|
||||||
|
<div
|
||||||
|
v-for="player in items"
|
||||||
|
:key="player.uuid"
|
||||||
|
class="flex flex-wrap items-center gap-3 rounded-xl bg-bg-raised p-3"
|
||||||
|
>
|
||||||
|
<div class="flex min-w-0 flex-1 flex-col">
|
||||||
|
<input
|
||||||
|
v-if="editingUuid === player.uuid"
|
||||||
|
v-model="editName"
|
||||||
|
type="text"
|
||||||
|
class="w-full rounded-lg border border-solid border-surface-5 bg-bg px-2 py-1 text-sm text-contrast outline-none focus:border-brand"
|
||||||
|
/>
|
||||||
|
<span v-else class="truncate text-sm font-semibold text-contrast">
|
||||||
|
{{ player.name }}
|
||||||
|
</span>
|
||||||
|
<span class="truncate font-mono text-[10px] text-secondary">{{ player.uuid }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<span class="shrink-0 text-xs text-secondary">{{ player.ownerUsername }}</span>
|
||||||
|
<span
|
||||||
|
class="shrink-0 rounded-full bg-button-bg px-2 py-0.5 text-[10px] font-semibold text-secondary"
|
||||||
|
>
|
||||||
|
{{ player.isMojang ? formatMessage(messages.mojang) : formatMessage(messages.custom) }}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-if="player.legacyInternalAdapted"
|
||||||
|
class="shrink-0 rounded-full bg-yellow px-2 py-0.5 text-[10px] font-semibold text-contrast"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.legacy) }}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<template v-if="editingUuid === player.uuid">
|
||||||
|
<label class="flex shrink-0 items-center gap-1 text-xs text-contrast">
|
||||||
|
<input v-model="editIsMojang" type="checkbox" />
|
||||||
|
{{ formatMessage(messages.mojang) }}
|
||||||
|
</label>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="shrink-0 rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="cancelEdit"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.cancel) }}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="shrink-0 rounded-full bg-brand px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110 disabled:opacity-50"
|
||||||
|
:disabled="saving"
|
||||||
|
@click="saveEdit"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.save) }}
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="shrink-0 rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="startEdit(player)"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.edit) }}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="shrink-0 rounded-full bg-red px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110 disabled:opacity-50"
|
||||||
|
:disabled="deletingUuid !== null"
|
||||||
|
@click="remove(player)"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.remove) }}
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-center justify-center gap-3 pt-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110 disabled:opacity-50"
|
||||||
|
:disabled="!hasPrev"
|
||||||
|
@click="prevPage"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.prev) }}
|
||||||
|
</button>
|
||||||
|
<span class="text-xs text-secondary">
|
||||||
|
{{ formatMessage(messages.page, { page }) }} / {{ pageCount }}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110 disabled:opacity-50"
|
||||||
|
:disabled="!hasNext"
|
||||||
|
@click="nextPage"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.next) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,466 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { SpinnerIcon } from '@modrinth/assets'
|
||||||
|
import { defineMessages, injectNotificationManager, useVIntl } from '@modrinth/ui'
|
||||||
|
import { computed, onMounted, ref } from 'vue'
|
||||||
|
|
||||||
|
import {
|
||||||
|
skinSiteDecideReviewSubmission,
|
||||||
|
skinSiteRegenerateReviewInvite,
|
||||||
|
type SkinSiteReviewResult,
|
||||||
|
type SkinSiteReviewSubmission,
|
||||||
|
skinSiteReviewSubmissionCount,
|
||||||
|
skinSiteReviewSubmissions,
|
||||||
|
} from '@/helpers/skin-site-api'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError, addNotification } = injectNotificationManager()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.skin-site.admin.review.title', defaultMessage: 'Player review' },
|
||||||
|
loading: { id: 'app.skin-site.admin.review.loading', defaultMessage: 'Loading…' },
|
||||||
|
failed: {
|
||||||
|
id: 'app.skin-site.admin.review.failed',
|
||||||
|
defaultMessage: 'Could not load submissions.',
|
||||||
|
},
|
||||||
|
empty: { id: 'app.skin-site.admin.review.empty', defaultMessage: 'No submissions found.' },
|
||||||
|
total: { id: 'app.skin-site.admin.review.total', defaultMessage: '{count} submissions' },
|
||||||
|
filterAll: { id: 'app.skin-site.admin.review.filter-all', defaultMessage: 'All' },
|
||||||
|
filterPending: { id: 'app.skin-site.admin.review.filter-pending', defaultMessage: 'Pending' },
|
||||||
|
filterPassed: { id: 'app.skin-site.admin.review.filter-passed', defaultMessage: 'Passed' },
|
||||||
|
filterRejected: { id: 'app.skin-site.admin.review.filter-rejected', defaultMessage: 'Rejected' },
|
||||||
|
resultPending: { id: 'app.skin-site.admin.review.result-pending', defaultMessage: 'Pending' },
|
||||||
|
resultPassed: { id: 'app.skin-site.admin.review.result-passed', defaultMessage: 'Passed' },
|
||||||
|
resultRejected: { id: 'app.skin-site.admin.review.result-rejected', defaultMessage: 'Rejected' },
|
||||||
|
modeAuto: { id: 'app.skin-site.admin.review.mode-auto', defaultMessage: 'Auto' },
|
||||||
|
modeManual: { id: 'app.skin-site.admin.review.mode-manual', defaultMessage: 'Manual' },
|
||||||
|
applicant: { id: 'app.skin-site.admin.review.applicant', defaultMessage: 'Applicant' },
|
||||||
|
submittedAt: { id: 'app.skin-site.admin.review.submitted-at', defaultMessage: 'Submitted' },
|
||||||
|
score: { id: 'app.skin-site.admin.review.score', defaultMessage: 'Score' },
|
||||||
|
reviewer: { id: 'app.skin-site.admin.review.reviewer', defaultMessage: 'Reviewer' },
|
||||||
|
details: { id: 'app.skin-site.admin.review.details', defaultMessage: 'Details' },
|
||||||
|
hide: { id: 'app.skin-site.admin.review.hide', defaultMessage: 'Hide' },
|
||||||
|
answers: { id: 'app.skin-site.admin.review.answers', defaultMessage: 'Answers' },
|
||||||
|
noAnswers: { id: 'app.skin-site.admin.review.no-answers', defaultMessage: 'No answers.' },
|
||||||
|
autoChecks: { id: 'app.skin-site.admin.review.auto-checks', defaultMessage: 'Automatic checks' },
|
||||||
|
context: { id: 'app.skin-site.admin.review.context', defaultMessage: 'Submission context' },
|
||||||
|
ip: { id: 'app.skin-site.admin.review.ip', defaultMessage: 'IP' },
|
||||||
|
userAgent: { id: 'app.skin-site.admin.review.user-agent', defaultMessage: 'User agent' },
|
||||||
|
activity: { id: 'app.skin-site.admin.review.activity', defaultMessage: 'Activity' },
|
||||||
|
duration: { id: 'app.skin-site.admin.review.duration', defaultMessage: 'Duration' },
|
||||||
|
hiddenTime: { id: 'app.skin-site.admin.review.hidden-time', defaultMessage: 'Hidden time' },
|
||||||
|
screenSwitches: {
|
||||||
|
id: 'app.skin-site.admin.review.screen-switches',
|
||||||
|
defaultMessage: 'Screen switches',
|
||||||
|
},
|
||||||
|
history: { id: 'app.skin-site.admin.review.history', defaultMessage: 'Decision history' },
|
||||||
|
accept: { id: 'app.skin-site.admin.review.accept', defaultMessage: 'Accept' },
|
||||||
|
reject: { id: 'app.skin-site.admin.review.reject', defaultMessage: 'Reject' },
|
||||||
|
reason: { id: 'app.skin-site.admin.review.reason', defaultMessage: 'Reason' },
|
||||||
|
acceptDone: {
|
||||||
|
id: 'app.skin-site.admin.review.accept-done',
|
||||||
|
defaultMessage: 'Submission accepted.',
|
||||||
|
},
|
||||||
|
rejectDone: {
|
||||||
|
id: 'app.skin-site.admin.review.reject-done',
|
||||||
|
defaultMessage: 'Submission rejected.',
|
||||||
|
},
|
||||||
|
regenInvite: {
|
||||||
|
id: 'app.skin-site.admin.review.regen-invite',
|
||||||
|
defaultMessage: 'Regenerate invite',
|
||||||
|
},
|
||||||
|
inviteRegenerated: {
|
||||||
|
id: 'app.skin-site.admin.review.invite-regenerated',
|
||||||
|
defaultMessage: 'Invite code regenerated.',
|
||||||
|
},
|
||||||
|
inviteSent: {
|
||||||
|
id: 'app.skin-site.admin.review.invite-sent',
|
||||||
|
defaultMessage: 'Email sent.',
|
||||||
|
},
|
||||||
|
inviteNotSent: {
|
||||||
|
id: 'app.skin-site.admin.review.invite-not-sent',
|
||||||
|
defaultMessage: 'Email not sent.',
|
||||||
|
},
|
||||||
|
prev: { id: 'app.skin-site.admin.review.prev', defaultMessage: 'Previous' },
|
||||||
|
next: { id: 'app.skin-site.admin.review.next', defaultMessage: 'Next' },
|
||||||
|
page: { id: 'app.skin-site.admin.review.page', defaultMessage: 'Page {page}' },
|
||||||
|
})
|
||||||
|
|
||||||
|
const PAGE_SIZE = 20
|
||||||
|
|
||||||
|
const items = ref<SkinSiteReviewSubmission[]>([])
|
||||||
|
const total = ref(0)
|
||||||
|
const offset = ref(0)
|
||||||
|
const loading = ref(true)
|
||||||
|
const failed = ref(false)
|
||||||
|
|
||||||
|
const filter = ref<'' | SkinSiteReviewResult | 'COMPLETED'>('PENDING')
|
||||||
|
|
||||||
|
const expandedId = ref<number | null>(null)
|
||||||
|
const decisions = ref<Record<number, { reason: string; working: boolean }>>({})
|
||||||
|
|
||||||
|
const page = computed(() => Math.floor(offset.value / PAGE_SIZE) + 1)
|
||||||
|
const pageCount = computed(() => Math.max(1, Math.ceil(total.value / PAGE_SIZE)))
|
||||||
|
const hasPrev = computed(() => offset.value > 0)
|
||||||
|
const hasNext = computed(() => offset.value + PAGE_SIZE < total.value)
|
||||||
|
|
||||||
|
const FILTERS: Array<{ key: '' | SkinSiteReviewResult | 'COMPLETED'; label: () => string }> = [
|
||||||
|
{ key: '', label: () => formatMessage(messages.filterAll) },
|
||||||
|
{ key: 'PENDING', label: () => formatMessage(messages.filterPending) },
|
||||||
|
{ key: 'PASSED', label: () => formatMessage(messages.filterPassed) },
|
||||||
|
{ key: 'REJECTED', label: () => formatMessage(messages.filterRejected) },
|
||||||
|
]
|
||||||
|
|
||||||
|
function resultLabel(result: SkinSiteReviewResult): string {
|
||||||
|
if (result === 'PASSED') return formatMessage(messages.resultPassed)
|
||||||
|
if (result === 'REJECTED') return formatMessage(messages.resultRejected)
|
||||||
|
return formatMessage(messages.resultPending)
|
||||||
|
}
|
||||||
|
|
||||||
|
function resultClass(result: SkinSiteReviewResult): string {
|
||||||
|
if (result === 'PASSED') return 'bg-green text-contrast'
|
||||||
|
if (result === 'REJECTED') return 'bg-red text-contrast'
|
||||||
|
return 'bg-button-bg text-secondary'
|
||||||
|
}
|
||||||
|
|
||||||
|
function modeLabel(mode: string): string {
|
||||||
|
return mode === 'AUTO' ? formatMessage(messages.modeAuto) : formatMessage(messages.modeManual)
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDateTime(ts?: number | null): string {
|
||||||
|
if (!ts) return ''
|
||||||
|
try {
|
||||||
|
return new Date(ts).toLocaleString()
|
||||||
|
} catch {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDuration(ms?: number | null): string {
|
||||||
|
if (!ms || ms < 0) return '—'
|
||||||
|
const totalSeconds = Math.floor(ms / 1000)
|
||||||
|
const m = Math.floor(totalSeconds / 60)
|
||||||
|
const s = totalSeconds % 60
|
||||||
|
return m > 0 ? m + 'm ' + s + 's' : s + 's'
|
||||||
|
}
|
||||||
|
|
||||||
|
function decisionFor(id: number) {
|
||||||
|
if (!decisions.value[id]) decisions.value[id] = { reason: '', working: false }
|
||||||
|
return decisions.value[id]
|
||||||
|
}
|
||||||
|
|
||||||
|
async function load(reset = false) {
|
||||||
|
if (reset) offset.value = 0
|
||||||
|
loading.value = true
|
||||||
|
failed.value = false
|
||||||
|
try {
|
||||||
|
const resultFilter = filter.value || undefined
|
||||||
|
const listResult = await skinSiteReviewSubmissions({
|
||||||
|
result: resultFilter,
|
||||||
|
limit: PAGE_SIZE,
|
||||||
|
offset: offset.value,
|
||||||
|
})
|
||||||
|
if (!listResult.success) throw new Error(listResult.errorMessage)
|
||||||
|
items.value = listResult.payload ?? []
|
||||||
|
const countResult = await skinSiteReviewSubmissionCount({ result: resultFilter })
|
||||||
|
if (countResult.success && typeof countResult.payload === 'number') {
|
||||||
|
total.value = countResult.payload
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
failed.value = true
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setFilter(key: '' | SkinSiteReviewResult | 'COMPLETED') {
|
||||||
|
filter.value = key
|
||||||
|
await load(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function prevPage() {
|
||||||
|
if (!hasPrev.value) return
|
||||||
|
offset.value = Math.max(0, offset.value - PAGE_SIZE)
|
||||||
|
await load()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function nextPage() {
|
||||||
|
if (!hasNext.value) return
|
||||||
|
offset.value += PAGE_SIZE
|
||||||
|
await load()
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleDetails(id: number) {
|
||||||
|
expandedId.value = expandedId.value === id ? null : id
|
||||||
|
}
|
||||||
|
|
||||||
|
async function decide(submission: SkinSiteReviewSubmission, accepted: boolean) {
|
||||||
|
const state = decisionFor(submission.id)
|
||||||
|
if (state.working) return
|
||||||
|
state.working = true
|
||||||
|
try {
|
||||||
|
const result = await skinSiteDecideReviewSubmission(
|
||||||
|
submission.id,
|
||||||
|
accepted,
|
||||||
|
{},
|
||||||
|
submission.revision,
|
||||||
|
state.reason,
|
||||||
|
)
|
||||||
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
|
addNotification({
|
||||||
|
type: 'success',
|
||||||
|
title: formatMessage(accepted ? messages.acceptDone : messages.rejectDone),
|
||||||
|
})
|
||||||
|
expandedId.value = null
|
||||||
|
await load()
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
state.working = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function regenerateInvite(submission: SkinSiteReviewSubmission) {
|
||||||
|
try {
|
||||||
|
const result = await skinSiteRegenerateReviewInvite(submission.id)
|
||||||
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
|
addNotification({
|
||||||
|
type: 'success',
|
||||||
|
title: formatMessage(result.payload.emailSent ? messages.inviteSent : messages.inviteNotSent),
|
||||||
|
})
|
||||||
|
await load()
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => void load())
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<h2 class="m-0 text-lg font-bold text-contrast">{{ formatMessage(messages.title) }}</h2>
|
||||||
|
<span class="text-xs text-secondary">
|
||||||
|
{{ formatMessage(messages.total, { count: total }) }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<button
|
||||||
|
v-for="f in FILTERS"
|
||||||
|
:key="f.key || 'all'"
|
||||||
|
type="button"
|
||||||
|
class="rounded-full px-3 py-1 text-xs font-semibold transition-colors"
|
||||||
|
:class="
|
||||||
|
filter === f.key
|
||||||
|
? 'bg-brand text-contrast'
|
||||||
|
: 'bg-button-bg text-secondary hover:text-contrast'
|
||||||
|
"
|
||||||
|
@click="setFilter(f.key)"
|
||||||
|
>
|
||||||
|
{{ f.label() }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="loading" class="flex items-center gap-2 text-sm text-secondary">
|
||||||
|
<SpinnerIcon class="size-4 animate-spin" />
|
||||||
|
{{ formatMessage(messages.loading) }}
|
||||||
|
</div>
|
||||||
|
<p v-else-if="failed" class="m-0 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.failed) }}
|
||||||
|
</p>
|
||||||
|
<p v-else-if="!items.length" class="m-0 rounded-xl bg-bg-raised p-4 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.empty) }}
|
||||||
|
</p>
|
||||||
|
<div v-else class="flex flex-col gap-2">
|
||||||
|
<div
|
||||||
|
v-for="submission in items"
|
||||||
|
:key="submission.id"
|
||||||
|
class="flex flex-col gap-2 rounded-xl bg-bg-raised p-3"
|
||||||
|
>
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<span class="shrink-0 text-xs text-secondary">#{{ submission.id }}</span>
|
||||||
|
<span class="min-w-0 flex-1 truncate text-sm font-semibold text-contrast">
|
||||||
|
{{ submission.applicantName }}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
class="shrink-0 rounded-full px-2 py-0.5 text-[10px] font-semibold"
|
||||||
|
:class="resultClass(submission.result)"
|
||||||
|
>
|
||||||
|
{{ resultLabel(submission.result) }}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
class="shrink-0 rounded-full bg-button-bg px-2 py-0.5 text-[10px] font-semibold text-secondary"
|
||||||
|
>
|
||||||
|
{{ modeLabel(submission.mode) }}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-if="submission.score !== null && submission.score !== undefined"
|
||||||
|
class="shrink-0 text-xs font-semibold text-contrast"
|
||||||
|
>
|
||||||
|
{{ submission.score }}
|
||||||
|
</span>
|
||||||
|
<span class="shrink-0 text-xs text-secondary">
|
||||||
|
{{ formatDateTime(submission.createdAt) }}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="shrink-0 rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="toggleDetails(submission.id)"
|
||||||
|
>
|
||||||
|
{{
|
||||||
|
expandedId === submission.id
|
||||||
|
? formatMessage(messages.hide)
|
||||||
|
: formatMessage(messages.details)
|
||||||
|
}}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="expandedId === submission.id"
|
||||||
|
class="flex flex-col gap-3 border-t border-solid border-surface-5 pt-3"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-if="submission.context"
|
||||||
|
class="flex flex-col gap-1 rounded-lg bg-bg p-3 text-xs text-secondary"
|
||||||
|
>
|
||||||
|
<span class="font-semibold text-contrast">
|
||||||
|
{{ formatMessage(messages.context) }}
|
||||||
|
</span>
|
||||||
|
<span>{{ formatMessage(messages.ip) }}: {{ submission.context.ip ?? '—' }}</span>
|
||||||
|
<span class="break-all">
|
||||||
|
{{ formatMessage(messages.userAgent) }}: {{ submission.context.userAgent }}
|
||||||
|
</span>
|
||||||
|
<span v-if="submission.context.activity">
|
||||||
|
{{ formatMessage(messages.duration) }}:
|
||||||
|
{{ formatDuration(submission.context.activity.durationMs) }} ·
|
||||||
|
{{ formatMessage(messages.hiddenTime) }}:
|
||||||
|
{{ formatDuration(submission.context.activity.hiddenMs) }} ·
|
||||||
|
{{ formatMessage(messages.screenSwitches) }}:
|
||||||
|
{{ submission.context.activity.screenSwitches }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-1">
|
||||||
|
<span class="text-xs font-semibold text-contrast">
|
||||||
|
{{ formatMessage(messages.answers) }}
|
||||||
|
</span>
|
||||||
|
<p
|
||||||
|
v-if="!submission.answers || !submission.answers.length"
|
||||||
|
class="m-0 text-xs text-secondary"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.noAnswers) }}
|
||||||
|
</p>
|
||||||
|
<div v-else class="flex flex-col gap-1.5">
|
||||||
|
<div
|
||||||
|
v-for="(answer, idx) in submission.answers"
|
||||||
|
:key="answer.id || idx"
|
||||||
|
class="rounded-lg bg-bg p-2 text-xs text-secondary"
|
||||||
|
>
|
||||||
|
<span class="text-contrast">
|
||||||
|
{{ answer.text ?? (answer.values ? answer.values.join(', ') : '—') }}
|
||||||
|
</span>
|
||||||
|
<span v-if="answer.score !== null && answer.score !== undefined">
|
||||||
|
· {{ formatMessage(messages.score) }}: {{ answer.score }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="Object.keys(submission.automaticResults || {}).length"
|
||||||
|
class="flex flex-col gap-1"
|
||||||
|
>
|
||||||
|
<span class="text-xs font-semibold text-contrast">
|
||||||
|
{{ formatMessage(messages.autoChecks) }}
|
||||||
|
</span>
|
||||||
|
<div class="flex flex-wrap gap-2">
|
||||||
|
<span
|
||||||
|
v-for="(passed, key) in submission.automaticResults"
|
||||||
|
:key="key"
|
||||||
|
class="rounded-full px-2 py-0.5 text-[10px] font-semibold"
|
||||||
|
:class="passed ? 'bg-green text-contrast' : 'bg-red text-contrast'"
|
||||||
|
>
|
||||||
|
{{ key }}: {{ passed ? '✓' : '✗' }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="submission.decisionHistory && submission.decisionHistory.length"
|
||||||
|
class="flex flex-col gap-1"
|
||||||
|
>
|
||||||
|
<span class="text-xs font-semibold text-contrast">
|
||||||
|
{{ formatMessage(messages.history) }}
|
||||||
|
</span>
|
||||||
|
<div
|
||||||
|
v-for="(h, idx) in submission.decisionHistory"
|
||||||
|
:key="idx"
|
||||||
|
class="rounded-lg bg-bg p-2 text-xs text-secondary"
|
||||||
|
>
|
||||||
|
{{ h.reviewer }} · {{ resultLabel(h.result) }} ·
|
||||||
|
{{ formatDateTime(h.at) }}
|
||||||
|
<span v-if="h.reason"> · {{ h.reason }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-2">
|
||||||
|
<input
|
||||||
|
v-model="decisionFor(submission.id).reason"
|
||||||
|
type="text"
|
||||||
|
:placeholder="formatMessage(messages.reason)"
|
||||||
|
class="rounded-lg border border-solid border-surface-5 bg-bg px-3 py-1.5 text-sm text-contrast outline-none focus:border-brand"
|
||||||
|
/>
|
||||||
|
<div class="flex flex-wrap gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-green px-4 py-1.5 text-xs font-semibold text-contrast hover:brightness-110 disabled:opacity-50"
|
||||||
|
:disabled="decisionFor(submission.id).working || submission.result === 'PASSED'"
|
||||||
|
@click="decide(submission, true)"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.accept) }}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-red px-4 py-1.5 text-xs font-semibold text-contrast hover:brightness-110 disabled:opacity-50"
|
||||||
|
:disabled="decisionFor(submission.id).working || submission.result === 'REJECTED'"
|
||||||
|
@click="decide(submission, false)"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.reject) }}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-button-bg px-4 py-1.5 text-xs font-semibold text-secondary hover:brightness-110"
|
||||||
|
@click="regenerateInvite(submission)"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.regenInvite) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-center justify-center gap-3 pt-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110 disabled:opacity-50"
|
||||||
|
:disabled="!hasPrev"
|
||||||
|
@click="prevPage"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.prev) }}
|
||||||
|
</button>
|
||||||
|
<span class="text-xs text-secondary">
|
||||||
|
{{ formatMessage(messages.page, { page }) }} / {{ pageCount }}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110 disabled:opacity-50"
|
||||||
|
:disabled="!hasNext"
|
||||||
|
@click="nextPage"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.next) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { SpinnerIcon } from '@modrinth/assets'
|
||||||
|
import { defineMessages, injectNotificationManager, useVIntl } from '@modrinth/ui'
|
||||||
|
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||||
|
|
||||||
|
import { type SkinSiteAdminStatus, skinSiteAdminStatus } from '@/helpers/skin-site-api'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError } = injectNotificationManager()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.skin-site.admin.summary.title', defaultMessage: 'System overview' },
|
||||||
|
loading: { id: 'app.skin-site.admin.summary.loading', defaultMessage: 'Loading…' },
|
||||||
|
failed: { id: 'app.skin-site.admin.summary.failed', defaultMessage: 'Could not load status.' },
|
||||||
|
uptime: { id: 'app.skin-site.admin.summary.uptime', defaultMessage: 'Uptime' },
|
||||||
|
memory: { id: 'app.skin-site.admin.summary.memory', defaultMessage: 'Memory usage' },
|
||||||
|
users: { id: 'app.skin-site.admin.summary.users', defaultMessage: 'Users' },
|
||||||
|
players: { id: 'app.skin-site.admin.summary.players', defaultMessage: 'Players' },
|
||||||
|
realtimeHint: {
|
||||||
|
id: 'app.skin-site.admin.summary.realtime-hint',
|
||||||
|
defaultMessage:
|
||||||
|
'Live CPU and GC charts require the admin WebSocket, which is not connected yet.',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const status = ref<SkinSiteAdminStatus | null>(null)
|
||||||
|
const loading = ref(true)
|
||||||
|
const failed = ref(false)
|
||||||
|
const now = ref(Date.now())
|
||||||
|
let ticker: number | undefined
|
||||||
|
|
||||||
|
const uptime = computed(() => {
|
||||||
|
if (!status.value) return ''
|
||||||
|
let ms = now.value - status.value.bootTime
|
||||||
|
if (ms < 0) ms = 0
|
||||||
|
const totalSeconds = Math.floor(ms / 1000)
|
||||||
|
const days = Math.floor(totalSeconds / 86400)
|
||||||
|
const hours = Math.floor((totalSeconds % 86400) / 3600)
|
||||||
|
const minutes = Math.floor((totalSeconds % 3600) / 60)
|
||||||
|
const seconds = totalSeconds % 60
|
||||||
|
const parts: string[] = []
|
||||||
|
if (days) parts.push(days + 'd')
|
||||||
|
if (hours) parts.push(hours + 'h')
|
||||||
|
if (minutes) parts.push(minutes + 'm')
|
||||||
|
parts.push(seconds + 's')
|
||||||
|
return parts.join(' ')
|
||||||
|
})
|
||||||
|
|
||||||
|
function formatSize(bytes: number): string {
|
||||||
|
if (!Number.isFinite(bytes) || bytes < 0) return '—'
|
||||||
|
const units = ['B', 'KB', 'MB', 'GB', 'TB']
|
||||||
|
let value = bytes
|
||||||
|
let idx = 0
|
||||||
|
while (value >= 1024 && idx < units.length - 1) {
|
||||||
|
value /= 1024
|
||||||
|
idx++
|
||||||
|
}
|
||||||
|
return value.toFixed(idx === 0 ? 0 : 2) + ' ' + units[idx]
|
||||||
|
}
|
||||||
|
|
||||||
|
async function load() {
|
||||||
|
loading.value = true
|
||||||
|
failed.value = false
|
||||||
|
try {
|
||||||
|
const result = await skinSiteAdminStatus()
|
||||||
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
|
status.value = result.payload
|
||||||
|
} catch (error) {
|
||||||
|
failed.value = true
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
void load()
|
||||||
|
ticker = window.setInterval(() => {
|
||||||
|
now.value = Date.now()
|
||||||
|
}, 1000)
|
||||||
|
})
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
if (ticker) clearInterval(ticker)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<h2 class="m-0 text-lg font-bold text-contrast">{{ formatMessage(messages.title) }}</h2>
|
||||||
|
|
||||||
|
<div v-if="loading" class="flex items-center gap-2 text-sm text-secondary">
|
||||||
|
<SpinnerIcon class="size-4 animate-spin" />
|
||||||
|
{{ formatMessage(messages.loading) }}
|
||||||
|
</div>
|
||||||
|
<p v-else-if="failed" class="m-0 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.failed) }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<template v-else-if="status">
|
||||||
|
<div class="grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4">
|
||||||
|
<div class="flex flex-col gap-1 rounded-xl bg-bg-raised p-4">
|
||||||
|
<span class="text-xs text-secondary">{{ formatMessage(messages.uptime) }}</span>
|
||||||
|
<span class="text-xl font-bold text-contrast">{{ uptime }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col gap-1 rounded-xl bg-bg-raised p-4">
|
||||||
|
<span class="text-xs text-secondary">{{ formatMessage(messages.memory) }}</span>
|
||||||
|
<span class="text-xl font-bold text-contrast">{{ formatSize(status.memoryUsage) }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col gap-1 rounded-xl bg-bg-raised p-4">
|
||||||
|
<span class="text-xs text-secondary">{{ formatMessage(messages.users) }}</span>
|
||||||
|
<span class="text-xl font-bold text-contrast">{{ status.userCount }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col gap-1 rounded-xl bg-bg-raised p-4">
|
||||||
|
<span class="text-xs text-secondary">{{ formatMessage(messages.players) }}</span>
|
||||||
|
<span class="text-xl font-bold text-contrast">{{ status.playerCount }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p class="m-0 rounded-xl border border-dashed border-surface-5 p-3 text-xs text-secondary">
|
||||||
|
{{ formatMessage(messages.realtimeHint) }}
|
||||||
|
</p>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,468 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { SpinnerIcon } from '@modrinth/assets'
|
||||||
|
import { defineMessages, injectNotificationManager, useVIntl } from '@modrinth/ui'
|
||||||
|
import { computed, onMounted, ref } from 'vue'
|
||||||
|
|
||||||
|
import {
|
||||||
|
skinSiteAdminDeleteUser,
|
||||||
|
type SkinSiteAdminPlayer,
|
||||||
|
skinSiteAdminUpdateUser,
|
||||||
|
type SkinSiteAdminUser,
|
||||||
|
skinSiteAdminUserCount,
|
||||||
|
skinSiteAdminUserList,
|
||||||
|
skinSiteAdminUserPlayers,
|
||||||
|
} from '@/helpers/skin-site-api'
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
const { handleError, addNotification } = injectNotificationManager()
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.skin-site.admin.users.title', defaultMessage: 'Users' },
|
||||||
|
loading: { id: 'app.skin-site.admin.users.loading', defaultMessage: 'Loading…' },
|
||||||
|
failed: { id: 'app.skin-site.admin.users.failed', defaultMessage: 'Could not load users.' },
|
||||||
|
empty: { id: 'app.skin-site.admin.users.empty', defaultMessage: 'No users found.' },
|
||||||
|
search: { id: 'app.skin-site.admin.users.search', defaultMessage: 'Search' },
|
||||||
|
searchName: { id: 'app.skin-site.admin.users.search-name', defaultMessage: 'Username' },
|
||||||
|
searchEmail: { id: 'app.skin-site.admin.users.search-email', defaultMessage: 'Email' },
|
||||||
|
searchUuid: { id: 'app.skin-site.admin.users.search-uuid', defaultMessage: 'UUID' },
|
||||||
|
total: { id: 'app.skin-site.admin.users.total', defaultMessage: '{count} users' },
|
||||||
|
prev: { id: 'app.skin-site.admin.users.prev', defaultMessage: 'Previous' },
|
||||||
|
next: { id: 'app.skin-site.admin.users.next', defaultMessage: 'Next' },
|
||||||
|
page: { id: 'app.skin-site.admin.users.page', defaultMessage: 'Page {page}' },
|
||||||
|
edit: { id: 'app.skin-site.admin.users.edit', defaultMessage: 'Edit' },
|
||||||
|
save: { id: 'app.skin-site.admin.users.save', defaultMessage: 'Save' },
|
||||||
|
cancel: { id: 'app.skin-site.admin.users.cancel', defaultMessage: 'Cancel' },
|
||||||
|
remove: { id: 'app.skin-site.admin.users.remove', defaultMessage: 'Delete' },
|
||||||
|
players: { id: 'app.skin-site.admin.users.players', defaultMessage: 'Players' },
|
||||||
|
updated: { id: 'app.skin-site.admin.users.updated', defaultMessage: 'User updated.' },
|
||||||
|
deleted: { id: 'app.skin-site.admin.users.deleted', defaultMessage: 'User deleted.' },
|
||||||
|
confirmDelete: {
|
||||||
|
id: 'app.skin-site.admin.users.confirm-delete',
|
||||||
|
defaultMessage: 'Delete user “{name}”? This cannot be undone.',
|
||||||
|
},
|
||||||
|
username: { id: 'app.skin-site.admin.users.username', defaultMessage: 'Username' },
|
||||||
|
email: { id: 'app.skin-site.admin.users.email', defaultMessage: 'Email' },
|
||||||
|
qq: { id: 'app.skin-site.admin.users.qq', defaultMessage: 'QQ' },
|
||||||
|
password: { id: 'app.skin-site.admin.users.password', defaultMessage: 'New password' },
|
||||||
|
passwordHint: {
|
||||||
|
id: 'app.skin-site.admin.users.password-hint',
|
||||||
|
defaultMessage: 'Leave empty to keep the current password.',
|
||||||
|
},
|
||||||
|
banned: { id: 'app.skin-site.admin.users.banned', defaultMessage: 'Banned' },
|
||||||
|
permissions: { id: 'app.skin-site.admin.users.permissions', defaultMessage: 'Permissions' },
|
||||||
|
permissionsHint: {
|
||||||
|
id: 'app.skin-site.admin.users.permissions-hint',
|
||||||
|
defaultMessage: 'Comma separated, e.g. WEB_ADMIN, SERVER_ADMIN.',
|
||||||
|
},
|
||||||
|
noPlayers: { id: 'app.skin-site.admin.users.no-players', defaultMessage: 'No linked players.' },
|
||||||
|
registered: { id: 'app.skin-site.admin.users.registered', defaultMessage: 'Registered' },
|
||||||
|
})
|
||||||
|
|
||||||
|
const PAGE_SIZE = 20
|
||||||
|
|
||||||
|
const items = ref<SkinSiteAdminUser[]>([])
|
||||||
|
const total = ref(0)
|
||||||
|
const offset = ref(0)
|
||||||
|
const loading = ref(true)
|
||||||
|
const failed = ref(false)
|
||||||
|
|
||||||
|
const keyword = ref('')
|
||||||
|
const searchField = ref<'username' | 'email' | 'uuid'>('username')
|
||||||
|
|
||||||
|
const editingUuid = ref<string | null>(null)
|
||||||
|
const editForm = ref({
|
||||||
|
username: '',
|
||||||
|
email: '',
|
||||||
|
qq: '',
|
||||||
|
password: '',
|
||||||
|
banned: false,
|
||||||
|
permissions: '',
|
||||||
|
})
|
||||||
|
const saving = ref(false)
|
||||||
|
const deletingUuid = ref<string | null>(null)
|
||||||
|
|
||||||
|
const playersFor = ref<SkinSiteAdminPlayer[] | null>(null)
|
||||||
|
const playersLoading = ref(false)
|
||||||
|
const playersUuid = ref<string | null>(null)
|
||||||
|
|
||||||
|
const page = computed(() => Math.floor(offset.value / PAGE_SIZE) + 1)
|
||||||
|
const pageCount = computed(() => Math.max(1, Math.ceil(total.value / PAGE_SIZE)))
|
||||||
|
const hasPrev = computed(() => offset.value > 0)
|
||||||
|
const hasNext = computed(() => offset.value + PAGE_SIZE < total.value)
|
||||||
|
|
||||||
|
const SEARCH_FIELDS: Array<'username' | 'email' | 'uuid'> = ['username', 'email', 'uuid']
|
||||||
|
|
||||||
|
function searchFieldLabel(field: string): string {
|
||||||
|
if (field === 'email') return formatMessage(messages.searchEmail)
|
||||||
|
if (field === 'uuid') return formatMessage(messages.searchUuid)
|
||||||
|
return formatMessage(messages.searchName)
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDate(ts: number): string {
|
||||||
|
try {
|
||||||
|
return new Date(ts).toLocaleDateString()
|
||||||
|
} catch {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function load(reset = false) {
|
||||||
|
if (reset) offset.value = 0
|
||||||
|
loading.value = true
|
||||||
|
failed.value = false
|
||||||
|
try {
|
||||||
|
const kw = keyword.value.trim()
|
||||||
|
const listResult = await skinSiteAdminUserList({
|
||||||
|
limit: PAGE_SIZE,
|
||||||
|
offset: offset.value,
|
||||||
|
searchField: kw ? searchField.value : undefined,
|
||||||
|
keyword: kw || undefined,
|
||||||
|
})
|
||||||
|
if (!listResult.success) throw new Error(listResult.errorMessage)
|
||||||
|
items.value = listResult.payload ?? []
|
||||||
|
const countResult = await skinSiteAdminUserCount(
|
||||||
|
kw ? { searchField: searchField.value, keyword: kw } : undefined,
|
||||||
|
)
|
||||||
|
if (countResult.success && typeof countResult.payload === 'number') {
|
||||||
|
total.value = countResult.payload
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
failed.value = true
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function prevPage() {
|
||||||
|
if (!hasPrev.value) return
|
||||||
|
offset.value = Math.max(0, offset.value - PAGE_SIZE)
|
||||||
|
await load()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function nextPage() {
|
||||||
|
if (!hasNext.value) return
|
||||||
|
offset.value += PAGE_SIZE
|
||||||
|
await load()
|
||||||
|
}
|
||||||
|
|
||||||
|
function startEdit(user: SkinSiteAdminUser) {
|
||||||
|
editingUuid.value = user.uuid
|
||||||
|
editForm.value = {
|
||||||
|
username: user.username,
|
||||||
|
email: user.email,
|
||||||
|
qq: user.qq === undefined || user.qq === null ? '' : String(user.qq),
|
||||||
|
password: '',
|
||||||
|
banned: user.banned,
|
||||||
|
permissions: user.permissions.join(', '),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelEdit() {
|
||||||
|
editingUuid.value = null
|
||||||
|
editForm.value = {
|
||||||
|
username: '',
|
||||||
|
email: '',
|
||||||
|
qq: '',
|
||||||
|
password: '',
|
||||||
|
banned: false,
|
||||||
|
permissions: '',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveEdit() {
|
||||||
|
if (!editingUuid.value || saving.value) return
|
||||||
|
saving.value = true
|
||||||
|
try {
|
||||||
|
const qqText = editForm.value.qq.trim()
|
||||||
|
const permissions = editForm.value.permissions
|
||||||
|
.split(',')
|
||||||
|
.map((p) => p.trim())
|
||||||
|
.filter(Boolean)
|
||||||
|
const result = await skinSiteAdminUpdateUser({
|
||||||
|
uuid: editingUuid.value,
|
||||||
|
username: editForm.value.username.trim(),
|
||||||
|
email: editForm.value.email.trim(),
|
||||||
|
qq: qqText ? Number(qqText) : undefined,
|
||||||
|
password: editForm.value.password ? editForm.value.password : undefined,
|
||||||
|
banned: editForm.value.banned,
|
||||||
|
permissions,
|
||||||
|
})
|
||||||
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
|
addNotification({ type: 'success', title: formatMessage(messages.updated) })
|
||||||
|
cancelEdit()
|
||||||
|
await load()
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
saving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function remove(user: SkinSiteAdminUser) {
|
||||||
|
if (deletingUuid.value !== null) return
|
||||||
|
if (!window.confirm(formatMessage(messages.confirmDelete, { name: user.username }))) return
|
||||||
|
deletingUuid.value = user.uuid
|
||||||
|
try {
|
||||||
|
const result = await skinSiteAdminDeleteUser(user.uuid)
|
||||||
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
|
addNotification({ type: 'success', title: formatMessage(messages.deleted) })
|
||||||
|
await load()
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
deletingUuid.value = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function togglePlayers(user: SkinSiteAdminUser) {
|
||||||
|
if (playersUuid.value === user.uuid) {
|
||||||
|
playersUuid.value = null
|
||||||
|
playersFor.value = null
|
||||||
|
return
|
||||||
|
}
|
||||||
|
playersUuid.value = user.uuid
|
||||||
|
playersLoading.value = true
|
||||||
|
playersFor.value = null
|
||||||
|
try {
|
||||||
|
const result = await skinSiteAdminUserPlayers(user.uuid)
|
||||||
|
if (result.success) {
|
||||||
|
playersFor.value = result.payload ?? []
|
||||||
|
} else {
|
||||||
|
playersFor.value = []
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
playersFor.value = []
|
||||||
|
handleError(error)
|
||||||
|
} finally {
|
||||||
|
playersLoading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => void load())
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<h2 class="m-0 text-lg font-bold text-contrast">{{ formatMessage(messages.title) }}</h2>
|
||||||
|
<span class="text-xs text-secondary">
|
||||||
|
{{ formatMessage(messages.total, { count: total }) }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<select
|
||||||
|
v-model="searchField"
|
||||||
|
class="rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast"
|
||||||
|
>
|
||||||
|
<option v-for="f in SEARCH_FIELDS" :key="f" :value="f">
|
||||||
|
{{ searchFieldLabel(f) }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
<input
|
||||||
|
v-model="keyword"
|
||||||
|
type="text"
|
||||||
|
:placeholder="formatMessage(messages.search)"
|
||||||
|
class="min-w-0 flex-1 rounded-full border border-solid border-surface-5 bg-bg px-3 py-1 text-xs text-contrast outline-none focus:border-brand"
|
||||||
|
@keyup.enter="load(true)"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-brand px-4 py-1 text-xs font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="load(true)"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.search) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="loading" class="flex items-center gap-2 text-sm text-secondary">
|
||||||
|
<SpinnerIcon class="size-4 animate-spin" />
|
||||||
|
{{ formatMessage(messages.loading) }}
|
||||||
|
</div>
|
||||||
|
<p v-else-if="failed" class="m-0 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.failed) }}
|
||||||
|
</p>
|
||||||
|
<p v-else-if="!items.length" class="m-0 rounded-xl bg-bg-raised p-4 text-sm text-secondary">
|
||||||
|
{{ formatMessage(messages.empty) }}
|
||||||
|
</p>
|
||||||
|
<div v-else class="flex flex-col gap-2">
|
||||||
|
<div
|
||||||
|
v-for="user in items"
|
||||||
|
:key="user.uuid"
|
||||||
|
class="flex flex-col gap-2 rounded-xl bg-bg-raised p-3"
|
||||||
|
>
|
||||||
|
<div class="flex flex-wrap items-center gap-3">
|
||||||
|
<div class="flex min-w-0 flex-1 flex-col">
|
||||||
|
<span class="truncate text-sm font-semibold text-contrast">
|
||||||
|
{{ user.username }}
|
||||||
|
<span class="text-xs font-normal text-secondary">#{{ user.id }}</span>
|
||||||
|
</span>
|
||||||
|
<span class="truncate text-xs text-secondary">{{ user.email }}</span>
|
||||||
|
<span class="truncate font-mono text-[10px] text-secondary">{{ user.uuid }}</span>
|
||||||
|
</div>
|
||||||
|
<span
|
||||||
|
v-if="user.banned"
|
||||||
|
class="shrink-0 rounded-full bg-red px-2 py-0.5 text-[10px] font-semibold text-contrast"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.banned) }}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-for="perm in user.permissions"
|
||||||
|
:key="perm"
|
||||||
|
class="shrink-0 rounded-full bg-button-bg px-2 py-0.5 text-[10px] font-semibold text-secondary"
|
||||||
|
>
|
||||||
|
{{ perm }}
|
||||||
|
</span>
|
||||||
|
<span class="shrink-0 text-xs text-secondary">
|
||||||
|
{{ formatDate(user.registerTime) }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<template v-if="editingUuid === user.uuid">
|
||||||
|
<div class="grid grid-cols-1 gap-2 sm:grid-cols-2">
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="text-xs font-semibold text-contrast">
|
||||||
|
{{ formatMessage(messages.username) }}
|
||||||
|
</span>
|
||||||
|
<input
|
||||||
|
v-model="editForm.username"
|
||||||
|
type="text"
|
||||||
|
class="rounded-lg border border-solid border-surface-5 bg-bg px-2 py-1 text-sm text-contrast outline-none focus:border-brand"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="text-xs font-semibold text-contrast">
|
||||||
|
{{ formatMessage(messages.email) }}
|
||||||
|
</span>
|
||||||
|
<input
|
||||||
|
v-model="editForm.email"
|
||||||
|
type="email"
|
||||||
|
class="rounded-lg border border-solid border-surface-5 bg-bg px-2 py-1 text-sm text-contrast outline-none focus:border-brand"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="text-xs font-semibold text-contrast">
|
||||||
|
{{ formatMessage(messages.qq) }}
|
||||||
|
</span>
|
||||||
|
<input
|
||||||
|
v-model="editForm.qq"
|
||||||
|
type="text"
|
||||||
|
inputmode="numeric"
|
||||||
|
class="rounded-lg border border-solid border-surface-5 bg-bg px-2 py-1 text-sm text-contrast outline-none focus:border-brand"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label class="flex flex-col gap-1">
|
||||||
|
<span class="text-xs font-semibold text-contrast">
|
||||||
|
{{ formatMessage(messages.password) }}
|
||||||
|
</span>
|
||||||
|
<input
|
||||||
|
v-model="editForm.password"
|
||||||
|
type="password"
|
||||||
|
:placeholder="formatMessage(messages.passwordHint)"
|
||||||
|
class="rounded-lg border border-solid border-surface-5 bg-bg px-2 py-1 text-sm text-contrast outline-none focus:border-brand"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label class="flex flex-col gap-1 sm:col-span-2">
|
||||||
|
<span class="text-xs font-semibold text-contrast">
|
||||||
|
{{ formatMessage(messages.permissions) }}
|
||||||
|
</span>
|
||||||
|
<input
|
||||||
|
v-model="editForm.permissions"
|
||||||
|
type="text"
|
||||||
|
:placeholder="formatMessage(messages.permissionsHint)"
|
||||||
|
class="rounded-lg border border-solid border-surface-5 bg-bg px-2 py-1 text-sm text-contrast outline-none focus:border-brand"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
<label class="flex items-center gap-2">
|
||||||
|
<input v-model="editForm.banned" type="checkbox" />
|
||||||
|
<span class="text-sm text-contrast">{{ formatMessage(messages.banned) }}</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-end gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="cancelEdit"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.cancel) }}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-brand px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110 disabled:opacity-50"
|
||||||
|
:disabled="saving"
|
||||||
|
@click="saveEdit"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.save) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-else>
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="startEdit(user)"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.edit) }}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110"
|
||||||
|
@click="togglePlayers(user)"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.players) }}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-red px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110 disabled:opacity-50"
|
||||||
|
:disabled="deletingUuid !== null"
|
||||||
|
@click="remove(user)"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.remove) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="playersUuid === user.uuid" class="flex flex-wrap gap-2 pt-1">
|
||||||
|
<div v-if="playersLoading" class="flex items-center gap-2 text-xs text-secondary">
|
||||||
|
<SpinnerIcon class="size-3 animate-spin" />
|
||||||
|
{{ formatMessage(messages.loading) }}
|
||||||
|
</div>
|
||||||
|
<span v-else-if="!playersFor || !playersFor.length" class="text-xs text-secondary">
|
||||||
|
{{ formatMessage(messages.noPlayers) }}
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
v-for="p in playersFor ?? []"
|
||||||
|
:key="p.uuid"
|
||||||
|
class="rounded-full bg-button-bg px-2 py-0.5 text-[10px] font-semibold text-contrast"
|
||||||
|
>
|
||||||
|
{{ p.name }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-center justify-center gap-3 pt-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110 disabled:opacity-50"
|
||||||
|
:disabled="!hasPrev"
|
||||||
|
@click="prevPage"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.prev) }}
|
||||||
|
</button>
|
||||||
|
<span class="text-xs text-secondary">
|
||||||
|
{{ formatMessage(messages.page, { page }) }} / {{ pageCount }}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full bg-button-bg px-3 py-1 text-xs font-semibold text-contrast hover:brightness-110 disabled:opacity-50"
|
||||||
|
:disabled="!hasNext"
|
||||||
|
@click="nextPage"
|
||||||
|
>
|
||||||
|
{{ formatMessage(messages.next) }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { CheckIcon, RotateCounterClockwiseIcon, XIcon } from '@modrinth/assets'
|
||||||
|
import {
|
||||||
|
type ArmorPreviewConfig,
|
||||||
|
ArmorTrimPanel,
|
||||||
|
Button,
|
||||||
|
defineMessages,
|
||||||
|
useVIntl,
|
||||||
|
} from '@modrinth/ui'
|
||||||
|
import { computed, onMounted, onUnmounted } from 'vue'
|
||||||
|
|
||||||
|
const messages = defineMessages({
|
||||||
|
title: { id: 'app.skins.armor.title', defaultMessage: 'Armour and trims' },
|
||||||
|
description: {
|
||||||
|
id: 'app.skins.armor.description',
|
||||||
|
defaultMessage: 'Try armour and trims on your skin. Nothing is stored until you save it.',
|
||||||
|
},
|
||||||
|
unsaved: { id: 'app.skins.armor.unsaved', defaultMessage: 'Unsaved changes' },
|
||||||
|
resetToSaved: { id: 'app.skins.armor.reset-to-saved', defaultMessage: 'Reset to saved' },
|
||||||
|
restoreDefaults: {
|
||||||
|
id: 'app.skins.armor.restore-defaults',
|
||||||
|
defaultMessage: 'Restore defaults',
|
||||||
|
},
|
||||||
|
save: { id: 'app.skins.armor.save', defaultMessage: 'Save' },
|
||||||
|
close: { id: 'app.skins.armor.close', defaultMessage: 'Close' },
|
||||||
|
})
|
||||||
|
|
||||||
|
const draft = defineModel<ArmorPreviewConfig>({ required: true })
|
||||||
|
const props = defineProps<{
|
||||||
|
saved: ArmorPreviewConfig
|
||||||
|
/** Stable id shared with the toggle so it can point `aria-controls` here. */
|
||||||
|
panelId: string
|
||||||
|
}>()
|
||||||
|
const emit = defineEmits<{
|
||||||
|
save: []
|
||||||
|
reset: []
|
||||||
|
defaults: []
|
||||||
|
close: []
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { formatMessage } = useVIntl()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The tab is mounted only while it is showing, so this listens exactly for that
|
||||||
|
* window. It listens in the capture phase because the app's own global
|
||||||
|
* shortcuts listen on `window` the same way, and a bubble-phase listener here
|
||||||
|
* would be skipped as soon as anything closer stopped the event. A modal on top
|
||||||
|
* of the page owns Escape while it is up, and focus sits inside it, so the key
|
||||||
|
* is left to it.
|
||||||
|
*/
|
||||||
|
function handleKeydown(event: KeyboardEvent) {
|
||||||
|
if (event.key !== 'Escape') return
|
||||||
|
if (
|
||||||
|
event.target instanceof Element &&
|
||||||
|
event.target.closest('[role="dialog"], [role="alertdialog"], [aria-modal="true"]')
|
||||||
|
) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
emit('close')
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => window.addEventListener('keydown', handleKeydown, true))
|
||||||
|
onUnmounted(() => window.removeEventListener('keydown', handleKeydown, true))
|
||||||
|
|
||||||
|
const isDirty = computed(() =>
|
||||||
|
Object.entries(draft.value).some(([slot, piece]) => {
|
||||||
|
const applied = props.saved[slot as keyof ArmorPreviewConfig]
|
||||||
|
return (
|
||||||
|
!applied ||
|
||||||
|
applied.material !== piece.material ||
|
||||||
|
applied.trimPattern !== piece.trimPattern ||
|
||||||
|
applied.trimMaterial !== piece.trimMaterial
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div
|
||||||
|
:id="panelId"
|
||||||
|
role="region"
|
||||||
|
:aria-label="formatMessage(messages.title)"
|
||||||
|
class="flex min-h-[24rem] flex-col gap-4 rounded-2xl border border-solid border-surface-5 bg-surface-2 p-4"
|
||||||
|
>
|
||||||
|
<header class="flex flex-wrap items-start justify-between gap-3">
|
||||||
|
<div class="min-w-0">
|
||||||
|
<h2 class="m-0 text-lg font-bold text-[var(--color-text-primary)]">
|
||||||
|
{{ formatMessage(messages.title) }}
|
||||||
|
</h2>
|
||||||
|
<p class="m-0 mt-1 text-sm leading-6 text-[var(--color-text-tertiary)]">
|
||||||
|
{{ formatMessage(messages.description) }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="flex shrink-0 flex-wrap items-center gap-2">
|
||||||
|
<span v-if="isDirty" class="text-sm font-semibold text-[var(--color-text-tertiary)]">
|
||||||
|
{{ formatMessage(messages.unsaved) }}
|
||||||
|
</span>
|
||||||
|
<Button type="outlined" @click="emit('close')"
|
||||||
|
><XIcon />{{ formatMessage(messages.close) }}</Button
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<ArmorTrimPanel v-model="draft" />
|
||||||
|
|
||||||
|
<footer
|
||||||
|
class="mt-auto flex flex-wrap items-center justify-between gap-2 border-0 border-t border-solid border-surface-5 pt-3"
|
||||||
|
>
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<Button type="outlined" :disabled="!isDirty" @click="emit('reset')"
|
||||||
|
><RotateCounterClockwiseIcon />{{ formatMessage(messages.resetToSaved) }}</Button
|
||||||
|
>
|
||||||
|
<Button type="outlined" @click="emit('defaults')">{{
|
||||||
|
formatMessage(messages.restoreDefaults)
|
||||||
|
}}</Button>
|
||||||
|
</div>
|
||||||
|
<Button type="colored" color="brand" :disabled="!isDirty" @click="emit('save')"
|
||||||
|
><CheckIcon />{{ formatMessage(messages.save) }}</Button
|
||||||
|
>
|
||||||
|
</footer>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
const { sections = 2, cards = 12 } = defineProps<{
|
||||||
|
sections?: number
|
||||||
|
cards?: number
|
||||||
|
}>()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<!--
|
||||||
|
Shaped after VirtualSkinSectionList: the same grid breakpoints and card
|
||||||
|
ratio, so the swap to real content does not move anything. Decorative, so
|
||||||
|
it stays out of the accessibility tree.
|
||||||
|
-->
|
||||||
|
<div class="flex flex-col gap-8" aria-hidden="true">
|
||||||
|
<div v-for="section in sections" :key="section" class="flex flex-col gap-4">
|
||||||
|
<div class="h-7 w-44 animate-pulse rounded-lg bg-surface-4" />
|
||||||
|
<div
|
||||||
|
class="grid w-full grid-cols-3 gap-3 min-[1300px]:grid-cols-4 min-[1750px]:grid-cols-5 min-[2050px]:grid-cols-6"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
v-for="card in cards"
|
||||||
|
:key="card"
|
||||||
|
class="aspect-[31/40] w-full animate-pulse rounded-[20px] bg-surface-4"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -1,607 +0,0 @@
|
|||||||
import assert from 'node:assert/strict'
|
|
||||||
import test from 'node:test'
|
|
||||||
|
|
||||||
import {
|
|
||||||
clearHostedSession,
|
|
||||||
HOSTED_ACCOUNT_REQUIRED_MESSAGE,
|
|
||||||
hostedCreate,
|
|
||||||
hostedDefault,
|
|
||||||
hostedSync,
|
|
||||||
onHostedPackAttemptStarted,
|
|
||||||
setInstanceMode,
|
|
||||||
} from '../helpers/hosted-packs.ts'
|
|
||||||
import {
|
|
||||||
openSkinSiteLogin,
|
|
||||||
receiveSkinSiteMessage,
|
|
||||||
requestSkinSiteDownloadToken,
|
|
||||||
requestSkinSiteLuck,
|
|
||||||
requestSkinSitePlayers,
|
|
||||||
requestSkinSiteSkinUpdate,
|
|
||||||
resetSkinSiteSession,
|
|
||||||
setSkinSiteFrame,
|
|
||||||
SKIN_SITE_ORIGIN,
|
|
||||||
skinSiteFrameUrl,
|
|
||||||
skinSitePlayers,
|
|
||||||
skinSitePlayersStatus,
|
|
||||||
skinSiteStatus,
|
|
||||||
skinSiteUser,
|
|
||||||
} from './skin-site-session.ts'
|
|
||||||
import { forgetHostedCreation, useHostedCreation } from './useHostedCreation.ts'
|
|
||||||
import { useHostedSync } from './useHostedSync.ts'
|
|
||||||
|
|
||||||
test('reconnecting the same skin site frame waits for verification instead of reporting signed out', () => {
|
|
||||||
const frame = { postMessage() {} } as unknown as Window
|
|
||||||
resetSkinSiteSession()
|
|
||||||
setSkinSiteFrame(frame)
|
|
||||||
resetSkinSiteSession()
|
|
||||||
setSkinSiteFrame(frame)
|
|
||||||
assert.equal(skinSiteStatus.value, 'checking')
|
|
||||||
setSkinSiteFrame(null)
|
|
||||||
resetSkinSiteSession()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('hosted installation sends the JWT to native commands while Local needs no session', async () => {
|
|
||||||
const previousWindow = Object.getOwnPropertyDescriptor(globalThis, 'window')
|
|
||||||
const calls: Array<{ command: string; args: Record<string, unknown> }> = []
|
|
||||||
let syncResponse: (() => Promise<unknown>) | undefined
|
|
||||||
let createdId = 'instance'
|
|
||||||
let instanceExists = false
|
|
||||||
let tokenRequests = 0
|
|
||||||
let accounts: Array<{
|
|
||||||
account_type: string
|
|
||||||
yggdrasil?: { api_root: string }
|
|
||||||
}> = [{ account_type: 'microsoft' }]
|
|
||||||
const frame = {
|
|
||||||
postMessage(data: { type: string; requestId: string }) {
|
|
||||||
if (data.type !== 'starlight-pack-token-request') return
|
|
||||||
tokenRequests++
|
|
||||||
receiveSkinSiteMessage(
|
|
||||||
{
|
|
||||||
origin: SKIN_SITE_ORIGIN,
|
|
||||||
source: frame,
|
|
||||||
data: {
|
|
||||||
type: 'starlight-pack-token-result',
|
|
||||||
requestId: data.requestId,
|
|
||||||
token: 'site.jwt.secret',
|
|
||||||
},
|
|
||||||
} as MessageEvent,
|
|
||||||
frame,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
} as unknown as Window
|
|
||||||
Object.defineProperty(globalThis, 'window', {
|
|
||||||
configurable: true,
|
|
||||||
value: {
|
|
||||||
__TAURI_INTERNALS__: {
|
|
||||||
async invoke(command: string, args: Record<string, unknown>) {
|
|
||||||
calls.push({ command, args })
|
|
||||||
if (command === 'plugin:install|hosted_has_game_account')
|
|
||||||
return accounts.some(
|
|
||||||
(account) =>
|
|
||||||
account.account_type === 'microsoft' ||
|
|
||||||
(account.account_type === 'yggdrasil' &&
|
|
||||||
account.yggdrasil?.api_root.replace(/\/+$/, '') ===
|
|
||||||
'https://skin.starlight.cool/yggdrasil'),
|
|
||||||
)
|
|
||||||
if (command === 'plugin:install|hosted_sync' && syncResponse) return syncResponse()
|
|
||||||
if (command === 'plugin:instance|instance_get')
|
|
||||||
return instanceExists ? { id: args.instanceId } : null
|
|
||||||
return command === 'plugin:install|hosted_create' ? createdId : null
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
try {
|
|
||||||
resetSkinSiteSession()
|
|
||||||
setSkinSiteFrame(frame)
|
|
||||||
receiveSkinSiteMessage(
|
|
||||||
{
|
|
||||||
origin: SKIN_SITE_ORIGIN,
|
|
||||||
source: frame,
|
|
||||||
data: {
|
|
||||||
type: 'starlight-skin-session',
|
|
||||||
status: 'signed-in',
|
|
||||||
user: { uuid: 'site', username: 'Site' },
|
|
||||||
},
|
|
||||||
} as MessageEvent,
|
|
||||||
frame,
|
|
||||||
)
|
|
||||||
await hostedDefault()
|
|
||||||
assert.equal(await hostedCreate(), 'instance')
|
|
||||||
await hostedSync('instance')
|
|
||||||
await setInstanceMode('instance', 'starlight')
|
|
||||||
assert.equal(tokenRequests, 4)
|
|
||||||
assert.deepEqual(
|
|
||||||
calls
|
|
||||||
.map(({ command }) => command)
|
|
||||||
.filter(
|
|
||||||
(command) =>
|
|
||||||
command.startsWith('plugin:install|') &&
|
|
||||||
command !== 'plugin:install|hosted_has_game_account',
|
|
||||||
),
|
|
||||||
[
|
|
||||||
'hosted_set_session',
|
|
||||||
'hosted_default',
|
|
||||||
'hosted_set_session',
|
|
||||||
'hosted_create',
|
|
||||||
'hosted_set_session',
|
|
||||||
'hosted_sync',
|
|
||||||
'hosted_set_session',
|
|
||||||
'hosted_set_instance_mode',
|
|
||||||
].map((name) => `plugin:install|${name}`),
|
|
||||||
)
|
|
||||||
for (const call of calls.filter(({ command }) => command.endsWith('hosted_set_session'))) {
|
|
||||||
assert.equal(call.args.token, 'site.jwt.secret')
|
|
||||||
}
|
|
||||||
let rejectSync!: (error: unknown) => void
|
|
||||||
let syncCalls = 0
|
|
||||||
syncResponse = () => {
|
|
||||||
syncCalls++
|
|
||||||
return new Promise((_, reject) => {
|
|
||||||
rejectSync = reject
|
|
||||||
})
|
|
||||||
}
|
|
||||||
const originalPage = useHostedSync(() => 'shared-progress-instance')
|
|
||||||
const pendingSync = originalPage.sync()
|
|
||||||
const reopenedPage = useHostedSync(() => 'shared-progress-instance')
|
|
||||||
assert.equal(reopenedPage.busy.value, true)
|
|
||||||
assert.equal(useHostedSync(() => 'other-instance').busy.value, false)
|
|
||||||
await reopenedPage.sync()
|
|
||||||
await new Promise((resolve) => setImmediate(resolve))
|
|
||||||
assert.equal(syncCalls, 1)
|
|
||||||
rejectSync({ message: 'download interrupted' })
|
|
||||||
await pendingSync
|
|
||||||
assert.equal(reopenedPage.busy.value, false)
|
|
||||||
assert.match(reopenedPage.error.value, /download interrupted/)
|
|
||||||
assert.equal(
|
|
||||||
useHostedSync(() => 'shared-progress-instance').error.value,
|
|
||||||
reopenedPage.error.value,
|
|
||||||
)
|
|
||||||
syncResponse = async () => ({ revision: 'new-version' })
|
|
||||||
await reopenedPage.sync()
|
|
||||||
assert.equal(originalPage.error.value, '')
|
|
||||||
assert.deepEqual(originalPage.result.value, { revision: 'new-version' })
|
|
||||||
|
|
||||||
const creation = useHostedCreation()
|
|
||||||
createdId = 'deleted-instance'
|
|
||||||
syncResponse = async () => {
|
|
||||||
throw new Error('download failed')
|
|
||||||
}
|
|
||||||
await creation.install()
|
|
||||||
assert.equal(creation.createdInstance.value, 'deleted-instance')
|
|
||||||
assert.match(creation.installError.value, /download failed/)
|
|
||||||
createdId = 'replacement-instance'
|
|
||||||
syncResponse = async () => ({
|
|
||||||
version: '1',
|
|
||||||
downloadedBytes: 0,
|
|
||||||
changedFiles: 0,
|
|
||||||
preservedFiles: [],
|
|
||||||
})
|
|
||||||
const retryCallStart = calls.length
|
|
||||||
assert.equal(await creation.install(), 'replacement-instance')
|
|
||||||
assert.equal(calls[retryCallStart].command, 'plugin:instance|instance_get')
|
|
||||||
assert.equal(
|
|
||||||
calls.filter((call) => call.command.endsWith('|hosted_sync')).at(-1)?.args.instanceId,
|
|
||||||
'replacement-instance',
|
|
||||||
)
|
|
||||||
assert.equal(creation.installError.value, '')
|
|
||||||
forgetHostedCreation('unrelated-instance')
|
|
||||||
assert.equal(creation.completed.value, true)
|
|
||||||
forgetHostedCreation('replacement-instance')
|
|
||||||
assert.equal(creation.createdInstance.value, undefined)
|
|
||||||
assert.equal(creation.completed.value, false)
|
|
||||||
createdId = 'third-instance'
|
|
||||||
syncResponse = () =>
|
|
||||||
new Promise((_, reject) => {
|
|
||||||
rejectSync = reject
|
|
||||||
})
|
|
||||||
const deletedDuringSync = creation.install()
|
|
||||||
await new Promise((resolve) => setImmediate(resolve))
|
|
||||||
forgetHostedCreation('third-instance')
|
|
||||||
rejectSync(new Error('Unknown instance'))
|
|
||||||
await deletedDuringSync
|
|
||||||
assert.equal(creation.installError.value, '')
|
|
||||||
assert.equal(creation.createdInstance.value, undefined)
|
|
||||||
createdId = 'existing-instance'
|
|
||||||
syncResponse = async () => {
|
|
||||||
throw new Error('download interrupted')
|
|
||||||
}
|
|
||||||
await creation.install()
|
|
||||||
instanceExists = true
|
|
||||||
syncResponse = async () => ({
|
|
||||||
version: '1',
|
|
||||||
downloadedBytes: 0,
|
|
||||||
changedFiles: 0,
|
|
||||||
preservedFiles: [],
|
|
||||||
})
|
|
||||||
const createCount = calls.filter((call) => call.command.endsWith('|hosted_create')).length
|
|
||||||
assert.equal(await creation.install(), 'existing-instance')
|
|
||||||
assert.equal(
|
|
||||||
calls.filter((call) => call.command.endsWith('|hosted_create')).length,
|
|
||||||
createCount,
|
|
||||||
)
|
|
||||||
creation.acknowledge('existing-instance')
|
|
||||||
const requestsBeforeLogout = tokenRequests
|
|
||||||
resetSkinSiteSession()
|
|
||||||
await clearHostedSession()
|
|
||||||
assert.equal(calls.at(-1)!.args.token, null)
|
|
||||||
await setInstanceMode('instance', 'local')
|
|
||||||
assert.equal(tokenRequests, requestsBeforeLogout)
|
|
||||||
const attempts: string[] = []
|
|
||||||
const stopListening = onHostedPackAttemptStarted((id) => attempts.push(id))
|
|
||||||
accounts = []
|
|
||||||
const installCallsBeforeAccountFailure = calls.filter(
|
|
||||||
({ command }) =>
|
|
||||||
command.startsWith('plugin:install|') &&
|
|
||||||
command !== 'plugin:install|hosted_has_game_account',
|
|
||||||
).length
|
|
||||||
await assert.rejects(hostedSync('failed-instance'), {
|
|
||||||
message: HOSTED_ACCOUNT_REQUIRED_MESSAGE,
|
|
||||||
})
|
|
||||||
await assert.rejects(hostedCreate(), {
|
|
||||||
message: HOSTED_ACCOUNT_REQUIRED_MESSAGE,
|
|
||||||
})
|
|
||||||
assert.deepEqual(attempts, [])
|
|
||||||
assert.equal(
|
|
||||||
calls.filter(
|
|
||||||
({ command }) =>
|
|
||||||
command.startsWith('plugin:install|') &&
|
|
||||||
command !== 'plugin:install|hosted_has_game_account',
|
|
||||||
).length,
|
|
||||||
installCallsBeforeAccountFailure,
|
|
||||||
)
|
|
||||||
const unauthenticatedCreation = useHostedCreation()
|
|
||||||
await unauthenticatedCreation.install()
|
|
||||||
assert.equal(unauthenticatedCreation.installError.value, HOSTED_ACCOUNT_REQUIRED_MESSAGE)
|
|
||||||
assert.equal(unauthenticatedCreation.createdInstance.value, undefined)
|
|
||||||
accounts = [{ account_type: 'microsoft' }]
|
|
||||||
const unauthenticatedRetry = hostedSync('failed-instance')
|
|
||||||
await assert.rejects(unauthenticatedRetry)
|
|
||||||
assert.deepEqual(attempts, ['failed-instance'])
|
|
||||||
stopListening()
|
|
||||||
await assert.rejects(hostedSync('failed-instance'))
|
|
||||||
assert.equal(attempts.length, 1)
|
|
||||||
await assert.rejects(hostedCreate(), /无需选择玩家/)
|
|
||||||
} finally {
|
|
||||||
resetSkinSiteSession()
|
|
||||||
setSkinSiteFrame(null)
|
|
||||||
if (previousWindow) Object.defineProperty(globalThis, 'window', previousWindow)
|
|
||||||
else Reflect.deleteProperty(globalThis, 'window')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
test('pack download gets the site JWT without choosing a player and rejects stale replies', async () => {
|
|
||||||
const sent: Array<{ type: string; requestId: string }> = []
|
|
||||||
const frame = {
|
|
||||||
postMessage(data: { type: string; requestId: string }) {
|
|
||||||
sent.push(data)
|
|
||||||
},
|
|
||||||
} as unknown as Window
|
|
||||||
const receive = (data: unknown, origin = SKIN_SITE_ORIGIN) =>
|
|
||||||
receiveSkinSiteMessage(
|
|
||||||
{
|
|
||||||
origin,
|
|
||||||
source: frame,
|
|
||||||
data,
|
|
||||||
} as MessageEvent,
|
|
||||||
frame,
|
|
||||||
)
|
|
||||||
resetSkinSiteSession()
|
|
||||||
setSkinSiteFrame(frame)
|
|
||||||
await assert.rejects(requestSkinSiteDownloadToken(), /无需选择玩家/)
|
|
||||||
receive({
|
|
||||||
type: 'starlight-skin-session',
|
|
||||||
status: 'signed-in',
|
|
||||||
user: { uuid: 'site-user', username: 'Site' },
|
|
||||||
})
|
|
||||||
const token = requestSkinSiteDownloadToken()
|
|
||||||
const requestId = sent.at(-1)!.requestId
|
|
||||||
const reply = { type: 'starlight-pack-token-result', requestId, token: 'site.jwt.secret' }
|
|
||||||
assert.equal(receive(reply, 'https://evil.example'), false)
|
|
||||||
assert.equal(receive(reply), true)
|
|
||||||
assert.equal(await token, 'site.jwt.secret')
|
|
||||||
assert.equal(skinSitePlayers.value.length, 0)
|
|
||||||
assert.equal(JSON.stringify(skinSiteUser.value).includes('secret'), false)
|
|
||||||
const stale = requestSkinSiteDownloadToken()
|
|
||||||
const staleId = sent.at(-1)!.requestId
|
|
||||||
const rejected = assert.rejects(stale, /登录状态已变化/)
|
|
||||||
resetSkinSiteSession()
|
|
||||||
await rejected
|
|
||||||
assert.equal(receive({ ...reply, requestId: staleId }), false)
|
|
||||||
setSkinSiteFrame(null)
|
|
||||||
})
|
|
||||||
|
|
||||||
test('skin site session accepts only the embedded origin and window, and redirects after verification', () => {
|
|
||||||
const frame = {} as Window
|
|
||||||
const message = (status: string, user?: unknown) =>
|
|
||||||
({
|
|
||||||
origin: SKIN_SITE_ORIGIN,
|
|
||||||
source: frame,
|
|
||||||
data: { type: 'starlight-skin-session', status, user },
|
|
||||||
}) as MessageEvent
|
|
||||||
resetSkinSiteSession()
|
|
||||||
openSkinSiteLogin()
|
|
||||||
assert.equal(skinSiteFrameUrl.value, `${SKIN_SITE_ORIGIN}/login`)
|
|
||||||
const signedIn = message('signed-in', {
|
|
||||||
uuid: 'test-user',
|
|
||||||
username: '测试用户',
|
|
||||||
jwt: 'must-not-copy',
|
|
||||||
})
|
|
||||||
assert.equal(
|
|
||||||
receiveSkinSiteMessage({ ...signedIn, origin: 'https://evil.example' } as MessageEvent, frame),
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
assert.equal(receiveSkinSiteMessage(signedIn, {} as Window), false)
|
|
||||||
assert.equal(receiveSkinSiteMessage(message('signed-in', {}), frame), false)
|
|
||||||
assert.equal(skinSiteUser.value, null)
|
|
||||||
assert.equal(receiveSkinSiteMessage(signedIn, frame), true)
|
|
||||||
assert.deepEqual(skinSiteUser.value, { uuid: 'test-user', username: '测试用户' })
|
|
||||||
assert.equal(skinSiteStatus.value, 'signed-in')
|
|
||||||
assert.equal(skinSiteFrameUrl.value, `${SKIN_SITE_ORIGIN}/profile`)
|
|
||||||
assert.equal(receiveSkinSiteMessage(message('checking'), frame), true)
|
|
||||||
assert.equal(skinSiteUser.value, null)
|
|
||||||
receiveSkinSiteMessage(message('signed-in', { uuid: 'second', username: '另一个账号' }), frame)
|
|
||||||
assert.deepEqual(skinSiteUser.value, { uuid: 'second', username: '另一个账号' })
|
|
||||||
receiveSkinSiteMessage(message('signed-out'), frame)
|
|
||||||
assert.equal(skinSiteUser.value, null)
|
|
||||||
assert.equal(skinSiteStatus.value, 'signed-out')
|
|
||||||
receiveSkinSiteMessage(message('error'), frame)
|
|
||||||
assert.equal(skinSiteStatus.value, 'error')
|
|
||||||
resetSkinSiteSession()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('luck requests use only the connected skin site frame and validate its result', async () => {
|
|
||||||
const sent: Array<{ data: unknown; targetOrigin: string }> = []
|
|
||||||
const frame = {
|
|
||||||
postMessage(data: unknown, targetOrigin: string) {
|
|
||||||
sent.push({ data, targetOrigin })
|
|
||||||
},
|
|
||||||
} as unknown as Window
|
|
||||||
const sessionMessage = {
|
|
||||||
origin: SKIN_SITE_ORIGIN,
|
|
||||||
source: frame,
|
|
||||||
data: {
|
|
||||||
type: 'starlight-skin-session',
|
|
||||||
status: 'signed-in',
|
|
||||||
user: { uuid: 'lucky-user', username: 'Lucky' },
|
|
||||||
},
|
|
||||||
} as MessageEvent
|
|
||||||
|
|
||||||
resetSkinSiteSession()
|
|
||||||
setSkinSiteFrame(frame)
|
|
||||||
receiveSkinSiteMessage(sessionMessage, frame)
|
|
||||||
const automaticPlayersRequest = sent.at(-1)?.data as { type: string; requestId: string }
|
|
||||||
assert.equal(automaticPlayersRequest.type, 'starlight-skin-players-request')
|
|
||||||
receiveSkinSiteMessage(
|
|
||||||
{
|
|
||||||
origin: SKIN_SITE_ORIGIN,
|
|
||||||
source: frame,
|
|
||||||
data: {
|
|
||||||
type: 'starlight-skin-players-result',
|
|
||||||
requestId: automaticPlayersRequest.requestId,
|
|
||||||
ok: true,
|
|
||||||
players: [],
|
|
||||||
},
|
|
||||||
} as MessageEvent,
|
|
||||||
frame,
|
|
||||||
)
|
|
||||||
const result = requestSkinSiteLuck()
|
|
||||||
assert.equal(sent.at(-1)?.targetOrigin, SKIN_SITE_ORIGIN)
|
|
||||||
const request = sent.at(-1)?.data as { type: string; requestId: string }
|
|
||||||
assert.equal(request.type, 'starlight-skin-luck-request')
|
|
||||||
assert.match(request.requestId, /^skin-luck-\d+-\d+$/)
|
|
||||||
assert.equal(
|
|
||||||
receiveSkinSiteMessage(
|
|
||||||
{
|
|
||||||
origin: SKIN_SITE_ORIGIN,
|
|
||||||
source: frame,
|
|
||||||
data: {
|
|
||||||
type: 'starlight-skin-luck-result',
|
|
||||||
requestId: request.requestId,
|
|
||||||
ok: true,
|
|
||||||
luck: 88,
|
|
||||||
},
|
|
||||||
} as MessageEvent,
|
|
||||||
frame,
|
|
||||||
),
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
assert.equal(await result, 88)
|
|
||||||
setSkinSiteFrame(null)
|
|
||||||
resetSkinSiteSession()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('player requests validate identities and replace the collection atomically', async () => {
|
|
||||||
const sent: Array<{ data: unknown; targetOrigin: string }> = []
|
|
||||||
const frame = {
|
|
||||||
postMessage(data: unknown, targetOrigin: string) {
|
|
||||||
sent.push({ data, targetOrigin })
|
|
||||||
},
|
|
||||||
} as unknown as Window
|
|
||||||
|
|
||||||
resetSkinSiteSession()
|
|
||||||
setSkinSiteFrame(frame)
|
|
||||||
receiveSkinSiteMessage(
|
|
||||||
{
|
|
||||||
origin: SKIN_SITE_ORIGIN,
|
|
||||||
source: frame,
|
|
||||||
data: {
|
|
||||||
type: 'starlight-skin-session',
|
|
||||||
status: 'signed-in',
|
|
||||||
user: { uuid: 'skin-user', username: 'Skin User' },
|
|
||||||
},
|
|
||||||
} as MessageEvent,
|
|
||||||
frame,
|
|
||||||
)
|
|
||||||
const automaticRequest = sent.at(-1)?.data as { requestId: string }
|
|
||||||
assert.equal(skinSitePlayersStatus.value, 'checking')
|
|
||||||
assert.equal(
|
|
||||||
receiveSkinSiteMessage(
|
|
||||||
{
|
|
||||||
origin: SKIN_SITE_ORIGIN,
|
|
||||||
source: frame,
|
|
||||||
data: {
|
|
||||||
type: 'starlight-skin-players-result',
|
|
||||||
requestId: automaticRequest.requestId,
|
|
||||||
ok: true,
|
|
||||||
players: [
|
|
||||||
{
|
|
||||||
uuid: '0123456789abcdef0123456789abcdef',
|
|
||||||
name: 'PlayerOne',
|
|
||||||
isMojang: false,
|
|
||||||
skinState: 'ready',
|
|
||||||
headDataUrl: 'data:image/png;base64,SEVBRERBVEE=',
|
|
||||||
skinDataUrl: 'data:image/png;base64,SEVBRERBVEE=',
|
|
||||||
model: 'slim',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
uuid: 'fedcba9876543210fedcba9876543210',
|
|
||||||
name: 'NoSkinPlayer',
|
|
||||||
isMojang: false,
|
|
||||||
skinState: 'empty',
|
|
||||||
},
|
|
||||||
{ uuid: 'invalid', name: 'Ignored', isMojang: false },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
} as MessageEvent,
|
|
||||||
frame,
|
|
||||||
),
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
assert.deepEqual(skinSitePlayers.value, [
|
|
||||||
{
|
|
||||||
uuid: '0123456789abcdef0123456789abcdef',
|
|
||||||
name: 'PlayerOne',
|
|
||||||
isMojang: false,
|
|
||||||
skinState: 'ready',
|
|
||||||
headDataUrl: 'data:image/png;base64,SEVBRERBVEE=',
|
|
||||||
skinDataUrl: 'data:image/png;base64,SEVBRERBVEE=',
|
|
||||||
model: 'slim',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
uuid: 'fedcba9876543210fedcba9876543210',
|
|
||||||
name: 'NoSkinPlayer',
|
|
||||||
isMojang: false,
|
|
||||||
skinState: 'empty',
|
|
||||||
},
|
|
||||||
])
|
|
||||||
assert.equal(skinSitePlayersStatus.value, 'ready')
|
|
||||||
|
|
||||||
const transientFailure = requestSkinSitePlayers()
|
|
||||||
const transientFailureRequest = sent.at(-1)?.data as { requestId: string }
|
|
||||||
receiveSkinSiteMessage(
|
|
||||||
{
|
|
||||||
origin: SKIN_SITE_ORIGIN,
|
|
||||||
source: frame,
|
|
||||||
data: {
|
|
||||||
type: 'starlight-skin-players-result',
|
|
||||||
requestId: transientFailureRequest.requestId,
|
|
||||||
ok: true,
|
|
||||||
players: [
|
|
||||||
{
|
|
||||||
uuid: '0123456789abcdef0123456789abcdef',
|
|
||||||
name: 'PlayerOne Renamed',
|
|
||||||
isMojang: false,
|
|
||||||
skinState: 'error',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
} as MessageEvent,
|
|
||||||
frame,
|
|
||||||
)
|
|
||||||
assert.equal((await transientFailure)[0].skinState, 'ready')
|
|
||||||
assert.equal(skinSitePlayers.value[0].name, 'PlayerOne Renamed')
|
|
||||||
assert.equal(skinSitePlayers.value[0].headDataUrl, 'data:image/png;base64,SEVBRERBVEE=')
|
|
||||||
|
|
||||||
const retry = requestSkinSitePlayers()
|
|
||||||
const retryRequest = sent.at(-1)?.data as { requestId: string }
|
|
||||||
receiveSkinSiteMessage(
|
|
||||||
{
|
|
||||||
origin: SKIN_SITE_ORIGIN,
|
|
||||||
source: frame,
|
|
||||||
data: {
|
|
||||||
type: 'starlight-skin-players-result',
|
|
||||||
requestId: retryRequest.requestId,
|
|
||||||
ok: true,
|
|
||||||
players: [],
|
|
||||||
},
|
|
||||||
} as MessageEvent,
|
|
||||||
frame,
|
|
||||||
)
|
|
||||||
assert.deepEqual(await retry, [])
|
|
||||||
assert.deepEqual(skinSitePlayers.value, [])
|
|
||||||
setSkinSiteFrame(null)
|
|
||||||
resetSkinSiteSession()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('skin updates are restricted to known non-Mojang players and validated results', async () => {
|
|
||||||
const sent: Array<{ data: unknown; targetOrigin: string }> = []
|
|
||||||
const frame = {
|
|
||||||
postMessage(data: unknown, targetOrigin: string) {
|
|
||||||
sent.push({ data, targetOrigin })
|
|
||||||
},
|
|
||||||
} as unknown as Window
|
|
||||||
|
|
||||||
resetSkinSiteSession()
|
|
||||||
setSkinSiteFrame(frame)
|
|
||||||
receiveSkinSiteMessage(
|
|
||||||
{
|
|
||||||
origin: SKIN_SITE_ORIGIN,
|
|
||||||
source: frame,
|
|
||||||
data: {
|
|
||||||
type: 'starlight-skin-session',
|
|
||||||
status: 'signed-in',
|
|
||||||
user: { uuid: 'skin-user', username: 'Skin User' },
|
|
||||||
},
|
|
||||||
} as MessageEvent,
|
|
||||||
frame,
|
|
||||||
)
|
|
||||||
const automaticRequest = sent.at(-1)?.data as { requestId: string }
|
|
||||||
receiveSkinSiteMessage(
|
|
||||||
{
|
|
||||||
origin: SKIN_SITE_ORIGIN,
|
|
||||||
source: frame,
|
|
||||||
data: {
|
|
||||||
type: 'starlight-skin-players-result',
|
|
||||||
requestId: automaticRequest.requestId,
|
|
||||||
ok: true,
|
|
||||||
players: [
|
|
||||||
{
|
|
||||||
uuid: '0123456789abcdef0123456789abcdef',
|
|
||||||
name: 'PlayerOne',
|
|
||||||
isMojang: false,
|
|
||||||
skinState: 'empty',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
} as MessageEvent,
|
|
||||||
frame,
|
|
||||||
)
|
|
||||||
|
|
||||||
const result = requestSkinSiteSkinUpdate(
|
|
||||||
'0123456789abcdef0123456789abcdef',
|
|
||||||
'data:image/png;base64,SEVBRERBVEE=',
|
|
||||||
'slim',
|
|
||||||
)
|
|
||||||
const request = sent.at(-1)?.data as { type: string; requestId: string; playerId: string }
|
|
||||||
assert.equal(request.type, 'starlight-skin-update-request')
|
|
||||||
assert.equal(request.playerId, '0123456789abcdef0123456789abcdef')
|
|
||||||
receiveSkinSiteMessage(
|
|
||||||
{
|
|
||||||
origin: SKIN_SITE_ORIGIN,
|
|
||||||
source: frame,
|
|
||||||
data: { type: 'starlight-skin-update-result', requestId: request.requestId, ok: true },
|
|
||||||
} as MessageEvent,
|
|
||||||
frame,
|
|
||||||
)
|
|
||||||
await result
|
|
||||||
await assert.rejects(
|
|
||||||
requestSkinSiteSkinUpdate(
|
|
||||||
'fedcba9876543210fedcba9876543210',
|
|
||||||
'data:image/png;base64,SEVBRERBVEE=',
|
|
||||||
'default',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
setSkinSiteFrame(null)
|
|
||||||
resetSkinSiteSession()
|
|
||||||
})
|
|
||||||
@@ -1,7 +1,25 @@
|
|||||||
import { readonly, ref, watch } from 'vue'
|
import { readonly, ref } from 'vue'
|
||||||
|
|
||||||
|
import {
|
||||||
|
clearSkinSiteToken,
|
||||||
|
getSkinSiteToken,
|
||||||
|
setSkinSiteToken,
|
||||||
|
skinSiteCurrentUser,
|
||||||
|
skinSiteLogin,
|
||||||
|
skinSiteLuck,
|
||||||
|
skinSitePlayerList,
|
||||||
|
type SkinSitePlayerSkin,
|
||||||
|
skinSitePlayerSkin,
|
||||||
|
skinSiteRefresh,
|
||||||
|
type SkinSiteResponse,
|
||||||
|
skinSiteUploadTexture,
|
||||||
|
type SkinSiteUser as ApiSkinSiteUser,
|
||||||
|
} from '@/helpers/skin-site-api'
|
||||||
|
import { fetchImageAsDataUrl, renderSkinHead } from '@/helpers/skin-site-render'
|
||||||
|
|
||||||
export const SKIN_SITE_ORIGIN = 'https://skin.starlight.cool'
|
export const SKIN_SITE_ORIGIN = 'https://skin.starlight.cool'
|
||||||
export type SkinSiteUser = { uuid: string; username: string }
|
|
||||||
|
export type SkinSiteUser = { uuid: string; username: string; permissions: string[] }
|
||||||
export type SkinSiteStatus = 'checking' | 'signed-out' | 'signed-in' | 'error'
|
export type SkinSiteStatus = 'checking' | 'signed-out' | 'signed-in' | 'error'
|
||||||
export type SkinSitePlayer = {
|
export type SkinSitePlayer = {
|
||||||
uuid: string
|
uuid: string
|
||||||
@@ -15,152 +33,227 @@ export type SkinSitePlayer = {
|
|||||||
export type SkinSitePlayersStatus = 'idle' | 'checking' | 'ready' | 'error'
|
export type SkinSitePlayersStatus = 'idle' | 'checking' | 'ready' | 'error'
|
||||||
|
|
||||||
const user = ref<SkinSiteUser | null>(null)
|
const user = ref<SkinSiteUser | null>(null)
|
||||||
const status = ref<SkinSiteStatus>('signed-out')
|
const status = ref<SkinSiteStatus>('checking')
|
||||||
const players = ref<SkinSitePlayer[]>([])
|
const players = ref<SkinSitePlayer[]>([])
|
||||||
const playersStatus = ref<SkinSitePlayersStatus>('idle')
|
const playersStatus = ref<SkinSitePlayersStatus>('idle')
|
||||||
const selectedPlayerId = ref<string | null>(null)
|
const selectedPlayerId = ref<string | null>(null)
|
||||||
const frameUrl = ref(`${SKIN_SITE_ORIGIN}/`)
|
let playersRequest: Promise<SkinSitePlayer[]> | null = null
|
||||||
let connectedFrame: Window | null = null
|
|
||||||
let luckRequestSequence = 0
|
|
||||||
let playersRequestSequence = 0
|
|
||||||
let skinUpdateRequestSequence = 0
|
|
||||||
let packTokenRequestSequence = 0
|
|
||||||
const pendingPackTokens = new Map<
|
|
||||||
string,
|
|
||||||
{
|
|
||||||
resolve: (token: string) => void
|
|
||||||
reject: (error: Error) => void
|
|
||||||
timeout: ReturnType<typeof setTimeout>
|
|
||||||
}
|
|
||||||
>()
|
|
||||||
|
|
||||||
function rejectPendingPackTokens() {
|
|
||||||
for (const request of pendingPackTokens.values()) {
|
|
||||||
clearTimeout(request.timeout)
|
|
||||||
request.reject(new Error('StarLight 登录状态已变化,请重试。'))
|
|
||||||
}
|
|
||||||
pendingPackTokens.clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
export function requestSkinSiteDownloadToken(): Promise<string> {
|
|
||||||
if (!connectedFrame || status.value !== 'signed-in' || !user.value) {
|
|
||||||
return Promise.reject(
|
|
||||||
new Error('请先在启动器中登录 StarLight 皮肤站,再下载整合包。无需选择玩家。'),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
const requestId = `pack-token-${Date.now()}-${++packTokenRequestSequence}`
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const timeout = setTimeout(() => {
|
|
||||||
pendingPackTokens.delete(requestId)
|
|
||||||
reject(new Error('获取 StarLight 登录凭据超时,请重试。'))
|
|
||||||
}, 10_000)
|
|
||||||
pendingPackTokens.set(requestId, { resolve, reject, timeout })
|
|
||||||
try {
|
|
||||||
connectedFrame?.postMessage(
|
|
||||||
{ type: 'starlight-pack-token-request', requestId },
|
|
||||||
SKIN_SITE_ORIGIN,
|
|
||||||
)
|
|
||||||
} catch {
|
|
||||||
clearTimeout(timeout)
|
|
||||||
pendingPackTokens.delete(requestId)
|
|
||||||
reject(new Error('无法读取 StarLight 登录状态,请重新登录。'))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
type PendingLuckRequest = {
|
|
||||||
resolve: (luck: number) => void
|
|
||||||
reject: (error: Error) => void
|
|
||||||
timeout: ReturnType<typeof setTimeout>
|
|
||||||
}
|
|
||||||
|
|
||||||
const pendingLuckRequests = new Map<string, PendingLuckRequest>()
|
|
||||||
type PendingPlayersRequest = {
|
|
||||||
resolve: (players: SkinSitePlayer[]) => void
|
|
||||||
reject: (error: Error) => void
|
|
||||||
timeout: ReturnType<typeof setTimeout>
|
|
||||||
}
|
|
||||||
const pendingPlayersRequests = new Map<string, PendingPlayersRequest>()
|
|
||||||
type PendingSkinUpdateRequest = {
|
|
||||||
resolve: () => void
|
|
||||||
reject: (error: Error) => void
|
|
||||||
timeout: ReturnType<typeof setTimeout>
|
|
||||||
}
|
|
||||||
const pendingSkinUpdateRequests = new Map<string, PendingSkinUpdateRequest>()
|
|
||||||
|
|
||||||
function isSafePngDataUrl(value: unknown, maxLength: number) {
|
|
||||||
return (
|
|
||||||
typeof value === 'string' &&
|
|
||||||
value.length <= maxLength &&
|
|
||||||
/^data:image\/png;base64,[a-z0-9+/]+={0,2}$/i.test(value)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function hasSafeSkinHead(player: SkinSitePlayer) {
|
|
||||||
if (!['ready', 'empty', 'error'].includes(player.skinState)) return false
|
|
||||||
if (player.skinState !== 'ready') return player.headDataUrl === undefined
|
|
||||||
return (
|
|
||||||
isSafePngDataUrl(player.headDataUrl, 100_000) &&
|
|
||||||
(player.skinDataUrl === undefined || isSafePngDataUrl(player.skinDataUrl, 2_000_000)) &&
|
|
||||||
(player.model === undefined || player.model === 'default' || player.model === 'slim')
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const skinSiteUser = readonly(user)
|
export const skinSiteUser = readonly(user)
|
||||||
export const skinSiteStatus = readonly(status)
|
export const skinSiteStatus = readonly(status)
|
||||||
export const skinSitePlayers = readonly(players)
|
export const skinSitePlayers = readonly(players)
|
||||||
export const skinSitePlayersStatus = readonly(playersStatus)
|
export const skinSitePlayersStatus = readonly(playersStatus)
|
||||||
export const selectedSkinSitePlayerId = readonly(selectedPlayerId)
|
export const selectedSkinSitePlayerId = readonly(selectedPlayerId)
|
||||||
export const skinSiteFrameUrl = readonly(frameUrl)
|
|
||||||
|
|
||||||
export async function waitForSkinSiteSession() {
|
function toUser(raw: ApiSkinSiteUser): SkinSiteUser {
|
||||||
if (status.value !== 'checking') return
|
return {
|
||||||
await new Promise<void>((resolve, reject) => {
|
uuid: raw.uuid,
|
||||||
const stop = watch(status, next => {
|
username: raw.username,
|
||||||
if (next === 'checking') return
|
permissions: Array.isArray(raw.permissions) ? raw.permissions : [],
|
||||||
clearTimeout(timer)
|
|
||||||
stop()
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
const timer = setTimeout(() => {
|
|
||||||
stop()
|
|
||||||
reject(new Error('皮肤站登录状态仍在检查,请稍后重试。'))
|
|
||||||
}, 10_000)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function rejectPendingLuckRequests(message: string) {
|
|
||||||
for (const request of pendingLuckRequests.values()) {
|
|
||||||
clearTimeout(request.timeout)
|
|
||||||
request.reject(new Error(message))
|
|
||||||
}
|
}
|
||||||
pendingLuckRequests.clear()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function rejectPendingPlayersRequests(message: string) {
|
function clearSessionState() {
|
||||||
for (const request of pendingPlayersRequests.values()) {
|
user.value = null
|
||||||
clearTimeout(request.timeout)
|
players.value = []
|
||||||
request.reject(new Error(message))
|
playersStatus.value = 'idle'
|
||||||
|
selectedPlayerId.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Session lifecycle
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
let initialized: Promise<void> | null = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve the current session from the stored JWT. Safe to call repeatedly;
|
||||||
|
* the first call performs the actual work and later ones reuse it.
|
||||||
|
*/
|
||||||
|
export function initSkinSiteSession(): Promise<void> {
|
||||||
|
if (initialized) return initialized
|
||||||
|
initialized = (async () => {
|
||||||
|
const token = getSkinSiteToken()
|
||||||
|
if (!token) {
|
||||||
|
status.value = 'signed-out'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
status.value = 'checking'
|
||||||
|
const result = await skinSiteCurrentUser()
|
||||||
|
if (result.success) {
|
||||||
|
user.value = toUser(result.payload)
|
||||||
|
status.value = 'signed-in'
|
||||||
|
void requestSkinSitePlayers().catch(() => {})
|
||||||
|
} else if (result.errorCode === 401 || result.errorCode === 403) {
|
||||||
|
clearSkinSiteToken()
|
||||||
|
clearSessionState()
|
||||||
|
status.value = 'signed-out'
|
||||||
|
} else {
|
||||||
|
status.value = 'error'
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
return initialized
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Force a re-check (e.g. after the user signs in from another view). */
|
||||||
|
export function reloadSkinSiteSession(): Promise<void> {
|
||||||
|
initialized = null
|
||||||
|
return initSkinSiteSession()
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function signInSkinSite(payload: {
|
||||||
|
username: string
|
||||||
|
password: string
|
||||||
|
clientId: string
|
||||||
|
}): Promise<SkinSiteResponse<{ username: string; jwt: string }>> {
|
||||||
|
const result = await skinSiteLogin(payload)
|
||||||
|
if (result.success) {
|
||||||
|
setSkinSiteToken(result.payload.jwt)
|
||||||
|
const current = await skinSiteCurrentUser()
|
||||||
|
if (current.success) {
|
||||||
|
user.value = toUser(current.payload)
|
||||||
|
status.value = 'signed-in'
|
||||||
|
void requestSkinSitePlayers().catch(() => {})
|
||||||
|
} else {
|
||||||
|
user.value = { uuid: '', username: result.payload.username, permissions: [] }
|
||||||
|
status.value = 'signed-in'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pendingPlayersRequests.clear()
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
function rejectPendingSkinUpdateRequests(message: string) {
|
export function signOutSkinSite() {
|
||||||
for (const request of pendingSkinUpdateRequests.values()) {
|
clearSkinSiteToken()
|
||||||
clearTimeout(request.timeout)
|
clearSessionState()
|
||||||
request.reject(new Error(message))
|
status.value = 'signed-out'
|
||||||
|
initialized = null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Refresh the JWT; returns true when a new token was stored. */
|
||||||
|
export async function refreshSkinSiteSession(): Promise<boolean> {
|
||||||
|
if (status.value !== 'signed-in') return false
|
||||||
|
const result = await skinSiteRefresh()
|
||||||
|
if (result.success) {
|
||||||
|
setSkinSiteToken(result.payload.jwt)
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
pendingSkinUpdateRequests.clear()
|
if (result.errorCode === 401 || result.errorCode === 403) signOutSkinSite()
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setSkinSiteFrame(frame: Window | null) {
|
// ---------------------------------------------------------------------------
|
||||||
if (frame && !user.value) status.value = 'checking'
|
// Compatibility shims for the old iframe-based API
|
||||||
if (connectedFrame === frame) return
|
// ---------------------------------------------------------------------------
|
||||||
rejectPendingPackTokens()
|
|
||||||
rejectPendingLuckRequests('The skin site connection changed.')
|
/** @deprecated The session is no longer driven by an iframe. No-op. */
|
||||||
rejectPendingPlayersRequests('The skin site connection changed.')
|
export function setSkinSiteFrame(_frame: Window | null) {}
|
||||||
rejectPendingSkinUpdateRequests('The skin site connection changed.')
|
|
||||||
connectedFrame = frame
|
/** @deprecated The session is no longer driven by an iframe. No-op. */
|
||||||
|
export function receiveSkinSiteMessage(_event: MessageEvent, _frame: Window | null): boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @deprecated Use the in-app login view instead. No-op. */
|
||||||
|
export function openSkinSiteLogin() {}
|
||||||
|
|
||||||
|
export function resetSkinSiteSession() {
|
||||||
|
clearSessionState()
|
||||||
|
status.value = getSkinSiteToken() ? 'checking' : 'signed-out'
|
||||||
|
initialized = null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Resolves once the initial session check has settled. */
|
||||||
|
export async function waitForSkinSiteSession(): Promise<void> {
|
||||||
|
await initSkinSiteSession()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Download token (the launcher's hosted pack downloader)
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The hosted pack downloader authenticates with the skin site JWT. We hold it
|
||||||
|
* locally now, so this simply surfaces it (refreshing once if it is missing).
|
||||||
|
*/
|
||||||
|
export async function requestSkinSiteDownloadToken(): Promise<string> {
|
||||||
|
if (status.value !== 'signed-in') {
|
||||||
|
await initSkinSiteSession()
|
||||||
|
}
|
||||||
|
if (status.value !== 'signed-in') {
|
||||||
|
throw new Error('请先在启动器中登录 StarLight 皮肤站,再下载整合包。')
|
||||||
|
}
|
||||||
|
let token = getSkinSiteToken()
|
||||||
|
if (!token) {
|
||||||
|
if (await refreshSkinSiteSession()) token = getSkinSiteToken()
|
||||||
|
}
|
||||||
|
if (!token) throw new Error('StarLight 登录凭据不可用,请重新登录。')
|
||||||
|
return token
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Players
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
async function buildPlayer(entry: {
|
||||||
|
uuid: string
|
||||||
|
name: string
|
||||||
|
isMojang: boolean
|
||||||
|
}): Promise<SkinSitePlayer> {
|
||||||
|
const base: SkinSitePlayer = {
|
||||||
|
uuid: entry.uuid,
|
||||||
|
name: entry.name,
|
||||||
|
isMojang: entry.isMojang,
|
||||||
|
skinState: 'empty',
|
||||||
|
}
|
||||||
|
const skinResult = await skinSitePlayerSkin(entry.uuid)
|
||||||
|
if (!skinResult.success) return { ...base, skinState: 'error' }
|
||||||
|
|
||||||
|
const texture: SkinSitePlayerSkin = skinResult.payload ?? {}
|
||||||
|
if (!texture.skin) return base
|
||||||
|
|
||||||
|
try {
|
||||||
|
const [headDataUrl, skinDataUrl] = await Promise.all([
|
||||||
|
renderSkinHead(texture.skin),
|
||||||
|
fetchImageAsDataUrl(texture.skin),
|
||||||
|
])
|
||||||
|
return {
|
||||||
|
...base,
|
||||||
|
skinState: 'ready',
|
||||||
|
headDataUrl,
|
||||||
|
skinDataUrl,
|
||||||
|
model: texture.model === 'slim' ? 'slim' : 'default',
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
return { ...base, skinState: 'error' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function requestSkinSitePlayers(): Promise<SkinSitePlayer[]> {
|
||||||
|
if (playersRequest) return playersRequest
|
||||||
|
if (status.value !== 'signed-in' || !user.value) {
|
||||||
|
return Promise.reject(new Error('请先登录 StarLight 皮肤站。'))
|
||||||
|
}
|
||||||
|
|
||||||
|
playersStatus.value = 'checking'
|
||||||
|
playersRequest = (async () => {
|
||||||
|
try {
|
||||||
|
const list = await skinSitePlayerList()
|
||||||
|
if (!list.success) throw new Error(list.errorMessage)
|
||||||
|
const built = await Promise.all(list.payload.map(buildPlayer))
|
||||||
|
players.value = built
|
||||||
|
if (selectedPlayerId.value && !built.some((p) => p.uuid === selectedPlayerId.value)) {
|
||||||
|
selectedPlayerId.value = null
|
||||||
|
}
|
||||||
|
playersStatus.value = 'ready'
|
||||||
|
return players.value
|
||||||
|
} catch (error) {
|
||||||
|
playersStatus.value = 'error'
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
playersRequest = null
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
return playersRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
export function selectSkinSitePlayer(playerId: string | null) {
|
export function selectSkinSitePlayer(playerId: string | null) {
|
||||||
@@ -171,267 +264,59 @@ export function selectSkinSitePlayer(playerId: string | null) {
|
|||||||
if (players.value.some((player) => player.uuid === playerId)) selectedPlayerId.value = playerId
|
if (players.value.some((player) => player.uuid === playerId)) selectedPlayerId.value = playerId
|
||||||
}
|
}
|
||||||
|
|
||||||
export function openSkinSiteLogin() {
|
// ---------------------------------------------------------------------------
|
||||||
frameUrl.value = `${SKIN_SITE_ORIGIN}/login`
|
// Luck
|
||||||
}
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
export function resetSkinSiteSession() {
|
export async function requestSkinSiteLuck(): Promise<number> {
|
||||||
rejectPendingPackTokens()
|
if (status.value !== 'signed-in') throw new Error('请先登录 StarLight 皮肤站。')
|
||||||
rejectPendingLuckRequests('The skin site session ended.')
|
const result = await skinSiteLuck()
|
||||||
rejectPendingPlayersRequests('The skin site session ended.')
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
rejectPendingSkinUpdateRequests('The skin site session ended.')
|
return result.payload.luck
|
||||||
user.value = null
|
|
||||||
status.value = 'signed-out'
|
|
||||||
players.value = []
|
|
||||||
playersStatus.value = 'idle'
|
|
||||||
selectedPlayerId.value = null
|
|
||||||
}
|
}
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Legacy compatibility
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
export function requestSkinSiteSkinUpdate(
|
/**
|
||||||
|
* Replace a player's skin texture.
|
||||||
|
*
|
||||||
|
* The caller hands us a base64 PNG (what the in-app editor produces); we turn
|
||||||
|
* it back into a File and upload it through the skin site's texture endpoint.
|
||||||
|
*/
|
||||||
|
export async function requestSkinSiteSkinUpdate(
|
||||||
playerId: string,
|
playerId: string,
|
||||||
textureDataUrl: string,
|
textureDataUrl: string,
|
||||||
model: 'default' | 'slim',
|
model: 'default' | 'slim',
|
||||||
) {
|
): Promise<void> {
|
||||||
|
if (status.value !== 'signed-in' || !user.value) {
|
||||||
|
throw new Error('请先登录 StarLight 皮肤站。')
|
||||||
|
}
|
||||||
const player = players.value.find((candidate) => candidate.uuid === playerId)
|
const player = players.value.find((candidate) => candidate.uuid === playerId)
|
||||||
if (!connectedFrame || status.value !== 'signed-in' || !user.value) {
|
|
||||||
return Promise.reject(new Error('Sign in to the skin site before changing a skin.'))
|
|
||||||
}
|
|
||||||
if (!player || player.isMojang) {
|
if (!player || player.isMojang) {
|
||||||
return Promise.reject(new Error('This skin site player cannot be changed.'))
|
throw new Error('该玩家无法修改皮肤。')
|
||||||
}
|
}
|
||||||
if (!isSafePngDataUrl(textureDataUrl, 2_000_000)) {
|
if (!/^data:image\/png;base64,[a-z0-9+/]+={0,2}$/i.test(textureDataUrl)) {
|
||||||
return Promise.reject(new Error('The selected skin texture is invalid or too large.'))
|
throw new Error('皮肤图片无效或过大。')
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestId = `skin-update-${Date.now()}-${++skinUpdateRequestSequence}`
|
const file = await dataUrlToFile(textureDataUrl, `${player.name}.png`)
|
||||||
return new Promise<void>((resolve, reject) => {
|
const result = await skinSiteUploadTexture(playerId, file, 'SKIN', { model })
|
||||||
const timeout = setTimeout(() => {
|
if (!result.success) throw new Error(result.errorMessage)
|
||||||
pendingSkinUpdateRequests.delete(requestId)
|
|
||||||
reject(new Error('The skin site update timed out.'))
|
const refreshed = await skinSitePlayerSkin(playerId)
|
||||||
}, 20_000)
|
if (refreshed.success && refreshed.payload?.skin) {
|
||||||
pendingSkinUpdateRequests.set(requestId, { resolve, reject, timeout })
|
const updated = await buildPlayer({
|
||||||
try {
|
uuid: player.uuid,
|
||||||
connectedFrame?.postMessage(
|
name: player.name,
|
||||||
{
|
isMojang: player.isMojang,
|
||||||
type: 'starlight-skin-update-request',
|
})
|
||||||
requestId,
|
players.value = players.value.map((entry) => (entry.uuid === playerId ? updated : entry))
|
||||||
playerId,
|
}
|
||||||
textureDataUrl,
|
|
||||||
model,
|
|
||||||
},
|
|
||||||
SKIN_SITE_ORIGIN,
|
|
||||||
)
|
|
||||||
} catch (error) {
|
|
||||||
clearTimeout(timeout)
|
|
||||||
pendingSkinUpdateRequests.delete(requestId)
|
|
||||||
reject(error instanceof Error ? error : new Error(String(error)))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function requestSkinSitePlayers() {
|
async function dataUrlToFile(dataUrl: string, filename: string): Promise<File> {
|
||||||
if (!connectedFrame || status.value !== 'signed-in' || !user.value) {
|
const response = await fetch(dataUrl)
|
||||||
return Promise.reject(new Error('Sign in to the skin site before requesting players.'))
|
const blob = await response.blob()
|
||||||
}
|
return new File([blob], filename, { type: 'image/png' })
|
||||||
|
|
||||||
playersStatus.value = 'checking'
|
|
||||||
const requestId = `skin-players-${Date.now()}-${++playersRequestSequence}`
|
|
||||||
return new Promise<SkinSitePlayer[]>((resolve, reject) => {
|
|
||||||
const timeout = setTimeout(() => {
|
|
||||||
pendingPlayersRequests.delete(requestId)
|
|
||||||
playersStatus.value = 'error'
|
|
||||||
reject(new Error('The skin site player request timed out.'))
|
|
||||||
}, 30_000)
|
|
||||||
pendingPlayersRequests.set(requestId, { resolve, reject, timeout })
|
|
||||||
try {
|
|
||||||
connectedFrame?.postMessage(
|
|
||||||
{ type: 'starlight-skin-players-request', requestId },
|
|
||||||
SKIN_SITE_ORIGIN,
|
|
||||||
)
|
|
||||||
} catch (error) {
|
|
||||||
clearTimeout(timeout)
|
|
||||||
pendingPlayersRequests.delete(requestId)
|
|
||||||
playersStatus.value = 'error'
|
|
||||||
reject(error instanceof Error ? error : new Error(String(error)))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export function requestSkinSiteLuck() {
|
|
||||||
if (!connectedFrame || status.value !== 'signed-in' || !user.value) {
|
|
||||||
return Promise.reject(new Error('Sign in to the skin site before requesting luck.'))
|
|
||||||
}
|
|
||||||
|
|
||||||
const requestId = `skin-luck-${Date.now()}-${++luckRequestSequence}`
|
|
||||||
return new Promise<number>((resolve, reject) => {
|
|
||||||
const timeout = setTimeout(() => {
|
|
||||||
pendingLuckRequests.delete(requestId)
|
|
||||||
reject(new Error('The skin site luck request timed out.'))
|
|
||||||
}, 12_000)
|
|
||||||
pendingLuckRequests.set(requestId, { resolve, reject, timeout })
|
|
||||||
try {
|
|
||||||
connectedFrame?.postMessage(
|
|
||||||
{ type: 'starlight-skin-luck-request', requestId },
|
|
||||||
SKIN_SITE_ORIGIN,
|
|
||||||
)
|
|
||||||
} catch (error) {
|
|
||||||
clearTimeout(timeout)
|
|
||||||
pendingLuckRequests.delete(requestId)
|
|
||||||
reject(error instanceof Error ? error : new Error(String(error)))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export function receiveSkinSiteMessage(event: MessageEvent, frame: Window | null) {
|
|
||||||
if (!frame || event.source !== frame || event.origin !== SKIN_SITE_ORIGIN) return false
|
|
||||||
const data = event.data
|
|
||||||
if (!data || typeof data !== 'object') return false
|
|
||||||
if (data.type === 'starlight-pack-token-result') {
|
|
||||||
const pending = pendingPackTokens.get(data.requestId)
|
|
||||||
if (!pending) return false
|
|
||||||
clearTimeout(pending.timeout)
|
|
||||||
pendingPackTokens.delete(data.requestId)
|
|
||||||
if (
|
|
||||||
status.value === 'signed-in' &&
|
|
||||||
typeof data.token === 'string' &&
|
|
||||||
data.token.length > 0 &&
|
|
||||||
data.token.length <= 16_384 &&
|
|
||||||
!/\s/.test(data.token)
|
|
||||||
) {
|
|
||||||
pending.resolve(data.token)
|
|
||||||
} else pending.reject(new Error('StarLight 登录凭据不可用,请重新登录。'))
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.type === 'starlight-skin-players-result') {
|
|
||||||
if (typeof data.requestId !== 'string') return false
|
|
||||||
const pending = pendingPlayersRequests.get(data.requestId)
|
|
||||||
if (!pending) return false
|
|
||||||
clearTimeout(pending.timeout)
|
|
||||||
pendingPlayersRequests.delete(data.requestId)
|
|
||||||
if (data.ok === true && Array.isArray(data.players)) {
|
|
||||||
const nextPlayers = data.players.filter(
|
|
||||||
(player: unknown): player is SkinSitePlayer =>
|
|
||||||
typeof player === 'object' &&
|
|
||||||
player !== null &&
|
|
||||||
typeof (player as SkinSitePlayer).uuid === 'string' &&
|
|
||||||
/^[0-9a-f-]{32,36}$/i.test((player as SkinSitePlayer).uuid) &&
|
|
||||||
typeof (player as SkinSitePlayer).name === 'string' &&
|
|
||||||
(player as SkinSitePlayer).name.length > 0 &&
|
|
||||||
(player as SkinSitePlayer).name.length <= 64 &&
|
|
||||||
typeof (player as SkinSitePlayer).isMojang === 'boolean' &&
|
|
||||||
hasSafeSkinHead(player as SkinSitePlayer),
|
|
||||||
)
|
|
||||||
const previousPlayers = new Map(players.value.map((player) => [player.uuid, player]))
|
|
||||||
players.value = nextPlayers.map((player) => {
|
|
||||||
const previous = previousPlayers.get(player.uuid)
|
|
||||||
return player.skinState === 'error' && previous?.skinState === 'ready'
|
|
||||||
? { ...player, ...previous, name: player.name, isMojang: player.isMojang }
|
|
||||||
: player
|
|
||||||
})
|
|
||||||
if (
|
|
||||||
selectedPlayerId.value &&
|
|
||||||
!nextPlayers.some((player) => player.uuid === selectedPlayerId.value)
|
|
||||||
) {
|
|
||||||
selectedPlayerId.value = null
|
|
||||||
}
|
|
||||||
playersStatus.value = 'ready'
|
|
||||||
pending.resolve(players.value)
|
|
||||||
} else {
|
|
||||||
playersStatus.value = 'error'
|
|
||||||
pending.reject(
|
|
||||||
new Error(
|
|
||||||
typeof data.error === 'string' && data.error
|
|
||||||
? data.error.slice(0, 300)
|
|
||||||
: 'The skin site returned an invalid player list.',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.type === 'starlight-skin-luck-result') {
|
|
||||||
if (typeof data.requestId !== 'string') return false
|
|
||||||
const pending = pendingLuckRequests.get(data.requestId)
|
|
||||||
if (!pending) return false
|
|
||||||
clearTimeout(pending.timeout)
|
|
||||||
pendingLuckRequests.delete(data.requestId)
|
|
||||||
if (
|
|
||||||
data.ok === true &&
|
|
||||||
typeof data.luck === 'number' &&
|
|
||||||
Number.isFinite(data.luck) &&
|
|
||||||
data.luck >= 0 &&
|
|
||||||
data.luck <= 100
|
|
||||||
) {
|
|
||||||
pending.resolve(data.luck)
|
|
||||||
} else {
|
|
||||||
pending.reject(
|
|
||||||
new Error(
|
|
||||||
typeof data.error === 'string' && data.error
|
|
||||||
? data.error.slice(0, 300)
|
|
||||||
: 'The skin site returned an invalid luck result.',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.type === 'starlight-skin-update-result') {
|
|
||||||
if (typeof data.requestId !== 'string') return false
|
|
||||||
const pending = pendingSkinUpdateRequests.get(data.requestId)
|
|
||||||
if (!pending) return false
|
|
||||||
clearTimeout(pending.timeout)
|
|
||||||
pendingSkinUpdateRequests.delete(data.requestId)
|
|
||||||
if (data.ok === true) pending.resolve()
|
|
||||||
else {
|
|
||||||
pending.reject(
|
|
||||||
new Error(
|
|
||||||
typeof data.error === 'string' && data.error
|
|
||||||
? data.error.slice(0, 300)
|
|
||||||
: 'The skin site rejected the skin update.',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.type !== 'starlight-skin-session') return false
|
|
||||||
if (!['checking', 'signed-out', 'signed-in', 'error'].includes(data.status)) return false
|
|
||||||
let refreshPlayers = false
|
|
||||||
if (data.status === 'signed-in') {
|
|
||||||
if (
|
|
||||||
!data.user ||
|
|
||||||
typeof data.user.uuid !== 'string' ||
|
|
||||||
typeof data.user.username !== 'string' ||
|
|
||||||
!data.user.uuid ||
|
|
||||||
!data.user.username ||
|
|
||||||
data.user.username.length > 256
|
|
||||||
)
|
|
||||||
return false
|
|
||||||
if (user.value?.uuid && user.value.uuid !== data.user.uuid) {
|
|
||||||
rejectPendingPackTokens()
|
|
||||||
rejectPendingPlayersRequests('The skin site account changed.')
|
|
||||||
rejectPendingSkinUpdateRequests('The skin site account changed.')
|
|
||||||
players.value = []
|
|
||||||
playersStatus.value = 'idle'
|
|
||||||
selectedPlayerId.value = null
|
|
||||||
}
|
|
||||||
user.value = { uuid: data.user.uuid, username: data.user.username }
|
|
||||||
if ([`${SKIN_SITE_ORIGIN}/`, `${SKIN_SITE_ORIGIN}/login`].includes(frameUrl.value)) {
|
|
||||||
frameUrl.value = `${SKIN_SITE_ORIGIN}/profile`
|
|
||||||
}
|
|
||||||
refreshPlayers = true
|
|
||||||
} else {
|
|
||||||
rejectPendingPackTokens()
|
|
||||||
rejectPendingLuckRequests('The skin site session is unavailable.')
|
|
||||||
rejectPendingPlayersRequests('The skin site session is unavailable.')
|
|
||||||
rejectPendingSkinUpdateRequests('The skin site session is unavailable.')
|
|
||||||
user.value = null
|
|
||||||
players.value = []
|
|
||||||
playersStatus.value = 'idle'
|
|
||||||
selectedPlayerId.value = null
|
|
||||||
}
|
|
||||||
status.value = data.status
|
|
||||||
if (refreshPlayers) void requestSkinSitePlayers().catch(() => {})
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
@@ -7,15 +7,22 @@ export const UNGROUPED_GROUP_KEY = '__ungrouped__'
|
|||||||
|
|
||||||
export type GridGroupingOption = 'Group' | 'Loader' | 'Game version' | 'None'
|
export type GridGroupingOption = 'Group' | 'Loader' | 'Game version' | 'None'
|
||||||
export type GridSortOption =
|
export type GridSortOption =
|
||||||
| 'Name'
|
'Name' | 'Last played' | 'Date created' | 'Date modified' | 'Game version'
|
||||||
| 'Last played'
|
|
||||||
| 'Date created'
|
export type GridSortDirection = 'asc' | 'desc'
|
||||||
| 'Date modified'
|
|
||||||
| 'Game version'
|
export const defaultSortDirections: Record<GridSortOption, GridSortDirection> = {
|
||||||
|
Name: 'asc',
|
||||||
|
'Last played': 'desc',
|
||||||
|
'Date created': 'desc',
|
||||||
|
'Date modified': 'desc',
|
||||||
|
'Game version': 'asc',
|
||||||
|
}
|
||||||
|
|
||||||
export interface GridDisplayState {
|
export interface GridDisplayState {
|
||||||
group: GridGroupingOption
|
group: GridGroupingOption
|
||||||
sortBy: GridSortOption
|
sortBy: GridSortOption
|
||||||
|
sortDirections: Partial<Record<GridSortOption, GridSortDirection>>
|
||||||
collapsedGroups: string[]
|
collapsedGroups: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,6 +45,7 @@ export function useGridGrouping<T extends Record<string, unknown>>(
|
|||||||
{
|
{
|
||||||
group: 'Group',
|
group: 'Group',
|
||||||
sortBy: 'Name',
|
sortBy: 'Name',
|
||||||
|
sortDirections: {},
|
||||||
collapsedGroups: [],
|
collapsedGroups: [],
|
||||||
},
|
},
|
||||||
localStorage,
|
localStorage,
|
||||||
@@ -66,7 +74,7 @@ export function useGridGrouping<T extends Record<string, unknown>>(
|
|||||||
state.value.collapsedGroups = [...collapsedSections]
|
state.value.collapsedGroups = [...collapsedSections]
|
||||||
}
|
}
|
||||||
|
|
||||||
function sortInstances(instances: T[], sortBy: GridSortOption): T[] {
|
function sortInstances(instances: T[], sortBy: GridSortOption, ascending: boolean): T[] {
|
||||||
const sorted = [...instances]
|
const sorted = [...instances]
|
||||||
const getGameVersion = options.getGameVersion ?? ((i: T) => i.game_version ?? '')
|
const getGameVersion = options.getGameVersion ?? ((i: T) => i.game_version ?? '')
|
||||||
const getLastPlayed = options.getLastPlayed ?? ((i: T) => i.last_played ?? 0)
|
const getLastPlayed = options.getLastPlayed ?? ((i: T) => i.last_played ?? 0)
|
||||||
@@ -83,16 +91,19 @@ export function useGridGrouping<T extends Record<string, unknown>>(
|
|||||||
)
|
)
|
||||||
break
|
break
|
||||||
case 'Last played':
|
case 'Last played':
|
||||||
sorted.sort((a, b) => dayjs(getLastPlayed(b)).diff(dayjs(getLastPlayed(a))))
|
sorted.sort((a, b) => dayjs(getLastPlayed(a)).diff(dayjs(getLastPlayed(b))))
|
||||||
break
|
break
|
||||||
case 'Date created':
|
case 'Date created':
|
||||||
sorted.sort((a, b) => dayjs(getDateCreated(b)).diff(dayjs(getDateCreated(a))))
|
sorted.sort((a, b) => dayjs(getDateCreated(a)).diff(dayjs(getDateCreated(b))))
|
||||||
break
|
break
|
||||||
case 'Date modified':
|
case 'Date modified':
|
||||||
sorted.sort((a, b) => dayjs(getDateModified(b)).diff(dayjs(getDateModified(a))))
|
sorted.sort((a, b) => dayjs(getDateModified(a)).diff(dayjs(getDateModified(b))))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ascending) {
|
||||||
|
sorted.reverse()
|
||||||
|
}
|
||||||
return sorted
|
return sorted
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,11 +159,25 @@ export function useGridGrouping<T extends Record<string, unknown>>(
|
|||||||
function sortSections(
|
function sortSections(
|
||||||
instanceMap: Map<string, T[]>,
|
instanceMap: Map<string, T[]>,
|
||||||
group: GridGroupingOption,
|
group: GridGroupingOption,
|
||||||
|
sortBy: GridSortOption,
|
||||||
): Map<string, T[]> {
|
): Map<string, T[]> {
|
||||||
if (group !== 'Group' && group !== 'Game version') {
|
if (group !== 'Group' && group !== 'Game version') {
|
||||||
return instanceMap
|
return instanceMap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (group === 'Group' && sortBy !== 'Name') {
|
||||||
|
if (instanceMap.has(UNGROUPED_GROUP_KEY) && instanceMap.size > 1) {
|
||||||
|
const ungroupedInstances = instanceMap.get(UNGROUPED_GROUP_KEY)!
|
||||||
|
instanceMap.delete(UNGROUPED_GROUP_KEY)
|
||||||
|
const newMap = new Map<string, T[]>([[UNGROUPED_GROUP_KEY, ungroupedInstances]])
|
||||||
|
for (const [key, instances] of instanceMap) {
|
||||||
|
newMap.set(key, instances)
|
||||||
|
}
|
||||||
|
return newMap
|
||||||
|
}
|
||||||
|
return instanceMap
|
||||||
|
}
|
||||||
|
|
||||||
const sortedEntries = [...instanceMap.entries()].sort((a, b) => {
|
const sortedEntries = [...instanceMap.entries()].sort((a, b) => {
|
||||||
if (group === 'Group') {
|
if (group === 'Group') {
|
||||||
if (a[0] === UNGROUPED_GROUP_KEY && b[0] !== UNGROUPED_GROUP_KEY) return -1
|
if (a[0] === UNGROUPED_GROUP_KEY && b[0] !== UNGROUPED_GROUP_KEY) return -1
|
||||||
@@ -166,12 +191,30 @@ export function useGridGrouping<T extends Record<string, unknown>>(
|
|||||||
return instanceMap
|
return instanceMap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sortDirection = computed<GridSortDirection>(() => {
|
||||||
|
return (
|
||||||
|
state.value.sortDirections[state.value.sortBy] ?? defaultSortDirections[state.value.sortBy]
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
const isSortAscending = computed(() => sortDirection.value === 'asc')
|
||||||
|
|
||||||
|
const toggleSortDirection = () => {
|
||||||
|
const current = sortDirection.value
|
||||||
|
const next: GridSortDirection = current === 'asc' ? 'desc' : 'asc'
|
||||||
|
state.value.sortDirections = {
|
||||||
|
...state.value.sortDirections,
|
||||||
|
[state.value.sortBy]: next,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const filteredResults = computed(() => {
|
const filteredResults = computed(() => {
|
||||||
const { group = 'Group', sortBy = 'Name' } = state.value
|
const { group = 'Group', sortBy = 'Name' } = state.value
|
||||||
|
const ascending = isSortAscending.value
|
||||||
|
|
||||||
const sorted = sortInstances(instances.value, sortBy)
|
const sorted = sortInstances(instances.value, sortBy, ascending)
|
||||||
const grouped = groupInstances(sorted, group)
|
const grouped = groupInstances(sorted, group)
|
||||||
return sortSections(grouped, group)
|
return sortSections(grouped, group, sortBy)
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -180,6 +223,9 @@ export function useGridGrouping<T extends Record<string, unknown>>(
|
|||||||
filteredResults,
|
filteredResults,
|
||||||
isSectionCollapsed,
|
isSectionCollapsed,
|
||||||
setSectionCollapsed,
|
setSectionCollapsed,
|
||||||
|
sortDirection,
|
||||||
|
isSortAscending,
|
||||||
|
toggleSortDirection,
|
||||||
UNGROUPED_GROUP_KEY,
|
UNGROUPED_GROUP_KEY,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,182 @@
|
|||||||
|
import { computed, type Ref, ref, watch } from 'vue'
|
||||||
|
|
||||||
|
import { instance_groups_listener } from '@/helpers/events'
|
||||||
|
import {
|
||||||
|
create_group,
|
||||||
|
delete_group,
|
||||||
|
type InstanceGroupDefinition,
|
||||||
|
type InstanceGroupMembershipUpdate,
|
||||||
|
list_groups,
|
||||||
|
MAX_INSTANCE_GROUP_NAME_LENGTH,
|
||||||
|
rename_group,
|
||||||
|
set_group_memberships,
|
||||||
|
set_group_order,
|
||||||
|
} from '@/helpers/instance-groups'
|
||||||
|
|
||||||
|
export const FAVORITES_GROUP_ID = 'group:favorites'
|
||||||
|
|
||||||
|
export const UNGROUPED_GROUP_ID = 'group:none'
|
||||||
|
|
||||||
|
export { MAX_INSTANCE_GROUP_NAME_LENGTH }
|
||||||
|
|
||||||
|
export { type InstanceGroupDefinition, type InstanceGroupMembershipUpdate }
|
||||||
|
|
||||||
|
export interface InstanceGroupWithMembership {
|
||||||
|
key: string
|
||||||
|
name: string
|
||||||
|
instances: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useInstanceGroups(instances: Ref<{ id: string; groups: string[] }[]>) {
|
||||||
|
const libraryGroups = ref<InstanceGroupDefinition[]>([])
|
||||||
|
const libraryGroupsLoaded = ref(false)
|
||||||
|
|
||||||
|
async function fetchGroups() {
|
||||||
|
libraryGroups.value = await list_groups()
|
||||||
|
libraryGroupsLoaded.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchGroups()
|
||||||
|
|
||||||
|
instance_groups_listener(() => {
|
||||||
|
fetchGroups()
|
||||||
|
})
|
||||||
|
|
||||||
|
const orderedLibraryGroupIds = ref<string[]>([])
|
||||||
|
|
||||||
|
watch(
|
||||||
|
libraryGroups,
|
||||||
|
(groups) => {
|
||||||
|
orderedLibraryGroupIds.value = groups.map((g) => g.id)
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
)
|
||||||
|
|
||||||
|
const instanceGroups = computed(() => {
|
||||||
|
if (!libraryGroupsLoaded.value) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
const instanceGroupMap = new Map<string, string[]>()
|
||||||
|
|
||||||
|
for (const instance of instances.value) {
|
||||||
|
const groups = instance.groups ?? []
|
||||||
|
for (const groupId of groups) {
|
||||||
|
if (!instanceGroupMap.has(groupId)) {
|
||||||
|
instanceGroupMap.set(groupId, [])
|
||||||
|
}
|
||||||
|
instanceGroupMap.get(groupId)!.push(instance.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const allGroupIds = new Set<string>()
|
||||||
|
const groupMap = new Map<string, string[]>()
|
||||||
|
|
||||||
|
for (const groupId of orderedLibraryGroupIds.value) {
|
||||||
|
allGroupIds.add(groupId)
|
||||||
|
groupMap.set(groupId, instanceGroupMap.get(groupId) ?? [])
|
||||||
|
}
|
||||||
|
|
||||||
|
const ungroupedIds: string[] = []
|
||||||
|
for (const instance of instances.value) {
|
||||||
|
const instanceGroups = instance.groups ?? []
|
||||||
|
const isInAnyGroup = instanceGroups.some((g) => allGroupIds.has(g))
|
||||||
|
if (!isInAnyGroup) {
|
||||||
|
ungroupedIds.push(instance.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ungroupedIds.length > 0) {
|
||||||
|
groupMap.set(UNGROUPED_GROUP_ID, ungroupedIds)
|
||||||
|
}
|
||||||
|
|
||||||
|
return [...groupMap.entries()].map(([key, instances]) => ({
|
||||||
|
key,
|
||||||
|
name:
|
||||||
|
key === UNGROUPED_GROUP_ID
|
||||||
|
? 'Ungrouped'
|
||||||
|
: (libraryGroups.value.find((g) => g.id === key)?.name ?? key),
|
||||||
|
instances,
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
|
||||||
|
const creatingGroup = ref(false)
|
||||||
|
const reorderingGroups = ref(false)
|
||||||
|
|
||||||
|
async function createNewGroup(name: string): Promise<string | null> {
|
||||||
|
creatingGroup.value = true
|
||||||
|
try {
|
||||||
|
const group = await create_group(name)
|
||||||
|
libraryGroups.value = [...libraryGroups.value, group]
|
||||||
|
orderedLibraryGroupIds.value = [...orderedLibraryGroupIds.value, group.id]
|
||||||
|
return group.id
|
||||||
|
} finally {
|
||||||
|
creatingGroup.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function renameGroupById(id: string, newName: string): Promise<boolean> {
|
||||||
|
if (id === FAVORITES_GROUP_ID) return false
|
||||||
|
const result = await rename_group(id, newName)
|
||||||
|
const idx = libraryGroups.value.findIndex((g) => g.id === id)
|
||||||
|
if (idx !== -1) {
|
||||||
|
libraryGroups.value = [
|
||||||
|
...libraryGroups.value.slice(0, idx),
|
||||||
|
result,
|
||||||
|
...libraryGroups.value.slice(idx + 1),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteGroupById(id: string): Promise<boolean> {
|
||||||
|
if (id === FAVORITES_GROUP_ID) return false
|
||||||
|
await delete_group(id)
|
||||||
|
libraryGroups.value = libraryGroups.value.filter((g) => g.id !== id)
|
||||||
|
orderedLibraryGroupIds.value = orderedLibraryGroupIds.value.filter((gid) => gid !== id)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
async function reorderGroups(groupIds: string[]): Promise<boolean> {
|
||||||
|
reorderingGroups.value = true
|
||||||
|
try {
|
||||||
|
await set_group_order(groupIds)
|
||||||
|
// Favorites is rendered separately from draggable sections. Keep it in
|
||||||
|
// the local order after a drag even though the backend accepts only the
|
||||||
|
// reorderable group ids; otherwise it appears again as an ordinary
|
||||||
|
// section until the next full group refresh.
|
||||||
|
orderedLibraryGroupIds.value = [
|
||||||
|
FAVORITES_GROUP_ID,
|
||||||
|
...groupIds.filter((id) => id !== FAVORITES_GROUP_ID),
|
||||||
|
]
|
||||||
|
return true
|
||||||
|
} finally {
|
||||||
|
reorderingGroups.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setMemberships(updates: InstanceGroupMembershipUpdate[]): Promise<boolean> {
|
||||||
|
await set_group_memberships(updates)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
function groupNameById(id: string): string | undefined {
|
||||||
|
if (id === UNGROUPED_GROUP_ID) return 'Ungrouped'
|
||||||
|
return libraryGroups.value.find((g) => g.id === id)?.name
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
libraryGroups,
|
||||||
|
libraryGroupsLoaded,
|
||||||
|
orderedLibraryGroupIds,
|
||||||
|
instanceGroups,
|
||||||
|
creatingGroup,
|
||||||
|
reorderingGroups,
|
||||||
|
createGroup: createNewGroup,
|
||||||
|
renameGroupById,
|
||||||
|
deleteGroupById,
|
||||||
|
reorderGroups,
|
||||||
|
setMemberships,
|
||||||
|
groupNameById,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,215 @@
|
|||||||
|
import {
|
||||||
|
type KeyBinding,
|
||||||
|
bindingMatchesKeyboardEvent,
|
||||||
|
bindingMatchesMouseEvent,
|
||||||
|
bindingMatchesWheelEvent,
|
||||||
|
useModalStack,
|
||||||
|
} from '@modrinth/ui'
|
||||||
|
import { computed, onUnmounted } from 'vue'
|
||||||
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
|
|
||||||
|
import { useNetworkStatus } from '@/composables/useNetworkStatus'
|
||||||
|
import {
|
||||||
|
SCROLL_ACTIONS,
|
||||||
|
SHORTCUT_ACTIONS,
|
||||||
|
type ShortcutAction,
|
||||||
|
} from '@/helpers/shortcut-actions'
|
||||||
|
import { resolveAllBindings } from '@/helpers/shortcut-bindings'
|
||||||
|
import { getNavShortcutEnabled } from '@/helpers/nav-shortcut-state'
|
||||||
|
import { getQuickScrollEnabled } from '@/helpers/scroll-top-state'
|
||||||
|
import { useTheming } from '@/store/theme'
|
||||||
|
|
||||||
|
/** Editing surfaces keep these keys for themselves. */
|
||||||
|
function isEditableTarget(target: EventTarget | null) {
|
||||||
|
return (
|
||||||
|
target instanceof HTMLInputElement ||
|
||||||
|
target instanceof HTMLTextAreaElement ||
|
||||||
|
target instanceof HTMLSelectElement ||
|
||||||
|
(target instanceof HTMLElement && target.isContentEditable)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function scrollsAtOwnLevel(element: Element) {
|
||||||
|
const { overflowY } = getComputedStyle(element)
|
||||||
|
return /(auto|scroll|overlay)/.test(overflowY) && element.scrollHeight > element.clientHeight
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A container that scrolls the page itself rather than a widget on it. */
|
||||||
|
function isPageScroller(element: Element) {
|
||||||
|
return scrollsAtOwnLevel(element) && element.clientHeight >= window.innerHeight / 2
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Nearest scrolling ancestor, whatever its size. */
|
||||||
|
function nearestScrollContainer(target: EventTarget | null) {
|
||||||
|
let element = target instanceof Element ? target : null
|
||||||
|
while (element) {
|
||||||
|
if (scrollsAtOwnLevel(element)) return element
|
||||||
|
element = element.parentElement
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The page's own scroller. Most pages scroll inside `.app-viewport`, but some
|
||||||
|
* screens (settings, consoles, studios) turn that element's scrolling off and
|
||||||
|
* host a full-height container inside it, so fall back to whatever fills the
|
||||||
|
* middle of the viewport.
|
||||||
|
*/
|
||||||
|
function resolvePageScroller() {
|
||||||
|
const viewport = document.querySelector<HTMLElement>('.app-viewport')
|
||||||
|
if (!viewport) return null
|
||||||
|
if (isPageScroller(viewport)) return viewport
|
||||||
|
|
||||||
|
const bounds = viewport.getBoundingClientRect()
|
||||||
|
let element: Element | null = document.elementFromPoint(
|
||||||
|
bounds.left + bounds.width / 2,
|
||||||
|
bounds.top + bounds.height / 2,
|
||||||
|
)
|
||||||
|
while (element) {
|
||||||
|
if (isPageScroller(element)) return element
|
||||||
|
element = element.parentElement
|
||||||
|
}
|
||||||
|
|
||||||
|
return viewport
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setupKeyboardShortcuts() {
|
||||||
|
const themeStore = useTheming()
|
||||||
|
const { hasModal } = useModalStack()
|
||||||
|
const route = useRoute()
|
||||||
|
const router = useRouter()
|
||||||
|
const { offline } = useNetworkStatus()
|
||||||
|
|
||||||
|
themeStore.quickScrollEnabled = getQuickScrollEnabled()
|
||||||
|
for (const shortcut of SHORTCUT_ACTIONS) {
|
||||||
|
if (shortcut.group === 'nav') themeStore[shortcut.enabledField] = getNavShortcutEnabled(shortcut.id)
|
||||||
|
}
|
||||||
|
themeStore.shortcutBindings = resolveAllBindings()
|
||||||
|
|
||||||
|
/** The combination an action answers to now: recorded if there is one, default otherwise. */
|
||||||
|
function bindingFor(action: ShortcutAction): KeyBinding {
|
||||||
|
return themeStore.shortcutBindings[action.id] ?? action.defaultBinding
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Whether an action is switched on and reachable in the current state. */
|
||||||
|
function shortcutIsAvailable(action: ShortcutAction): boolean {
|
||||||
|
if (!themeStore[action.enabledField]) return false
|
||||||
|
return !action.unavailable?.({
|
||||||
|
worldsTabEnabled: themeStore.featureFlags.worlds_tab,
|
||||||
|
offline: offline.value,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function findShortcut<E extends Event>(
|
||||||
|
event: E,
|
||||||
|
matches: (binding: KeyBinding, event: E) => boolean,
|
||||||
|
{ includeDisabled = false }: { includeDisabled?: boolean } = {},
|
||||||
|
): ShortcutAction | null {
|
||||||
|
if (hasModal.value) return null
|
||||||
|
if (isEditableTarget(event.target)) return null
|
||||||
|
|
||||||
|
for (const action of SHORTCUT_ACTIONS) {
|
||||||
|
if (!includeDisabled && !shortcutIsAvailable(action)) continue
|
||||||
|
if (matches(bindingFor(action), event)) return action
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Does what an action is for. Scrolling actions move the page's own scroller. */
|
||||||
|
function runShortcut(action: ShortcutAction, event: Event) {
|
||||||
|
if (action.target) {
|
||||||
|
router.push(action.target(route))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const focusedContainer = nearestScrollContainer(event.target)
|
||||||
|
if (focusedContainer && !isPageScroller(focusedContainer)) return
|
||||||
|
|
||||||
|
const scroller = resolvePageScroller()
|
||||||
|
if (!scroller) return
|
||||||
|
|
||||||
|
action.applyScroll?.(scroller)
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleScrollShortcutKey(event: KeyboardEvent) {
|
||||||
|
if (event.isComposing) return
|
||||||
|
|
||||||
|
const match = findShortcut(event, bindingMatchesKeyboardEvent, { includeDisabled: true })
|
||||||
|
if (match?.group !== 'scroll') return
|
||||||
|
|
||||||
|
const focusedContainer = nearestScrollContainer(event.target)
|
||||||
|
if (focusedContainer && !isPageScroller(focusedContainer)) return
|
||||||
|
|
||||||
|
const scroller = resolvePageScroller()
|
||||||
|
if (!scroller) return
|
||||||
|
|
||||||
|
event.preventDefault()
|
||||||
|
if (!shortcutIsAvailable(match)) return
|
||||||
|
|
||||||
|
match.applyScroll?.(scroller)
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleNavShortcutKey(event: KeyboardEvent) {
|
||||||
|
if (event.isComposing) return
|
||||||
|
|
||||||
|
const match = findShortcut(event, bindingMatchesKeyboardEvent)
|
||||||
|
if (match?.group !== 'nav') return
|
||||||
|
|
||||||
|
event.preventDefault()
|
||||||
|
runShortcut(match, event)
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasPointerBindings = computed(() =>
|
||||||
|
SHORTCUT_ACTIONS.some((action) => bindingFor(action).device === 'mouse'),
|
||||||
|
)
|
||||||
|
|
||||||
|
function handleShortcutMouse(event: MouseEvent) {
|
||||||
|
if (!hasPointerBindings.value) return
|
||||||
|
|
||||||
|
const match = findShortcut(event, bindingMatchesMouseEvent)
|
||||||
|
if (!match) return
|
||||||
|
|
||||||
|
event.preventDefault()
|
||||||
|
event.stopPropagation()
|
||||||
|
runShortcut(match, event)
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleShortcutWheel(event: WheelEvent) {
|
||||||
|
if (!hasPointerBindings.value) return
|
||||||
|
|
||||||
|
const match = findShortcut(event, bindingMatchesWheelEvent)
|
||||||
|
if (!match) return
|
||||||
|
|
||||||
|
event.preventDefault()
|
||||||
|
event.stopPropagation()
|
||||||
|
runShortcut(match, event)
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleGlobalKeydown(event: KeyboardEvent) {
|
||||||
|
const key = event.key.toLowerCase()
|
||||||
|
const isFindShortcut = key === 'f' && (event.ctrlKey || event.metaKey)
|
||||||
|
const isBlockedDevtoolsShortcut = event.key === 'F12' && !themeStore.devMode
|
||||||
|
|
||||||
|
if (isFindShortcut || isBlockedDevtoolsShortcut) {
|
||||||
|
event.preventDefault()
|
||||||
|
event.stopPropagation()
|
||||||
|
}
|
||||||
|
|
||||||
|
handleScrollShortcutKey(event)
|
||||||
|
handleNavShortcutKey(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('keydown', handleGlobalKeydown, true)
|
||||||
|
window.addEventListener('mousedown', handleShortcutMouse, true)
|
||||||
|
// Not passive: a bound wheel direction has to keep the page from scrolling.
|
||||||
|
window.addEventListener('wheel', handleShortcutWheel, { capture: true, passive: false })
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
window.removeEventListener('keydown', handleGlobalKeydown, true)
|
||||||
|
window.removeEventListener('mousedown', handleShortcutMouse, true)
|
||||||
|
window.removeEventListener('wheel', handleShortcutWheel, { capture: true, passive: false })
|
||||||
|
})
|
||||||
|
|
||||||
|
return { bindingFor, shortcutIsAvailable, SCROLL_ACTIONS }
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
interface InstanceProperties {
|
||||||
|
loader: string
|
||||||
|
game_version: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ProjectProperties extends InstanceProperties {
|
||||||
|
id: string
|
||||||
|
project_type: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type AnalyticsEventMap = {
|
||||||
|
Launched: { version: string; dev: boolean; onboarded: boolean }
|
||||||
|
PageView: { path: string; fromPath: string; failed: unknown }
|
||||||
|
InstanceCreate: { source: string }
|
||||||
|
InstanceCreateStart: { source: string }
|
||||||
|
InstanceStart: InstanceProperties & { source: string }
|
||||||
|
InstanceStop: Partial<InstanceProperties> & { source?: string }
|
||||||
|
InstanceDuplicate: InstanceProperties
|
||||||
|
InstanceRepair: InstanceProperties
|
||||||
|
InstanceSetIcon: Record<string, never>
|
||||||
|
InstanceRemoveIcon: Record<string, never>
|
||||||
|
InstanceUpdateAll: InstanceProperties & { count: number; selected: boolean }
|
||||||
|
InstanceProjectUpdate: InstanceProperties & { id: string; name: string; project_type: string }
|
||||||
|
InstanceProjectDisable: InstanceProperties & {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
project_type: string
|
||||||
|
disabled: boolean
|
||||||
|
}
|
||||||
|
InstanceProjectRemove: InstanceProperties & { id: string; name: string; project_type: string }
|
||||||
|
ProjectInstall: ProjectProperties & { version_id: string; title: string; source: string }
|
||||||
|
ProjectInstallStart: { source: string }
|
||||||
|
PackInstall: { id: string; version_id: string; title: string; source: string }
|
||||||
|
PackInstallStart: Record<string, never>
|
||||||
|
AccountLogIn: { source?: string }
|
||||||
|
AccountLogOut: Record<string, never>
|
||||||
|
JavaTest: { path: string; success: boolean }
|
||||||
|
JavaManualSelect: { version: string }
|
||||||
|
JavaAutoDetect: { path: string; version: string }
|
||||||
|
GalleryImageNext: { project_id: string; url: string }
|
||||||
|
GalleryImagePrevious: { project_id: string; url: unknown }
|
||||||
|
GalleryImageExpand: { project_id: string; url: string }
|
||||||
|
}
|
||||||
|
|
||||||
|
export type AnalyticsEvent = keyof AnalyticsEventMap
|
||||||
|
|
||||||
|
let optedIn = false
|
||||||
|
let debugEnabled = false
|
||||||
|
|
||||||
|
export const initAnalytics = () => {
|
||||||
|
optedIn = true
|
||||||
|
}
|
||||||
|
|
||||||
|
export const debugAnalytics = () => {
|
||||||
|
debugEnabled = true
|
||||||
|
}
|
||||||
|
|
||||||
|
export const optOutAnalytics = () => {
|
||||||
|
optedIn = false
|
||||||
|
}
|
||||||
|
|
||||||
|
export const optInAnalytics = () => {
|
||||||
|
optedIn = true
|
||||||
|
}
|
||||||
|
|
||||||
|
type OptionalArgs<T> = Record<string, never> extends T ? [properties?: T] : [properties: T]
|
||||||
|
|
||||||
|
export const trackEvent = <E extends AnalyticsEvent>(
|
||||||
|
eventName: E,
|
||||||
|
...args: OptionalArgs<AnalyticsEventMap[E]>
|
||||||
|
) => {
|
||||||
|
if (optedIn && debugEnabled) {
|
||||||
|
console.debug('[Starlight telemetry disabled]', eventName, args[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/**
|
||||||
|
* Starlight anniversary helpers.
|
||||||
|
*
|
||||||
|
* Starlight's first release was on 2014-10-04, so every October 4th the
|
||||||
|
* launcher shows a small celebration. The anniversary number is simply
|
||||||
|
* `currentYear - 2014`.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** Year of Starlight's first release. */
|
||||||
|
export const STARLIGHT_FOUNDING_YEAR = 2014
|
||||||
|
|
||||||
|
/** Month (1-12) of Starlight's anniversary. */
|
||||||
|
export const STARLIGHT_ANNIVERSARY_MONTH = 10
|
||||||
|
|
||||||
|
/** Day of month of Starlight's anniversary. */
|
||||||
|
export const STARLIGHT_ANNIVERSARY_DAY = 4
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the given date falls on Starlight's anniversary (October 4th).
|
||||||
|
* Uses the local timezone, which is what the launcher user experiences.
|
||||||
|
*/
|
||||||
|
export function isAnniversary(date: Date = new Date()): boolean {
|
||||||
|
return (
|
||||||
|
date.getMonth() + 1 === STARLIGHT_ANNIVERSARY_MONTH &&
|
||||||
|
date.getDate() === STARLIGHT_ANNIVERSARY_DAY
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The anniversary number for the given date (e.g. 12 for 2026).
|
||||||
|
* Not clamped: callers decide whether to guard against pre-2014 dates.
|
||||||
|
*/
|
||||||
|
export function anniversaryYear(date: Date = new Date()): number {
|
||||||
|
return date.getFullYear() - STARLIGHT_FOUNDING_YEAR
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the celebration should currently be shown.
|
||||||
|
*
|
||||||
|
* Normally this is only true on October 4th, but the developer-page
|
||||||
|
* `force_anniversary_celebration` feature flag forces it on for previewing.
|
||||||
|
*/
|
||||||
|
export function shouldCelebrate(force = false, date: Date = new Date()): boolean {
|
||||||
|
return force || isAnniversary(date)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** English ordinal suffix for a number (1 -> "1st", 12 -> "12th"). */
|
||||||
|
export function ordinal(n: number): string {
|
||||||
|
const mod100 = n % 100
|
||||||
|
if (mod100 >= 11 && mod100 <= 13) return `${n}th`
|
||||||
|
switch (n % 10) {
|
||||||
|
case 1:
|
||||||
|
return `${n}st`
|
||||||
|
case 2:
|
||||||
|
return `${n}nd`
|
||||||
|
case 3:
|
||||||
|
return `${n}rd`
|
||||||
|
default:
|
||||||
|
return `${n}th`
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -82,6 +82,16 @@ export async function instance_bulk_update_progress_listener(callback) {
|
|||||||
return await listen('instance_bulk_update_progress', (event) => callback(event.payload))
|
return await listen('instance_bulk_update_progress', (event) => callback(event.payload))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Payload for the 'instance_groups_changed' event
|
||||||
|
/*
|
||||||
|
InstanceGroupsChangedPayload {
|
||||||
|
instance_ids: string[]
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
export async function instance_groups_listener(callback) {
|
||||||
|
return await listen('instance_groups_changed', (event) => callback(event.payload))
|
||||||
|
}
|
||||||
|
|
||||||
export async function install_job_listener(callback) {
|
export async function install_job_listener(callback) {
|
||||||
return await listen('install_job', (event) => callback(event.payload))
|
return await listen('install_job', (event) => callback(event.payload))
|
||||||
}
|
}
|
||||||
@@ -150,6 +160,10 @@ export async function notification_listener(callback) {
|
|||||||
return await listen('notification', (event) => callback(event.payload))
|
return await listen('notification', (event) => callback(event.payload))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function logshare_ai_listener(callback) {
|
||||||
|
return await listen('logshare_ai', (event) => callback(event.payload))
|
||||||
|
}
|
||||||
|
|
||||||
/// Payload for the 'log' event
|
/// Payload for the 'log' event
|
||||||
/*
|
/*
|
||||||
LogPayload {
|
LogPayload {
|
||||||
|
|||||||
@@ -0,0 +1,179 @@
|
|||||||
|
/**
|
||||||
|
* Font family plumbing shared by the appearance settings pickers and the theme
|
||||||
|
* store. Kept free of imports so `node --test` can load it directly.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** Mirrors `--font-standard` in `packages/assets/styles/defaults.scss`. */
|
||||||
|
export const DEFAULT_UI_FONT_STACK =
|
||||||
|
'Inter, -apple-system, BlinkMacSystemFont, Segoe UI, Oxygen, Ubuntu, Roboto, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif'
|
||||||
|
|
||||||
|
/** Mirrors `--mono-font` in `packages/assets/styles/defaults.scss`. */
|
||||||
|
export const DEFAULT_MONO_FONT_STACK =
|
||||||
|
'ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace'
|
||||||
|
|
||||||
|
/** Picker value for "follow the launcher default"; persisted as `null`. */
|
||||||
|
export const FOLLOW_DEFAULT_FONT = ''
|
||||||
|
|
||||||
|
export interface SystemFontFamily {
|
||||||
|
family: string
|
||||||
|
monospaced: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FontFamilyOption {
|
||||||
|
value: string
|
||||||
|
label: string
|
||||||
|
subLabel?: string
|
||||||
|
searchTerms?: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export type FontFamilyOptionOrDivider = FontFamilyOption | { type: 'divider' }
|
||||||
|
|
||||||
|
export interface FontFamilyOptionsConfig {
|
||||||
|
defaultLabel: string
|
||||||
|
selected?: string | null
|
||||||
|
missingLabel?: string
|
||||||
|
monospaceLabel?: string
|
||||||
|
groupMonospaced?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const MAX_FONT_FAMILY_LENGTH = 128
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quotes and escapes an installed family name so it cannot break out of the
|
||||||
|
* font-family declaration it is spliced into. Returns null when the name has
|
||||||
|
* nothing usable left.
|
||||||
|
*/
|
||||||
|
export function cssFontFamilyName(name: string): string | null {
|
||||||
|
const trimmed = name.replace(/\p{Cc}/gu, '').trim()
|
||||||
|
|
||||||
|
if (!trimmed || trimmed.length > MAX_FONT_FAMILY_LENGTH) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return `"${trimmed.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The value written into `--font-standard` / `--mono-font`. The launcher stack
|
||||||
|
* always trails the chosen family so an unresolvable name degrades to the
|
||||||
|
* previous default instead of the user agent's own font.
|
||||||
|
*/
|
||||||
|
export function resolveFontFamily(
|
||||||
|
setting: string | null | undefined,
|
||||||
|
fallbackStack: string,
|
||||||
|
): string {
|
||||||
|
if (!setting) {
|
||||||
|
return fallbackStack
|
||||||
|
}
|
||||||
|
|
||||||
|
const family = cssFontFamilyName(setting)
|
||||||
|
|
||||||
|
return family ? `${family}, ${fallbackStack}` : fallbackStack
|
||||||
|
}
|
||||||
|
|
||||||
|
export function fontSettingToOptionValue(setting: string | null | undefined): string {
|
||||||
|
return setting ?? FOLLOW_DEFAULT_FONT
|
||||||
|
}
|
||||||
|
|
||||||
|
export function optionValueToFontSetting(value: string): string | null {
|
||||||
|
const trimmed = value.trim()
|
||||||
|
|
||||||
|
return trimmed === FOLLOW_DEFAULT_FONT ? null : trimmed
|
||||||
|
}
|
||||||
|
|
||||||
|
function compareFamilies(first: SystemFontFamily, second: SystemFontFamily): number {
|
||||||
|
const left = first.family.toLowerCase()
|
||||||
|
const right = second.family.toLowerCase()
|
||||||
|
|
||||||
|
if (left === right) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return left < right ? -1 : 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function toOption(family: SystemFontFamily, monospaceLabel?: string): FontFamilyOption {
|
||||||
|
return {
|
||||||
|
value: family.family,
|
||||||
|
label: family.family,
|
||||||
|
...(family.monospaced && monospaceLabel
|
||||||
|
? { subLabel: monospaceLabel, searchTerms: [monospaceLabel] }
|
||||||
|
: {}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The spelling the font list uses for a stored family. Font names are matched
|
||||||
|
* case-insensitively so a stored value that only differs in case still selects
|
||||||
|
* its option instead of leaving the picker blank.
|
||||||
|
*/
|
||||||
|
export function canonicalFontFamily(
|
||||||
|
fonts: SystemFontFamily[],
|
||||||
|
setting: string | null | undefined,
|
||||||
|
): string {
|
||||||
|
const selected = optionValueToFontSetting(setting ?? '')
|
||||||
|
if (!selected) {
|
||||||
|
return FOLLOW_DEFAULT_FONT
|
||||||
|
}
|
||||||
|
|
||||||
|
const listed = fonts.find((font) => font.family.trim().toLowerCase() === selected.toLowerCase())
|
||||||
|
|
||||||
|
return listed ? listed.family.trim() : selected
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the picker options for the installed font collection: the default
|
||||||
|
* entry first, the current selection re-added when it is no longer installed,
|
||||||
|
* and — for the monospace picker — monospaced families ahead of the rest.
|
||||||
|
*/
|
||||||
|
export function buildFontFamilyOptions(
|
||||||
|
fonts: SystemFontFamily[],
|
||||||
|
config: FontFamilyOptionsConfig,
|
||||||
|
): FontFamilyOptionOrDivider[] {
|
||||||
|
const families = new Map<string, SystemFontFamily>()
|
||||||
|
for (const font of fonts) {
|
||||||
|
const family = font.family.trim()
|
||||||
|
|
||||||
|
if (!family) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
const key = family.toLowerCase()
|
||||||
|
const known = families.get(key)
|
||||||
|
|
||||||
|
if (known) {
|
||||||
|
known.monospaced ||= font.monospaced
|
||||||
|
} else {
|
||||||
|
families.set(key, { family, monospaced: font.monospaced })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const sorted = [...families.values()].sort(compareFamilies)
|
||||||
|
const selected = optionValueToFontSetting(config.selected ?? '')
|
||||||
|
const options: FontFamilyOptionOrDivider[] = [
|
||||||
|
{ value: FOLLOW_DEFAULT_FONT, label: config.defaultLabel },
|
||||||
|
]
|
||||||
|
|
||||||
|
if (selected && !families.has(selected.toLowerCase()) && config.missingLabel) {
|
||||||
|
options.push({ value: selected, label: selected, subLabel: config.missingLabel })
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.groupMonospaced) {
|
||||||
|
const monospaced = sorted.filter((font) => font.monospaced)
|
||||||
|
const proportional = sorted.filter((font) => !font.monospaced)
|
||||||
|
|
||||||
|
options.push(...monospaced.map((font) => toOption(font, config.monospaceLabel)))
|
||||||
|
|
||||||
|
if (monospaced.length > 0 && proportional.length > 0) {
|
||||||
|
options.push({ type: 'divider' })
|
||||||
|
}
|
||||||
|
|
||||||
|
options.push(...proportional.map((font) => toOption(font, config.monospaceLabel)))
|
||||||
|
|
||||||
|
return options
|
||||||
|
}
|
||||||
|
|
||||||
|
options.push(...sorted.map((font) => toOption(font)))
|
||||||
|
|
||||||
|
return options
|
||||||
|
}
|
||||||
@@ -0,0 +1,244 @@
|
|||||||
|
import { queryOptions } from '@tanstack/vue-query'
|
||||||
|
import { invoke } from '@tauri-apps/api/core'
|
||||||
|
|
||||||
|
export type GameOptionCanonicalValue =
|
||||||
|
| { type: 'bool'; value: boolean }
|
||||||
|
| { type: 'integer'; value: number }
|
||||||
|
| { type: 'decimal'; value: string }
|
||||||
|
| { type: 'enum'; value: string }
|
||||||
|
| { type: 'text'; value: string }
|
||||||
|
| { type: 'string_list'; value: string[] }
|
||||||
|
| { type: 'key_binding'; value: string }
|
||||||
|
| { type: 'external_raw'; value: string }
|
||||||
|
|
||||||
|
export type GameOptionValueState = 'canonical' | 'uniform_local' | 'mixed' | 'unset' | 'invalid'
|
||||||
|
|
||||||
|
export type GameOptionCompatibilityStatus =
|
||||||
|
| 'ready'
|
||||||
|
| 'deferred'
|
||||||
|
| 'waiting_for_file'
|
||||||
|
| 'waiting_for_base'
|
||||||
|
| 'not_available'
|
||||||
|
| 'unsupported_value'
|
||||||
|
| 'unmappable'
|
||||||
|
| 'catalog_uncovered'
|
||||||
|
| 'controlled'
|
||||||
|
| 'degraded'
|
||||||
|
|
||||||
|
export type GameOptionMappingKind = 'direct' | 'legacy' | 'migrated' | 'lossless' | 'lossy'
|
||||||
|
|
||||||
|
export type GameOptionCompatibilityReason =
|
||||||
|
| 'launcher_controlled'
|
||||||
|
| 'catalog_uncovered'
|
||||||
|
| 'inspection_failed'
|
||||||
|
| 'waiting_for_options_file'
|
||||||
|
| 'unsupported_value'
|
||||||
|
| 'migrates_on_write'
|
||||||
|
| 'waiting_for_compatible_base'
|
||||||
|
| 'missing_setting'
|
||||||
|
|
||||||
|
export type GameOptionCompatibilityBucket = {
|
||||||
|
instance_count: number
|
||||||
|
write_keys: string[]
|
||||||
|
eventual_keys: string[]
|
||||||
|
game_versions: string[]
|
||||||
|
status: GameOptionCompatibilityStatus
|
||||||
|
mapping?: GameOptionMappingKind | null
|
||||||
|
reason?: GameOptionCompatibilityReason | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export type GameOptionCompatibilitySummary = {
|
||||||
|
total_participating: number
|
||||||
|
will_receive: number
|
||||||
|
write_now: number
|
||||||
|
left_local: number
|
||||||
|
buckets: GameOptionCompatibilityBucket[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export type GameOptionEditorChoice = {
|
||||||
|
value: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type GameOptionEditor = {
|
||||||
|
type:
|
||||||
|
| 'bool'
|
||||||
|
| 'integer'
|
||||||
|
| 'decimal'
|
||||||
|
| 'enum'
|
||||||
|
| 'text'
|
||||||
|
| 'string_list'
|
||||||
|
| 'key_binding'
|
||||||
|
| 'external_raw'
|
||||||
|
min?: number | null
|
||||||
|
max?: number | null
|
||||||
|
step?: number | null
|
||||||
|
unit?: string | null
|
||||||
|
choices?: GameOptionEditorChoice[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export type GameSettingCategory = {
|
||||||
|
id: string
|
||||||
|
is_custom?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export type GameOptionValidationError =
|
||||||
|
'missing_value' | 'no_compatible_instances' | 'invalid_value' | 'changed_since_opened'
|
||||||
|
|
||||||
|
export type EditableGameSetting = {
|
||||||
|
option_id: string
|
||||||
|
category_id: string
|
||||||
|
kind: 'vanilla' | 'external'
|
||||||
|
raw_key?: string | null
|
||||||
|
sync_enabled: boolean
|
||||||
|
canonical_value?: GameOptionCanonicalValue | null
|
||||||
|
value_state: GameOptionValueState
|
||||||
|
option_revision: number
|
||||||
|
editor: GameOptionEditor
|
||||||
|
compatibility: GameOptionCompatibilitySummary
|
||||||
|
validation_error?: GameOptionValidationError | null
|
||||||
|
controlled?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export type GameSettingsEditorState = {
|
||||||
|
summary_revision: string
|
||||||
|
canonical_revision: number
|
||||||
|
catalog_revision: number
|
||||||
|
total_participating: number
|
||||||
|
categories: GameSettingCategory[]
|
||||||
|
settings: EditableGameSetting[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export type GameSettingChange = {
|
||||||
|
option_id: string
|
||||||
|
base_option_revision: number
|
||||||
|
sync_enabled?: boolean
|
||||||
|
canonical_value?: GameOptionCanonicalValue | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export type UpdateGameSettingsRequest = {
|
||||||
|
expected_summary_revision: string
|
||||||
|
expected_canonical_revision: number
|
||||||
|
expected_catalog_revision: number
|
||||||
|
changes: GameSettingChange[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export type GameOptionsSourceCandidate = {
|
||||||
|
source_id: string
|
||||||
|
instance_id: string
|
||||||
|
name: string
|
||||||
|
icon_path?: string | null
|
||||||
|
game_version?: string | null
|
||||||
|
eligible: boolean
|
||||||
|
disabled_reason?: GameOptionsSourceDisabledReason | null
|
||||||
|
recognized_setting_count: number
|
||||||
|
custom_setting_count: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export type GameOptionsSourceDisabledReason =
|
||||||
|
| 'installing_or_updating'
|
||||||
|
| 'unsupported_version'
|
||||||
|
| 'missing_options_file'
|
||||||
|
| 'no_syncable_settings'
|
||||||
|
| 'unreadable_options_file'
|
||||||
|
|
||||||
|
export type SaveGameSettingsResult = {
|
||||||
|
state?: GameSettingsEditorState
|
||||||
|
applied: number
|
||||||
|
migrated: number
|
||||||
|
deferred: number
|
||||||
|
unsupported: number
|
||||||
|
failed: number
|
||||||
|
conflicts?: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export type GameSettingLocaleLabel = {
|
||||||
|
label: string
|
||||||
|
choices: Record<string, string>
|
||||||
|
source?: GameSettingSource | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export type GameSettingSource = {
|
||||||
|
instance_id: string
|
||||||
|
file_name: string
|
||||||
|
file_path: string
|
||||||
|
project: {
|
||||||
|
id: string
|
||||||
|
title: string
|
||||||
|
icon_url: string | null
|
||||||
|
} | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function get_game_setting_locale_labels(
|
||||||
|
instanceId: string | undefined,
|
||||||
|
locale: string,
|
||||||
|
optionIds: string[],
|
||||||
|
refreshSources = false,
|
||||||
|
): Promise<{ settings: Record<string, GameSettingLocaleLabel> }> {
|
||||||
|
return await invoke('plugin:instance|instance_get_game_setting_locale_labels', {
|
||||||
|
instanceId,
|
||||||
|
locale,
|
||||||
|
optionIds,
|
||||||
|
refreshSources,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function list_game_options_sync_sources(): Promise<GameOptionsSourceCandidate[]> {
|
||||||
|
return await invoke('plugin:instance|instance_list_game_options_sync_sources')
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function get_synced_game_options_config(): Promise<GameSettingsEditorState> {
|
||||||
|
return await invoke('plugin:instance|instance_get_synced_game_options_config')
|
||||||
|
}
|
||||||
|
|
||||||
|
export const gameSettingsKeys = {
|
||||||
|
synced: ['game-settings', 'synced'] as const,
|
||||||
|
local: (instanceId: string) => ['game-settings', 'local', instanceId] as const,
|
||||||
|
}
|
||||||
|
|
||||||
|
export function gameSettingsQueryOptions(instanceId?: string) {
|
||||||
|
return queryOptions({
|
||||||
|
queryKey: instanceId ? gameSettingsKeys.local(instanceId) : gameSettingsKeys.synced,
|
||||||
|
queryFn: () =>
|
||||||
|
instanceId ? get_local_game_options_config(instanceId) : get_synced_game_options_config(),
|
||||||
|
staleTime: 30_000,
|
||||||
|
retry: false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function preview_synced_game_option_changes(
|
||||||
|
request: UpdateGameSettingsRequest,
|
||||||
|
): Promise<GameSettingsEditorState> {
|
||||||
|
return await invoke('plugin:instance|instance_preview_synced_game_option_changes', { request })
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function save_synced_game_option_changes(
|
||||||
|
request: UpdateGameSettingsRequest,
|
||||||
|
): Promise<SaveGameSettingsResult> {
|
||||||
|
return await invoke('plugin:instance|instance_save_synced_game_option_changes', { request })
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function get_local_game_options_config(
|
||||||
|
instanceId: string,
|
||||||
|
): Promise<GameSettingsEditorState> {
|
||||||
|
return await invoke('plugin:instance|instance_get_local_game_options_config', { instanceId })
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function preview_local_game_option_changes(
|
||||||
|
instanceId: string,
|
||||||
|
request: UpdateGameSettingsRequest,
|
||||||
|
): Promise<GameSettingsEditorState> {
|
||||||
|
return await invoke('plugin:instance|instance_preview_local_game_option_changes', {
|
||||||
|
instanceId,
|
||||||
|
request,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function save_local_game_option_changes(
|
||||||
|
instanceId: string,
|
||||||
|
request: UpdateGameSettingsRequest,
|
||||||
|
): Promise<SaveGameSettingsResult> {
|
||||||
|
return await invoke('plugin:instance|instance_save_local_game_option_changes', {
|
||||||
|
instanceId,
|
||||||
|
request,
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -2,10 +2,13 @@ import { invoke } from '@tauri-apps/api/core'
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
requestSkinSiteDownloadToken,
|
requestSkinSiteDownloadToken,
|
||||||
|
requestSkinSitePlayers,
|
||||||
|
skinSitePlayers,
|
||||||
skinSiteStatus,
|
skinSiteStatus,
|
||||||
skinSiteUser,
|
skinSiteUser,
|
||||||
waitForSkinSiteSession,
|
waitForSkinSiteSession,
|
||||||
} from '../composables/skin-site-session.ts'
|
} from '../composables/skin-site-session.ts'
|
||||||
|
import { authenticateInstancePlayer } from './instance-player.ts'
|
||||||
|
|
||||||
export const HOSTED_ACCOUNT_REQUIRED_MESSAGE = '您需要登录正版或皮肤站账号后才能操作'
|
export const HOSTED_ACCOUNT_REQUIRED_MESSAGE = '您需要登录正版或皮肤站账号后才能操作'
|
||||||
|
|
||||||
@@ -24,10 +27,36 @@ function startHostedPackAttempt(instanceId: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function requireHostedGameAccount(): Promise<void> {
|
export async function requireHostedGameAccount(): Promise<void> {
|
||||||
const available = await invokeHosted<boolean>('plugin:install|hosted_has_game_account')
|
if (await invokeHosted<boolean>('plugin:install|hosted_has_game_account')) return
|
||||||
if (!available) {
|
|
||||||
throw new Error(HOSTED_ACCOUNT_REQUIRED_MESSAGE)
|
// No game credential yet, but a signed-in skin site already lists the
|
||||||
|
// user's players. Authenticate the first one automatically so the user
|
||||||
|
// does not have to pick a player manually before creating an instance.
|
||||||
|
await waitForSkinSiteSession()
|
||||||
|
if (skinSiteStatus.value === 'signed-in' && skinSiteUser.value) {
|
||||||
|
if (skinSitePlayers.value.length === 0) {
|
||||||
|
await requestSkinSitePlayers().catch(() => {})
|
||||||
|
}
|
||||||
|
const player =
|
||||||
|
skinSitePlayers.value.find((candidate) => !candidate.isMojang) ?? skinSitePlayers.value[0]
|
||||||
|
if (player) {
|
||||||
|
try {
|
||||||
|
await authenticateInstancePlayer({
|
||||||
|
id: player.uuid,
|
||||||
|
name: player.name,
|
||||||
|
account_type: 'yggdrasil',
|
||||||
|
skin_site_user: skinSiteUser.value.uuid,
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
// Fall through to the login-required error below.
|
||||||
|
}
|
||||||
|
if (await invokeHosted<boolean>('plugin:install|hosted_has_game_account')) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new Error(HOSTED_ACCOUNT_REQUIRED_MESSAGE)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function clearHostedSession(): Promise<void> {
|
export function clearHostedSession(): Promise<void> {
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import test from 'node:test'
|
||||||
|
|
||||||
|
import { canonicalizeBackupExclusions, formatBackupExclusionPath } from './instance-backup.ts'
|
||||||
|
|
||||||
|
test('directory exclusions display with a trailing slash', () => {
|
||||||
|
assert.equal(formatBackupExclusionPath({ path: 'caches', kind: 'directory' }), 'caches/')
|
||||||
|
assert.equal(
|
||||||
|
formatBackupExclusionPath({ path: 'config/somemod/bigdb.sqlite', kind: 'file' }),
|
||||||
|
'config/somemod/bigdb.sqlite',
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('directory exclusions cover descendants while file exclusions stay exact', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
canonicalizeBackupExclusions([
|
||||||
|
{ path: 'saves/world', kind: 'directory' },
|
||||||
|
{ path: 'config\\bigdb.sqlite', kind: 'file' },
|
||||||
|
{ path: 'saves', kind: 'directory' },
|
||||||
|
{ path: 'config', kind: 'file' },
|
||||||
|
]),
|
||||||
|
[
|
||||||
|
{ path: 'config', kind: 'file' },
|
||||||
|
{ path: 'saves', kind: 'directory' },
|
||||||
|
{ path: 'config/bigdb.sqlite', kind: 'file' },
|
||||||
|
],
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('directory wins when the same exclusion is selected as both kinds', () => {
|
||||||
|
assert.deepEqual(
|
||||||
|
canonicalizeBackupExclusions([
|
||||||
|
{ path: 'cache', kind: 'file' },
|
||||||
|
{ path: 'cache', kind: 'directory' },
|
||||||
|
]),
|
||||||
|
[{ path: 'cache', kind: 'directory' }],
|
||||||
|
)
|
||||||
|
})
|
||||||
@@ -0,0 +1,237 @@
|
|||||||
|
import { invoke } from '@tauri-apps/api/core'
|
||||||
|
import { listen, type UnlistenFn } from '@tauri-apps/api/event'
|
||||||
|
|
||||||
|
export type InstanceBackupEligibility =
|
||||||
|
| 'eligible'
|
||||||
|
| 'not_installed'
|
||||||
|
| 'symlink_instance'
|
||||||
|
| 'direct_linked_instance'
|
||||||
|
| 'external_game_directory'
|
||||||
|
| 'root_missing'
|
||||||
|
| 'root_is_link'
|
||||||
|
|
||||||
|
export interface BackupRepositoryStatus {
|
||||||
|
path: string
|
||||||
|
initialized: boolean
|
||||||
|
available: boolean
|
||||||
|
stored_size: number
|
||||||
|
logical_size: number
|
||||||
|
snapshot_count: number
|
||||||
|
error: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export type BackupExclusionKind = 'file' | 'directory'
|
||||||
|
|
||||||
|
export interface BackupExclusion {
|
||||||
|
path: string
|
||||||
|
kind: BackupExclusionKind
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatBackupExclusionPath(exclusion: BackupExclusion): string {
|
||||||
|
return exclusion.kind === 'directory' ? `${exclusion.path}/` : exclusion.path
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface InstanceBackupConfig {
|
||||||
|
instance_id: string
|
||||||
|
enabled: boolean
|
||||||
|
eligibility: InstanceBackupEligibility
|
||||||
|
excluded_paths: BackupExclusion[]
|
||||||
|
snapshot_count: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BackupSnapshot {
|
||||||
|
id: string
|
||||||
|
instance_id: string
|
||||||
|
instance_name: string
|
||||||
|
created_at: number
|
||||||
|
file_count: number
|
||||||
|
symlink_count: number
|
||||||
|
logical_size: number
|
||||||
|
added_size: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BackupDeleteSummary {
|
||||||
|
snapshot_count: number
|
||||||
|
logical_size: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BackupRestorePreview {
|
||||||
|
added_files: number
|
||||||
|
modified_files: number
|
||||||
|
deleted_files: number
|
||||||
|
plan_token: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type BackupOperationType =
|
||||||
|
'create' | 'restore' | 'restore_preview' | 'delete' | 'repository_move'
|
||||||
|
export type BackupOperationState =
|
||||||
|
| 'queued'
|
||||||
|
| 'scanning'
|
||||||
|
| 'hashing'
|
||||||
|
| 'saving'
|
||||||
|
| 'validating'
|
||||||
|
| 'materializing'
|
||||||
|
| 'applying'
|
||||||
|
| 'completed'
|
||||||
|
| 'cancelled'
|
||||||
|
| 'failed'
|
||||||
|
| 'interrupted'
|
||||||
|
|
||||||
|
export interface BackupOperation {
|
||||||
|
id: string
|
||||||
|
operation_type: BackupOperationType
|
||||||
|
instance_id: string
|
||||||
|
snapshot_id?: string
|
||||||
|
state: BackupOperationState
|
||||||
|
processed_bytes: number
|
||||||
|
total_bytes: number
|
||||||
|
cancellable: boolean
|
||||||
|
cancel_requested: boolean
|
||||||
|
error?: string
|
||||||
|
created_at: number
|
||||||
|
updated_at: number
|
||||||
|
finished_at?: number
|
||||||
|
restore_preview?: BackupRestorePreview
|
||||||
|
}
|
||||||
|
|
||||||
|
export type BackupProgressStage =
|
||||||
|
| 'scanning'
|
||||||
|
| 'hashing'
|
||||||
|
| 'saving'
|
||||||
|
| 'validating'
|
||||||
|
| 'copying'
|
||||||
|
| 'restoring'
|
||||||
|
| 'deleting'
|
||||||
|
| 'completed'
|
||||||
|
| 'cancelled'
|
||||||
|
| 'failed'
|
||||||
|
|
||||||
|
export type BackupOperationFinalState = 'completed' | 'cancelled' | 'failed'
|
||||||
|
|
||||||
|
export interface BackupProgressEvent {
|
||||||
|
operationId: string
|
||||||
|
instanceId?: string
|
||||||
|
operationType: BackupOperationType
|
||||||
|
stage: BackupProgressStage
|
||||||
|
processedBytes: number
|
||||||
|
totalBytes: number
|
||||||
|
finalState?: BackupOperationFinalState
|
||||||
|
snapshotId?: string
|
||||||
|
message?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function canonicalizeBackupExclusions(values: BackupExclusion[]): BackupExclusion[] {
|
||||||
|
const normalized = values
|
||||||
|
.map((value) => ({ ...value, path: value.path.replaceAll('\\', '/') }))
|
||||||
|
.sort(
|
||||||
|
(left, right) =>
|
||||||
|
left.path.split('/').length - right.path.split('/').length ||
|
||||||
|
left.path.localeCompare(right.path),
|
||||||
|
)
|
||||||
|
const result: BackupExclusion[] = []
|
||||||
|
for (const value of normalized) {
|
||||||
|
const duplicate = result.find((existing) => existing.path === value.path)
|
||||||
|
if (duplicate) {
|
||||||
|
if (value.kind === 'directory') duplicate.kind = 'directory'
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
result.some(
|
||||||
|
(parent) => parent.kind === 'directory' && value.path.startsWith(`${parent.path}/`),
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
result.push(value)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getBackupRepositoryStatus(): Promise<BackupRepositoryStatus> {
|
||||||
|
return invoke('plugin:instance|instance_get_backup_repository_status')
|
||||||
|
}
|
||||||
|
|
||||||
|
export function moveBackupRepository(destination: string): Promise<string> {
|
||||||
|
return invoke('plugin:instance|instance_move_backup_repository', { destination })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getBackupConfig(instanceId: string): Promise<InstanceBackupConfig> {
|
||||||
|
return invoke('plugin:instance|instance_get_backup_config', { instanceId })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function normalizeBackupExclusion(
|
||||||
|
instanceId: string,
|
||||||
|
selectedPath: string,
|
||||||
|
kind: BackupExclusionKind,
|
||||||
|
): Promise<BackupExclusion> {
|
||||||
|
return invoke('plugin:instance|instance_normalize_backup_exclusion', {
|
||||||
|
instanceId,
|
||||||
|
selectedPath,
|
||||||
|
kind,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function enableBackups(
|
||||||
|
instanceId: string,
|
||||||
|
excludedPaths: BackupExclusion[],
|
||||||
|
): Promise<InstanceBackupConfig> {
|
||||||
|
return invoke('plugin:instance|instance_enable_backups', { instanceId, excludedPaths })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function updateBackupExclusions(
|
||||||
|
instanceId: string,
|
||||||
|
excludedPaths: BackupExclusion[],
|
||||||
|
): Promise<InstanceBackupConfig> {
|
||||||
|
return invoke('plugin:instance|instance_update_backup_exclusions', {
|
||||||
|
instanceId,
|
||||||
|
excludedPaths,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function disableBackups(instanceId: string): Promise<void> {
|
||||||
|
return invoke('plugin:instance|instance_disable_backups', { instanceId })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function startBackup(instanceId: string): Promise<string> {
|
||||||
|
return invoke('plugin:instance|instance_start_backup', { instanceId })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function cancelBackup(operationId: string): Promise<boolean> {
|
||||||
|
return invoke('plugin:instance|instance_cancel_backup', { operationId })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function listBackupOperations(
|
||||||
|
instanceId?: string,
|
||||||
|
activeOnly = false,
|
||||||
|
): Promise<BackupOperation[]> {
|
||||||
|
return invoke('plugin:instance|instance_list_backup_operations', {
|
||||||
|
instanceId,
|
||||||
|
activeOnly,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function listBackups(instanceId: string): Promise<BackupSnapshot[]> {
|
||||||
|
return invoke('plugin:instance|instance_list_backups', { instanceId })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deleteBackup(snapshotId: string): Promise<void> {
|
||||||
|
return invoke('plugin:instance|instance_delete_backup', { snapshotId })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function startBackupRestorePreview(snapshotId: string): Promise<string> {
|
||||||
|
return invoke('plugin:instance|instance_get_backup_restore_preview', { snapshotId })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function restoreBackup(snapshotId: string, planToken: string): Promise<string> {
|
||||||
|
return invoke('plugin:instance|instance_restore_backup', { snapshotId, planToken })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getBackupDeleteSummary(instanceId: string): Promise<BackupDeleteSummary> {
|
||||||
|
return invoke('plugin:instance|instance_get_backup_delete_summary', { instanceId })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function listenBackupProgress(
|
||||||
|
handler: (event: BackupProgressEvent) => void,
|
||||||
|
): Promise<UnlistenFn> {
|
||||||
|
return listen<BackupProgressEvent>('instance_backup_progress', (event) => handler(event.payload))
|
||||||
|
}
|
||||||
@@ -1 +1,46 @@
|
|||||||
|
import { invoke } from '@tauri-apps/api/core'
|
||||||
|
|
||||||
export const MAX_INSTANCE_GROUP_NAME_LENGTH = 256
|
export const MAX_INSTANCE_GROUP_NAME_LENGTH = 256
|
||||||
|
|
||||||
|
export type InstanceGroupDefinition = {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type InstanceGroupMembershipUpdate = {
|
||||||
|
instance_id: string
|
||||||
|
group_ids: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function list_groups(): Promise<InstanceGroupDefinition[]> {
|
||||||
|
return await invoke('plugin:instance|instance_list_groups')
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function create_group(name: string): Promise<InstanceGroupDefinition> {
|
||||||
|
return await invoke('plugin:instance|instance_create_group', { name })
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function rename_group(id: string, newName: string): Promise<InstanceGroupDefinition> {
|
||||||
|
return await invoke('plugin:instance|instance_rename_group', {
|
||||||
|
id,
|
||||||
|
newName,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function delete_group(id: string): Promise<void> {
|
||||||
|
return await invoke('plugin:instance|instance_delete_group', { id })
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function set_group_order(group_ids: string[]): Promise<void> {
|
||||||
|
return await invoke('plugin:instance|instance_set_group_order', {
|
||||||
|
groupIds: group_ids,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function set_group_memberships(
|
||||||
|
updates: InstanceGroupMembershipUpdate[],
|
||||||
|
): Promise<void> {
|
||||||
|
return await invoke('plugin:instance|instance_set_group_memberships', {
|
||||||
|
updates,
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -108,6 +108,104 @@ export async function get_many(instanceIds: string[]): Promise<GameInstance[]> {
|
|||||||
return await invoke('plugin:instance|instance_get_many', { instanceIds })
|
return await invoke('plugin:instance|instance_get_many', { instanceIds })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function adaptContentItems(items: ContentItem[]): ContentItem[] {
|
||||||
|
return items.map((item) => {
|
||||||
|
const embeddedMetadata = item.embedded_metadata
|
||||||
|
if (!embeddedMetadata?.icon_path) return item
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
embedded_metadata: {
|
||||||
|
...embeddedMetadata,
|
||||||
|
icon_url: convertFileSrc(embeddedMetadata.icon_path),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export type SyncedOption =
|
||||||
|
| 'game_options'
|
||||||
|
| 'command_history'
|
||||||
|
| 'multiplayer_servers'
|
||||||
|
| 'creative_hotbars'
|
||||||
|
| 'screenshots'
|
||||||
|
| 'resource_packs'
|
||||||
|
| 'data_packs'
|
||||||
|
export type GlobalSyncedOptions = Record<SyncedOption, boolean>
|
||||||
|
export type SyncedOptionCapability = {
|
||||||
|
option: SyncedOption
|
||||||
|
supported: boolean
|
||||||
|
disabled_reason: string | null
|
||||||
|
}
|
||||||
|
export type SyncedOptionJoinPreview = { action: string }
|
||||||
|
export type SyncedOptionsOverview = {
|
||||||
|
global_options: GlobalSyncedOptions
|
||||||
|
capabilities: SyncedOptionCapability[]
|
||||||
|
}
|
||||||
|
export async function get_global_synced_options(): Promise<GlobalSyncedOptions> {
|
||||||
|
return await invoke('plugin:instance|instance_get_synced_options')
|
||||||
|
}
|
||||||
|
export async function get_initialized_synced_options(): Promise<GlobalSyncedOptions> {
|
||||||
|
return await invoke('plugin:instance|instance_get_initialized_synced_options')
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Every synced option is currently available on every instance. The parameter
|
||||||
|
* stays so callers keep passing the option they are asking about, which is what
|
||||||
|
* a real implementation will need.
|
||||||
|
*/
|
||||||
|
export function isSyncedOptionAvailable(_option: SyncedOption): boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
export async function set_global_synced_option(
|
||||||
|
option: SyncedOption,
|
||||||
|
enabled: boolean,
|
||||||
|
baseInstanceId?: string | null,
|
||||||
|
): Promise<GlobalSyncedOptions> {
|
||||||
|
return await invoke('plugin:instance|instance_set_synced_option', {
|
||||||
|
option,
|
||||||
|
enabled,
|
||||||
|
baseInstanceId,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
export async function set_instance_synced_option(
|
||||||
|
instanceId: string,
|
||||||
|
option: SyncedOption,
|
||||||
|
enabled: boolean,
|
||||||
|
resolution?: string | null,
|
||||||
|
): Promise<GameInstance> {
|
||||||
|
return await invoke('plugin:instance|instance_set_instance_synced_option', {
|
||||||
|
instanceId,
|
||||||
|
option,
|
||||||
|
enabled,
|
||||||
|
resolution,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
export async function get_synced_options_overview(
|
||||||
|
instanceId: string,
|
||||||
|
): Promise<SyncedOptionsOverview> {
|
||||||
|
return await invoke('plugin:instance|instance_get_synced_options_overview', { instanceId })
|
||||||
|
}
|
||||||
|
export async function get_command_history(): Promise<string> {
|
||||||
|
return await invoke('plugin:instance|instance_get_synced_command_history')
|
||||||
|
}
|
||||||
|
export async function set_command_history(contents: string): Promise<string> {
|
||||||
|
return await invoke('plugin:instance|instance_set_synced_command_history', { contents })
|
||||||
|
}
|
||||||
|
export type SyncedServer = {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
address: string
|
||||||
|
accept_textures: boolean | null
|
||||||
|
}
|
||||||
|
export async function list_synced_servers(): Promise<SyncedServer[]> {
|
||||||
|
return await invoke('plugin:instance|instance_list_synced_servers')
|
||||||
|
}
|
||||||
|
export async function update_synced_server(server: SyncedServer): Promise<void> {
|
||||||
|
await invoke('plugin:instance|instance_update_synced_server', { server })
|
||||||
|
}
|
||||||
|
export async function remove_synced_server(id: string): Promise<void> {
|
||||||
|
await invoke('plugin:instance|instance_remove_synced_server', { id })
|
||||||
|
}
|
||||||
|
|
||||||
export async function get_projects(
|
export async function get_projects(
|
||||||
instanceId: string,
|
instanceId: string,
|
||||||
cacheBehaviour?: CacheBehaviour,
|
cacheBehaviour?: CacheBehaviour,
|
||||||
|
|||||||
Loaded 100 of 416 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user