Compare commits
No commits in common. "09f272de15116ec688492206af13db59d2a4b9d3" and "850c629eca7471d20191e2ea088b744c7be61b20" have entirely different histories.
09f272de15
...
850c629eca
2 changed files with 97 additions and 43 deletions
|
@ -41,14 +41,14 @@ pub fn run_calendar(args: &CliArgs) {
|
||||||
}
|
}
|
||||||
let value = buffer[21..].to_string();
|
let value = buffer[21..].to_string();
|
||||||
|
|
||||||
if let Some(time) = value.strip_prefix("Moonrise") {
|
if value.starts_with("Moonrise") {
|
||||||
moonrise = parse_time(time.trim());
|
moonrise = parse_time(value[8..].trim());
|
||||||
} else if let Some(time) = value.strip_prefix("Moonset") {
|
} else if value.starts_with("Moonset") {
|
||||||
moonset = parse_time(time.trim());
|
moonset = parse_time(value[7..].trim());
|
||||||
} else if let Some(time) = value.strip_prefix("Moonday") {
|
} else if value.starts_with("Moonday") {
|
||||||
moonday = parse_time(time.trim());
|
moonday = parse_time(value[7..].trim());
|
||||||
} else if let Some(phase) = value.strip_prefix("Moonphase") {
|
} else if value.starts_with("Moonphase") {
|
||||||
moonphase = match phase.trim()[0..2].parse::<u32>() {
|
moonphase = match value[9..].trim()[0..2].parse::<u32>() {
|
||||||
Ok(val) => Some(val),
|
Ok(val) => Some(val),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if args.debug {
|
if args.debug {
|
||||||
|
@ -57,10 +57,10 @@ pub fn run_calendar(args: &CliArgs) {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else if let Some(time) = value.strip_prefix("Sunrise") {
|
} else if value.starts_with("Sunrise") {
|
||||||
sunrise = parse_time(time.trim());
|
sunrise = parse_time(value[7..].trim());
|
||||||
} else if let Some(time) = value.strip_prefix("Sunset") {
|
} else if value.starts_with("Sunset") {
|
||||||
sunset = parse_time(time.trim());
|
sunset = parse_time(value[6..].trim());
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -83,61 +83,76 @@ pub fn run_calendar(args: &CliArgs) {
|
||||||
moonphase: 0,
|
moonphase: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(moon_phase) = moonphase {
|
if moonphase.is_some() {
|
||||||
output_state.moonphase = moon_phase;
|
output_state.moonphase = moonphase.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let now_mins = (Local::now().hour() * 60 +Local::now().minute()) as i32;
|
let now_mins = (Local::now().hour() * 60 +Local::now().minute()) as i32;
|
||||||
|
|
||||||
if sunrise.is_none() {
|
if sunrise.is_none() {
|
||||||
sunrise = Some(8 * 60);
|
sunrise = Some(8 * 60 + 0);
|
||||||
}
|
}
|
||||||
if sunset.is_none() {
|
if sunset.is_none() {
|
||||||
sunset = Some(18 * 60);
|
sunset = Some(18 * 60 + 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
let sun_rise = sunrise.unwrap();
|
let sun_rise = sunrise.clone().unwrap();
|
||||||
let sun_set = sunset.unwrap();
|
let sun_set = sunset.clone().unwrap();
|
||||||
if now_mins > sun_rise && now_mins < sun_set {
|
if now_mins > sun_rise && now_mins < sun_set {
|
||||||
// it is after sunrise, and before sunset
|
// it is after sunrise, and before sunset
|
||||||
output_state.has_bg = true;
|
output_state.has_bg = true;
|
||||||
output_state.is_sun = true;
|
output_state.is_sun = true;
|
||||||
output_state.gradient_angle_percentage =
|
output_state.gradient_angle_percentage = {
|
||||||
(now_mins - sun_rise) as f32 / (sun_set - sun_rise) as f32;
|
(now_mins - sun_rise) as f32
|
||||||
|
/ (sun_set - sun_rise) as f32
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
// Check if the moon is up
|
// Check if the moon is up
|
||||||
if let Some(moon_rise) = moonphase {
|
if moonrise.is_some() {
|
||||||
if let Some(moon_set) = moonset {
|
let moon_rise = moonrise.clone().unwrap();
|
||||||
if now_mins > moon_rise as i32 && now_mins < moon_set {
|
if moonset.is_some() {
|
||||||
|
let moon_set = moonset.clone().unwrap();
|
||||||
|
if now_mins > moon_rise
|
||||||
|
&& now_mins < moon_set
|
||||||
|
{
|
||||||
// moon is up
|
// moon is up
|
||||||
output_state.has_bg = true;
|
output_state.has_bg = true;
|
||||||
output_state.is_sun = false;
|
output_state.is_sun = false;
|
||||||
}
|
}
|
||||||
} else if now_mins > moon_rise as i32 {
|
} else {
|
||||||
|
if now_mins > moon_rise {
|
||||||
output_state.has_bg = true;
|
output_state.has_bg = true;
|
||||||
output_state.is_sun = false;
|
output_state.is_sun = false;
|
||||||
}
|
}
|
||||||
} else if let Some(moon_set) = moonset {
|
}
|
||||||
|
} else {
|
||||||
|
if moonset.is_some() {
|
||||||
|
let moon_set = moonset.clone().unwrap();
|
||||||
if now_mins < moon_set {
|
if now_mins < moon_set {
|
||||||
// moon is up
|
// moon is up
|
||||||
output_state.has_bg = true;
|
output_state.has_bg = true;
|
||||||
output_state.is_sun = false;
|
output_state.is_sun = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if output_state.has_bg && !output_state.is_sun {
|
if output_state.has_bg == true && output_state.is_sun == false {
|
||||||
// moon is up, get the position
|
// moon is up, get the position
|
||||||
if let Some(moon_rise) = moonrise {
|
if moonrise.is_some() {
|
||||||
let moon_day = moonday.unwrap();
|
let moon_rise = moonrise.clone().unwrap();
|
||||||
|
let moon_day = moonday.clone().unwrap();
|
||||||
|
|
||||||
output_state.gradient_angle_percentage =
|
output_state.gradient_angle_percentage = {
|
||||||
(now_mins - moon_rise) as f32 / moon_day as f32;
|
(now_mins - moon_rise) as f32
|
||||||
|
/ moon_day as f32
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
let moon_set = moonset.unwrap();
|
let moon_set = moonset.clone().unwrap();
|
||||||
let moon_day = moonday.unwrap();
|
let moon_day = moonday.clone().unwrap();
|
||||||
let begin_mins: i32 = moon_set - moon_day;
|
let begin_mins: i32 = moon_set - moon_day;
|
||||||
let time_since_rise = now_mins + (begin_mins.abs());
|
let time_since_rise = now_mins + (begin_mins.abs());
|
||||||
output_state.gradient_angle_percentage = time_since_rise as f32 / moon_set as f32;
|
output_state.gradient_angle_percentage = time_since_rise as f32 / moon_set as f32;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
47
flake.nix
47
flake.nix
|
@ -18,7 +18,7 @@ Some utility commands:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
{
|
{
|
||||||
description = "A utility written in rust that my eww configuration uses";
|
description = "";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
@ -39,8 +39,8 @@ Some utility commands:
|
||||||
cargoHash = nixpkgs.lib.fakeHash;
|
cargoHash = nixpkgs.lib.fakeHash;
|
||||||
};
|
};
|
||||||
meta = with nixpkgs.lib; {
|
meta = with nixpkgs.lib; {
|
||||||
homepage = "https://git.nickiel.net";
|
#homepage = "https://example.com";
|
||||||
license = [ licenses.gpl3 ];
|
#license = [ licenses.gpl3 ];
|
||||||
platforms = [ system ];
|
platforms = [ system ];
|
||||||
#maintainers = with maintainers; [ ];
|
#maintainers = with maintainers; [ ];
|
||||||
};
|
};
|
||||||
|
@ -61,11 +61,50 @@ Some utility commands:
|
||||||
pname = "ewwtilities";
|
pname = "ewwtilities";
|
||||||
version = "0.1.0";
|
version = "0.1.0";
|
||||||
buildAndTestSubdir = "ewwtilities";
|
buildAndTestSubdir = "ewwtilities";
|
||||||
cargoHash = "sha256-vY+2bCWlW2SxzAxB9nPighjaa63qW1XttC2vLGqBGWI=";
|
cargoHash = "sha256-+TaGIiKf+Pz2bTABeG8aCZz0/ZTCKl5398+qbas4Nvo=";
|
||||||
meta = meta // {
|
meta = meta // {
|
||||||
description = "";
|
description = "";
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
/*
|
||||||
|
nixosModules.default = { config, ... }: let
|
||||||
|
lib = nixpkgs.lib;
|
||||||
|
in {
|
||||||
|
options.services.ewwtilities = {
|
||||||
|
enable = lib.mkEnableOption (lib.mdDoc "ewwtilities service");
|
||||||
|
package = lib.mkOption {
|
||||||
|
type = lib.types.package;
|
||||||
|
default = self.packages.${system}.ewwtilities;
|
||||||
|
defaultText = "pkgs.ewwtilities";
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
The ewwtilities package that should be used.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
port = lib.mkOption {
|
||||||
|
type = lib.types.port;
|
||||||
|
default = 8000;
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
The port at which to run.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
config.systemd.services.ewwtilities = let
|
||||||
|
cfg = config.services.ewwtilities;
|
||||||
|
pkg = self.packages.${system}.ewwtilities;
|
||||||
|
in lib.mkIf cfg.enable {
|
||||||
|
description = pkg.meta.description;
|
||||||
|
after = [ "network.target" ];
|
||||||
|
wantedBy = [ "network.target" ];
|
||||||
|
serviceConfig = {
|
||||||
|
ExecStart = ''
|
||||||
|
${cfg.package}/bin/ewwtilities --port ${builtins.toString cfg.port}
|
||||||
|
'';
|
||||||
|
Restart = "always";
|
||||||
|
DynamicUser = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
*/
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue