Skip to content

Commit

Permalink
make autoupdate optional
Browse files Browse the repository at this point in the history
  • Loading branch information
bananaturtlesandwich committed Jul 6, 2023
1 parent f37a62b commit e6d4298
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pub struct Stove {
aes: String,
#[cfg(not(target_family = "wasm"))]
client: Option<discord_rich_presence::DiscordIpcClient>,
#[cfg(not(target_family = "wasm"))]
autoupdate: bool,
}

fn home_dir() -> Option<std::path::PathBuf> {
Expand Down Expand Up @@ -172,13 +174,11 @@ impl Stove {
pub fn new(ctx: &mut GraphicsContext) -> Self {
ctx.set_cull_face(CullFace::Back);
let mut notifs = egui_notify::Toasts::new();
#[cfg(not(any(target_family = "wasm")))]
std::thread::spawn(auto_update);
#[cfg(not(target_family = "wasm"))]
if std::fs::remove_file(format!("{EXE}.old")).is_ok() {
notifs.success(format!("successfully updated to {}", env!("CARGO_PKG_VERSION")));
}
let (version, paks, distance, aes) = match config() {
let (version, paks, distance, aes, autoupdate) = match config() {
Some(ref cfg) => {
if !cfg.exists() && std::fs::create_dir(cfg).is_err() {
notifs.error("failed to create config directory");
Expand All @@ -195,13 +195,18 @@ impl Stove {
.parse()
.unwrap_or(1000.0),
std::fs::read_to_string(cfg.join("AES")).unwrap_or_default(),
std::fs::read_to_string(cfg.join("AUTOUPDATE"))
.unwrap_or_else(|_| "false".to_string())
.parse::<bool>()
.unwrap_or_default(),
)
}
None => (
0,
String::default(),
1000.0,
String::default(),
false
),
};
let paks = paks.lines().map(str::to_string).collect();
Expand All @@ -219,6 +224,10 @@ impl Stove {
None
}
});
#[cfg(not(any(target_family = "wasm")))]
if autoupdate {
std::thread::spawn(auto_update);
}
#[cfg(not(target_family = "wasm"))]
let client = discord_rich_presence::DiscordIpcClient::new("1059578289737433249")
.ok()
Expand Down Expand Up @@ -278,6 +287,8 @@ impl Stove {
aes,
#[cfg(not(target_family = "wasm"))]
client,
#[cfg(not(target_family = "wasm"))]
autoupdate
};
refresh!(stove, ctx);
if stove.map.is_none() {
Expand Down Expand Up @@ -440,6 +451,10 @@ impl EventHandler for Stove {
binding(ui, "delete", "delete");
});
});
ui.horizontal(|ui|{
ui.label("autoupdate:");
ui.add(egui::Checkbox::without_text(&mut self.autoupdate));
});
ui.horizontal(|ui| {
ui.label("render distance:");
ui.add(
Expand Down Expand Up @@ -841,6 +856,7 @@ impl Drop for Stove {
std::fs::write(path.join("PAKS"), self.paks.join("\n")).unwrap_or_default();
std::fs::write(path.join("DISTANCE"), self.distance.to_string()).unwrap_or_default();
std::fs::write(path.join("AES"), &self.aes).unwrap_or_default();
std::fs::write(path.join("AUTOUPDATE"), self.autoupdate.to_string()).unwrap_or_default();
}
}
}
Expand Down

0 comments on commit e6d4298

Please sign in to comment.