This commit is contained in:
afkarxyz
2026-01-11 08:39:14 +07:00
parent cb6dfc1638
commit 9260adc2d2
97 changed files with 9452 additions and 12379 deletions
+42 -54
View File
@@ -1,60 +1,48 @@
import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"
import { BrowserOpenURL } from "../../wailsjs/runtime/runtime"
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
import { BrowserOpenURL } from "../../wailsjs/runtime/runtime";
import type { Settings } from "./settings";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
return twMerge(clsx(inputs));
}
export function sanitizePath(input: string, os: string): string {
let sanitized = input.trim(); // it will trim whitespace
if (os === "Windows") {
return input.replace(/[<>:"/\\|?*]/g, "_");
}
// unix-based OS
return input.replace(/\//g, "_");
}
export function joinPath(os: string, ...parts: string[]): string {
const sep = os === "Windows" ? "\\" : "/";
const filtered = parts.filter(Boolean);
if (filtered.length === 0) return "";
const joined = filtered
.map((p, i) => {
// For first part, only remove trailing slashes (preserve leading slash for absolute paths)
if (i === 0) {
return p.replace(/[/\\]+$/g, "");
}
// For other parts, remove both leading and trailing slashes
return p.replace(/^[/\\]+|[/\\]+$/g, "");
})
.filter(Boolean) // Remove empty strings after trimming
.join(sep);
return joined;
}
export function buildOutputPath(settings: Settings, folder?: string) {
const os = settings.operatingSystem;
const base = settings.downloadPath || "";
const sanitized = folder ? sanitizePath(folder, os) : undefined;
return sanitized ? joinPath(os, base, sanitized) : base;
}
export function openExternal(url: string) {
if (!url) return;
try {
BrowserOpenURL(url);
} catch (error) {
if (typeof window !== "undefined") {
window.open(url, "_blank", "noopener,noreferrer");
let sanitized = input.trim();
if (os === "Windows") {
return sanitized.replace(/[<>:"/\\|?*]/g, "_");
}
return sanitized.replace(/\//g, "_");
}
export function joinPath(os: string, ...parts: string[]): string {
const sep = os === "Windows" ? "\\" : "/";
const filtered = parts.filter(Boolean);
if (filtered.length === 0)
return "";
const joined = filtered
.map((p, i) => {
if (i === 0) {
return p.replace(/[/\\]+$/g, "");
}
return p.replace(/^[/\\]+|[/\\]+$/g, "");
})
.filter(Boolean)
.join(sep);
return joined;
}
export function buildOutputPath(settings: Settings, folder?: string) {
const os = settings.operatingSystem;
const base = settings.downloadPath || "";
const sanitized = folder ? sanitizePath(folder, os) : undefined;
return sanitized ? joinPath(os, base, sanitized) : base;
}
export function openExternal(url: string) {
if (!url)
return;
try {
BrowserOpenURL(url);
}
catch (error) {
if (typeof window !== "undefined") {
window.open(url, "_blank", "noopener,noreferrer");
}
}
}
}