-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows for users to "stick" if they've been manually shown some number of times I chose to write this logic in the most performant way I could figure out, so it's somewhat compex. I absolutely don't want to be responsible for delaying VRC startup time.
- Loading branch information
Showing
6 changed files
with
475 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# Planned Features | ||
|
||
- Users can be whitelisted to exempt them from the auto-clear | ||
- Tracks the number of times you've shown someone's avatar | ||
- Users who have been shown a certain number of times can be exempted from the auto-clear | ||
- Config management UI | ||
- Config management interface | ||
- Think about what happens if someone manages to launch a bunch of hooligan instances simultaneously. Spoiler alert: I'm pretty sure it's file corruption. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// This file is part of hooligan and is licenced under the GNU GPL v3.0. | ||
// See LICENSE file for full text. | ||
// Copyright © 2024 Michael Ripley | ||
|
||
use std::fs::File; | ||
use std::io; | ||
use std::io::{BufRead, BufReader, BufWriter, Write}; | ||
use std::path::Path; | ||
|
||
const AUTO_HIDE_THRESHOLD: &str = "auto_hide_threshold"; | ||
|
||
pub struct Config { | ||
/// a user that has been manually shown this many times in a row is exempt from auto hide | ||
pub auto_hide_threshold: u32, | ||
} | ||
|
||
impl Default for Config { | ||
fn default() -> Self { | ||
Self { | ||
auto_hide_threshold: 3, | ||
} | ||
} | ||
} | ||
|
||
impl Config { | ||
pub fn load<P: AsRef<Path>>(path: P) -> Result<Self, Error> { | ||
let file = File::open(path).map_err(Error::Io)?; | ||
let reader = BufReader::new(file); | ||
let mut config = Self::new(); | ||
for line in reader.lines() { | ||
let line = line.map_err(Error::Io)?; | ||
config.parse_line(&line)?; | ||
} | ||
Ok(config) | ||
} | ||
|
||
const fn new() -> Self { | ||
Self { | ||
auto_hide_threshold: 0, | ||
} | ||
} | ||
|
||
fn parse_line(&mut self, line: &str) -> Result<(), Error> { | ||
let (key, value) = line.split_once('=').ok_or(Error::Split)?; | ||
match key { | ||
AUTO_HIDE_THRESHOLD => self.parse_auto_hide_threshold(value), | ||
_ => Err(Error::Key), | ||
} | ||
} | ||
|
||
fn parse_auto_hide_threshold(&mut self, value: &str) -> Result<(), Error> { | ||
self.auto_hide_threshold = value.parse().map_err(|_| Error::Int)?; | ||
Ok(()) | ||
} | ||
|
||
pub fn serialize<P: AsRef<Path>>(&self, path: P) -> Result<(), io::Error> { | ||
let file = File::create_new(path).unwrap(); | ||
let mut writer = BufWriter::new(file); | ||
writeln!(writer, "{}={}", AUTO_HIDE_THRESHOLD, self.auto_hide_threshold)?; | ||
writer.flush() | ||
} | ||
} | ||
|
||
#[allow(dead_code)] // lint misses usage in debug printing this error | ||
#[derive(Debug)] | ||
pub enum Error { | ||
Split, | ||
Int, | ||
Key, | ||
Io(io::Error), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.