Skip to content

Commit

Permalink
Added suppress notifications option, added log file rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
EMcNugget committed Sep 4, 2024
1 parent 5742199 commit a876405
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 62 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-pillows-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"d-atis-to-vatis": patch
---

Added ability to suppress new ATIS notification
29 changes: 23 additions & 6 deletions src-tauri/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@ use serde_json::{self, Value};
use sysinfo::System;
use tauri::{AppHandle, Manager};

fn get_atis_type(atis_type: &str) -> &'static str {
return match atis_type {
"dep" => "Departure",
"arr" => "Arrival",
"combined" => "Combined",
_ => "Combined",
};
}

fn find_composite(
data: &Value,
profile: &str,
facility: &str,
atis_type: Option<&str>,
) -> Option<FindComposite> {
let atis_type_str = match atis_type {
Some("dep") => "Departure",
Some("arr") => "Arrival",
Some("combined") => "Combined",
_ => "Combined",
};
let atis_type_str = get_atis_type(atis_type.unwrap_or("unknown"));

let profiles = data.get("profiles").and_then(|p| p.as_array()).unwrap();

Expand Down Expand Up @@ -133,6 +137,8 @@ pub fn write_atis(facility: String, atis: Value, app_handle: AppHandle) -> Resul
message: String::new(),
};

let mut codes: Vec<String> = Vec::new();

let file_path = get_vatis_path(&app_handle);

for atis_entry in atis_array {
Expand All @@ -148,6 +154,11 @@ pub fn write_atis(facility: String, atis: Value, app_handle: AppHandle) -> Resul
match result {
Ok(_) => {
let data = &format!("Successfully wrote ATIS for {}", &facility);
codes.push(format!(
"{}: {}",
get_atis_type(atis_entry["atis_type"].as_str().unwrap_or("unknown")),
&atis_entry["atis_code"].as_str().unwrap_or_default()
));
info!("{}", data);
if alert.message == *data {
// do nothing
Expand All @@ -168,6 +179,12 @@ pub fn write_atis(facility: String, atis: Value, app_handle: AppHandle) -> Resul
}
}

if !codes.is_empty() {
for code in codes {
alert.message.push_str(&format!(" {}", code));
}
}

Ok(alert)
}

Expand Down
8 changes: 1 addition & 7 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use log::info;
use tauri::{AppHandle, Listener};
use tauri_plugin_log::{Target, TargetKind};

mod app;
mod audio;
Expand Down Expand Up @@ -37,13 +36,8 @@ fn main() {
.plugin(tauri_plugin_dialog::init())
.plugin(
tauri_plugin_log::Builder::new()
.targets([
Target::new(TargetKind::Stdout),
Target::new(TargetKind::LogDir {
file_name: Some("log".to_string()),
}),
])
.timezone_strategy(tauri_plugin_log::TimezoneStrategy::UseLocal)
.max_file_size(50_000)
.rotation_strategy(tauri_plugin_log::RotationStrategy::KeepOne)
.build(),
)
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub fn check_settings_file(app_handle: &AppHandle) -> Response {
"save_facility": false,
"open_vatis_on_fetch": false,
"check_updates": false,
"suppress_notification": false,
"check_updates_freq": false,
"fetch_for_profile": false,
"update_time": 60,
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct Settings {
pub save_facility: bool,
pub open_vatis_on_fetch: bool,
pub check_updates: bool,
pub suppress_notification: bool,
pub check_updates_freq: bool,
pub fetch_for_profile: bool,
pub update_time: u64,
Expand Down
8 changes: 8 additions & 0 deletions src/components/CSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ const check_updates = computed({
set: (v) => store.set_individual("check_updates", v),
});
const suppress_notification = computed({
get: () => store.get_individual("suppress_notification"),
set: (v) => store.set_individual("suppress_notification", v),
});
const check_updates_freq = computed({
get: () => store.get_individual("check_updates_freq"),
set: (v) => store.set_individual("check_updates_freq", v),
Expand Down Expand Up @@ -210,6 +215,9 @@ watch(
<CLabel title="Check for ATIS Updates">
<input type="checkbox" class="toggle" v-model="check_updates" />
</CLabel>
<CLabel title="Suppress ATIS Notification">
<input type="checkbox" class="toggle" v-model="suppress_notification" />
</CLabel>
<CLabel title="Fetch ATIS for All Airports in a Profile">
<input type="checkbox" class="toggle" v-model="fetch_for_profile" />
</CLabel>
Expand Down
6 changes: 6 additions & 0 deletions src/lib/router.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Atis from "../views/Atis.vue";
import RecordAtis from "../views/RecordAtis.vue";
import EditContractions from "../views/EditContractions.vue";
import { createRouter, createWebHashHistory } from "vue-router";

const routes = [
Expand All @@ -13,6 +14,11 @@ const routes = [
name: "Record ATIS",
component: RecordAtis,
},
{
path: "/contractions",
name: "Edit Contractions",
component: EditContractions,
}
];

export const router = createRouter({
Expand Down
1 change: 1 addition & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type TSettings = {
save_facility: boolean;
open_vatis_on_fetch: boolean;
check_updates: boolean;
suppress_notification: boolean;
check_updates_freq: boolean;
fetch_for_profile: boolean;
update_time: number;
Expand Down
55 changes: 6 additions & 49 deletions src/views/Atis.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@
import Layout from "./Layout.vue";
import { fetch_atis } from "../lib/parser";
import { use_store } from "../lib/stores";
import {
TAlert,
TATISCode,
facilities,
vATIS,
TATIS,
alert_types,
} from "../lib/types";
import { TAlert, facilities, vATIS, TATIS, alert_types } from "../lib/types";
import { invoke } from "@tauri-apps/api/core";
import { emit } from "@tauri-apps/api/event";
import { computed, ref, watch } from "vue";
Expand Down Expand Up @@ -74,33 +67,6 @@ const validate_iaco = (value: string) => {
}
};
const get_atis_code = (atis: vATIS[]): TATISCode[] => {
return atis.map((k) => {
switch (k.atis_type) {
case "arr":
return {
type: "Arrival",
code: k.atis_code,
};
case "dep":
return {
type: "Departure",
code: k.atis_code,
};
case "combined":
return {
type: "Combined",
code: k.atis_code,
};
default:
return {
type: "Combined",
code: k.atis_code,
};
}
});
};
const get_alert_level = (level: string) => {
switch (level) {
case "error":
Expand Down Expand Up @@ -145,22 +111,12 @@ const get_atis = async () => {
const promises = facs.map(async (fac) => {
let atis: vATIS[] = [];
const concat_codes = (atis: vATIS[], message: string) => {
message = message.concat(
` ${get_atis_code(atis)
.map((k) => `${k.type}: ${k.code}`)
.join(", ")}`
);
return message;
};
try {
atis = await fetch_atis(fac);
} catch (e) {
const alert = e as TAlert;
if (alert.payload) {
atis.push(alert.payload as vATIS);
alert.message = concat_codes(atis, alert.message as string);
}
messages.push({ key: fac, message: alert.message as string });
status[fac] = alert.alert_type;
Expand All @@ -172,9 +128,7 @@ const get_atis = async () => {
});
const success = alert.alert_type === "success";
alert.message = success
? concat_codes(atis, alert.message as string)
: "";
alert.message = success ? alert.message : "";
if (!messages.some((k) => k.key === fac)) {
messages.push({ key: fac, message: alert.message as string });
Expand Down Expand Up @@ -216,12 +170,15 @@ const alert_new_codes = (codes: Record<string, string[]>) => {
Object.entries(codes).forEach(([key, value]) => {
rows.push({ key, message: value.join(", ") });
});
message.value = {
alert_type: "info",
message: rows,
slot: `New ATIS's found for ${rows.map((k) => k.key).join(", ")}`,
};
emit("new-codes");
if (!store.get_individual("suppress_notification")) {
emit("new-codes");
}
};
const get_zulu_time = () => {
Expand Down
8 changes: 8 additions & 0 deletions src/views/EditContractions.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script setup lang="ts">
import Layout from './Layout.vue';
</script>

<template>
<Layout></Layout>
</template>
2 changes: 2 additions & 0 deletions src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ invoke("read_settings").then(async (k) => {
<RouterLink to="/record" class="btn btn-primary w-2/3"
>Record ATIS</RouterLink
>
<RouterLink to="/contractions" class="btn btn-primary w-2/3"
>Edit Contractions</RouterLink>
</div>
</Layout>
<RouterView v-else />
Expand Down

0 comments on commit a876405

Please sign in to comment.