-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
3,309 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
actual fun copyToClipboard(text: String) { | ||
writeToClipboard(text) | ||
} | ||
|
||
@JsFun("text => navigator.clipboard.writeText(text)") | ||
external fun writeToClipboard(text: String) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import dev.whyoleg.cryptography.CryptographyProvider | ||
import dev.whyoleg.cryptography.providers.webcrypto.WebCrypto | ||
|
||
actual suspend fun provider() = CryptographyProvider.WebCrypto | ||
|
||
actual fun ownEncrypt(string: String): Pair<String, String> = Pair(string, "") | ||
|
||
actual fun ownDecrypt(encryptedText: String, encodedIv: String): String = encryptedText | ||
|
||
actual fun generateKey() = Unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import kotlinx.browser.document | ||
import org.w3c.dom.HTMLAnchorElement | ||
|
||
actual fun downloadToLocal(url: String, fileName: String) { | ||
val anchorElement = document.createElement("a") as HTMLAnchorElement | ||
anchorElement.href = url | ||
anchorElement.download = fileName | ||
document.body?.appendChild(anchorElement) | ||
anchorElement.click() | ||
document.body?.removeChild(anchorElement) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import io.ktor.client.HttpClient | ||
import io.ktor.client.engine.js.Js | ||
|
||
actual fun httpClientPlatform(): HttpClient { | ||
return HttpClient(Js) | ||
} | ||
|
||
actual fun md5Hash(input: String): String { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
actual fun isWasm(): Boolean = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import kotlinx.browser.window | ||
|
||
actual fun perfSet(key: String, value: String) { | ||
window.localStorage.setItem(key, value) | ||
} | ||
|
||
actual fun perfGet(key: String): String? { | ||
return window.localStorage.getItem(key) | ||
} | ||
|
||
actual fun perfRemove(key: String) { | ||
window.localStorage.removeItem(key) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import androidx.compose.material3.ColorScheme | ||
import androidx.compose.material3.darkColorScheme | ||
import androidx.compose.material3.lightColorScheme | ||
|
||
actual fun platformDarkColor(): ColorScheme = darkColorScheme() | ||
actual fun platformLightColor(): ColorScheme = lightColorScheme() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
actual fun useToast(): Boolean = false | ||
actual fun isSupportMiuiStrongToast(): Boolean = false | ||
actual fun showToast(message: String, duration: Long) {} | ||
actual fun showExtToast(message: String, duration: Long) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.ExperimentalComposeUiApi | ||
import androidx.compose.ui.platform.LocalFontFamilyResolver | ||
import androidx.compose.ui.text.font.FontFamily | ||
import androidx.compose.ui.text.platform.Font | ||
import androidx.compose.ui.window.CanvasBasedWindow | ||
import io.ktor.client.fetch.Response | ||
import kotlinx.browser.window | ||
import kotlinx.coroutines.await | ||
import org.khronos.webgl.ArrayBuffer | ||
import org.khronos.webgl.Int8Array | ||
import kotlin.wasm.unsafe.UnsafeWasmMemoryApi | ||
import kotlin.wasm.unsafe.withScopedMemoryAllocator | ||
|
||
private const val MiSanVF = "./MiSansVF.woff2" | ||
|
||
@OptIn(ExperimentalComposeUiApi::class) | ||
fun main() { | ||
CanvasBasedWindow(canvasElementId = "Updater") { | ||
val fontFamilyResolver = LocalFontFamilyResolver.current | ||
val fontsLoaded = remember { mutableStateOf(false) } | ||
|
||
if (fontsLoaded.value) { | ||
App() | ||
} | ||
|
||
LaunchedEffect(Unit) { | ||
val miSanVFBytes = loadRes(MiSanVF).toByteArray() | ||
val fontFamily = FontFamily(Font("MiSans VF", miSanVFBytes)) | ||
fontFamilyResolver.preload(fontFamily) | ||
fontsLoaded.value = true | ||
} | ||
} | ||
} | ||
|
||
suspend fun loadRes(url: String): ArrayBuffer { | ||
return window.fetch(url).await<Response>().arrayBuffer().await() | ||
} | ||
|
||
fun ArrayBuffer.toByteArray(): ByteArray { | ||
val source = Int8Array(this, 0, byteLength) | ||
return jsInt8ArrayToKotlinByteArray(source) | ||
} | ||
|
||
@JsFun( | ||
""" (src, size, dstAddr) => { | ||
const mem8 = new Int8Array(wasmExports.memory.buffer, dstAddr, size); | ||
mem8.set(src); | ||
} | ||
""" | ||
) | ||
external fun jsExportInt8ArrayToWasm(src: Int8Array, size: Int, dstAddr: Int) | ||
|
||
internal fun jsInt8ArrayToKotlinByteArray(x: Int8Array): ByteArray { | ||
val size = x.length | ||
|
||
@OptIn(UnsafeWasmMemoryApi::class) | ||
return withScopedMemoryAllocator { allocator -> | ||
val memBuffer = allocator.allocate(size) | ||
val dstAddress = memBuffer.address.toInt() | ||
jsExportInt8ArrayToWasm(x, size, dstAddress) | ||
ByteArray(size) { i -> (memBuffer + i).loadByte() } | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Updater</title> | ||
<link rel="icon" href="./favicon.ico"> | ||
<link rel="shortcut icon" href="./favicon.ico"> | ||
<script type="application/javascript" src="skiko.js"></script> | ||
<script type="application/javascript" src="Updater.js"></script> | ||
</head> | ||
|
||
<body> | ||
<canvas id="Updater"></canvas> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.