2121
2222 <!-- GitHub 和设置按钮 -->
2323 <div class =" header-actions" >
24+ <!-- 更新提示按钮 -->
25+ <el-tooltip
26+ v-if =" hasUpdate"
27+ :content =" `发现新版本 ${updateInfo?.latestVersion || ''},点击下载`"
28+ placement =" bottom"
29+ >
30+ <button
31+ class =" icon-btn update-btn"
32+ @click =" openUpdatePage"
33+ >
34+ <span class =" update-icon" >🔔</span >
35+ <span class =" update-badge" ></span >
36+ </button >
37+ </el-tooltip >
2438 <button
2539 class =" icon-btn github-btn"
2640 @click =" openGithub"
@@ -151,6 +165,10 @@ const appVersion = ref("");
151165const isMac = ref (false );
152166const maximised = ref (false );
153167
168+ // 更新相关
169+ const hasUpdate = ref (false );
170+ const updateInfo = ref <any >(null );
171+
154172onMounted (async () => {
155173 // 检测用户代理或使用Wails API检测平台
156174 isMac .value = navigator .userAgent .toUpperCase ().indexOf (" MAC" ) >= 0 ;
@@ -163,6 +181,9 @@ onMounted(async () => {
163181 console .error (' 获取版本失败:' , error );
164182 appVersion .value = ' unknown' ;
165183 }
184+
185+ // 静默检查更新
186+ checkForUpdateSilent ();
166187});
167188
168189// 菜单标题映射
@@ -344,15 +365,15 @@ const checkForUpdate = async () => {
344365 const owner = ' zzdylan' ;
345366 const repo = ' dev-tools' ;
346367
347- const updateInfo = await CheckForUpdate (owner , repo );
368+ const result = await CheckForUpdate (owner , repo );
348369 loading .close ();
349370
350- if (updateInfo .hasUpdate ) {
371+ if (result .hasUpdate ) {
351372 // 有新版本
352- const description = updateInfo .description .substring (0 , 300 ).replace (/ \n / g , ' <br>' );
373+ const description = result .description .substring (0 , 300 ).replace (/ \n / g , ' <br>' );
353374
354375 await ElMessageBox .confirm (
355- ` 最新版本: <strong>${updateInfo .latestVersion }</strong><br>当前版本: ${updateInfo .currentVersion }<br><br>${description } ` ,
376+ ` 最新版本: <strong>${result .latestVersion }</strong><br>当前版本: ${result .currentVersion }<br><br>${description } ` ,
356377 ' 发现新版本' ,
357378 {
358379 confirmButtonText: ' 立即下载' ,
@@ -362,15 +383,15 @@ const checkForUpdate = async () => {
362383 );
363384
364385 // 打开下载页面
365- const downloadUrl = updateInfo .downloadUrl && updateInfo .downloadUrl .trim () !== ' '
366- ? updateInfo .downloadUrl
386+ const downloadUrl = result .downloadUrl && result .downloadUrl .trim () !== ' '
387+ ? result .downloadUrl
367388 : ' https://github.com/zzdylan/dev-tools/releases/latest' ;
368389
369390 console .log (' 打开下载地址:' , downloadUrl );
370391 BrowserOpenURL (downloadUrl );
371392 } else {
372393 // 已是最新版本
373- ElMessage .success (` 当前已是最新版本: ${updateInfo .currentVersion } ` );
394+ ElMessage .success (` 当前已是最新版本: ${result .currentVersion } ` );
374395 }
375396 } catch (error : any ) {
376397 loading .close ();
@@ -385,6 +406,38 @@ const checkForUpdate = async () => {
385406 ElMessage .error (' 检查更新失败,请稍后重试' );
386407 }
387408};
409+
410+ // 静默检查更新(启动时调用)
411+ const checkForUpdateSilent = async () => {
412+ try {
413+ const owner = ' zzdylan' ;
414+ const repo = ' dev-tools' ;
415+
416+ const result = await CheckForUpdate (owner , repo );
417+
418+ if (result .hasUpdate ) {
419+ // 有新版本,设置状态
420+ hasUpdate .value = true ;
421+ updateInfo .value = result ;
422+ console .log (' 发现新版本:' , result .latestVersion );
423+ }
424+ } catch (error : any ) {
425+ // 静默失败,不显示错误消息
426+ console .log (' 静默检查更新失败:' , error );
427+ }
428+ };
429+
430+ // 打开更新页面
431+ const openUpdatePage = () => {
432+ if (updateInfo .value ) {
433+ const downloadUrl = updateInfo .value .downloadUrl && updateInfo .value .downloadUrl .trim () !== ' '
434+ ? updateInfo .value .downloadUrl
435+ : ' https://github.com/zzdylan/dev-tools/releases/latest' ;
436+
437+ console .log (' 打开下载地址:' , downloadUrl );
438+ BrowserOpenURL (downloadUrl );
439+ }
440+ };
388441 </script >
389442
390443<style scoped>
@@ -663,7 +716,44 @@ const checkForUpdate = async () => {
663716 display : flex ;
664717 align-items : center ;
665718 gap : 8px ;
666- margin-right : 0 ;
719+ margin-right : 12px ;
720+ }
721+
722+ .update-btn {
723+ padding : 6px ;
724+ border : 1px solid #ef4444 ;
725+ border-radius : 4px ;
726+ position : relative ;
727+ animation : pulse 2s cubic-bezier (0.4 , 0 , 0.6 , 1 ) infinite ;
728+ }
729+
730+ .update-btn :hover {
731+ background : #fef2f2 ;
732+ }
733+
734+ .update-icon {
735+ font-size : 18px ;
736+ display : block ;
737+ }
738+
739+ .update-badge {
740+ position : absolute ;
741+ top : 2px ;
742+ right : 2px ;
743+ width : 8px ;
744+ height : 8px ;
745+ background : #ef4444 ;
746+ border-radius : 50% ;
747+ border : 2px solid #fff ;
748+ }
749+
750+ @keyframes pulse {
751+ 0% , 100% {
752+ opacity : 1 ;
753+ }
754+ 50% {
755+ opacity : 0.7 ;
756+ }
667757}
668758
669759.github-btn {
0 commit comments