Skip to content

Commit

Permalink
refactor: Rename "Session" to "Test" (#107)
Browse files Browse the repository at this point in the history
This terminology is more precise, and less prone to misunderstandings.
  • Loading branch information
bragefuglseth authored Feb 9, 2025
1 parent fc6c58c commit c13a973
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 150 deletions.
8 changes: 4 additions & 4 deletions data/resources/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ KpResultsView .key-number {

headerbar .start,
headerbar .end,
window.hide-controls headerbar.session:focus-within .start,
window.hide-controls headerbar.session:focus-within .end {
window.hide-controls headerbar.test:focus-within .start,
window.hide-controls headerbar.test:focus-within .end {
opacity: 1;
transition: opacity 200ms;
}

window.hide-controls headerbar.session .start,
window.hide-controls headerbar.session .end {
window.hide-controls headerbar.test .start,
window.hide-controls headerbar.test .end {
opacity: 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ mod imp {
obj.setup_gactions();

obj.set_accels_for_action("win.text-language-dialog", &["<primary>comma"]);
obj.set_accels_for_action("win.cancel-session", &["Escape"]);
obj.set_accels_for_action("win.cancel-test", &["Escape"]);
obj.set_accels_for_action("window.close", &["<primary>w"]);
obj.set_accels_for_action("app.quit", &["<primary>q"]);
}
Expand Down
18 changes: 9 additions & 9 deletions src/discord_rpc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* discord_rpc.rs
*
* SPDX-FileCopyrightText: © 2024 Brage Fuglseth <[email protected]>
* SPDX-FileCopyrightText: © 2024–2025 Brage Fuglseth <[email protected]>
* SPDX-License-Identifier: GPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use crate::session_enums::*;
use crate::typing_test_utils::*;
use discord_presence::models::rich_presence::Activity;
use discord_presence::Client;
use std::sync::mpsc;
Expand All @@ -29,7 +29,7 @@ const DISCORD_CLIENT_ID: u64 = 1320106636743802923;

enum RpcMessage {
SendStored,
Change(SessionConfig, PresenceState),
Change(TestConfig, PresenceState),
UpdateStats(f64, f64),
}

Expand Down Expand Up @@ -67,14 +67,14 @@ impl Default for RpcWrapper {
for msg in receiver.iter() {
if let RpcMessage::Change(session_config, state) = msg {
let details_string = match session_config {
SessionConfig::Finite => "Custom text".to_string(),
SessionConfig::Generated {
difficulty: GeneratedSessionDifficulty::Simple,
TestConfig::Finite => "Custom text".to_string(),
TestConfig::Generated {
difficulty: GeneratedTestDifficulty::Simple,
duration,
..
} => format!("Simple, {}", duration.english_string()),
SessionConfig::Generated {
difficulty: GeneratedSessionDifficulty::Advanced,
TestConfig::Generated {
difficulty: GeneratedTestDifficulty::Advanced,
duration,
..
} => format!("Advanced, {}", duration.english_string()),
Expand Down Expand Up @@ -121,7 +121,7 @@ impl Default for RpcWrapper {
}

impl RpcWrapper {
pub fn set_activity(&self, session_config: SessionConfig, state: PresenceState) {
pub fn set_activity(&self, session_config: TestConfig, state: PresenceState) {
self.sender
.send(RpcMessage::Change(session_config, state))
.expect("channel exists until app shuts down");
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
mod application;
mod config;
mod discord_rpc;
mod session_enums;
mod typing_test_utils;
mod settings;
mod text_generation;
mod text_utils;
Expand Down
68 changes: 34 additions & 34 deletions src/session_enums.rs → src/typing_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,47 +27,47 @@ use std::time::{Duration, Instant, SystemTime};
use strum_macros::{Display as EnumDisplay, EnumIter, EnumString};

#[derive(Clone, Copy, PartialEq, EnumString, EnumDisplay)]
pub enum GeneratedSessionDifficulty {
pub enum GeneratedTestDifficulty {
Simple,
Advanced,
}

impl GeneratedSessionDifficulty {
impl GeneratedTestDifficulty {
pub fn from_settings_string(s: &str) -> Option<Self> {
match s {
"simple" => Some(GeneratedSessionDifficulty::Simple),
"advanced" => Some(GeneratedSessionDifficulty::Advanced),
"simple" => Some(GeneratedTestDifficulty::Simple),
"advanced" => Some(GeneratedTestDifficulty::Advanced),
_ => None,
}
}
}

#[derive(Clone, Copy, PartialEq)]
pub enum SessionConfig {
pub enum TestConfig {
Finite,
Generated {
language: Language,
difficulty: GeneratedSessionDifficulty,
duration: SessionDuration,
difficulty: GeneratedTestDifficulty,
duration: TestDuration,
},
}

impl SessionConfig {
impl TestConfig {
pub fn from_settings(settings: &gio::Settings) -> Self {
match settings.string("session-type").as_str() {
difficulty_string @ ("Simple" | "Advanced") => SessionConfig::Generated {
difficulty_string @ ("Simple" | "Advanced") => TestConfig::Generated {
language: Language::from_str(&settings.string("text-language")).unwrap(),
difficulty: GeneratedSessionDifficulty::from_str(&difficulty_string).unwrap(),
duration: SessionDuration::from_str(&settings.string("session-duration")).unwrap(),
difficulty: GeneratedTestDifficulty::from_str(&difficulty_string).unwrap(),
duration: TestDuration::from_str(&settings.string("session-duration")).unwrap(),
},
"Custom" => SessionConfig::Finite,
"Custom" => TestConfig::Finite,
_ => panic!("invalid settings value for `session-type` key"),
}
}
}

#[derive(Copy, Clone, Default, PartialEq, EnumString, EnumDisplay, EnumIter)]
pub enum SessionDuration {
pub enum TestDuration {
#[default]
Sec15,
Sec30,
Expand All @@ -76,24 +76,24 @@ pub enum SessionDuration {
Min10,
}

impl SessionDuration {
impl TestDuration {
pub fn ui_string(&self) -> String {
match self {
SessionDuration::Sec15 => gettext("15 seconds"),
SessionDuration::Sec30 => gettext("30 seconds"),
SessionDuration::Min1 => gettext("1 minute"),
SessionDuration::Min5 => gettext("5 minutes"),
SessionDuration::Min10 => gettext("10 minutes"),
TestDuration::Sec15 => gettext("15 seconds"),
TestDuration::Sec30 => gettext("30 seconds"),
TestDuration::Min1 => gettext("1 minute"),
TestDuration::Min5 => gettext("5 minutes"),
TestDuration::Min10 => gettext("10 minutes"),
}
}

pub fn english_string(&self) -> &str {
match self {
SessionDuration::Sec15 => "15 seconds",
SessionDuration::Sec30 => "30 seconds",
SessionDuration::Min1 => "1 minute",
SessionDuration::Min5 => "5 minutes",
SessionDuration::Min10 => "10 minutes",
TestDuration::Sec15 => "15 seconds",
TestDuration::Sec30 => "30 seconds",
TestDuration::Min1 => "1 minute",
TestDuration::Min5 => "5 minutes",
TestDuration::Min10 => "10 minutes",
}
}
}
Expand All @@ -116,15 +116,15 @@ impl PresenceState {
}

#[derive(Clone, Copy)]
pub struct TypingSession {
pub config: SessionConfig,
pub struct TypingTest {
pub config: TestConfig,
pub start_instant: Instant,
pub start_system_time: SystemTime,
}

impl TypingSession {
pub fn new(config: SessionConfig) -> Self {
TypingSession {
impl TypingTest {
pub fn new(config: TestConfig) -> Self {
TypingTest {
config,
start_instant: Instant::now(),
start_system_time: SystemTime::now(),
Expand All @@ -133,20 +133,20 @@ impl TypingSession {
}

#[derive(Clone, Copy)]
pub struct SessionSummary {
pub config: SessionConfig,
pub struct TestSummary {
pub config: TestConfig,
pub real_duration: Duration,
pub wpm: f64,
pub start_timestamp: SystemTime,
pub accuracy: f64,
}

impl SessionSummary {
impl TestSummary {
pub fn new(
start_timestamp: SystemTime,
start_instant: Instant,
end_instant: Instant,
config: SessionConfig,
config: TestConfig,
original: &str,
typed: &str,
keystrokes: &Vec<(Instant, bool)>,
Expand All @@ -155,7 +155,7 @@ impl SessionSummary {
let correct_keystrokes = keystrokes.iter().filter(|(_, correct)| *correct).count();
let total_keystrokes = keystrokes.len();

SessionSummary {
TestSummary {
config,
real_duration,
wpm: calculate_wpm(real_duration, &original, &typed),
Expand Down
8 changes: 4 additions & 4 deletions src/widgets/results_view.blp
Original file line number Diff line number Diff line change
Expand Up @@ -91,27 +91,27 @@ template $KpResultsView: Widget{
}
}

Box session_info_box {
Box test_info_box {
halign: center;
homogeneous: true;

Box {
halign: center;
spacing: 6;
tooltip-text: _("Session Type");
tooltip-text: _("Test Type");

Image {
icon-name: "quotation-symbolic";
accessible-role: presentation;
}

Label session_type_label {}
Label test_type_label {}
}

Box {
halign: center;
spacing: 6;
tooltip-text: _("Session Duration");
tooltip-text: _("Test Duration");

Image {
icon-name: "timer-symbolic";
Expand Down
38 changes: 19 additions & 19 deletions src/widgets/results_view.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* results_view.rs
*
* SPDX-FileCopyrightText: © 2024 Brage Fuglseth <[email protected]>
* SPDX-FileCopyrightText: © 2024–2025 Brage Fuglseth <[email protected]>
* SPDX-License-Identifier: GPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -17,7 +17,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use crate::session_enums::*;
use crate::typing_test_utils::*;
use adw::prelude::*;
use adw::subclass::prelude::*;
use gettextrs::gettext;
Expand All @@ -41,9 +41,9 @@ mod imp {
#[template_child]
pub accuracy_label: TemplateChild<gtk::Label>,
#[template_child]
pub session_info_box: TemplateChild<gtk::Box>,
pub test_info_box: TemplateChild<gtk::Box>,
#[template_child]
pub session_type_label: TemplateChild<gtk::Label>,
pub test_type_label: TemplateChild<gtk::Label>,
#[template_child]
pub duration_label: TemplateChild<gtk::Label>,
#[template_child]
Expand Down Expand Up @@ -80,8 +80,8 @@ mod imp {
wpm_accuracy_box: Default::default(),
wpm_label: Default::default(),
accuracy_label: Default::default(),
session_info_box: Default::default(),
session_type_label: Default::default(),
test_info_box: Default::default(),
test_type_label: Default::default(),
duration_label: Default::default(),
language_box: Default::default(),
language_label: Default::default(),
Expand Down Expand Up @@ -109,17 +109,17 @@ mod imp {
self.parent_constructed();

let wpm_accuracy_box = self.wpm_accuracy_box.get();
let session_info_box = self.session_info_box.get();
let test_info_box = self.test_info_box.get();

let obj = self.obj();

obj.bind_property("orientation", &wpm_accuracy_box, "orientation")
.build();

obj.bind_property("orientation", &session_info_box, "orientation")
obj.bind_property("orientation", &test_info_box, "orientation")
.build();

obj.bind_property("orientation", &session_info_box, "spacing")
obj.bind_property("orientation", &test_info_box, "spacing")
.transform_to(|_, orientation| match orientation {
gtk::Orientation::Horizontal => Some(30),
gtk::Orientation::Vertical => Some(18),
Expand All @@ -144,8 +144,8 @@ glib::wrapper! {
}

impl KpResultsView {
pub fn set_summary(&self, summary: SessionSummary) {
let SessionSummary {
pub fn set_summary(&self, summary: TestSummary) {
let TestSummary {
config,
real_duration,
wpm,
Expand All @@ -167,19 +167,19 @@ impl KpResultsView {
imp.duration_label
.set_label(&human_readable_duration(real_duration));

let session_type_string = match config {
SessionConfig::Finite => gettext("Custom"),
SessionConfig::Generated { difficulty, .. } => match difficulty {
GeneratedSessionDifficulty::Simple => gettext("Simple"),
GeneratedSessionDifficulty::Advanced => gettext("Advanced"),
let test_type_string = match config {
TestConfig::Finite => gettext("Custom"),
TestConfig::Generated { difficulty, .. } => match difficulty {
GeneratedTestDifficulty::Simple => gettext("Simple"),
GeneratedTestDifficulty::Advanced => gettext("Advanced"),
},
};

imp.session_type_label.set_label(&session_type_string);
imp.test_type_label.set_label(&test_type_string);

match config {
SessionConfig::Finite => imp.language_box.set_visible(false),
SessionConfig::Generated { language, .. } => {
TestConfig::Finite => imp.language_box.set_visible(false),
TestConfig::Generated { language, .. } => {
imp.language_box.set_visible(true);
imp.language_label
.set_label(&language.get_message().unwrap());
Expand Down
Loading

0 comments on commit c13a973

Please sign in to comment.