Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: login triggered unexpectedly #358

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions phira/src/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ impl Login {
return true;
}
if self.btn_reg.touch(touch, t) {
if !check_read_tos_and_policy() {
if !check_read_tos_and_policy(true) {
self.after_accept_tos = Some(NextAction::Register);
return true;
}
if let Some(error) = self.register() {
Expand All @@ -172,7 +173,8 @@ impl Login {
return true;
}
if self.btn_login.touch(touch, t) {
if !check_read_tos_and_policy() {
if !check_read_tos_and_policy(true) {
self.after_accept_tos = Some(NextAction::Login);
return true;
}
let email = self.t_email.clone();
Expand Down
2 changes: 1 addition & 1 deletion phira/src/page/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl LibraryPage {
}

pub fn load_online(&mut self) {
if !check_read_tos_and_policy() {
if !check_read_tos_and_policy(false) {
return;
}
if get_data().config.offline_mode {
Expand Down
33 changes: 24 additions & 9 deletions phira/src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ pub fn confirm_dialog(title: impl Into<String>, content: impl Into<String>, res:
.show();
}

pub fn check_read_tos_and_policy() -> bool {
if get_data().read_tos_and_policy {

pub fn check_read_tos_and_policy(change_just_accepted: bool) -> bool {
if get_data().read_tos_and_policy_version.is_some() {

return true;
}

Expand All @@ -130,13 +132,26 @@ pub fn check_read_tos_and_policy() -> bool {
open_url("https://phira.moe/terms-of-use").unwrap();
true
}
-1 => true,
0 => false,
1 => {
if !opened {
opened = true;
open_url("https://phira.moe/terms-of-use").unwrap();
return true;
*tos_task = None;
}
}
drop(tos_task);
if let (Some(tos_policy), Some(version)) = (TOS_AND_POLICY.get(), TOS_AND_POLICY_VERSION.get()) {
Dialog::plain(ttl!("tos-and-policy"), ttl!("tos-and-policy-desc") + "\n\n" + tos_policy.as_str())
.buttons(vec![ttl!("tos-deny").into_owned(), ttl!("tos-accept").into_owned()])
.listener(move |pos| match pos {
-2 | -1 => true,
0 => {
show_message(ttl!("warn-deny-tos-policy")).warn();
false
}
1 => {
get_data_mut().read_tos_and_policy_version = Some(version.clone());
let _ = save_data();
if change_just_accepted {
*JUST_ACCEPTED_TOS.lock().unwrap() = true;
}
false
}
get_data_mut().read_tos_and_policy = true;
let _ = save_data();
Expand Down