@@ -37,6 +37,7 @@ import {
3737 HEADER_NOTICES ,
3838 DOMAIN_STORE ,
3939 DARK_MODE ,
40+ LATEST_CS_VERSION ,
4041 CUSTOM_COLUMNS
4142} from '@/store/mutation-types'
4243
@@ -154,6 +155,7 @@ const user = {
154155 state . loginFlag = flag
155156 } ,
156157 SET_LATEST_VERSION : ( state , version ) => {
158+ vueProps . $localStorage . set ( LATEST_CS_VERSION , version )
157159 state . latestVersion = version
158160 }
159161 } ,
@@ -200,7 +202,8 @@ const user = {
200202 commit ( 'SET_2FA_PROVIDER' , result . providerfor2fa )
201203 commit ( 'SET_2FA_ISSUER' , result . issuerfor2fa )
202204 commit ( 'SET_LOGIN_FLAG' , false )
203- commit ( 'SET_LATEST_VERSION' , '' )
205+ const latestVersion = vueProps . $localStorage . get ( LATEST_CS_VERSION , { version : '' , fetchedTs : 0 } )
206+ commit ( 'SET_LATEST_VERSION' , latestVersion )
204207 notification . destroy ( )
205208
206209 resolve ( )
@@ -219,10 +222,12 @@ const user = {
219222 const cachedCustomColumns = vueProps . $localStorage . get ( CUSTOM_COLUMNS , { } )
220223 const domainStore = vueProps . $localStorage . get ( DOMAIN_STORE , { } )
221224 const darkMode = vueProps . $localStorage . get ( DARK_MODE , false )
225+ const latestVersion = vueProps . $localStorage . get ( LATEST_CS_VERSION , { version : '' , fetchedTs : 0 } )
222226 const hasAuth = Object . keys ( cachedApis ) . length > 0
223227
224228 commit ( 'SET_DOMAIN_STORE' , domainStore )
225229 commit ( 'SET_DARK_MODE' , darkMode )
230+ commit ( 'SET_LATEST_VERSION' , latestVersion )
226231 if ( hasAuth ) {
227232 console . log ( 'Login detected, using cached APIs' )
228233 commit ( 'SET_ZONES' , cachedZones )
@@ -236,20 +241,7 @@ const user = {
236241 const result = response . listusersresponse . user [ 0 ]
237242 commit ( 'SET_INFO' , result )
238243 commit ( 'SET_NAME' , result . firstname + ' ' + result . lastname )
239- if ( result . rolename === 'Root Admin' ) {
240- axios . get (
241- 'https://api.github.com/repos/apache/cloudstack/releases'
242- ) . then ( response => {
243- for ( const release of response ) {
244- if ( release . tag_name . toLowerCase ( ) . includes ( 'rc' ) ) {
245- continue
246- } else {
247- commit ( 'SET_LATEST_VERSION' , release . tag_name )
248- break
249- }
250- }
251- } ) . catch ( ignored => { } )
252- }
244+ store . dispatch ( 'SetCsLatestVersion' , result . rolename )
253245 resolve ( cachedApis )
254246 } ) . catch ( error => {
255247 reject ( error )
@@ -327,6 +319,7 @@ const user = {
327319 const result = response . listusersresponse . user [ 0 ]
328320 commit ( 'SET_INFO' , result )
329321 commit ( 'SET_NAME' , result . firstname + ' ' + result . lastname )
322+ store . dispatch ( 'SetCsLatestVersion' , result . rolename )
330323 } ) . catch ( error => {
331324 reject ( error )
332325 } )
@@ -461,6 +454,22 @@ const user = {
461454 SetDomainStore ( { commit } , domainStore ) {
462455 commit ( 'SET_DOMAIN_STORE' , domainStore )
463456 } ,
457+ SetCsLatestVersion ( { commit } , rolename ) {
458+ if ( rolename === 'Root Admin' && ( + new Date ( ) - store . getters . latestVersion . fetchedTs ) > 24 * 60 * 60 * 1000 ) {
459+ axios . get (
460+ 'https://api.github.com/repos/apache/cloudstack/releases'
461+ ) . then ( response => {
462+ for ( const release of response ) {
463+ if ( release . tag_name . toLowerCase ( ) . includes ( 'rc' ) ) {
464+ continue
465+ } else {
466+ commit ( 'SET_LATEST_VERSION' , { version : release . tag_name , fetchedTs : ( + new Date ( ) ) } )
467+ break
468+ }
469+ }
470+ } ) . catch ( ignored => { } )
471+ }
472+ } ,
464473 SetDarkMode ( { commit } , darkMode ) {
465474 commit ( 'SET_DARK_MODE' , darkMode )
466475 } ,
0 commit comments