Skip to content

Commit

Permalink
🔥 chore: remove cache manager
Browse files Browse the repository at this point in the history
Signed-off-by: SimonShiki <sinangentoo@gmail.com>
  • Loading branch information
SimonShiki committed Jan 6, 2025
1 parent 4b2684d commit 2529ef1
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 216 deletions.
162 changes: 0 additions & 162 deletions src-tauri/src/cache_manager.rs

This file was deleted.

2 changes: 0 additions & 2 deletions src-tauri/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub enum AppError {
FileNotFound(String),
FileOpenError(String),
DecodeError(String),
SinkCreationError(String),
InvalidOperation(String),
SeekError(String),
NetworkError(String),
Expand All @@ -24,7 +23,6 @@ impl Display for AppError {
AppError::FileNotFound(path) => write!(f, "File not found: {}", path),
AppError::FileOpenError(err) => write!(f, "Failed to open file: {}", err),
AppError::DecodeError(err) => write!(f, "Failed to decode audio: {}", err),
AppError::SinkCreationError(err) => write!(f, "Failed to create audio sink: {}", err),
AppError::InvalidOperation(err) => write!(f, "Invalid operation: {}", err),
AppError::SeekError(err) => write!(f, "Failed to seek: {}", err),
AppError::NetworkError(err) => write!(f, "Network error: {}", err),
Expand Down
10 changes: 1 addition & 9 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
mod audio;
mod cache_manager;
mod error;
mod local_scanner;
mod media_control;

use audio::AudioState;
use cache_manager::{CacheManager, CacheManagerState};
use media_control::MediaControlState;
use rodio::OutputStreamBuilder;
use std::sync::atomic::AtomicBool;
Expand Down Expand Up @@ -49,10 +47,6 @@ pub async fn run() {
.manage(audio_state)
.manage(media_control_state)
.setup(|app| {
let cache_dir = app.path().app_cache_dir().unwrap();
let cache_manager = Arc::new(CacheManager::new(cache_dir, 1024 * 1024 * 1024)); // 1GB cache limit
app.manage(CacheManagerState(cache_manager));

let show = MenuItemBuilder::with_id("show", "Show").build(app)?;
let pause_resume =
MenuItemBuilder::with_id("pause_resume", "Pause/Resume").build(app)?;
Expand Down Expand Up @@ -120,9 +114,7 @@ pub async fn run() {
media_control::update_media_metadata,
media_control::update_playback_status,
local_scanner::get_song_buffer,
local_scanner::scan_folder,
cache_manager::get_cache_size,
cache_manager::clear_cache,
local_scanner::scan_folder
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Expand Down
34 changes: 0 additions & 34 deletions src/pages/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import type { NCMConfig, NCMQuality } from '../storages/ncm';
import Spinner from '../components/base/spinner';
import { FormattedMessage, useIntl } from 'react-intl';
import { langMap } from '../../locales';
import { clearCache, getCacheSize } from '../utils/cache';
import { nowPlayingBarJotai } from '../jotais/play';

const localStorageConfigJotai = focusAtom(storagesConfigJotai, (optic) => optic.prop('local')) as unknown as WritableAtom<LocalConfig, [SetStateAction<LocalConfig>], void>;
Expand All @@ -41,8 +40,6 @@ export default function Settings () {
const [ncmAuthModalOpen, setNcmAuthModalOpen] = useState(false);
const [qr, setQr] = useState(false);
const [qrUrl, setQrUrl] = useState('');
const [cacheSize, setCacheSize] = useState(-1);
const [clearingCache, setClearingCache] = useState(false);
const {instance: localStorage} = useAtomValue(localStorageJotai);
const ncmConfig = useAtomValue(ncmStorageConfigJotai);
const localScanned = useAtomValue(localScannedJotai);
Expand Down Expand Up @@ -72,19 +69,6 @@ export default function Settings () {
{ value: 'jymaster', label: intl.formatMessage({ defaultMessage: 'Ultra HD Mastering' }) }
];

useEffect(() => {
if (cacheSize > 0) return;
getCacheSize().then(setCacheSize);
}, [cacheSize]);

useEffect(() => {
if (!clearingCache) return;
clearCache().then(() => {
setCacheSize(-1);
setClearingCache(false);
});
}, [clearingCache]);

useEffect(() => {
if (!qr) {
setQrUrl('');
Expand Down Expand Up @@ -178,24 +162,6 @@ export default function Settings () {
<span className='color-text-pri dark:color-text-dark-pri font-size-sm my-2'>
<FormattedMessage defaultMessage='Play' />
</span>
<Card className='flex flex-col gap-2 color-text-pri dark:color-text-dark-pri'>
<div className='flex flex-row items-center gap-4'>
<span className='i-fluent:database-arrow-down-20-regular w-5 h-5' />
<span className='grow-1'>
<FormattedMessage defaultMessage='Cache' />
</span>
<span className='font-size-sm color-text-sec dark:color-text-dark-sec'>{cacheSize < 0 ? (
<FormattedMessage defaultMessage='Loading...' />
) : (
<FormattedMessage defaultMessage='{megabyte} MB' values={{ megabyte: Math.ceil(cacheSize / 1048576)}} />
)}</span>
<Button disabled={clearingCache} onClick={() => {
setClearingCache(true);
}}>
<FormattedMessage defaultMessage='Clear' />
</Button>
</div>
</Card>
<span className='color-text-pri dark:color-text-dark-pri font-size-sm my-2'>
<FormattedMessage defaultMessage='Local' />
</span>
Expand Down
9 changes: 0 additions & 9 deletions src/utils/cache.ts

This file was deleted.

0 comments on commit 2529ef1

Please sign in to comment.