Skip to content

Commit

Permalink
Merge pull request #45 from CharlieS1103/functionality-without-scripting
Browse files Browse the repository at this point in the history
Functionality without scripting
  • Loading branch information
CharlieS1103 authored Oct 30, 2024
2 parents 4525c6c + cd897ab commit 21a66d4
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 482 deletions.
9 changes: 0 additions & 9 deletions postcss.config.js

This file was deleted.

33 changes: 33 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
mod app_structs;
mod config;
mod parser;
mod utils;
use std::{path::{PathBuf, Path}, error::Error, fs::{self, File, read_dir}, io::{BufReader, Read, BufWriter, Cursor},};
use app_structs::{mac_app::MacApplication, icon_states::generate_toml_file, icon_states::parse_toml_file,};
use config::{parse_config, generate_config};
use plist::Value;
use utils::image_handling::icns_conversion::{convert_icns_to_png, /*convert_pngs_to_icns*/};


fn main() {
Expand Down Expand Up @@ -91,6 +93,10 @@ fn mac_logic(){
if app.is_err() {
continue;
}
else if app_file.display().to_string().split(".app").collect::<Vec<&str>>().len() > 2 {
// This should in all hopes remove any apps which contain additional helper apps inside the directory
continue;
}
else{
mac_apps.push(app.unwrap());
}
Expand All @@ -111,6 +117,7 @@ fn mac_logic(){
}else{
println!("Error storing icns files: {}", mac_store_icns_files(&mac_apps).err().unwrap());
}
// Store the icns files for each app as a png file in the icons directory as well
}

/*
Expand Down Expand Up @@ -220,6 +227,32 @@ fn get_icon_file_name(app_dir: &str) -> Result<String, Box<dyn std::error::Error
Err("Icon file name not found in Info.plist".into())
}

// If a user wants to uninstall overgrowth we should use the backed up icns files in the specified directory to restore the icons to their original state
fn uninstall_overgrowth() -> Result<(), Box<dyn Error>> {
// THIS FUNCTION IS SUPER SCARY TO TEST!! TODO: WRITE UNIT TESTS FOR THIS FUNCTION
let config = parse_config(&get_home_dir().unwrap());
let home_dir = get_home_dir().unwrap();
let icon_dir = home_dir.join(PathBuf::from(&config.icon_dir));
let app_dir = home_dir.join("Applications");

for entry in read_dir(icon_dir)? {
let entry = entry?;
let path = entry.path();
let file_name = path.file_name().unwrap().to_str().unwrap();
let app_name = file_name.split(".icns").collect::<Vec<&str>>()[0];
let app_path = app_dir.join(app_name);
let app_icon_path = app_path.join(file_name);
let original_icon_path = path;

if app_icon_path.exists() {
fs::remove_file(app_icon_path.clone())?;
}

fs::copy(original_icon_path, app_icon_path)?;
}

Ok(())
}


// What i need to do for parsing
Expand Down
135 changes: 0 additions & 135 deletions src-tauri/src/parser/interpreter.rs
Original file line number Diff line number Diff line change
@@ -1,135 +0,0 @@
use icns::Image;

use super::parser::image_metadata;
use super::parser::ImageMetadata;
use super::parser::MetadataField;
use super::parser::Action;
use super::parser::parse;
use super::parser::ComparisonOperator::{Equals, LessThan, GreaterThan, LessThanOrEqual, GreaterThanOrEqual, NotEquals};
pub struct Interpreter {
state: std::collections::HashMap<String, String>,
}

impl Interpreter {
pub fn new() -> Self {
Self {
state: std::collections::HashMap::new(),
}
}

pub fn interpret(&mut self, metadata: ImageMetadata) {
for field in metadata.fields {

match field {
MetadataField::Type(mut key, value) => {
key = "FIELD:".to_owned() + &key.to_uppercase();
println!("Setting type {} to {}", key, value);
self.state.insert(key, value);
}
MetadataField::Author(mut key, value) => {
key = "FIELD:".to_owned() + &key.to_uppercase();
println!("Setting author {} to {}", key, value);
self.state.insert(key, value);
}
MetadataField::Date(mut key, value, op, value2) => {
key = "FIELD:".to_owned() + &key.to_uppercase();
// Compare the dates, store key and true/false in state
// print op
println!("Operation: {:?}", op);
match op
{
Equal => {
if value == value2 {
self.state.insert(key, "true".to_string());


} else {
self.state.insert(key, "false".to_string());
}

}
LessThan => {
if value < value2 {
self.state.insert(key, "true".to_string());
} else {
self.state.insert(key, "false".to_string());
}
}
GreaterThan => {
if value > value2 {
self.state.insert(key, "true".to_string());
} else {
self.state.insert(key, "false".to_string());
}
}
LessThanOrEqual => {
if value <= value2 {
self.state.insert(key, "true".to_string());
} else {
self.state.insert(key, "false".to_string());
}
}
GreaterThanOrEqual => {
if value >= value2 {
self.state.insert(key, "true".to_string());
} else {
self.state.insert(key, "false".to_string());
}
}
NotEquals => {
if value != value2 {
self.state.insert(key, "true".to_string());
} else {
self.state.insert(key, "false".to_string());
}
}

}

}
MetadataField::Other(mut key, value) => {
key = "FIELD:".to_owned() + &key.to_uppercase();
println!("Setting other {} to {}", key, value);
self.state.insert(key, value);
}
}
}

for action in metadata.actions {
match action {
Action::ChangeColor(color) => {
println!("Changing color to {}", color);
}
Action::AddOverlay(overlay) => {
println!("Adding overlay {}", overlay);
}
}
}
}
}



#[cfg(test)]
mod tests {


use super::*;

#[test]
fn test_basic() {
let mut interpreter = Interpreter::new();
let metadata = parse(r#"where metadata field Type is "Landscape"{ change color to "blue" }"#).unwrap().0;
interpreter.interpret(metadata);
// I dont like seeing FIELD:TYPE, need to figure out a hashmap structure for comparison operators and the such
assert_eq!(interpreter.state.get("FIELD:TYPE"), Some(&"Landscape".to_string()));

}
#[test]
fn test_date() {
let mut interpreter = Interpreter::new();
let metadata = parse(r#"where metadata field Date 12/03/2005 = 12/03/2005{ change color to "blue" }"#).unwrap().0;
interpreter.interpret(metadata);
assert_eq!(interpreter.state.get("FIELD:DATE"), Some(&"true".to_string()));
}
}
Loading

0 comments on commit 21a66d4

Please sign in to comment.