Add 'Auto Check Update' config to control whether to check for updates on start

This commit is contained in:
tk103331
2023-01-04 13:10:46 +08:00
parent c19698bc41
commit a7cd73b314
6 changed files with 38 additions and 13 deletions

View File

@@ -194,15 +194,7 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
); );
} }
"check_update" => { "check_update" => {
tauri::async_runtime::spawn(async move { utils::run_check_update(app).unwrap();
let result = app.updater().check().await;
let update_resp = result.unwrap();
if update_resp.is_update_available() {
tauri::async_runtime::spawn(async move {
utils::prompt_for_install(app, update_resp).await.unwrap();
});
}
});
} }
// Preferences // Preferences
"control_center" => window::control_window(&app), "control_center" => window::control_window(&app),

View File

@@ -1,6 +1,7 @@
use std::borrow::Borrow;
use crate::{app::window, conf::ChatConfJson, utils}; use crate::{app::window, conf::ChatConfJson, utils};
use log::info; use log::info;
use tauri::{utils::config::WindowUrl, window::WindowBuilder, App, GlobalShortcutManager, Manager}; use tauri::{utils::config::WindowUrl, window::WindowBuilder, App, GlobalShortcutManager, Manager, AppHandle, Wry};
use wry::application::accelerator::Accelerator; use wry::application::accelerator::Accelerator;
pub fn init(app: &mut App) -> std::result::Result<(), Box<dyn std::error::Error>> { pub fn init(app: &mut App) -> std::result::Result<(), Box<dyn std::error::Error>> {
@@ -89,6 +90,11 @@ pub fn init(app: &mut App) -> std::result::Result<(), Box<dyn std::error::Error>
.unwrap(); .unwrap();
}); });
} }
// auto_check_update
if chat_conf.auto_check_update {
let app = app.handle();
utils::run_check_update(app).unwrap();
}
Ok(()) Ok(())
} }

View File

@@ -18,6 +18,7 @@ pub const GITHUB_PROMPTS_CSV_URL: &str =
"https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv"; "https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv";
pub const DEFAULT_CHAT_CONF: &str = r#"{ pub const DEFAULT_CHAT_CONF: &str = r#"{
"stay_on_top": false, "stay_on_top": false,
"auto_check_update": true,
"theme": "Light", "theme": "Light",
"titlebar": true, "titlebar": true,
"global_shortcut": "", "global_shortcut": "",
@@ -29,6 +30,7 @@ pub const DEFAULT_CHAT_CONF: &str = r#"{
}"#; }"#;
pub const DEFAULT_CHAT_CONF_MAC: &str = r#"{ pub const DEFAULT_CHAT_CONF_MAC: &str = r#"{
"stay_on_top": false, "stay_on_top": false,
"auto_check_update": true,
"theme": "Light", "theme": "Light",
"titlebar": false, "titlebar": false,
"global_shortcut": "", "global_shortcut": "",
@@ -60,6 +62,7 @@ pub struct ChatConfJson {
// macOS and Windows // macOS and Windows
pub theme: String, pub theme: String,
pub auto_check_update: bool,
pub stay_on_top: bool, pub stay_on_top: bool,
pub default_origin: String, pub default_origin: String,
pub origin: String, pub origin: String,

View File

@@ -10,7 +10,6 @@ use std::{
}; };
use tauri::{utils::config::Config, Manager, AppHandle, Wry}; use tauri::{utils::config::Config, Manager, AppHandle, Wry};
use tauri::updater::UpdateResponse; use tauri::updater::UpdateResponse;
pub fn chat_root() -> PathBuf { pub fn chat_root() -> PathBuf {
tauri::api::path::home_dir().unwrap().join(".chatgpt") tauri::api::path::home_dir().unwrap().join(".chatgpt")
} }
@@ -129,6 +128,20 @@ pub async fn get_data(
Ok(None) Ok(None)
} }
} }
pub fn run_check_update(app: AppHandle<Wry>) -> Result<()> {
tauri::async_runtime::spawn(async move {
let result = app.updater().check().await;
let update_resp = result.unwrap();
if update_resp.is_update_available() {
tauri::async_runtime::spawn(async move {
prompt_for_install(app, update_resp).await.unwrap();
});
}
});
Ok(())
}
// Copy private api in tauri/updater/mod.rs. TODO: refactor to public api // Copy private api in tauri/updater/mod.rs. TODO: refactor to public api
// Prompt a dialog asking if the user want to install the new version // Prompt a dialog asking if the user want to install the new version
// Maybe we should add an option to customize it in future versions. // Maybe we should add an option to customize it in future versions.

View File

@@ -7,7 +7,7 @@
}, },
"package": { "package": {
"productName": "ChatGPT", "productName": "ChatGPT",
"version": "0.7.4" "version": "0.7.2"
}, },
"tauri": { "tauri": {
"allowlist": { "allowlist": {
@@ -67,7 +67,7 @@
"csp": null "csp": null
}, },
"updater": { "updater": {
"active": true, "active": false,
"dialog": true, "dialog": true,
"endpoints": [ "endpoints": [
"https://lencx.github.io/ChatGPT/install.json" "https://lencx.github.io/ChatGPT/install.json"

11
src/view/General.tsx vendored
View File

@@ -10,6 +10,14 @@ import { clone, omit, isEqual } from 'lodash';
import useInit from '@/hooks/useInit'; import useInit from '@/hooks/useInit';
import { DISABLE_AUTO_COMPLETE, chatRoot } from '@/utils'; import { DISABLE_AUTO_COMPLETE, chatRoot } from '@/utils';
const CheckUpdateLabel = () => {
return (
<span>
Auto Check Update <Tooltip title={`check update on start`}><QuestionCircleOutlined style={{ color: '#1677ff' }} /></Tooltip>
</span>
)
}
const OriginLabel = ({ url }: { url: string }) => { const OriginLabel = ({ url }: { url: string }) => {
return ( return (
<span> <span>
@@ -108,6 +116,9 @@ export default function General() {
<Form.Item label="Stay On Top" name="stay_on_top" valuePropName="checked"> <Form.Item label="Stay On Top" name="stay_on_top" valuePropName="checked">
<Switch /> <Switch />
</Form.Item> </Form.Item>
<Form.Item label={<CheckUpdateLabel />} name="auto_check_update" valuePropName="checked">
<Switch />
</Form.Item>
<Form.Item label={<GlobalShortcut />} name="global_shortcut"> <Form.Item label={<GlobalShortcut />} name="global_shortcut">
<Input placeholder="CmdOrCtrl+Shift+O" {...DISABLE_AUTO_COMPLETE} /> <Input placeholder="CmdOrCtrl+Shift+O" {...DISABLE_AUTO_COMPLETE} />
</Form.Item> </Form.Item>