Skip to content

Commit

Permalink
Fix erroneous torrent complete notifications when transmission restarts
Browse files Browse the repository at this point in the history
When transmission restarts it will reassign ids to torrents. This means
that a downloading torrent with id x may still be downloading after
restart but the id is now assigned to a complete torrent which could
trigger a notification in error.

Now with name check it's not a complete fix but reduces the chance
of such match by a lot. Checking torrent hash would be best option
but it would increase traffic.
  • Loading branch information
qu1ck committed May 26, 2024
1 parent d2fd0e4 commit 6178ade
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions src-tauri/src/torrentcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,24 @@ pub async fn process_response(
let mut buf = Vec::new();

match headers.get(hyper::header::CONTENT_ENCODING) {
Some(value) => {
match value.to_str().unwrap().to_lowercase().as_str() {
"deflate" => {
let mut deflater = flate2::bufread::DeflateDecoder::new(response_bytes.as_ref());
buf.reserve(128 * 1024);
deflater.read_to_end(&mut buf).ok();
data_bytes = buf.as_slice();
},
"gzip" => {
let mut unzipper = flate2::bufread::GzDecoder::new(response_bytes.as_ref());
buf.reserve(128 * 1024);
unzipper.read_to_end(&mut buf).ok();
data_bytes = buf.as_slice();
},
encoding => {
println!("Unexpected response encoding: {}", encoding);
data_bytes = response_bytes.as_ref();
},
Some(value) => match value.to_str().unwrap().to_lowercase().as_str() {
"deflate" => {
let mut deflater = flate2::bufread::DeflateDecoder::new(response_bytes.as_ref());
buf.reserve(128 * 1024);
deflater.read_to_end(&mut buf).ok();
data_bytes = buf.as_slice();
}
}
"gzip" => {
let mut unzipper = flate2::bufread::GzDecoder::new(response_bytes.as_ref());
buf.reserve(128 * 1024);
unzipper.read_to_end(&mut buf).ok();
data_bytes = buf.as_slice();
}
encoding => {
println!("Unexpected response encoding: {}", encoding);
data_bytes = response_bytes.as_ref();
}
},
None => {
data_bytes = response_bytes.as_ref();
}
Expand Down Expand Up @@ -146,8 +144,13 @@ async fn process_torrents(
old_map.iter().for_each(|(id, old_torrent)| {
if let Some(new_torrent) = map.get(id) {
// If status switches from downloading (4) to seeding (6) or queued to seed (5)
// then show a "download complete" notification
if new_torrent.status > 4 && old_torrent.status == 4 {
// then show a "download complete" notification.
// Also check that torrent name is still the same just in case there was a restart
// since the last pull and the torrent ids are reassigned.
if new_torrent.name == old_torrent.name
&& new_torrent.status > 4
&& old_torrent.status == 4
{
play_sound = sound;
if toast {
show_notification(app, new_torrent.name.as_str());
Expand Down

0 comments on commit 6178ade

Please sign in to comment.