Skip to content

Commit

Permalink
Add initial msix support
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Jun 26, 2023
1 parent e7e5665 commit 11036d3
Show file tree
Hide file tree
Showing 12 changed files with 652 additions and 21 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ jobs:
with:
distribution: 'temurin'
java-version: ${{env.JAVA_VERSION}}
- uses: actions-rs/toolchain@v1
if: matrix.os == 'windows-latest'
with:
toolchain: 'stable'
- name: Setup MacOS signing
if: matrix.os == 'macos-latest'
env:
Expand Down Expand Up @@ -90,10 +94,14 @@ jobs:
New-Item -ItemType directory -Path certificate
Set-Content -Path certificate\certificate.txt -Value '${{ secrets.WINDOWS_CERTIFICATE }}'
certutil -decode certificate\certificate.txt certificate\certificate.pfx
- name: Build MSIX
if: matrix.os == 'windows-latest'
run: |
& 'C:/Program Files (x86)/Windows Kits/10/bin/10.0.17763.0/x86/signtool.exe' pack /d app/desktop/build/msix-workspace /p Tonbrett.msix
- name: Code Sign 2021
if: matrix.os == 'windows-latest'
run: |
& 'C:/Program Files (x86)/Windows Kits/10/bin/10.0.17763.0/x86/signtool.exe' sign /f certificate\certificate.pfx /p '${{ secrets.WINDOWS_CERTIFICATE_PASSWORD }}' /t http://timestamp.sectigo.com/ /d Tonbrett app/desktop/build/compose/binaries/main-release/msi/*.msi
& 'C:/Program Files (x86)/Windows Kits/10/bin/10.0.17763.0/x86/signtool.exe' sign /f certificate\certificate.pfx /p '${{ secrets.WINDOWS_CERTIFICATE_PASSWORD }}' /t http://timestamp.sectigo.com/ /d Tonbrett Tonbrett.msix
- name: Notarize MacOS installer
#if: matrix.os == 'macos-latest'
# waiting for https://github.com/JetBrains/compose-multiplatform/issues/3208
Expand All @@ -108,9 +116,8 @@ jobs:
with:
name: desktopapp-${{ matrix.os }}
path: |
*.msix
app/desktop/build/compose/binaries/main-release/deb/*.deb
app/desktop/build/compose/binaries/main-release/msi/*.msi
app/desktop/build/compose/binaries/main-release/pkg/*.pkg
app/desktop/build/compose/binaries/main-release/pkg/*.pkg
app/desktop/build/distributions/*.tar.gz
build_android_app:
Expand Down Expand Up @@ -206,7 +213,7 @@ jobs:
files: |
compose/binaries/main-release/deb/*.deb
compose/binaries/main-release/pkg/*.pkg
compose/binaries/main-release/msi/*.msi
*.msix
distributions/*.tar.gz
*.zip
*-signed.apk
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ out/
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

Expand Down Expand Up @@ -56,3 +55,5 @@ app/ios/iosApp.xcworkspace/*
app/ios/iosApp.xcodeproj/*
!app/ios/iosApp.xcodeproj/project.pbxproj
app/ios/ios.podspec

**/target
35 changes: 34 additions & 1 deletion app/desktop/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.compose.desktop.application.tasks.AbstractJPackageTask
import org.jetbrains.kotlin.org.jline.utils.OSUtils
import kotlin.io.path.pathString

Expand All @@ -25,7 +26,7 @@ compose.desktop {
"java.naming" // required by logback
)
when {
OSUtils.IS_WINDOWS -> targetFormats(TargetFormat.Msi)
OSUtils.IS_WINDOWS -> targetFormats(TargetFormat.AppImage)
OSUtils.IS_OSX -> targetFormats(TargetFormat.Pkg)
else -> targetFormats(TargetFormat.Deb)
}
Expand Down Expand Up @@ -78,4 +79,36 @@ tasks {
compression = Compression.GZIP
archiveExtension = "tar.gz"
}

val buildUwpHelper by creating(Exec::class) {
inputs.dir("uwp_helper/src")
outputs.dir("uwp_helper/target")

workingDir = file("uwp_helper")
commandLine("cargo", "build", "--release")
}

val prepareUwpWorkspace by creating(Copy::class) {
dependsOn(buildUwpHelper)
afterEvaluate {
from(named("packageReleaseAppImage")) {
eachFile {
path = path.substringAfter("Tonbrett")
}
}
}
from(file("uwp_helper/target/release")) {
include("*.exe")
}
from(file("msix"))
into(buildDir.resolve("msix-workspace"))
}

afterEvaluate {
"packageReleaseDistributionForCurrentOS" {
if (OSUtils.IS_WINDOWS) {
dependsOn(prepareUwpWorkspace)
}
}
}
}
47 changes: 47 additions & 0 deletions app/desktop/msix/appxmanifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5"
xmlns:uap10="http://schemas.microsoft.com/appx/manifest/uap/windows10/10">
<Identity Name="dev.schlaubi.Tonbrett" Version="1.10.2.0" Publisher="CN=Michael Rittmeister, O=Michael Rittmeister, S=Bayern, C=DE"
ProcessorArchitecture="x64"/>
<Properties>
<DisplayName>Tonbrett</DisplayName>
<PublisherDisplayName>Schlaubi</PublisherDisplayName>
<Description>Companion app for Discord soundboard bot</Description>
<Logo>logo.png</Logo>
</Properties>
<Resources>
<Resource Language="en-us"/>
<Resource Language="de-de"/>
</Resources>
<Dependencies>
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14316.0" MaxVersionTested="10.0.15063.0"/>
</Dependencies>
<Capabilities>
<Capability Name="internetClient" />
</Capabilities>
<Applications>
<Application Id="Tonbrett" Executable="Tonbrett.exe"
EntryPoint="Windows.PartialTrustApplication"
uap10:RuntimeBehavior="packagedClassicApp"
>
<uap:VisualElements DisplayName="Tonbrett"
Description="Companion" Square150x150Logo="logo.png"
Square44x44Logo="logo.png" BackgroundColor="#111214"/>
<Extensions>
<uap5:Extension Category="windows.appExecutionAlias">
<uap5:AppExecutionAlias>
<uap5:ExecutionAlias Alias="Tonbrett.exe"/>
</uap5:AppExecutionAlias>
</uap5:Extension>
<uap:Extension Category="windows.protocol">
<uap:Protocol Name="tonbrett">
<uap:DisplayName>Tonbrett Protocol</uap:DisplayName>
</uap:Protocol>
</uap:Extension>
</Extensions>
</Application>
</Applications>
</Package>
Empty file added app/desktop/msix/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 23 additions & 9 deletions app/desktop/src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,41 @@ import androidx.compose.ui.window.*
import dev.schlaubi.tonbrett.app.ColorScheme
import dev.schlaubi.tonbrett.app.ProvideImageLoader
import dev.schlaubi.tonbrett.app.TonbrettApp
import dev.schlaubi.tonbrett.app.api.AppContext
import dev.schlaubi.tonbrett.app.api.ProvideContext
import dev.schlaubi.tonbrett.app.api.getConfig
import dev.schlaubi.tonbrett.app.api.getUrl
import dev.schlaubi.tonbrett.app.api.*
import dev.schlaubi.tonbrett.app.strings.LocalStrings
import dev.schlaubi.tonbrett.app.title
import dev.schlaubi.tonbrett.client.href
import dev.schlaubi.tonbrett.common.Route
import io.ktor.http.*
import mu.KotlinLogging
import java.net.URI
import java.awt.Window as AWTWindow

private val LOG = KotlinLogging.logger { }

fun main() = main(reAuthorize = false) { startApplication() }
fun main(args: Array<String>) {
if (windowsAppDataFolder != null) {
System.setProperty("user.home", windowsAppDataFolder!!)
}

val argsString = args.joinToString(" ")
if (argsString.startsWith("tonbrett://login")) {
try {
LOG.info { "Launched App with $argsString saving token now" }
val token = Url(argsString).parameters["token"]
saveConfig(Config(token))
} catch (e: Exception) {
e.printStackTrace()
Thread.sleep(50000)
}
startApplication()
} else {
main(reAuthorize = false) { startApplication() }
}
}

fun main(reAuthorize: Boolean, onAuth: () -> Unit) {
val config = getConfig()
if (reAuthorize || config.sessionToken == null) {
browseUrl(href(Route.Auth(Route.Auth.Type.APP), URLBuilder(getUrl())).build().toURI())
if (true && config.sessionToken == null) {
//browseUrl(href(Route.Auth(Route.Auth.Type.APP), URLBuilder(getUrl())).build().toURI())
startAuthorizationServer(reAuthorize, onAuth)
} else {
startApplication()
Expand Down
15 changes: 11 additions & 4 deletions app/desktop/src/main/kotlin/URIUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ import java.awt.Desktop
import java.net.URI

fun browseUrl(url: URI) {
val desktop = Desktop.getDesktop()
if (desktop.isSupported(Desktop.Action.BROWSE)) {
desktop.browse(url)
// Desktop#browse() internally uses ShellExecute, which doesn't work in UWP apps, therefore,
// We use a Rust binary, which calls:
// https://learn.microsoft.com/de-de/uwp/api/windows.system.launcher.launchuriasync?view=winrt-22621
if (System.getProperty("os.name").contains("windows", ignoreCase = true)) {
Runtime.getRuntime().exec(arrayOf("url_launcher.exe", "-u", url.toString()))
} else {
Runtime.getRuntime().exec(arrayOf("xdg-open", url.toString()))
val desktop = Desktop.getDesktop()
if (desktop.isSupported(Desktop.Action.BROWSE)) {
desktop.browse(url)
} else {
Runtime.getRuntime().exec(arrayOf("xdg-open", url.toString()))
}
}
}
Loading

0 comments on commit 11036d3

Please sign in to comment.