aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ui/src/stores
diff options
context:
space:
mode:
authorHsiangNianian <44714368+HsiangNianian@users.noreply.github.com>2026-01-16 01:35:23 +0000
committergithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>2026-01-16 01:35:23 +0000
commit963b4b8567ac1bd8b23c41e1bfbd6a99d202d1ed (patch)
tree6df911b964d0d32facf55844c55e61ba3878ae3f /ui/src/stores
parente21e288275806df7785d869667c90062e1890bf0 (diff)
downloadDropOut-963b4b8567ac1bd8b23c41e1bfbd6a99d202d1ed.tar.gz
DropOut-963b4b8567ac1bd8b23c41e1bfbd6a99d202d1ed.zip
style: auto format and lint fix [skip ci]
Diffstat (limited to 'ui/src/stores')
-rw-r--r--ui/src/stores/auth.svelte.ts27
-rw-r--r--ui/src/stores/logs.svelte.ts46
-rw-r--r--ui/src/stores/settings.svelte.ts89
-rw-r--r--ui/src/stores/ui.svelte.ts4
4 files changed, 90 insertions, 76 deletions
diff --git a/ui/src/stores/auth.svelte.ts b/ui/src/stores/auth.svelte.ts
index eb9dccd..1b613a7 100644
--- a/ui/src/stores/auth.svelte.ts
+++ b/ui/src/stores/auth.svelte.ts
@@ -14,7 +14,7 @@ export class AuthState {
deviceCodeData = $state<DeviceCodeResponse | null>(null);
msLoginLoading = $state(false);
msLoginStatus = $state("Waiting for authorization...");
-
+
private pollInterval: ReturnType<typeof setInterval> | null = null;
private isPollingRequestActive = false;
private authProgressUnlisten: UnlistenFn | null = null;
@@ -87,9 +87,7 @@ export class AuthState {
this.setupAuthProgressListener();
try {
- this.deviceCodeData = (await invoke(
- "start_microsoft_login"
- )) as DeviceCodeResponse;
+ this.deviceCodeData = (await invoke("start_microsoft_login")) as DeviceCodeResponse;
if (this.deviceCodeData) {
try {
@@ -99,13 +97,17 @@ export class AuthState {
}
open(this.deviceCodeData.verification_uri);
- logsState.addLog("info", "Auth", "Microsoft login started, waiting for browser authorization...");
+ logsState.addLog(
+ "info",
+ "Auth",
+ "Microsoft login started, waiting for browser authorization...",
+ );
console.log("Starting polling for token...");
const intervalMs = (this.deviceCodeData.interval || 5) * 1000;
this.pollInterval = setInterval(
() => this.checkLoginStatus(this.deviceCodeData!.device_code),
- intervalMs
+ intervalMs,
);
}
} catch (e) {
@@ -159,7 +161,11 @@ export class AuthState {
this.stopPolling();
this.cleanupAuthListener();
this.isLoginModalOpen = false;
- logsState.addLog("info", "Auth", `Login successful! Welcome, ${this.currentAccount.username}`);
+ logsState.addLog(
+ "info",
+ "Auth",
+ `Login successful! Welcome, ${this.currentAccount.username}`,
+ );
uiState.setStatus("Welcome back, " + this.currentAccount.username);
} catch (e: any) {
const errStr = e.toString();
@@ -169,11 +175,8 @@ export class AuthState {
console.error("Polling Error:", errStr);
this.msLoginStatus = "Error: " + errStr;
logsState.addLog("error", "Auth", `Login error: ${errStr}`);
-
- if (
- errStr.includes("expired_token") ||
- errStr.includes("access_denied")
- ) {
+
+ if (errStr.includes("expired_token") || errStr.includes("access_denied")) {
this.stopPolling();
this.cleanupAuthListener();
alert("Login failed: " + errStr);
diff --git a/ui/src/stores/logs.svelte.ts b/ui/src/stores/logs.svelte.ts
index 5491f70..5df9abc 100644
--- a/ui/src/stores/logs.svelte.ts
+++ b/ui/src/stores/logs.svelte.ts
@@ -17,7 +17,14 @@ function parseGameLogLevel(levelStr: string): LogEntry["level"] {
if (upper === "INFO") return "info";
if (upper === "WARN" || upper === "WARNING") return "warn";
if (upper === "ERROR" || upper === "SEVERE") return "error";
- if (upper === "DEBUG" || upper === "TRACE" || upper === "FINE" || upper === "FINER" || upper === "FINEST") return "debug";
+ if (
+ upper === "DEBUG" ||
+ upper === "TRACE" ||
+ upper === "FINE" ||
+ upper === "FINER" ||
+ upper === "FINEST"
+ )
+ return "debug";
if (upper === "FATAL") return "fatal";
return "info";
}
@@ -37,8 +44,9 @@ export class LogsState {
addLog(level: LogEntry["level"], source: string, message: string) {
const now = new Date();
- const timestamp = now.toLocaleTimeString() + "." + now.getMilliseconds().toString().padStart(3, "0");
-
+ const timestamp =
+ now.toLocaleTimeString() + "." + now.getMilliseconds().toString().padStart(3, "0");
+
this.logs.push({
id: this.nextId++,
timestamp,
@@ -60,7 +68,7 @@ export class LogsState {
// Parse game output and extract level/source
addGameLog(rawLine: string, isStderr: boolean) {
const match = rawLine.match(GAME_LOG_REGEX);
-
+
if (match) {
const [, thread, levelStr, extraSource, message] = match;
const level = parseGameLogLevel(levelStr);
@@ -105,33 +113,33 @@ export class LogsState {
// Download Events (Summarized)
await listen("download-start", (e) => {
- this.addLog("info", "Downloader", `Starting batch download of ${e.payload} files...`);
+ this.addLog("info", "Downloader", `Starting batch download of ${e.payload} files...`);
});
await listen("download-complete", () => {
- this.addLog("info", "Downloader", "All downloads completed.");
+ this.addLog("info", "Downloader", "All downloads completed.");
});
// Listen to file download progress to log finished files
await listen<any>("download-progress", (e) => {
- const p = e.payload;
- if (p.status === "Finished") {
- if (p.file.endsWith(".jar")) {
- this.addLog("info", "Downloader", `Downloaded ${p.file}`);
- }
+ const p = e.payload;
+ if (p.status === "Finished") {
+ if (p.file.endsWith(".jar")) {
+ this.addLog("info", "Downloader", `Downloaded ${p.file}`);
}
+ }
});
// Java Download
await listen<any>("java-download-progress", (e) => {
- const p = e.payload;
- if (p.status === "Downloading" && p.percentage === 0) {
- this.addLog("info", "JavaInstaller", `Downloading Java: ${p.file_name}`);
- } else if (p.status === "Completed") {
- this.addLog("info", "JavaInstaller", `Java installed: ${p.file_name}`);
- } else if (p.status === "Error") {
- this.addLog("error", "JavaInstaller", `Java download error`);
- }
+ const p = e.payload;
+ if (p.status === "Downloading" && p.percentage === 0) {
+ this.addLog("info", "JavaInstaller", `Downloading Java: ${p.file_name}`);
+ } else if (p.status === "Completed") {
+ this.addLog("info", "JavaInstaller", `Java installed: ${p.file_name}`);
+ } else if (p.status === "Error") {
+ this.addLog("error", "JavaInstaller", `Java download error`);
+ }
});
}
}
diff --git a/ui/src/stores/settings.svelte.ts b/ui/src/stores/settings.svelte.ts
index b85e5fb..12e4a1c 100644
--- a/ui/src/stores/settings.svelte.ts
+++ b/ui/src/stores/settings.svelte.ts
@@ -28,7 +28,7 @@ export class SettingsState {
log_upload_service: "paste.rs",
pastebin_api_key: undefined,
});
-
+
// Convert background path to proper asset URL
get backgroundUrl(): string | undefined {
if (this.settings.custom_background_path) {
@@ -42,59 +42,59 @@ export class SettingsState {
// Java download modal state
showJavaDownloadModal = $state(false);
selectedDownloadSource = $state<JavaDownloadSource>("adoptium");
-
+
// Java catalog state
javaCatalog = $state<JavaCatalog | null>(null);
isLoadingCatalog = $state(false);
catalogError = $state("");
-
+
// Version selection state
selectedMajorVersion = $state<number | null>(null);
selectedImageType = $state<"jre" | "jdk">("jre");
showOnlyRecommended = $state(true);
searchQuery = $state("");
-
+
// Download progress state
isDownloadingJava = $state(false);
downloadProgress = $state<JavaDownloadProgress | null>(null);
javaDownloadStatus = $state("");
-
+
// Pending downloads
pendingDownloads = $state<PendingJavaDownload[]>([]);
-
+
// Event listener cleanup
private progressUnlisten: UnlistenFn | null = null;
// Computed: filtered releases based on selection
get filteredReleases(): JavaReleaseInfo[] {
if (!this.javaCatalog) return [];
-
+
let releases = this.javaCatalog.releases;
-
+
// Filter by major version if selected
if (this.selectedMajorVersion !== null) {
- releases = releases.filter(r => r.major_version === this.selectedMajorVersion);
+ releases = releases.filter((r) => r.major_version === this.selectedMajorVersion);
}
-
+
// Filter by image type
- releases = releases.filter(r => r.image_type === this.selectedImageType);
-
+ releases = releases.filter((r) => r.image_type === this.selectedImageType);
+
// Filter by recommended (LTS) versions
if (this.showOnlyRecommended) {
- releases = releases.filter(r => r.is_lts);
+ releases = releases.filter((r) => r.is_lts);
}
-
+
// Filter by search query
if (this.searchQuery.trim()) {
const query = this.searchQuery.toLowerCase();
releases = releases.filter(
- r =>
+ (r) =>
r.release_name.toLowerCase().includes(query) ||
r.version.toLowerCase().includes(query) ||
- r.major_version.toString().includes(query)
+ r.major_version.toString().includes(query),
);
}
-
+
return releases;
}
@@ -102,36 +102,39 @@ export class SettingsState {
get availableMajorVersions(): number[] {
if (!this.javaCatalog) return [];
let versions = [...this.javaCatalog.available_major_versions];
-
+
// Filter by LTS if showOnlyRecommended is enabled
if (this.showOnlyRecommended) {
- versions = versions.filter(v => this.javaCatalog!.lts_versions.includes(v));
+ versions = versions.filter((v) => this.javaCatalog!.lts_versions.includes(v));
}
-
+
// Sort descending (newest first)
return versions.sort((a, b) => b - a);
}
// Get installation status for a release: 'installed' | 'download'
- getInstallStatus(release: JavaReleaseInfo): 'installed' | 'download' {
+ getInstallStatus(release: JavaReleaseInfo): "installed" | "download" {
// Find installed Java that matches the major version and image type (by path pattern)
- const matchingInstallations = this.javaInstallations.filter(inst => {
+ const matchingInstallations = this.javaInstallations.filter((inst) => {
// Check if this is a DropOut-managed Java (path contains temurin-XX-jre/jdk pattern)
const pathLower = inst.path.toLowerCase();
const pattern = `temurin-${release.major_version}-${release.image_type}`;
return pathLower.includes(pattern);
});
-
+
// If any matching installation exists, it's installed
- return matchingInstallations.length > 0 ? 'installed' : 'download';
+ return matchingInstallations.length > 0 ? "installed" : "download";
}
// Computed: selected release details
get selectedRelease(): JavaReleaseInfo | null {
if (!this.javaCatalog || this.selectedMajorVersion === null) return null;
- return this.javaCatalog.releases.find(
- r => r.major_version === this.selectedMajorVersion && r.image_type === this.selectedImageType
- ) || null;
+ return (
+ this.javaCatalog.releases.find(
+ (r) =>
+ r.major_version === this.selectedMajorVersion && r.image_type === this.selectedImageType,
+ ) || null
+ );
}
async loadSettings() {
@@ -145,7 +148,7 @@ export class SettingsState {
}
// Ensure custom_background_path is reactive
if (!this.settings.custom_background_path) {
- this.settings.custom_background_path = undefined;
+ this.settings.custom_background_path = undefined;
}
} catch (e) {
console.error("Failed to load settings:", e);
@@ -158,7 +161,7 @@ export class SettingsState {
if (this.settings.custom_background_path === "") {
this.settings.custom_background_path = undefined;
}
-
+
await invoke("save_settings", { config: this.settings });
uiState.setStatus("Settings saved!");
} catch (e) {
@@ -193,13 +196,13 @@ export class SettingsState {
this.javaDownloadStatus = "";
this.catalogError = "";
this.downloadProgress = null;
-
+
// Setup progress event listener
await this.setupProgressListener();
-
+
// Load catalog
await this.loadJavaCatalog(false);
-
+
// Check for pending downloads
await this.loadPendingDownloads();
}
@@ -219,13 +222,13 @@ export class SettingsState {
if (this.progressUnlisten) {
this.progressUnlisten();
}
-
+
this.progressUnlisten = await listen<JavaDownloadProgress>(
"java-download-progress",
(event) => {
this.downloadProgress = event.payload;
this.javaDownloadStatus = event.payload.status;
-
+
if (event.payload.status === "Completed") {
this.isDownloadingJava = false;
setTimeout(async () => {
@@ -235,18 +238,18 @@ export class SettingsState {
} else if (event.payload.status === "Error") {
this.isDownloadingJava = false;
}
- }
+ },
);
}
async loadJavaCatalog(forceRefresh: boolean) {
this.isLoadingCatalog = true;
this.catalogError = "";
-
+
try {
const command = forceRefresh ? "refresh_java_catalog" : "fetch_java_catalog";
this.javaCatalog = await invoke<JavaCatalog>(command);
-
+
// Auto-select first LTS version
if (this.selectedMajorVersion === null && this.javaCatalog.lts_versions.length > 0) {
// Select most recent LTS (21 or highest)
@@ -283,21 +286,21 @@ export class SettingsState {
uiState.setStatus("Selected Java version is not available for this platform");
return;
}
-
+
this.isDownloadingJava = true;
this.javaDownloadStatus = "Starting download...";
this.downloadProgress = null;
-
+
try {
const result: JavaInstallation = await invoke("download_adoptium_java", {
majorVersion: this.selectedMajorVersion,
imageType: this.selectedImageType,
customPath: null,
});
-
+
this.settings.java_path = result.path;
await this.detectJava();
-
+
setTimeout(() => {
this.showJavaDownloadModal = false;
uiState.setStatus(`Java ${this.selectedMajorVersion} is ready to use!`);
@@ -324,10 +327,10 @@ export class SettingsState {
async resumeDownloads() {
if (this.pendingDownloads.length === 0) return;
-
+
this.isDownloadingJava = true;
this.javaDownloadStatus = "Resuming download...";
-
+
try {
const installed = await invoke<JavaInstallation[]>("resume_java_downloads");
if (installed.length > 0) {
diff --git a/ui/src/stores/ui.svelte.ts b/ui/src/stores/ui.svelte.ts
index 9c29c25..e88f6b4 100644
--- a/ui/src/stores/ui.svelte.ts
+++ b/ui/src/stores/ui.svelte.ts
@@ -10,9 +10,9 @@ export class UIState {
setStatus(msg: string) {
if (this.statusTimeout) clearTimeout(this.statusTimeout);
-
+
this.status = msg;
-
+
if (msg !== "Ready") {
this.statusTimeout = setTimeout(() => {
this.status = "Ready";