Compare commits

...

3 Commits

11 changed files with 185 additions and 25 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "vidbee",
"version": "0.2.1",
"version": "0.2.2",
"description": "A modern Electron application for downloading videos and audios",
"main": "./out/main/index.js",
"author": "VidBee",

View File

@@ -90,6 +90,11 @@ export const buildDownloadArgs = (
args.push('--cookies-from-browser', settings.browserForCookies)
}
const cookiesPath = settings.cookiesPath?.trim()
if (cookiesPath) {
args.push('--cookies', cookiesPath)
}
if (settings.proxy) {
args.push('--proxy', settings.proxy)
}

View File

@@ -3,6 +3,33 @@ import { type IpcContext, IpcMethod, IpcService } from 'electron-ipc-decorator'
import { autoUpdater } from 'electron-updater'
import { settingsManager } from '../../settings'
const isNewerVersion = (latest: string, current: string): boolean => {
const toSegments = (version: string) =>
version.split(/[.-]/).map((segment) => {
const parsed = Number.parseInt(segment, 10)
return Number.isNaN(parsed) ? 0 : parsed
})
const latestSegments = toSegments(latest)
const currentSegments = toSegments(current)
const maxLength = Math.max(latestSegments.length, currentSegments.length)
for (let index = 0; index < maxLength; index += 1) {
const latestValue = latestSegments[index] ?? 0
const currentValue = currentSegments[index] ?? 0
if (latestValue > currentValue) {
return true
}
if (latestValue < currentValue) {
return false
}
}
return false
}
class UpdateService extends IpcService {
static readonly groupName = 'update'
@@ -11,11 +38,20 @@ class UpdateService extends IpcService {
_context: IpcContext
): Promise<{ available: boolean; version?: string; error?: string }> {
try {
// In production, use checkForUpdatesAndNotify for automatic notifications
const result = await autoUpdater.checkForUpdatesAndNotify()
const currentVersion = app.getVersion()
const result = await autoUpdater.checkForUpdates()
const latestVersion = result?.updateInfo?.version
if (latestVersion && isNewerVersion(latestVersion, currentVersion)) {
return {
available: true,
version: latestVersion
}
}
return {
available: result !== null,
version: result?.updateInfo?.version
available: false,
version: latestVersion ?? currentVersion
}
} catch (error) {
return {

View File

@@ -61,6 +61,11 @@ class DownloadEngine extends EventEmitter {
args.push('--cookies-from-browser', settings.browserForCookies)
}
const cookiesPath = settings.cookiesPath?.trim()
if (cookiesPath) {
args.push('--cookies', cookiesPath)
}
// Add config file if configured
if (settings.configPath) {
args.push('--config-location', `"${settings.configPath}"`)
@@ -130,6 +135,11 @@ class DownloadEngine extends EventEmitter {
args.push('--cookies-from-browser', settings.browserForCookies)
}
const cookiesPath = settings.cookiesPath?.trim()
if (cookiesPath) {
args.push('--cookies', cookiesPath)
}
args.push(url)
return new Promise((resolve, reject) => {

View File

@@ -53,8 +53,8 @@ function AppContent() {
{/* Main Content */}
<main className="flex flex-col flex-1 min-h-0 overflow-hidden bg-background">
{/* Custom Title Bar - Hide on macOS */}
{platform !== 'darwin' && <TitleBar />}
{/* Custom Title Bar */}
<TitleBar platform={platform} />
<ScrollArea
className="flex-1 w-full overflow-y-auto overflow-x-hidden"

View File

@@ -7,11 +7,15 @@ import IconFluentSubtract20Regular from '~icons/fluent/subtract-20-regular'
import { ipcEvents, ipcServices } from '../../lib/ipc'
import '../../assets/title-bar.css'
export function TitleBar() {
interface TitleBarProps {
platform?: string
}
export function TitleBar({ platform }: TitleBarProps) {
const [isMaximized, setIsMaximized] = useState(false)
useEffect(() => {
// 监听窗口最大化状态变化
// Listen for window maximize state changes
const handleMaximized = () => {
setIsMaximized(true)
}
@@ -41,8 +45,17 @@ export function TitleBar() {
ipcServices.window.close()
}
const isMac = platform === 'darwin'
const containerClass = `flex drag-region bg-background select-none ${
isMac ? 'h-10 items-center px-4' : 'justify-end pt-4 px-5'
}`
if (isMac) {
return <div className={containerClass} />
}
return (
<div className="flex drag-region justify-end bg-background pt-4 px-5 select-none">
<div className={containerClass}>
{/* Window controls */}
<div className="flex items-center gap-1 no-drag">
<Button

View File

@@ -255,6 +255,14 @@
"audio": "Audio Preferences",
"browserForCookies": "Select browser to use cookies from",
"browserForCookiesDescription": "Browser to extract cookies from for authentication",
"cookiesFile": "Cookies file",
"cookiesFileDescription": "Netscape formatted cookies file to load for authentication",
"clearCookiesFile": "Clear",
"cookiesHelpTitle": "Using cookies",
"cookiesHelpBrowser": "Pick your browser above to reuse its signed-in session automatically.",
"cookiesHelpFile": "Export a Netscape cookies file (see the yt-dlp FAQ) and select it here when needed.",
"cookiesHelpFaq": "Open yt-dlp cookies FAQ",
"openLinkError": "Failed to open link",
"browserOptions": {
"brave": "Brave",
"chrome": "Chrome",

View File

@@ -165,6 +165,13 @@ export function About() {
const aboutResources = useMemo<AboutResource[]>(
() => [
{
icon: LinkIcon,
label: t('about.resources.website'),
description: t('about.resources.websiteDescription'),
actionLabel: t('about.actions.visit'),
href: 'https://vidbee.org/'
},
{
icon: FileText,
label: t('about.resources.changelog'),

View File

@@ -71,6 +71,31 @@ export function Settings() {
}
}
const handleSelectCookiesFile = async () => {
try {
const { ipcServices } = await import('../lib/ipc')
const path = await ipcServices.fs.selectFile()
if (path) {
await handleSettingChange('cookiesPath', path)
}
} catch (error) {
console.error('Failed to select cookies file:', error)
toast.error(t('settings.fileSelectError'))
}
}
const handleOpenCookiesFaq = async () => {
try {
const { ipcServices } = await import('../lib/ipc')
await ipcServices.fs.openExternal(
'https://github.com/yt-dlp/yt-dlp/wiki/FAQ#how-do-i-pass-cookies-to-yt-dlp'
)
} catch (error) {
console.error('Failed to open cookies FAQ:', error)
toast.error(t('settings.openLinkError'))
}
}
const handleThemeChange = async (value: 'light' | 'dark' | 'system') => {
const currentTheme = (theme ?? settings.theme ?? 'system') as 'light' | 'dark' | 'system'
if (currentTheme === value) {
@@ -269,6 +294,38 @@ export function Settings() {
<ItemSeparator />
<Item variant="muted">
<ItemContent>
<ItemTitle>{t('settings.proxy')}</ItemTitle>
<ItemDescription>{t('settings.proxyDescription')}</ItemDescription>
</ItemContent>
<ItemActions>
<Input
placeholder={t('settings.proxyPlaceholder')}
value={settings.proxy}
onChange={(e) => handleSettingChange('proxy', e.target.value)}
className="w-64"
/>
</ItemActions>
</Item>
<ItemSeparator />
<Item variant="muted">
<ItemContent>
<ItemTitle>{t('settings.configFile')}</ItemTitle>
<ItemDescription>{t('settings.configFileDescription')}</ItemDescription>
</ItemContent>
<ItemActions>
<div className="flex gap-2 w-full max-w-md">
<Input value={settings.configPath} readOnly className="flex-1" />
<Button onClick={handleSelectConfigFile}>{t('settings.selectPath')}</Button>
</div>
</ItemActions>
</Item>
</ItemGroup>
<ItemGroup>
<Item variant="muted">
<ItemContent>
<ItemTitle>{t('settings.browserForCookies')}</ItemTitle>
@@ -300,16 +357,21 @@ export function Settings() {
<Item variant="muted">
<ItemContent>
<ItemTitle>{t('settings.proxy')}</ItemTitle>
<ItemDescription>{t('settings.proxyDescription')}</ItemDescription>
<ItemTitle>{t('settings.cookiesFile')}</ItemTitle>
<ItemDescription>{t('settings.cookiesFileDescription')}</ItemDescription>
</ItemContent>
<ItemActions>
<Input
placeholder={t('settings.proxyPlaceholder')}
value={settings.proxy}
onChange={(e) => handleSettingChange('proxy', e.target.value)}
className="w-64"
/>
<div className="flex gap-2 w-full max-w-md">
<Input value={settings.cookiesPath ?? ''} readOnly className="flex-1" />
<Button onClick={handleSelectCookiesFile}>{t('settings.selectPath')}</Button>
<Button
variant="secondary"
onClick={() => void handleSettingChange('cookiesPath', '')}
disabled={!settings.cookiesPath}
>
{t('settings.clearCookiesFile')}
</Button>
</div>
</ItemActions>
</Item>
@@ -317,14 +379,18 @@ export function Settings() {
<Item variant="muted">
<ItemContent>
<ItemTitle>{t('settings.configFile')}</ItemTitle>
<ItemDescription>{t('settings.configFileDescription')}</ItemDescription>
<ItemTitle>{t('settings.cookiesHelpTitle')}</ItemTitle>
<ItemDescription>
<ul className="list-disc list-inside space-y-1">
<li>{t('settings.cookiesHelpBrowser')}</li>
<li>{t('settings.cookiesHelpFile')}</li>
</ul>
</ItemDescription>
</ItemContent>
<ItemActions>
<div className="flex gap-2 w-full max-w-md">
<Input value={settings.configPath} readOnly className="flex-1" />
<Button onClick={handleSelectConfigFile}>{t('settings.selectPath')}</Button>
</div>
<Button variant="link" className="px-0" onClick={handleOpenCookiesFaq}>
{t('settings.cookiesHelpFaq')}
</Button>
</ItemActions>
</Item>
</ItemGroup>

View File

@@ -1,6 +1,8 @@
import { atom } from 'jotai'
import { normalizeLanguageCode } from '../../../shared/languages'
import type { AppSettings } from '../../../shared/types'
import { defaultSettings } from '../../../shared/types'
import i18n from '../i18n'
import { ipcServices } from '../lib/ipc'
// Settings atom
@@ -10,7 +12,18 @@ export const settingsAtom = atom<AppSettings>(defaultSettings)
export const loadSettingsAtom = atom(null, async (_get, set) => {
try {
const settings = await ipcServices.settings.getAll()
set(settingsAtom, settings)
const savedLanguage = normalizeLanguageCode(settings.language)
const currentLanguage = normalizeLanguageCode(i18n.language)
if (currentLanguage !== savedLanguage) {
try {
await i18n.changeLanguage(savedLanguage)
} catch (error) {
console.error('Failed to apply saved language:', error)
}
}
set(settingsAtom, { ...settings, language: savedLanguage })
} catch (error) {
console.error('Failed to load settings:', error)
}

View File

@@ -146,6 +146,7 @@ export interface AppSettings {
showMoreFormats: boolean
maxConcurrentDownloads: number
browserForCookies: string
cookiesPath: string
proxy: string
configPath: string
betaProgram: boolean
@@ -163,6 +164,7 @@ export const defaultSettings: AppSettings = {
showMoreFormats: false,
maxConcurrentDownloads: 5,
browserForCookies: 'none',
cookiesPath: '',
proxy: '',
configPath: '',
betaProgram: false,