Skip to content

Commit

Permalink
frontend: make internet checks non-binary
Browse files Browse the repository at this point in the history
  • Loading branch information
Williangalvani committed Jan 9, 2025
1 parent 104dc15 commit 469352e
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 15 deletions.
18 changes: 16 additions & 2 deletions core/frontend/src/components/app/InternetTrayMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
color="white"
:title="tooltip"
>
{{ helper.has_internet ? 'mdi-web' : 'mdi-web-off' }}
{{ icon }}
</v-icon>
</v-card>
</template>
Expand All @@ -42,6 +42,7 @@ import Vue from 'vue'
import settings from '@/libs/settings'
import helper from '@/store/helper'
import { InternetConnectionState } from '@/types/helper'
import NetworkInterfaceMenu from './NetworkInterfaceMenu.vue'
Expand All @@ -51,14 +52,27 @@ export default Vue.extend({
NetworkInterfaceMenu,
},
data: () => ({
helper,
settings,
show_menu: false,
}),
computed: {
tooltip() {
return helper.has_internet ? 'Vehicle has internet access.' : 'Internet connection is not available.'
},
icon(): string {
switch (helper.has_internet) {
case InternetConnectionState.ONLINE:
return 'mdi-web'
case InternetConnectionState.OFFLINE:
return 'mdi-web-off'
case InternetConnectionState.LIMITED:
return 'mdi-web-minus'
case InternetConnectionState.UNKNOWN:
return 'mdi-web-refresh'
default:
return 'mdi-web-off'
}
},
},
})
</script>
3 changes: 2 additions & 1 deletion core/frontend/src/components/kraken/BackAlleyTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ import SpinningLogo from '@/components/common/SpinningLogo.vue'
import StoreExtensionCard, { ImgProcessedResult } from '@/components/kraken/cards/StoreExtensionCard.vue'
import { getLatestVersion } from '@/components/kraken/Utils'
import helper from '@/store/helper'
import { InternetConnectionState } from '@/types/helper'
import { ExtensionData, InstalledExtensionData } from '@/types/kraken'
enum AvailableSorts {
Expand Down Expand Up @@ -328,7 +329,7 @@ export default Vue.extend({
return this.manifest_is_loading || this.manifest_has_error
},
internet_offline(): boolean {
return !helper.has_internet
return helper.has_internet === InternetConnectionState.OFFLINE
},
show_info_card(): boolean {
return this.is_manifest_invalid || this.internet_offline
Expand Down
3 changes: 2 additions & 1 deletion core/frontend/src/components/kraken/BazaarTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import BrIframe from '@/components/utils/BrIframe.vue'
import { OneMoreTime } from '@/one-more-time'
import bag from '@/store/bag'
import helper from '@/store/helper'
import { InternetConnectionState } from '@/types/helper'
export default Vue.extend({
name: 'BazaarTab',
Expand All @@ -76,7 +77,7 @@ export default Vue.extend({
return this.bazaar_url_loading || this.bazaar_url_error !== undefined
},
internet_offline(): boolean {
return !helper.has_internet
return helper.has_internet === InternetConnectionState.OFFLINE
},
major_tom_not_configured(): boolean {
return this.bazaar_url === undefined && !this.internet_offline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
width="100%"
absolute
opacity="0.92"
:value="!helper.has_internet"
:value="helper.has_internet === InternetConnectionState.OFFLINE"
>
Waiting for internet connection..
</v-overlay>
Expand Down
4 changes: 3 additions & 1 deletion core/frontend/src/components/version-chooser/VersionCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ import Vue, { PropType } from 'vue'
import settings from '@/libs/settings'
import helper from '@/store/helper'
import { Dictionary } from '@/types/common'
import { InternetConnectionState } from '@/types/helper'
import { DEFAULT_REMOTE_IMAGE } from '@/utils/version_chooser'
import SpinningLogo from '../common/SpinningLogo.vue'
Expand Down Expand Up @@ -248,7 +249,8 @@ export default Vue.extend({
return this.image.repository === 'bluerobotics/blueos-core'
},
showBootstrapUpdate(): boolean {
if (!this.bootstrapVersion || !helper.has_internet) {
if (!this.bootstrapVersion || helper.has_internet === InternetConnectionState.OFFLINE
|| helper.has_internet === InternetConnectionState.UNKNOWN) {
return false
}
return this.settings.is_pirate_mode && this.current && !this.updateAvailable && this.isFromBR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ import Notifier from '@/libs/notifier'
import settings from '@/libs/settings'
import helper from '@/store/helper'
import { version_chooser_service } from '@/types/frontend_services'
import { InternetConnectionState } from '@/types/helper'
import {
isServerResponse,
LocalVersionsQuery, Version, VersionsQuery, VersionType,
Expand Down Expand Up @@ -270,7 +271,7 @@ export default Vue.extend({
return 'File is required'
},
has_internet(): boolean {
return helper.has_internet
return helper.has_internet !== InternetConnectionState.OFFLINE
},
},
watch: {
Expand Down
30 changes: 22 additions & 8 deletions core/frontend/src/store/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Notifier from '@/libs/notifier'
import { OneMoreTime } from '@/one-more-time'
import store from '@/store'
import { helper_service } from '@/types/frontend_services'
import { Service, SpeedTestResult } from '@/types/helper'
import { InternetConnectionState, Service, SpeedTestResult } from '@/types/helper'
import back_axios, { backend_offline_error } from '@/utils/api'

const notifier = new Notifier(helper_service)
Expand All @@ -29,7 +29,7 @@ type SiteStatus = Record<string, CheckSiteStatus>
class PingStore extends VuexModule {
API_URL = '/helper/latest'

has_internet = false
has_internet: InternetConnectionState = InternetConnectionState.UNKNOWN

services: Service[] = []

Expand All @@ -42,7 +42,7 @@ class PingStore extends VuexModule {
)

@Mutation
setHasInternet(has_internet: boolean): void {
setHasInternet(has_internet: InternetConnectionState): void {
this.has_internet = has_internet
}

Expand All @@ -59,13 +59,27 @@ class PingStore extends VuexModule {
timeout: 10000,
})
.then((response) => {
const has_internet = !Object.values(response.data as SiteStatus)
.filter((item) => item.online)
.isEmpty()

this.setHasInternet(has_internet)
const sites = Object.values(response.data as SiteStatus)
const online_sites = sites.filter((item) => item.online)

// If no sites are reachable, we're offline
if (online_sites.length === 0) {
this.setHasInternet(InternetConnectionState.OFFLINE)
return
}

// If all sites are reachable, we're fully online
if (online_sites.length === sites.length) {
this.setHasInternet(InternetConnectionState.ONLINE)
return
}

// If some sites are reachable but not all, we have limited connectivity
this.setHasInternet(InternetConnectionState.LIMITED)
})
.catch((error) => {
// If we can't even reach the backend, we're in an unknown state
this.setHasInternet(InternetConnectionState.UNKNOWN)
notifier.pushBackError('INTERNET_CHECK_FAIL', error)
})
}
Expand Down
7 changes: 7 additions & 0 deletions core/frontend/src/types/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,10 @@ export interface SpeedTestResult {
share: string | null
client: SpeedtestClient
}

export enum InternetConnectionState {
OFFLINE = 0,
UNKNOWN = 1,
LIMITED = 2,
ONLINE = 3,
}

0 comments on commit 469352e

Please sign in to comment.