mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
alert after connecting to new wifi
This commit is contained in:
committed by
Aiden McClelland
parent
7b0f99881b
commit
7a3811235e
@@ -1,5 +1,5 @@
|
|||||||
import { Injectable } from '@angular/core'
|
import { Injectable } from '@angular/core'
|
||||||
import { ToastController } from '@ionic/angular'
|
import { AlertController, ToastController } from '@ionic/angular'
|
||||||
import { ApiService } from 'src/app/services/api/api.service'
|
import { ApiService } from 'src/app/services/api/api.service'
|
||||||
import { pauseFor } from 'src/app/util/misc.util'
|
import { pauseFor } from 'src/app/util/misc.util'
|
||||||
import { ServerModel } from 'src/app/models/server-model'
|
import { ServerModel } from 'src/app/models/server-model'
|
||||||
@@ -12,6 +12,7 @@ export class WifiService {
|
|||||||
constructor (
|
constructor (
|
||||||
private readonly apiService: ApiService,
|
private readonly apiService: ApiService,
|
||||||
private readonly toastCtrl: ToastController,
|
private readonly toastCtrl: ToastController,
|
||||||
|
private readonly alertCtrl: AlertController,
|
||||||
private readonly serverModel: ServerModel,
|
private readonly serverModel: ServerModel,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
@@ -30,10 +31,13 @@ export class WifiService {
|
|||||||
const maxAttempts = 5
|
const maxAttempts = 5
|
||||||
let attempts = 0
|
let attempts = 0
|
||||||
|
|
||||||
|
let old: string | null
|
||||||
|
|
||||||
while (attempts < maxAttempts) {
|
while (attempts < maxAttempts) {
|
||||||
try {
|
try {
|
||||||
const start = new Date().valueOf()
|
const start = new Date().valueOf()
|
||||||
const { current, ssids } = (await this.apiService.getServer(timeout)).wifi
|
const { current, ssids } = (await this.apiService.getServer(timeout)).wifi
|
||||||
|
old = current
|
||||||
const end = new Date().valueOf()
|
const end = new Date().valueOf()
|
||||||
if (current === ssid) {
|
if (current === ssid) {
|
||||||
this.serverModel.update({ wifi: { current, ssids } })
|
this.serverModel.update({ wifi: { current, ssids } })
|
||||||
@@ -53,7 +57,13 @@ export class WifiService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.serverModel.peek().wifi.current === ssid) {
|
if (this.serverModel.peek().wifi.current === ssid) {
|
||||||
return true
|
let message = 'Note. It may take a few minutes for your Embassy to reconnect over Tor. If it does not reconnect after 5 minutes, please unplug the device and plug it back in. You may also need to hard refresh your browser cache.'
|
||||||
|
const alert = await this.alertCtrl.create({
|
||||||
|
header: `Connected to "${ssid}"`,
|
||||||
|
message: old ? message : 'You may now unplug your Embassy from Ethernet.<br /></br />' + message,
|
||||||
|
buttons: ['OK'],
|
||||||
|
})
|
||||||
|
await alert.present()
|
||||||
} else {
|
} else {
|
||||||
const toast = await this.toastCtrl.create({
|
const toast = await this.toastCtrl.create({
|
||||||
header: 'Failed to connect:',
|
header: 'Failed to connect:',
|
||||||
|
|||||||
@@ -11,7 +11,10 @@ export interface ApiServer {
|
|||||||
versionInstalled: string
|
versionInstalled: string
|
||||||
alternativeRegistryUrl: string | null
|
alternativeRegistryUrl: string | null
|
||||||
specs: ServerSpecs
|
specs: ServerSpecs
|
||||||
wifi: { ssids: string[]; current: string; }
|
wifi: {
|
||||||
|
ssids: string[]
|
||||||
|
current: string | null
|
||||||
|
}
|
||||||
ssh: SSHFingerprint[]
|
ssh: SSHFingerprint[]
|
||||||
serverId: string
|
serverId: string
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user