mirror of
https://github.com/FranP-code/ChatGPT.git
synced 2025-10-13 00:13:25 +00:00
Manually check for updates
This commit is contained in:
@@ -24,6 +24,7 @@ pub fn init() -> Menu {
|
|||||||
MenuItem::About(name.into(), AboutMetadata::default()).into(),
|
MenuItem::About(name.into(), AboutMetadata::default()).into(),
|
||||||
#[cfg(not(target_os = "macos"))]
|
#[cfg(not(target_os = "macos"))]
|
||||||
CustomMenuItem::new("about".to_string(), "About ChatGPT").into(),
|
CustomMenuItem::new("about".to_string(), "About ChatGPT").into(),
|
||||||
|
CustomMenuItem::new("check_update".to_string(), "Check for Updates").into(),
|
||||||
MenuItem::Services.into(),
|
MenuItem::Services.into(),
|
||||||
MenuItem::Hide.into(),
|
MenuItem::Hide.into(),
|
||||||
MenuItem::HideOthers.into(),
|
MenuItem::HideOthers.into(),
|
||||||
@@ -192,6 +193,17 @@ pub fn menu_handler(event: WindowMenuEvent<tauri::Wry>) {
|
|||||||
format!("Version {}", tauri_conf.package.version.unwrap()),
|
format!("Version {}", tauri_conf.package.version.unwrap()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
"check_update" => {
|
||||||
|
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 {
|
||||||
|
utils::prompt_for_install(app, update_resp).await.unwrap();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
// Preferences
|
// Preferences
|
||||||
"control_center" => window::control_window(&app),
|
"control_center" => window::control_window(&app),
|
||||||
"restart" => tauri::api::process::restart(&app.env()),
|
"restart" => tauri::api::process::restart(&app.env()),
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ use std::{
|
|||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::Command,
|
process::Command,
|
||||||
};
|
};
|
||||||
use tauri::{utils::config::Config, Manager};
|
use tauri::{utils::config::Config, Manager, AppHandle, Wry};
|
||||||
|
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")
|
||||||
@@ -128,3 +129,50 @@ pub async fn get_data(
|
|||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 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
|
||||||
|
// Maybe we should add an option to customize it in future versions.
|
||||||
|
pub async fn prompt_for_install (
|
||||||
|
app: AppHandle<Wry>,
|
||||||
|
update: UpdateResponse<Wry>
|
||||||
|
) -> Result<()> {
|
||||||
|
let windows = app.windows();
|
||||||
|
let parent_window = windows.values().next();
|
||||||
|
let package_info = app.package_info().clone();
|
||||||
|
|
||||||
|
let body = update.body().unwrap();
|
||||||
|
// todo(lemarier): We should review this and make sure we have
|
||||||
|
// something more conventional.
|
||||||
|
let should_install = tauri::api::dialog::blocking::ask(
|
||||||
|
parent_window,
|
||||||
|
format!(r#"A new version of {} is available! "#, package_info.name),
|
||||||
|
format!(
|
||||||
|
r#"{} {} is now available -- you have {}.
|
||||||
|
|
||||||
|
Would you like to install it now?
|
||||||
|
|
||||||
|
Release Notes:
|
||||||
|
{}"#,
|
||||||
|
package_info.name, update.latest_version(), package_info.version, body),
|
||||||
|
);
|
||||||
|
|
||||||
|
if should_install {
|
||||||
|
// Launch updater download process
|
||||||
|
// macOS we display the `Ready to restart dialog` asking to restart
|
||||||
|
// Windows is closing the current App and launch the downloaded MSI when ready (the process stop here)
|
||||||
|
// Linux we replace the AppImage by launching a new install, it start a new AppImage instance, so we're closing the previous. (the process stop here)
|
||||||
|
update.download_and_install().await?;
|
||||||
|
|
||||||
|
// Ask user if we need to restart the application
|
||||||
|
let should_exit = tauri::api::dialog::blocking::ask(
|
||||||
|
parent_window,
|
||||||
|
"Ready to Restart",
|
||||||
|
"The installation was successful, do you want to restart the application now?",
|
||||||
|
);
|
||||||
|
if should_exit {
|
||||||
|
app.restart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
5
src/layout/index.scss
vendored
5
src/layout/index.scss
vendored
@@ -7,7 +7,10 @@
|
|||||||
height: 48px;
|
height: 48px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.chat-info {
|
||||||
|
text-align: center;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
.ant-layout-sider-trigger {
|
.ant-layout-sider-trigger {
|
||||||
user-select: none;
|
user-select: none;
|
||||||
-webkit-user-select: none;
|
-webkit-user-select: none;
|
||||||
|
|||||||
30
src/layout/index.tsx
vendored
30
src/layout/index.tsx
vendored
@@ -1,12 +1,19 @@
|
|||||||
import { FC, useState } from 'react';
|
import { FC, useState } from 'react';
|
||||||
import { Layout, Menu } from 'antd';
|
import {Layout, Menu, Button, Tooltip, message} from 'antd';
|
||||||
|
import { SyncOutlined } from '@ant-design/icons';
|
||||||
import { useNavigate, useLocation } from 'react-router-dom';
|
import { useNavigate, useLocation } from 'react-router-dom';
|
||||||
|
import { getName, getVersion } from '@tauri-apps/api/app';
|
||||||
|
import { checkUpdate, installUpdate } from '@tauri-apps/api/updater';
|
||||||
|
import { relaunch } from '@tauri-apps/api/process';
|
||||||
|
|
||||||
import Routes, { menuItems } from '@/routes';
|
import Routes, { menuItems } from '@/routes';
|
||||||
import './index.scss';
|
import './index.scss';
|
||||||
|
|
||||||
const { Content, Footer, Sider } = Layout;
|
const { Content, Footer, Sider } = Layout;
|
||||||
|
|
||||||
|
const appName = await getName();
|
||||||
|
const appVersion = await getVersion();
|
||||||
|
|
||||||
interface ChatLayoutProps {
|
interface ChatLayoutProps {
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
}
|
}
|
||||||
@@ -16,6 +23,14 @@ const ChatLayout: FC<ChatLayoutProps> = ({ children }) => {
|
|||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const go = useNavigate();
|
const go = useNavigate();
|
||||||
|
|
||||||
|
const checkAppUpdate = async () => {
|
||||||
|
try {
|
||||||
|
await checkUpdate();
|
||||||
|
}catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout style={{ minHeight: '100vh' }} hasSider>
|
<Layout style={{ minHeight: '100vh' }} hasSider>
|
||||||
<Sider
|
<Sider
|
||||||
@@ -34,6 +49,19 @@ const ChatLayout: FC<ChatLayoutProps> = ({ children }) => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className="chat-logo"><img src="/logo.png" /></div>
|
<div className="chat-logo"><img src="/logo.png" /></div>
|
||||||
|
<div className="chat-info">
|
||||||
|
<span>{appName}</span>
|
||||||
|
</div>
|
||||||
|
<div className="chat-info">
|
||||||
|
<span>{appVersion}</span>
|
||||||
|
<span> </span>
|
||||||
|
{
|
||||||
|
<Tooltip title="click to check update">
|
||||||
|
<a onClick={checkAppUpdate}><SyncOutlined /></a>
|
||||||
|
</Tooltip>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
<Menu
|
<Menu
|
||||||
defaultSelectedKeys={[location.pathname]}
|
defaultSelectedKeys={[location.pathname]}
|
||||||
mode="inline"
|
mode="inline"
|
||||||
|
|||||||
Reference in New Issue
Block a user