Skip to content

Commit 26af0a7

Browse files
Merge pull request #7 from gianzellweger/dev
Release 0.3.1
2 parents 7471d85 + c5177d5 commit 26af0a7

File tree

5 files changed

+58
-55
lines changed

5 files changed

+58
-55
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "badlang"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
authors = ["Gian Zellweger <[email protected]"]
55
rust-version = "1.72.0"
66
description = "Next generation stack-based programming language"

rust-toolchain

-1
This file was deleted.

rust-toolchain.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[toolchain]
2+
channel = "nightly"
3+

src/main.rs

+53-52
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ use strum_macros::{EnumCount as EnumCountMacro, EnumIter};
2323
extern crate savefile_derive;
2424

2525
fn report_error(string: String) -> ! {
26-
eprintln!("{}: {string}", "ERROR".bold().red());
27-
std::process::exit(1);
26+
panic!("{}: {string}", "ERROR".bold().red());
2827
}
2928

3029
fn report_warning(string: String) {
@@ -440,8 +439,14 @@ fn sillyness(save_data: &mut SaveData) {
440439
tauri::Builder::default()
441440
.any_thread()
442441
.invoke_handler(tauri::generate_handler!(tauri_handler))
443-
.run(tauri::generate_context!())
444-
.expect("error while running tauri application");
442+
.build(tauri::generate_context!())
443+
.expect("error while building tauri application")
444+
.run(|_app_handle, event| match event {
445+
tauri::RunEvent::ExitRequested { api, .. } => {
446+
api.prevent_exit();
447+
}
448+
_ => {}
449+
});
445450
});
446451
}
447452

@@ -730,70 +735,66 @@ fn main() {
730735
.arg(clap::arg!(--notroll).hide(true).required(false).value_parser(clap::value_parser!(bool))) // This argument isn't really needed and potentially defeats the purpose of the program but it is here so I can keep my sanity.
731736
.get_matches();
732737

733-
let tokens = match matches.get_one::<PathBuf>("file") {
734-
Some(path) => parse_file(path),
735-
None => report_error("Please provide a path to run!".to_string()),
736-
};
737-
738-
if let Some(no_troll) = matches.get_one::<bool>("notroll")
739-
&& *no_troll
740-
{
741-
execute_tokens(&tokens, false);
742-
return;
743-
}
744-
745-
let mut savefile_path = home::home_dir().expect("Couldn't locate your home directory, aborting");
746-
savefile_path.push(".config");
747-
savefile_path.push("badlang");
748-
savefile_path.push("badlang.bin");
749-
750-
let mut save_data = match load_file::<SaveData, &PathBuf>(&savefile_path, 0) {
751-
Ok(sd) => {
752-
if sd
753-
.account
754-
.as_ref()
755-
.is_some_and(|acc| acc.version == semver::Version::parse(env!("CARGO_PKG_VERSION")).expect("WTF cargo").to_string())
756-
{
757-
sd
758-
} else {
759-
report_warning("Because the version your account was created on doesn't match your current version, your account was invalidated. Create a new one.".to_string());
760-
SaveData {
761-
account: None,
762-
runs_so_far: 0,
763-
last_update: SystemTime::now().duration_since(UNIX_EPOCH).expect("Damn bro what kinda system you running").as_secs(),
764-
}
765-
}
766-
}
767-
Err(_) => SaveData {
768-
account: None,
769-
runs_so_far: 0,
770-
last_update: SystemTime::now().duration_since(UNIX_EPOCH).expect("Damn bro what kinda system you running").as_secs(),
771-
},
772-
};
773-
774738
if let Some(subscribe) = matches.get_one::<bool>("subscribe")
775739
&& *subscribe
776740
{
777741
let _ = open::that("https://www.youtube.com/watch?v=dQw4w9WgXcQ");
778742
report_error("I can't currently open a subscription page without doing some tax-evasion in-case somebody actually donates. Maybe later :/".to_string());
779743
}
780744

781-
sillyness(&mut save_data);
745+
let out_of_free_runs = if let Some(no_troll) = matches.get_one::<bool>("notroll")
746+
&& !(*no_troll)
747+
{
748+
let mut savefile_path = home::home_dir().expect("Couldn't locate your home directory, aborting");
749+
savefile_path.push(".config");
750+
savefile_path.push("badlang");
751+
savefile_path.push("badlang.bin");
752+
753+
let mut save_data = match load_file::<SaveData, &PathBuf>(&savefile_path, 0) {
754+
Ok(sd) => {
755+
if sd
756+
.account
757+
.as_ref()
758+
.is_some_and(|acc| acc.version == semver::Version::parse(env!("CARGO_PKG_VERSION")).expect("WTF cargo").to_string())
759+
{
760+
sd
761+
} else {
762+
report_warning("Because the version your account was created on doesn't match your current version, your account was invalidated. Create a new one.".to_string());
763+
SaveData {
764+
account: None,
765+
runs_so_far: 0,
766+
last_update: SystemTime::now().duration_since(UNIX_EPOCH).expect("Damn bro what kinda system you running").as_secs(),
767+
}
768+
}
769+
}
770+
Err(_) => SaveData {
771+
account: None,
772+
runs_so_far: 0,
773+
last_update: SystemTime::now().duration_since(UNIX_EPOCH).expect("Damn bro what kinda system you running").as_secs(),
774+
},
775+
};
776+
777+
sillyness(&mut save_data);
782778

783-
if let Some(parent_dir) = savefile_path.parent() {
784-
if let Err(err) = std::fs::DirBuilder::new().recursive(true).create(parent_dir) {
785-
report_error(format!("Couldn't create savefile because {err}"));
779+
if let Some(parent_dir) = savefile_path.parent() {
780+
if let Err(err) = std::fs::DirBuilder::new().recursive(true).create(parent_dir) {
781+
report_error(format!("Couldn't create savefile because {err}"));
782+
}
786783
}
787-
}
788784

789-
save_file(savefile_path, 0, &save_data).expect("Couldn't save damn");
785+
save_file(savefile_path, 0, &save_data).expect("Couldn't save damn");
786+
787+
save_data.runs_so_far >= FREE_RUNS
788+
} else {
789+
false
790+
};
790791

791792
let tokens = match matches.get_one::<PathBuf>("file") {
792793
Some(path) => parse_file(path),
793794
None => report_error("Please provide a path to run!".to_string()),
794795
};
795796

796-
execute_tokens(&tokens, save_data.runs_so_far >= FREE_RUNS);
797+
execute_tokens(&tokens, out_of_free_runs);
797798
}
798799

799800
// Because I hate code splitting (not really, it just doesn't fit the feel

0 commit comments

Comments
 (0)