feat(InstanceViewModel): 自动给用户输入的实例地址加上 https://
自动给用户输入的实例地址加上 https:// Signed-off-by: Ching <loooching@gmail.com>
This commit is contained in:
parent
0103281cd4
commit
d8ea4236cc
@ -11,11 +11,20 @@ class InstanceViewModel: ObservableObject {
|
|||||||
@Published var instance: Instance = .defaultInstance()
|
@Published var instance: Instance = .defaultInstance()
|
||||||
@Published var isLoading: Bool = false
|
@Published var isLoading: Bool = false
|
||||||
|
|
||||||
|
func addPrefixIfNecessary(_ str: String) -> String {
|
||||||
|
if str.hasPrefix("http://") || str.hasPrefix("https://") {
|
||||||
|
return str
|
||||||
|
} else {
|
||||||
|
return "https://" + str
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getInstance(from url: String) async {
|
func getInstance(from url: String) async {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.isLoading = true
|
self.isLoading = true
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
|
let url = addPrefixIfNecessary(url)
|
||||||
let newInstance = try await Instance.instanceFromURL(url: url)
|
let newInstance = try await Instance.instanceFromURL(url: url)
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.instance = newInstance
|
self.instance = newInstance
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user