diff --git a/phira/locales/en-US/common.ftl b/phira/locales/en-US/common.ftl index 967b84f8..dfc477a8 100644 --- a/phira/locales/en-US/common.ftl +++ b/phira/locales/en-US/common.ftl @@ -17,11 +17,9 @@ chart-unstable = Unstable list-empty = Nothing here tos-and-policy = Terms of Service and Privacy Policy -tos-and-policy-desc = You must read and agree to our Terms of Service and Privacy Policy before using Phira online services provided by TeamFlos. +tos-and-policy-desc = You must read (by clicking here) and agree to our Terms of Service and Privacy Policy before using Phira online services provided by TeamFlos. tos-deny = Deny tos-accept = Accept -fetch-tos-policy-failed = Failed to fetch Terms of Service and Privacy Policy -warn-deny-tos-policy = Accept to use online service open-in-web = Open in Web diff --git a/phira/locales/zh-CN/common.ftl b/phira/locales/zh-CN/common.ftl index 77cbdab4..0d45febb 100644 --- a/phira/locales/zh-CN/common.ftl +++ b/phira/locales/zh-CN/common.ftl @@ -17,11 +17,9 @@ chart-unstable = 未上架 list-empty = 空空如也 tos-and-policy = 《服务条款》和《隐私政策》 -tos-and-policy-desc = 在使用由 TeamFlos 提供的 Phira 线上服务部分之前,你必须阅读并同意我们的《服务条款》和《隐私政策》。 +tos-and-policy-desc = 在使用由 TeamFlos 提供的 Phira 线上服务部分之前,你必须 *点击此处* 阅读并同意我们的《服务条款》和《隐私政策》。 tos-deny = 拒绝 tos-accept = 同意 -fetch-tos-policy-failed = 获取服务条款和隐私政策内容失败 -warn-deny-tos-policy = 需接受条款才可使用线上服务 open-in-web = 在网站中打开 diff --git a/phira/src/client.rs b/phira/src/client.rs index 4f97fb39..28a3edab 100644 --- a/phira/src/client.rs +++ b/phira/src/client.rs @@ -19,7 +19,6 @@ pub struct Client; // const API_URL: &str = "http://localhost:2924"; const API_URL: &str = "https://api.phira.cn"; -const WEB_URL: &str = "https://phira.moe"; pub fn basic_client_builder() -> ClientBuilder { let mut builder = reqwest::ClientBuilder::new(); @@ -214,14 +213,6 @@ impl Client { .await?; Ok(resp.id) } - pub async fn get_tos_and_pp(language_id: &str) -> Result { - let resp = recv_raw(CLIENT.load().request(Method::GET, WEB_URL.to_owned() + "/tos_and_pp_plaintext_"+ language_id)).await?.text().await?; - Ok(resp) - } - pub async fn get_tos_and_pp_version() -> Result { - let resp= recv_raw(CLIENT.load().request(Method::GET, WEB_URL.to_owned() + "/tos_policy_version")).await?.text().await?; - Ok(resp) - } } #[must_use] diff --git a/phira/src/data.rs b/phira/src/data.rs index ac6ee3cb..c0402f75 100644 --- a/phira/src/data.rs +++ b/phira/src/data.rs @@ -15,7 +15,6 @@ use std::{ ops::DerefMut, path::Path, }; -use tracing::debug; #[derive(Clone, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] @@ -83,9 +82,7 @@ pub struct Data { pub respacks: Vec, pub respack_id: usize, pub accept_invalid_cert: bool, - // for compatibility pub read_tos_and_policy: bool, - pub read_tos_and_policy_version: Option, pub ignored_version: Option, pub character: Option, } @@ -158,11 +155,6 @@ impl Data { *res_pack_path = "chart.zip".to_owned(); } } - if self.read_tos_and_policy { - debug!("migrating from old version"); - self.read_tos_and_policy_version = Some("61c95573d1d4e9092fe64e18b4125af48ed73110c395c178543f1f305f5899bd".to_owned()); - self.read_tos_and_policy = false; - } self.config.init(); Ok(()) } diff --git a/phira/src/login.rs b/phira/src/login.rs index f91450fa..9c9a8b40 100644 --- a/phira/src/login.rs +++ b/phira/src/login.rs @@ -4,8 +4,7 @@ use crate::{ client::{Client, LoginParams, User, UserManager}, get_data_mut, page::Fader, - save_data, - scene::{check_read_tos_and_policy, JUST_ACCEPTED_TOS}, + save_data, scene::check_read_tos_and_policy, }; use anyhow::Result; use macroquad::prelude::*; @@ -62,12 +61,6 @@ pub struct Login { in_reg: bool, task: Option<(&'static str, Task>>)>, - after_accept_tos: Option, -} - -enum NextAction { - Login, - Register, } impl Login { @@ -99,7 +92,6 @@ impl Login { in_reg: false, task: None, - after_accept_tos: None, } } @@ -172,7 +164,6 @@ impl Login { } if self.btn_reg.touch(touch, t) { if !check_read_tos_and_policy() { - self.after_accept_tos = Some(NextAction::Register); return true; } if let Some(error) = self.register() { @@ -182,7 +173,6 @@ impl Login { } if self.btn_login.touch(touch, t) { if !check_read_tos_and_policy() { - self.after_accept_tos = Some(NextAction::Login); return true; } let email = self.t_email.clone(); @@ -222,30 +212,6 @@ impl Login { *tmp = text; } } - let just_accepted = *JUST_ACCEPTED_TOS.lock().unwrap(); - if just_accepted { - match self.after_accept_tos { - Some(NextAction::Login) => { - let email = self.t_email.clone(); - let pwd = self.t_pwd.clone(); - self.start("login", async move { - Client::login(LoginParams::Password { - email: &email, - password: &pwd, - }) - .await?; - Ok(Some(Client::get_me().await?)) - }); - } - Some(NextAction::Register) => { - if let Some(error) = self.register() { - show_message(error).error(); - } - } - None => () - } - self.after_accept_tos = None; - } if let Some((action, task)) = &mut self.task { if let Some(res) = task.take() { match res { diff --git a/phira/src/page/home.rs b/phira/src/page/home.rs index 1950cecf..96ef6307 100644 --- a/phira/src/page/home.rs +++ b/phira/src/page/home.rs @@ -11,7 +11,7 @@ use crate::{ icons::Icons, login::Login, save_data, - scene::{load_tos_and_policy, ProfileScene}, + scene::ProfileScene, sync_data, threed::ThreeD, }; @@ -355,7 +355,6 @@ impl Page for HomePage { self.sf.enter(s.t); self.need_back = false; } - load_tos_and_policy(); self.fetch_has_new(); Ok(()) } diff --git a/phira/src/scene.rs b/phira/src/scene.rs index 91d45b5c..ce4cc4f1 100644 --- a/phira/src/scene.rs +++ b/phira/src/scene.rs @@ -16,30 +16,21 @@ mod song; pub use song::{Downloading, SongScene, RECORD_ID}; mod unlock; -use tracing::{debug, warn}; pub use unlock::UnlockScene; mod profile; pub use profile::ProfileScene; -use crate::{ - client::{Client, UserManager}, - data::LocalChart, - dir, get_data, get_data_mut, - page::Fader, - save_data, ttl, -}; +use crate::{client::UserManager, data::LocalChart, dir, get_data, get_data_mut, page::Fader, save_data}; use anyhow::{bail, Context, Result}; use async_trait::async_trait; -use once_cell::sync::{Lazy, OnceCell}; +use once_cell::sync::Lazy; use prpr::{ config::Mods, core::{BOLD_FONT, PGR_FONT}, - ext::{semi_white, unzip_into, RectExt, SafeTexture}, + ext::{open_url, semi_white, unzip_into, RectExt, SafeTexture}, fs::{self, FileSystem}, info::ChartInfo, - scene::{show_error, show_message}, - task::Task, ui::{Dialog, RectButton, Scroll, Scroller, Ui}, }; use std::{ @@ -47,7 +38,6 @@ use std::{ cell::RefCell, fs::File, io::{BufReader, Write}, - ops::DerefMut, path::{Path, PathBuf}, sync::{ atomic::{AtomicBool, Ordering}, @@ -62,10 +52,7 @@ thread_local! { } pub static ASSET_CHART_INFO: Lazy>> = Lazy::new(Mutex::default); -pub static TOS_AND_POLICY: OnceCell = OnceCell::new(); -pub static TOS_AND_POLICY_VERSION: OnceCell = OnceCell::new(); -pub static LOAD_TOS_TASK: Lazy>>>>> = Lazy::new(Mutex::default); -pub static JUST_ACCEPTED_TOS: Lazy> = Lazy::new(Mutex::default); + #[derive(Clone)] pub struct AssetsChartFileSystem(pub String, pub String); @@ -130,85 +117,36 @@ pub fn confirm_dialog(title: impl Into, content: impl Into, res: } pub fn check_read_tos_and_policy() -> bool { - if get_data().read_tos_and_policy_version.is_some() { + if get_data().read_tos_and_policy { return true; } - let binding = LOAD_TOS_TASK.lock(); - let mut tos_task = binding.unwrap(); - if let Some(task) = &mut *tos_task { - if let Some(result) = task.take() { - match result { - Ok(Some((string, ver))) => { - let _ = TOS_AND_POLICY.set(string); - let _ = TOS_AND_POLICY_VERSION.set(ver); - } - Ok(None) => { - warn!("should be unreachable"); - } - Err(e) => { - show_error(e.context(ttl!("fetch-tos-policy-failed"))); - *tos_task = None; - return false; - } + + let mut opened = false; + Dialog::plain(ttl!("tos-and-policy"), ttl!("tos-and-policy-desc")) + .buttons(vec![ttl!("tos-deny").into_owned(), ttl!("tos-accept").into_owned()]) + .listener(move |pos| match pos { + -2 => { + opened = true; + open_url("https://phira.moe/terms-of-use").unwrap(); + 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(); - *JUST_ACCEPTED_TOS.lock().unwrap() = true; - false + -1 => true, + 0 => false, + 1 => { + if !opened { + opened = true; + open_url("https://phira.moe/terms-of-use").unwrap(); + return true; } - _ => unreachable!(), - }) - .show(); - } else { - warn!("loading data to read because `check_..` was called, this would result a delay and shouldn't happen"); - load_tos_and_policy(); - } - false -} - -pub fn load_tos_and_policy() { - if TOS_AND_POLICY.get().is_some() || TOS_AND_POLICY_VERSION.get().is_some() { - return; - } - *LOAD_TOS_TASK.lock().unwrap() = Some(Task::new(async { - debug!("checking tos and policy update..."); - let new_version = Client::get_tos_and_pp_version().await?; - if let Some(current) = &get_data().read_tos_and_policy_version { - if current != &new_version { - // updated, reset read - debug!("has update, new version {new_version}"); - get_data_mut().read_tos_and_policy_version = None; - } else { - // no need to download, skipping - return Ok(None); + get_data_mut().read_tos_and_policy = true; + let _ = save_data(); + false } - } - debug!("loading tos and policy"); - let mut lang = get_data().language.clone().unwrap_or("en-us".to_owned()).to_ascii_lowercase(); - if lang == "zh-tw" { - "zh-cn".clone_into(&mut lang); - } - if lang != "zh-cn" { - "en-us".clone_into(&mut lang); - } - let res = Client::get_tos_and_pp(&lang).await?; - debug!("loaded"); - Ok(Some((res, new_version))) - })); + _ => unreachable!(), + }) + .show(); + + false } #[inline]