Skip to content

Commit 20b8cf3

Browse files
committed
All of the app details now reside in env.json. See env_template.json for an idea on how to make your own config.
1 parent 52cc012 commit 20b8cf3

File tree

10 files changed

+77
-52
lines changed

10 files changed

+77
-52
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
Cargo.lock
55
scrap_code.txt
66
project.log
7-
assets/api_keys.json
7+
assets/env.json
88
assets/ignored/*

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ Or, with logging enabled:
5454
RUST_LOG=wbor_studio_dashboard cargo run --release
5555
```
5656

57-
You'll also want to create a file in `assets/` named `api_keys.json`. If you don't have an API key yet for any API, you can just put in a dummy value, and the dashboard will launch just fine. Most APIs already use custom proxies that don't require keys anyways, so the keys are there just for when the proxies fail.
57+
You'll also want to create a file in `assets/` named `env.json` (base it on `env_template.json`).
58+
If you don't have an API key yet for any API, you can just put in a dummy value, and the dashboard will launch just fine. Most APIs already use custom proxies that don't require keys anyways, so the keys are there just for when the proxies fail.
5859

5960
---
6061

@@ -66,7 +67,7 @@ The current themes are:
6667
- `barebones`
6768
- `retro_room`
6869

69-
You can change the theme in `app_config.json`.
70+
You can change the theme in `env.json`.
7071
If you want to make a new theme, start off by copying `standard.rs`, and make your changes from there. Make sure that it doesn't differ too much by running `diff standard.rs <YOUR_NEW_THEME.rs> --color=auto`.
7172

7273
---
@@ -75,7 +76,7 @@ If you want to make a new theme, start off by copying `standard.rs`, and make yo
7576

7677
- To delete recent Twilio messages, use `delete_twilio_msgs.sh`. Change the number of messages to delete in the script, and it'll delete that number of messages one-by-one.
7778

78-
- To run the dashboard on its computer, use `run_dashboard.sh`. Note that this is only made to work in the WBOR studio. If the dashboard ever panics, the script will sleep for a bit, and then try launching it again (while writing all output to a log file `project.log`). Also, if a Discord channel webhook is set up in `api_keys.json`, any crashes will automatically send a message to the channel associated with that webhook.
79+
- To run the dashboard on its computer, use `run_dashboard.sh`. Note that this is only made to work in the WBOR studio. If the dashboard ever panics, the script will sleep for a bit, and then try launching it again (while writing all output to a log file `project.log`). Also, if a Discord channel webhook is set up in `env.json`, any crashes will automatically send a message to the channel associated with that webhook.
7980

8081
- To communicate with the dashboard, use `communicate_with_dashboard.sh`:
8182
- To send a surprise (an image that appears for some amount of time, with a certain random chance of appearing during some time of the day), pass these arguments: `surprise assets/<surprise_with_given_path>`. The surprise path must be one previously defined in `src/dashboard_defs/themes/shared_utils.rs`.

assets/api_keys_template.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

assets/app_config.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

assets/env_template.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"window_config": {
3+
"title": "WBOR Studio Dashboard",
4+
"theme_name": "barebones",
5+
"icon_path": "assets/plane.bmp",
6+
7+
"background_color": [0, 0, 0],
8+
"max_remake_transition_queue_size": 10,
9+
10+
"hide_cursor": true,
11+
"draw_borders": true,
12+
"use_linear_filtering": true,
13+
"window_always_on_top": false,
14+
15+
"maybe_pause_subduration_ms_when_window_unfocused": null,
16+
17+
"o1": {"Windowed": [[1024, 768], false, null]},
18+
"o2": "FullscreenDesktop",
19+
"screen_option": "Fullscreen"
20+
},
21+
22+
"api_keys": {
23+
"spinitron": "SPINITRON API KEY HERE",
24+
"twilio_account_sid": "TWILIO ACCOUNT SID HERE",
25+
"twilio_auth_token": "TWILIO AUTH TOKEN HERE",
26+
"tomorrow_io": "TOMORROW.IO API KEY HERE",
27+
28+
"streaming_server_now_playing_url": "STREAMING SERVER URL HERE (PROBABLY 'https://azura.wbor.org/api/nowplaying/2' FOR THE NEAR FUTURE)",
29+
"dashboard_crash_discord_webhook_url": "OPTIONAL WEBHOOK URL HERE THAT IS CALLED WHEN THE DASHBOARD CRASHES"
30+
}
31+
}

src/dashboard_defs/themes/barebones.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use crate::{
1111

1212
utils::{
1313
request,
14-
file_utils,
1514
vec2f::Vec2f,
1615
time::Duration,
1716
generic_result::*,
@@ -74,7 +73,7 @@ pub async fn make_dashboard(
7473
let main_windows_gap_size = 0.01;
7574

7675
let mut rand_generator = rand::thread_rng();
77-
let api_keys: ApiKeys = file_utils::load_json_from_file("assets/api_keys.json").await?;
76+
let api_keys = ApiKeys::new().await?;
7877

7978
let (theme_color_1, theme_border_radius_1) = (ColorSDL::RGB(255, 133, 133), 8);
8079
let theme_border_info_1 = Some((theme_color_1, theme_border_radius_1));

src/dashboard_defs/themes/retro_room.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use crate::{
1111

1212
utils::{
1313
request,
14-
file_utils,
1514
vec2f::Vec2f,
1615
time::Duration,
1716
generic_result::*,
@@ -75,7 +74,7 @@ pub async fn make_dashboard(
7574
let main_windows_gap_size = 0.0;
7675

7776
let mut rand_generator = rand::thread_rng();
78-
let api_keys: ApiKeys = file_utils::load_json_from_file("assets/api_keys.json").await?;
77+
let api_keys = ApiKeys::new().await?;
7978

8079
let theme_color_1 = ColorSDL::RGB(134, 0, 41);
8180
let theme_border_info_1 = None;

src/dashboard_defs/themes/shared_utils.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ pub struct ApiKeys {
2828
pub streaming_server_now_playing_url: String // Not really an API key, but this is the best place to put it anyways
2929
}
3030

31+
impl ApiKeys {
32+
pub async fn new() -> GenericResult<Self> {
33+
#[derive(serde::Deserialize)]
34+
struct ApiKeysWrapper {
35+
api_keys: ApiKeys
36+
}
37+
38+
let wrapper: ApiKeysWrapper = file_utils::load_json_from_file("assets/env.json").await?;
39+
Ok(wrapper.api_keys)
40+
}
41+
}
42+
3143
//////////
3244

3345
lazy_static::lazy_static!(

src/dashboard_defs/themes/standard.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use crate::{
1111

1212
utils::{
1313
request,
14-
file_utils,
1514
vec2f::Vec2f,
1615
time::Duration,
1716
generic_result::*,
@@ -75,7 +74,7 @@ pub async fn make_dashboard(
7574
let main_windows_gap_size = 0.01;
7675

7776
let mut rand_generator = rand::thread_rng();
78-
let api_keys: ApiKeys = file_utils::load_json_from_file("assets/api_keys.json").await?;
77+
let api_keys = ApiKeys::new().await?;
7978

8079
let (theme_color_1, theme_border_radius_1) = (ColorSDL::RGB(249, 236, 210), 8);
8180
let theme_border_info_1 = Some((theme_color_1, theme_border_radius_1));

src/main.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ enum ScreenOption {
4646
}
4747

4848
#[derive(serde::Deserialize)]
49-
struct AppConfig {
49+
struct WindowConfig {
5050
title: String,
5151
theme_name: String,
5252
icon_path: String,
@@ -64,6 +64,18 @@ struct AppConfig {
6464
screen_option: ScreenOption
6565
}
6666

67+
impl WindowConfig{
68+
pub async fn new() -> GenericResult<Self> {
69+
#[derive(serde::Deserialize)]
70+
struct WindowConfigWrapper {
71+
window_config: WindowConfig
72+
}
73+
74+
let wrapper: WindowConfigWrapper = file_utils::load_json_from_file("assets/env.json").await?;
75+
Ok(wrapper.window_config)
76+
}
77+
}
78+
6779
//////////
6880

6981
fn get_fps(sdl_timer: &sdl2::TimerSubsystem,
@@ -103,7 +115,7 @@ async fn main() {
103115
env_logger::init();
104116
log::info!("App launched!");
105117

106-
let app_config: AppConfig = file_utils::load_json_from_file("assets/app_config.json").await.unwrap();
118+
let window_config = WindowConfig::new().await.unwrap();
107119

108120
////////// Setting up SDL and the initial window
109121

@@ -112,9 +124,9 @@ async fn main() {
112124
let mut sdl_event_pump = sdl_context.event_pump().unwrap();
113125

114126
let build_window = |size: PixelAreaSDL, applier: fn(&mut WindowBuilder) -> &mut WindowBuilder|
115-
applier(&mut sdl_video_subsystem.window(&app_config.title, size.0, size.1)).allow_highdpi().build();
127+
applier(&mut sdl_video_subsystem.window(&window_config.title, size.0, size.1)).allow_highdpi().build();
116128

117-
let mut sdl_window = match app_config.screen_option {
129+
let mut sdl_window = match window_config.screen_option {
118130
ScreenOption::Windowed(size, borderless, _) => build_window(
119131
size,
120132
if borderless {|wb| wb.position_centered().borderless()}
@@ -139,16 +151,16 @@ async fn main() {
139151

140152
////////// Setting the window always-on-top state, opacity, and icon
141153

142-
sdl_window.set_always_on_top(app_config.window_always_on_top);
154+
sdl_window.set_always_on_top(window_config.window_always_on_top);
143155

144156
// TODO: why does not setting the opacity result in broken fullscreen screen clearing?
145-
if let ScreenOption::Windowed(.., Some(opacity)) = app_config.screen_option {
157+
if let ScreenOption::Windowed(.., Some(opacity)) = window_config.screen_option {
146158
if let Err(err) = sdl_window.set_opacity(opacity as f32) {
147159
log::warn!("Window translucency not supported by your current platform! Official error: '{err}'.");
148160
}
149161
}
150162

151-
sdl_window.set_icon(Surface::from_file(app_config.icon_path).unwrap());
163+
sdl_window.set_icon(Surface::from_file(window_config.icon_path).unwrap());
152164

153165
////////// Making a SDL canvas
154166

@@ -164,13 +176,13 @@ async fn main() {
164176
let using_texture_filtering_option =
165177
sdl2::hint::set_with_priority(
166178
"SDL_RENDER_SCALE_QUALITY",
167-
if app_config.use_linear_filtering {"1"} else {"0"},
179+
if window_config.use_linear_filtering {"1"} else {"0"},
168180
&sdl2::hint::Hint::Override
169181
);
170182

171183
assert!(using_texture_filtering_option);
172184

173-
if app_config.hide_cursor {
185+
if window_config.hide_cursor {
174186
sdl_context.mouse().show_cursor(false);
175187
}
176188

@@ -187,19 +199,19 @@ async fn main() {
187199
let sdl_performance_frequency = sdl_timer.performance_frequency();
188200

189201
let texture_pool = texture::pool::TexturePool::new(
190-
&texture_creator, &sdl_ttf_context, max_texture_size, app_config.max_remake_transition_queue_size
202+
&texture_creator, &sdl_ttf_context, max_texture_size, window_config.max_remake_transition_queue_size
191203
);
192204

193205
let mut rendering_params =
194206
window_tree::PerFrameConstantRenderingParams {
195-
draw_borders: app_config.draw_borders,
207+
draw_borders: window_config.draw_borders,
196208
sdl_canvas,
197209
texture_pool,
198210
frame_counter: FrameCounter::new(),
199211
shared_window_state: DynamicOptional::NONE
200212
};
201213

202-
let bg = app_config.background_color;
214+
let bg = window_config.background_color;
203215
let standard_background_color = ColorSDL::RGB(bg.0, bg.1, bg.2);
204216

205217
log::info!("Canvas size: {:?}. Renderer info: {sdl_renderer_info:?}.", rendering_params.sdl_canvas.output_size().unwrap());
@@ -236,7 +248,7 @@ async fn main() {
236248
}
237249

238250
if pausing_window {
239-
if let Some(pause_subduration_ms) = app_config.maybe_pause_subduration_ms_when_window_unfocused {
251+
if let Some(pause_subduration_ms) = window_config.maybe_pause_subduration_ms_when_window_unfocused {
240252
sdl_timer.delay(pause_subduration_ms);
241253
continue;
242254
}
@@ -248,7 +260,7 @@ async fn main() {
248260
let time_before_making_core_init_info = get_timestamp();
249261

250262
let core_init_info = build_dashboard_theme!(
251-
app_config.theme_name.as_str(), &mut rendering_params.texture_pool,
263+
window_config.theme_name.as_str(), &mut rendering_params.texture_pool,
252264
UpdateRateCreator::new(fps), [standard, barebones, retro_room]
253265
);
254266

0 commit comments

Comments
 (0)