Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use iced::{
},
window::{self, Id, Settings},
};
use std::path::Path;

#[cfg(target_os = "macos")]
use crate::macos::{focus_this_app, transform_process_to_ui_element};
Expand Down Expand Up @@ -146,9 +145,6 @@ pub fn default_settings() -> Settings {
}
}

#[derive(Debug, Clone)]
pub struct Temp {}

#[derive(Debug, Clone)]
pub struct Tile {
theme: iced::Theme,
Expand All @@ -170,7 +166,7 @@ pub struct Tile {
impl Tile {
/// A base window
pub fn new(keybind_id: u32, config: &Config) -> (Self, Task<Message>) {
let mut settings = default_settings();
let settings = default_settings();
#[cfg(target_os = "windows")]
{
// get normal settings and modify position
Expand Down
30 changes: 13 additions & 17 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use std::{
process::exit,
};

use crate::app::{DEFAULT_WINDOW_HEIGHT, WINDOW_WIDTH};
use global_hotkey::hotkey::Code;
use iced::{futures::io::Window, widget::image::Handle};
use iced::widget::image::Handle;
use icns::IconFamily;
use image::RgbaImage;
use rayon::iter::{IntoParallelIterator, ParallelIterator};
Expand Down Expand Up @@ -300,29 +299,26 @@ pub fn to_key_code(key_str: &str) -> Option<Code> {
}

pub fn get_config_installation_dir() -> String {
let path = if cfg!(target_os = "windows") {
if cfg!(target_os = "windows") {
std::env::var("LOCALAPPDATA").unwrap()
} else {
std::env::var("HOME").unwrap()
};

return path;
}
}

pub fn get_config_file_path() -> String {
let home = get_config_installation_dir();
let file_path = if cfg!(target_os = "windows") {

if cfg!(target_os = "windows") {
home + "\\rustcast\\config.toml"
} else {
home + "/.config/rustcast/config.toml"
};

return file_path;
}
}
use crate::config::Config;

pub fn read_config_file(file_path: &str) -> Result<Config, std::io::Error> {
let config: Config = match std::fs::read_to_string(&file_path) {
let config: Config = match std::fs::read_to_string(file_path) {
Ok(a) => toml::from_str(&a).unwrap(),
Err(_) => Config::default(),
};
Expand All @@ -335,10 +331,10 @@ pub fn create_config_file_if_not_exists(
config: &Config,
) -> Result<(), std::io::Error> {
// check if file exists
if let Ok(exists) = std::fs::metadata(&file_path) {
if exists.is_file() {
return Ok(());
}
if let Ok(exists) = std::fs::metadata(file_path)
&& exists.is_file()
{
return Ok(());
}

let path = Path::new(&file_path);
Expand All @@ -347,15 +343,15 @@ pub fn create_config_file_if_not_exists(
}

std::fs::write(
&file_path,
file_path,
toml::to_string(&config).unwrap_or_else(|x| x.to_string()),
)
.unwrap();

Ok(())
}

pub fn open_application(path: &String) {
pub fn open_application(path: &str) {
#[cfg(target_os = "windows")]
{
use std::process::Command;
Expand Down