This commit is contained in:
2026-09-24 16:25:22 +08:00
commit 7428184f01
1198 changed files with 314515 additions and 0 deletions
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyAccessedAPITypes</key>
<array/>
<key>NSPrivacyCollectedDataTypes</key>
<array/>
<key>NSPrivacyTracking</key>
<false/>
<key>NSPrivacyTrackingDomains</key>
<array/>
</dict>
</plist>
@@ -0,0 +1,3 @@
{
"deploymentTarget": "12"
}
@@ -0,0 +1,72 @@
import { NWPathMonitor, NWPath, NWInterface } from 'Network';
import { DispatchQueue } from "Dispatch"
import { xNetworkType } from "../interface"
let network = new NWPathMonitor()
@UTSJS.keepAlive
export function xNetChange(call : (conecting : boolean) => void) {
network.pathUpdateHandler = (nwpath : NWPath) => {
if (nwpath.status == NWPath.Status.satisfied) {
DispatchQueue.main.async(execute = () : void => {
call(true)
})
} else {
DispatchQueue.main.async(execute = () : void => {
call(false)
})
}
}
network.start(queue = DispatchQueue.global())
}
export function xUnNetChange() {
let network = new NWPathMonitor()
network.cancel()
}
//当前是否有网络。
export function isNetworkAvailable() : Promise<boolean> {
return new Promise((res) => {
let network2 = new NWPathMonitor()
network2.pathUpdateHandler = (nwpath : NWPath) => {
if (nwpath.status == NWPath.Status.satisfied) {
DispatchQueue.main.async(execute = () : void => {
res(true)
})
} else {
DispatchQueue.main.async(execute = () : void => {
res(false)
})
}
network2.cancel()
}
network2.start(queue = DispatchQueue.global())
})
}
export function getNetworkType() : Promise<xNetworkType | null> {
return new Promise((res) => {
let network2 = new NWPathMonitor()
network2.pathUpdateHandler = (nwpath : NWPath) => {
if (nwpath.status == NWPath.Status.satisfied) {
DispatchQueue.main.async(execute = () : void => {
if (nwpath.usesInterfaceType(NWInterface.InterfaceType.wifi)) {
res('WiFi')
} else if (nwpath.usesInterfaceType(NWInterface.InterfaceType.cellular)) {
res('Mobile')
} else if (nwpath.usesInterfaceType(NWInterface.InterfaceType.wiredEthernet)) {
res('WiredNetwork')
} else {
res('Other')
}
})
} else {
DispatchQueue.main.async(execute = () : void => {
res(null)
})
}
network2.cancel()
}
network2.start(queue = DispatchQueue.global())
})
}