File tree Expand file tree Collapse file tree 4 files changed +42
-0
lines changed Expand file tree Collapse file tree 4 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import { BrowserOpenURL } from 'wailsjs/runtime/runtime.js'
1212import Log from ' @/components/icons/Log.vue'
1313import useConnectionStore from ' stores/connections.js'
1414import Help from ' @/components/icons/Help.vue'
15+ import usePreferencesStore from ' stores/preferences.js'
1516
1617const themeVars = useThemeVars ()
1718
@@ -80,12 +81,14 @@ const renderContextLabel = (option) => {
8081}
8182
8283const dialogStore = useDialogStore ()
84+ const preferencesStore = usePreferencesStore ()
8385const onSelectPreferenceMenu = (key ) => {
8486 switch (key) {
8587 case ' preferences' :
8688 dialogStore .openPreferencesDialog ()
8789 break
8890 case ' update' :
91+ preferencesStore .checkForUpdate (true )
8992 break
9093 }
9194}
Original file line number Diff line number Diff line change 142142 "help" : " Help" ,
143143 "check_update" : " Check for Updates..." ,
144144 "auto_refresh" : " Auto Refresh" ,
145+ "new_version_tip" : " A new version is available. Download now?" ,
146+ "no_update" : " You're update to date" ,
145147 "refresh" : " Refresh" ,
146148 "uptime" : " Uptime" ,
147149 "connected_clients" : " Clients" ,
Original file line number Diff line number Diff line change 142142 "help" : " 帮助" ,
143143 "check_update" : " 检查更新..." ,
144144 "auto_refresh" : " 自动刷新" ,
145+ "new_version_tip" : " 有可用的新版本,是否立即下载" ,
146+ "no_update" : " 当前已是最新版" ,
145147 "refresh" : " 立即刷新" ,
146148 "uptime" : " 运行时间" ,
147149 "connected_clients" : " 已连客户端" ,
Original file line number Diff line number Diff line change @@ -131,6 +131,10 @@ const usePreferencesStore = defineStore('preferences', {
131131 }
132132 return lang || 'en'
133133 } ,
134+
135+ autoCheckUpdate ( ) {
136+ return get ( this . general , 'checkUpdate' , false )
137+ } ,
134138 } ,
135139 actions : {
136140 _applyPreferences ( data ) {
@@ -216,6 +220,37 @@ const usePreferencesStore = defineStore('preferences', {
216220 setAsideWidth ( width ) {
217221 this . general . asideWidth = width
218222 } ,
223+
224+ async checkForUpdate ( manual = false ) {
225+ const message = useMessage ( )
226+ const confirmDialog = useConfirmDialog ( )
227+ let msgRef = null
228+ if ( manual ) {
229+ msgRef = message . loading ( 'Retrieving for new version' , { duration : 0 } )
230+ }
231+ let respObj = null
232+ try {
233+ const resp = await fetch ( 'https://api.github.com/repos/tiny-craft/tiny-rdm/releases/latest' )
234+ if ( resp . status === 200 ) {
235+ respObj = await resp . json ( )
236+ }
237+ } finally {
238+ if ( msgRef != null ) {
239+ msgRef . destroy ( )
240+ msgRef = null
241+ }
242+ }
243+
244+ if ( respObj != null && ! isEmpty ( respObj [ 'html_url' ] ) ) {
245+ confirmDialog . warning ( i18nGlobal . t ( 'new_version_tip' ) , ( ) => {
246+ BrowserOpenURL ( respObj [ 'html_url' ] )
247+ } )
248+ } else {
249+ if ( manual ) {
250+ message . info ( i18nGlobal . t ( 'no_update' ) )
251+ }
252+ }
253+ } ,
219254 } ,
220255} )
221256
You can’t perform that action at this time.
0 commit comments