Skip to content

Commit c9e9bfc

Browse files
committed
Merge branch 'badge'
2 parents fc7f5d2 + 15207ae commit c9e9bfc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+72
-12
lines changed

README.md

Lines changed: 5 additions & 0 deletions

src/icon_conversion.rs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ pub enum ProgressBarType {
1818
}
1919

2020
impl ProgressBarType {
21-
pub fn num_steps(&self) -> u64 {
21+
pub fn num_steps(&self, includes_badge: bool) -> u64 {
2222
match self {
2323
ProgressBarType::Input => 1,
24-
ProgressBarType::Conversion => 13,
24+
ProgressBarType::Conversion => 13 + if includes_badge { 1 } else { 0 },
2525
ProgressBarType::OutputWithAssignmentDefault => 2,
2626
ProgressBarType::OutputWithAssignmentUsingRez => 7,
2727
ProgressBarType::OutputIcns => 1,
@@ -36,9 +36,9 @@ use crate::{
3636
},
3737
convert::{density, BlurDown, CommandArgs, CompositingOperation},
3838
error::{FolderifyError, GeneralError},
39-
generic_folder_icon::get_folder_icon,
40-
options::{self, ColorScheme, Options, SetIconUsing},
39+
options::{Badge, ColorScheme, Options, SetIconUsing},
4140
primitives::{Dimensions, Extent, Offset, RGBColor},
41+
resources::{get_badge_icon, get_folder_icon},
4242
};
4343

4444
pub struct ScaledMaskInputs {
@@ -77,10 +77,11 @@ impl WorkingDir {
7777
progress_bar_type: ProgressBarType,
7878
stage_description: &str,
7979
multi_progress_bar: Option<MultiProgress>,
80+
includes_badge: bool,
8081
) -> IconConversion {
8182
let progress_bar = match multi_progress_bar {
8283
Some(multi_progress_bar) => {
83-
let progress_bar = ProgressBar::new(progress_bar_type.num_steps());
84+
let progress_bar = ProgressBar::new(progress_bar_type.num_steps(includes_badge));
8485
let progress_bar = match progress_bar_type {
8586
ProgressBarType::Conversion => multi_progress_bar.insert(1, progress_bar),
8687
_ => multi_progress_bar.insert_from_back(0, progress_bar),
@@ -286,7 +287,7 @@ impl IconConversion {
286287

287288
pub fn full_mask(
288289
&self,
289-
options: &options::Options,
290+
options: &Options,
290291
centering_dimensions: &Dimensions,
291292
) -> Result<PathBuf, FolderifyError> {
292293
self.step_unincremented("Preparing icon mask");
@@ -457,10 +458,25 @@ impl IconConversion {
457458
args.composite(&CompositingOperation::dissolve);
458459
args.push_path(output_path);
459460
run_convert(&args, Some(template_icon))?;
461+
Ok(())
462+
}
460463

461-
self.step("");
464+
pub fn badge_in_place(
465+
&self,
466+
icon_path: &Path,
467+
badge: Badge,
468+
resolution: &IconResolution,
469+
) -> Result<(), FolderifyError> {
470+
self.step("Adding badge"); // TODO: increase maximum step counter.
462471

463-
Ok(())
472+
let badge_icon = get_badge_icon(badge, resolution);
473+
474+
let mut args = CommandArgs::new();
475+
args.push_path(icon_path);
476+
args.push("-");
477+
args.composite(&CompositingOperation::dissolve);
478+
args.push_path(icon_path);
479+
run_convert(&args, Some(badge_icon))
464480
}
465481

466482
// TODO
@@ -524,6 +540,12 @@ impl IconConversion {
524540
},
525541
},
526542
);
543+
if let Some(badge) = options.badge {
544+
self.badge_in_place(output_path, badge, &inputs.resolution)?;
545+
};
546+
547+
self.step("");
548+
527549
if options.verbose {
528550
println!("[{}] {}", options.mask_path.display(), inputs.resolution);
529551
}

src/main.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ use crate::{output_paths::PotentialOutputPaths, primitives::Dimensions};
1010
mod command;
1111
mod convert;
1212
mod error;
13-
mod generic_folder_icon;
1413
mod icon_conversion;
1514
mod options;
1615
mod output_paths;
1716
mod primitives;
17+
mod resources;
1818

1919
fn main() {
2020
let options = options::get_options();
@@ -45,6 +45,7 @@ fn main() {
4545
icon_conversion::ProgressBarType::Input,
4646
"(Input)",
4747
multi_progress_bar.clone(),
48+
false,
4849
);
4950
let full_mask_path = input_icon_conversion
5051
.full_mask(
@@ -64,6 +65,7 @@ fn main() {
6465
icon_conversion::ProgressBarType::Conversion,
6566
&resolution.to_string(),
6667
multi_progress_bar.clone(),
68+
true,
6769
);
6870
let options = options.clone();
6971
let full_mask_path = full_mask_path.clone();
@@ -101,8 +103,12 @@ fn main() {
101103
}
102104
(None, _) => icon_conversion::ProgressBarType::OutputWithAssignmentDefault,
103105
};
104-
let output_icon_conversion =
105-
working_dir.icon_conversion(output_progress_bar_type, "(Output)", multi_progress_bar);
106+
let output_icon_conversion = working_dir.icon_conversion(
107+
output_progress_bar_type,
108+
"(Output)",
109+
multi_progress_bar,
110+
false,
111+
);
106112
output_icon_conversion.step_unincremented("Waiting…");
107113

108114
for handle in handles {

src/options.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ struct FolderifyArgs {
6363
#[arg(long, hide(true))]
6464
set_icon_using: Option<SetIconUsingOrAuto>,
6565

66+
/// Add a badge to the icon. Currently only supports one badge at a time.
67+
#[arg(long)]
68+
badge: Option<Badge>,
69+
6670
/// Detailed output. Also sets `--no-progress`.
6771
#[clap(short, long)]
6872
verbose: bool,
@@ -82,6 +86,12 @@ pub enum ColorScheme {
8286
Dark,
8387
}
8488

89+
#[derive(ValueEnum, Clone, Debug, PartialEq, Copy)]
90+
pub enum Badge {
91+
Alias,
92+
Locked,
93+
}
94+
8595
impl Display for ColorScheme {
8696
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
8797
write!(
@@ -127,6 +137,7 @@ pub struct Options {
127137
pub output_iconset: Option<PathBuf>,
128138
pub set_icon_using: SetIconUsing,
129139
pub show_progress: bool,
140+
pub badge: Option<Badge>,
130141
pub reveal: bool,
131142
pub verbose: bool,
132143
pub debug: bool,
@@ -202,6 +213,7 @@ pub fn get_options() -> Options {
202213
target: args.target,
203214
output_icns: args.output_icns,
204215
output_iconset: args.output_iconset,
216+
badge: args.badge,
205217
set_icon_using,
206218
show_progress,
207219
reveal: args.reveal,
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,31 @@ use std::path::PathBuf;
22

33
use include_dir::{include_dir, Dir};
44

5-
use crate::{icon_conversion::IconResolution, options::ColorScheme};
5+
use crate::{
6+
icon_conversion::IconResolution,
7+
options::{Badge, ColorScheme},
8+
};
69

710
static RESOURCES_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/src/resources");
811

912
pub fn get_folder_icon(color_scheme: ColorScheme, resolution: &IconResolution) -> &'static [u8] {
1013
let mut path = PathBuf::new();
14+
path.push("folders");
1115
path.push(match color_scheme {
1216
ColorScheme::Light => "GenericFolderIcon.BigSur.iconset",
1317
ColorScheme::Dark => "GenericFolderIcon.BigSur.dark.iconset",
1418
});
1519
path.push(resolution.icon_file());
1620
RESOURCES_DIR.get_file(&path).unwrap().contents()
1721
}
22+
23+
pub fn get_badge_icon(badge: Badge, resolution: &IconResolution) -> &'static [u8] {
24+
let mut path = PathBuf::new();
25+
path.push("badges");
26+
path.push(match badge {
27+
Badge::Alias => "AliasBadgeIcon.iconset",
28+
Badge::Locked => "LockedBadgeIcon.iconset",
29+
});
30+
path.push(resolution.icon_file());
31+
RESOURCES_DIR.get_file(&path).unwrap().contents()
32+
}
1.86 KB
5.32 KB
343 Bytes
671 Bytes
5.3 KB

0 commit comments

Comments
 (0)