Skip to content

Commit

Permalink
🐞 fix(lib): cfg target
Browse files Browse the repository at this point in the history
  • Loading branch information
CakeAL committed Nov 2, 2024
1 parent 3390c2e commit cdc01a3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
34 changes: 20 additions & 14 deletions src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use tauri::{utils::config::WindowConfig, Manager};
use crate::{
entities::{AppState, EveryLoginData},
requests::*,
setting::Setting, utils,
setting::Setting,
utils,
};

#[tauri::command(async)]
Expand Down Expand Up @@ -365,13 +366,13 @@ pub fn load_setting(

#[tauri::command(async)]
pub async fn manually_check_update(app: tauri::AppHandle) -> Result<(), String> {
#[cfg(not(target_os = "android"))]
#[cfg(not(any(target_os = "android", target_os = "linux")))]
crate::update(app, true)
.await
.map_err(|err| err.to_string())?;

if cfg!(target_os = "android") {
Err("安卓暂时不支持更新,请到 GitHub 查看是否有更新。".into())
if cfg!(target_os = "android") || cfg!(target_os = "linux") {
Err("安卓/Linux 不支持更新,请到 GitHub 查看是否有更新。".into())
} else {
Ok(())
}
Expand Down Expand Up @@ -415,15 +416,20 @@ pub async fn submit_login_ustb_wifi(user_name: String, password: String) -> Resu

#[tauri::command]
pub async fn return_os_type() -> i32 {
if cfg!(target_os = "windows") {
if utils::get_windows_build_number() >= 22000 {
1 // win11
} else {
2 // win10 及以下
}
} else if cfg!(target_os = "macos") {
3 // macOS
#[allow(unused_assignments)]
let mut res = 0; // others

#[cfg(target_os = "windows")]
if utils::get_windows_build_number() >= 22000 {
res = 1; // win11
} else {
4 // linux or android
res = 2; // win10 及以下
}

#[cfg(target_os = "macos")]
{
res = 3; // macos
}
}

res
}
10 changes: 5 additions & 5 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ use crate::entities::AppState;
use crate::setting::Setting;
use tauri::Manager;
use tauri_plugin_dialog::DialogExt;
#[cfg(not(target_os = "android"))]
#[cfg(not(any(target_os = "android", target_os = "linux")))]
use tauri_plugin_updater::UpdaterExt;

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
let mut builder = tauri::Builder::new().plugin(tauri_plugin_dialog::init());
#[cfg(not(target_os = "android"))]
#[cfg(not(any(target_os = "android", target_os = "linux")))]
{
builder = builder.plugin(tauri_plugin_updater::Builder::new().build());
}
Expand Down Expand Up @@ -51,7 +51,7 @@ pub fn run() {
return_os_type
])
.setup(|app| {
#[cfg(not(target_os = "android"))]
#[cfg(not(any(target_os = "android", target_os = "linux")))]
{
background_init(app)?;
let handle = app.handle().clone();
Expand All @@ -65,7 +65,7 @@ pub fn run() {
.expect("error while running tauri application");
}

#[cfg(not(target_os = "android"))]
#[cfg(not(any(target_os = "android", target_os = "linux")))]
fn background_init(app: &mut tauri::App) -> Result<(), Box<dyn std::error::Error>> {
let win = app.get_webview_window("main").unwrap();

Expand All @@ -89,7 +89,7 @@ fn background_init(app: &mut tauri::App) -> Result<(), Box<dyn std::error::Error
Ok(())
}

#[cfg(not(target_os = "android"))]
#[cfg(not(any(target_os = "android", target_os = "linux")))]
async fn update(app: tauri::AppHandle, manually: bool) -> anyhow::Result<()> {
if let Some(update) = app.updater()?.check().await? {
// 对话框
Expand Down

0 comments on commit cdc01a3

Please sign in to comment.