Skip to content

Commit

Permalink
Open Blackhole directory when initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamVenner committed Dec 30, 2020
1 parent 40f84af commit 539c6be
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "blackhole"
version = "1.1.0"
version = "1.2.0"
authors = ["William Venner <[email protected]>"]
edition = "2018"
repository = "https://github.com/WilliamVenner/blackhole"
Expand All @@ -13,24 +13,25 @@ identifier = "com.venner.blackhole"
icon = ["src/assets/blackhole.ico"]

[features]
gui = ["msgbox"]
gui = ["msgbox", "opener"]

[dependencies]
dirs = "3.0"
trash = "1.2"
msgbox = { version = "0.6.0", optional = true }
opener = { version = "0.4.1", optional = true }
lazy_static = "1.4.0"

[target.'cfg(target_os = "macos")'.dependencies]
[target.'cfg(target_os="macos")'.dependencies]
embed_plist = "1.2"
cocoa = "0.24.0"
objc = { version = "0.2.7", features = ["exception"] }

[target.'cfg(target_os = "windows")'.dependencies]
[target.'cfg(target_os="windows")'.dependencies]
powershell_script = "0.1"
winapi = { version = "0.3", features = ["winuser"] }
rust-ini = "0.16"
winreg = "0.8"

[target.'cfg(target_os = "windows")'.build-dependencies]
[target.'cfg(target_os="windows")'.build-dependencies]
winres = "0.1"
18 changes: 9 additions & 9 deletions src/blackhole.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ pub mod blackhole {
use trash;
use lazy_static::lazy_static;

#[cfg(target_os = "windows")]
#[cfg(target_os="windows")]
lazy_static! { static ref EMPTY_DIR_FILTER: HashSet<&'static str> = HashSet::from(["desktop.ini"].iter().cloned().collect()); }
#[cfg(target_os = "macos")]
#[cfg(target_os="macos")]
lazy_static! { static ref EMPTY_DIR_FILTER: HashSet<&'static str> = [".DS_Store", "Icon\r"].iter().cloned().collect(); }
#[cfg(not(any(target_os = "windows", target_os = "macos")))]
#[cfg(not(any(target_os="windows", target_os="macos")))]
lazy_static! { static ref EMPTY_DIR_FILTER: HashSet<&'static str> = return HashSet::new(); }

pub struct Blackhole {
Expand All @@ -36,7 +36,7 @@ pub mod blackhole {
if should_purge { new.purge() }

// Run any chores
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
#[cfg(any(target_os="windows", target_os="linux", target_os="macos"))]
new.chores();

Ok(new)
Expand Down Expand Up @@ -70,7 +70,7 @@ pub mod blackhole {
}
}

#[cfg(target_os = "macos")]
#[cfg(target_os="macos")]
fn move_n_purge(&self) -> Result<bool, io::Error> {
let mut temp_blackhole = self.path.to_owned();
temp_blackhole.push("$BLACKHOLE");
Expand Down Expand Up @@ -139,7 +139,7 @@ pub mod blackhole {

// On MacOS, it is not possible to add folders to the "Favourites" sidebar in Finder because Apple deprecated the API and provided no alternative.
// So that the user can still pin the Blackhole to their Favourites, we move all the contents into a new $BLACKHOLE directory which is then moved to the trash instead.
#[cfg(target_os = "macos")]
#[cfg(target_os="macos")]
match self.move_n_purge() {
Err(error) => { Show::panic(&format!("Failed to PURGE blackhole directory (\"{:?}\") at {:?}", error, self.path)); return },
Ok(_) => return
Expand All @@ -156,7 +156,7 @@ pub mod blackhole {
}
}

#[cfg(target_os = "windows")] use crate::windows::Windows;
#[cfg(target_os = "linux")] use crate::linux::Linux;
#[cfg(target_os = "macos")] use crate::macos::MacOS;
#[cfg(target_os="windows")] use crate::windows::Windows;
#[cfg(target_os="linux")] use crate::linux::Linux;
#[cfg(target_os="macos")] use crate::macos::MacOS;
}
19 changes: 13 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,25 @@ use show::show::Show;
mod blackhole;
use blackhole::blackhole::Blackhole;

#[cfg(target_os = "windows")] mod windows;
#[cfg(target_os = "linux")] mod linux;
#[cfg(target_os = "macos")] mod macos;
#[cfg(target_os="windows")] mod windows;
#[cfg(target_os="linux")] mod linux;
#[cfg(target_os="macos")] mod macos;

// TODO open blackhole after initialization
#[cfg(feature="gui")]
use opener::open;

fn main() {
let should_purge: bool = env::args_os().any(|arg| arg == "--purge");
match Blackhole::new(should_purge) {
Ok(blackhole) => {
if !should_purge { Show::msg(&String::from("Blackhole directory initialized!")); }
println!("Location: {}", blackhole.path.display())
println!("Location: {}", blackhole.path.display());

if !should_purge {
#[cfg(feature="gui")]
open(&blackhole.path).ok();

Show::msg(&String::from("Blackhole directory initialized!"));
}
},
Err(error) => { Show::panic(&String::from(error)); }
}
Expand Down

0 comments on commit 539c6be

Please sign in to comment.