Skip to content

Commit

Permalink
Merge pull request #411 from kubenav/v4-desktop
Browse files Browse the repository at this point in the history
Add desktop support
  • Loading branch information
ricoberger committed Sep 19, 2022
2 parents 3287bfe + 02e3e31 commit 6c138ea
Show file tree
Hide file tree
Showing 120 changed files with 10,737 additions and 859 deletions.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: [ricoberger]
custom: ["https://www.paypal.me/ricoberger"]
233 changes: 233 additions & 0 deletions .github/workflows/continuous-delivery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
name: Continuous Delivery

on:
pull_request:
release:
types: [created]

jobs:
macos:
name: macOS
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v3

# To sign the macOS version of kubenav we have to generate a new certificate, which can then be used in the GitHub
# Action. More information regarding the creation of the certificate and the usage within this GitHub Action can
# be found on the following sites:
# - https://localazy.com/blog/how-to-automatically-sign-macos-apps-using-github-actions
# - https://docs.github.com/en/actions/deployment/deploying-xcode-applications/installing-an-apple-certificate-on-macos-runners-for-xcode-development
- name: Install the Apple Certificate
env:
MACOS_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE }}
MACOS_CERTIFICATE_PASSWORD: ${{ secrets.MACOS_CERTIFICATE_PASSWORD }}
MACOS_KEYCHAIN_PASSWORD: ${{ secrets.MACOS_KEYCHAIN_PASSWORD }}
run: |
# create variables
CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12
KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db
# import certificate from secrets
echo -n "$MACOS_CERTIFICATE" | base64 --decode --output $CERTIFICATE_PATH
# create temporary keychain
security create-keychain -p "$MACOS_KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
security set-keychain-settings -lut 21600 $KEYCHAIN_PATH
security unlock-keychain -p "$MACOS_KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
# import certificate to keychain
security import $CERTIFICATE_PATH -P "$MACOS_CERTIFICATE_PASSWORD" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH
security list-keychain -d user -s $KEYCHAIN_PATH
# check that certificate was added
security find-identity -v
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version-file: go.mod
cache: true
cache-dependency-path: go.sum

- name: Generate Library
run: |
make library-macos
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.0.2'
channel: 'stable'
cache: true
cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:'
cache-path: '${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:'

- name: Install Dependencies
run: |
flutter pub get
- name: Build
run: |
flutter config --enable-macos-desktop
flutter build macos --release
- name: Package
run: |
codesign --deep --force --options runtime --sign "Developer ID Application: Rico Berger (75AP6HWLUD)" build/macos/Build/Products/Release/kubenav.app -v
ditto -c -k --keepParent "build/macos/Build/Products/Release/kubenav.app" "build/macos/Build/Products/Release/kubenav-macos-universal.zip"
# If the following step returns an error like
# Current status: Invalid..........Processing complete
# id: <RANDOM-ID>
# status: Invalid
#
# the following command can be used for debugging
# xcrun notarytool log <RANDOM-ID> --key AuthKey_${MACOS_ASC_API_KEY}.p8 --key-id $MACOS_ASC_API_KEY --issuer $MACOS_ACS_ISSUER
- name: Upload to Notarization Service
# if: ${{ github.event_name == 'release' && github.event.action == 'created' }}
env:
MACOS_ASC_AUTH_KEY: ${{ secrets.MACOS_ASC_AUTH_KEY }}
MACOS_ASC_API_KEY: ${{ secrets.MACOS_ASC_API_KEY }}
MACOS_ACS_ISSUER: ${{ secrets.MACOS_ACS_ISSUER }}
run: |
mkdir -p ~/.appstoreconnect/private_keys
echo -n "$MACOS_ASC_AUTH_KEY" > ~/.appstoreconnect/private_keys/AuthKey_${MACOS_ASC_API_KEY}.p8
xcrun notarytool submit build/macos/Build/Products/Release/kubenav-macos-universal.zip --key ~/.appstoreconnect/private_keys/AuthKey_${MACOS_ASC_API_KEY}.p8 --key-id $MACOS_ASC_API_KEY --issuer $MACOS_ACS_ISSUER --wait
- name: Upload Artifacts (PR)
if: ${{ github.event_name == 'pull_request' }}
uses: actions/upload-artifact@v3
with:
name: kubenav-macos-universal.zip
path: build/macos/Build/Products/Release/kubenav-macos-universal.zip

- name: Upload Artifacts (Release)
uses: softprops/action-gh-release@v1
if: ${{ github.event_name == 'release' && github.event.action == 'created' }}
with:
files: build/macos/Build/Products/Release/kubenav-macos-universal.zip

- name: Clean up Keychain and AuthKey for Notarization Service
if: ${{ always() }}
env:
MACOS_ASC_API_KEY: ${{ secrets.MACOS_ASC_API_KEY }}
run: |
security delete-keychain $RUNNER_TEMP/app-signing.keychain-db
rm -rf ~/.appstoreconnect/private_keys/AuthKey_${MACOS_ASC_API_KEY}.p8
linux:
name: Linux
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v3
with:
go-version-file: go.mod
cache: true
cache-dependency-path: go.sum

- name: Generate Library
run: |
make library-linux
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.0.2'
channel: 'stable'
cache: true
cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:'
cache-path: '${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:'

- name: Install Dependencies
run: |
flutter pub get
- name: Build
run: |
sudo apt-get update -y
sudo apt-get install -y ninja-build libgtk-3-dev
flutter config --enable-linux-desktop
flutter build linux --release
- name: Package
run: |
wget https://github.com/AppImage/AppImageKit/releases/download/13/appimagetool-x86_64.AppImage
chmod +x appimagetool-x86_64.AppImage
cp linux/kubenav.so build/linux/x64/release/bundle/lib/
cp linux/AppRun build/linux/x64/release/bundle/
cp linux/kubenav.desktop build/linux/x64/release/bundle/
cp linux/kubenav.png build/linux/x64/release/bundle/
./appimagetool-x86_64.AppImage build/linux/x64/release/bundle/
- name: Upload Artifacts (PR)
if: ${{ github.event_name == 'pull_request' }}
uses: actions/upload-artifact@v3
with:
name: kubenav-x86_64.AppImage
path: kubenav-x86_64.AppImage

- name: Upload Artifacts (Release)
uses: softprops/action-gh-release@v1
if: ${{ github.event_name == 'release' && github.event.action == 'created' }}
with:
files: kubenav-x86_64.AppImage

windows:
name: Windows
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v3
with:
go-version-file: go.mod
cache: true
cache-dependency-path: go.sum

- name: Generate Library
run: |
make library-windows
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.0.2'
channel: 'stable'
cache: true
cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:'
cache-path: '${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:'

- name: Install Dependencies
run: |
flutter pub get
- name: Build
run: |
flutter config --enable-windows-desktop
flutter build windows --release
- name: Package
run: |
cp windows/kubenav.dll build/windows/runner/Release/
mv build/windows/runner/Release build/windows/runner/kubenav
cd build/windows/runner && 7z a -tzip kubenav-windows-x86_64.zip kubenav
- name: Upload Artifacts (PR)
if: ${{ github.event_name == 'pull_request' }}
uses: actions/upload-artifact@v3
with:
name: kubenav-windows-x86_64.zip
path: build/windows/runner/kubenav-windows-x86_64.zip

- name: Upload Artifacts (Release)
uses: softprops/action-gh-release@v1
if: ${{ github.event_name == 'release' && github.event.action == 'created' }}
with:
files: build/windows/runner/kubenav-windows-x86_64.zip
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ app.*.map.json
# Go mobile builds
/ios/Runner/libs
/android/app/src/libs

# Temporarily created files
/tmp
24 changes: 22 additions & 2 deletions .metadata
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.
# This file should be version controlled.

version:
revision: 77d935af4db863f6abd0b9c31c7e6df2a13de57b
revision: cd41fdd495f6944ecd3506c21e94c6567b073278
channel: stable

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: cd41fdd495f6944ecd3506c21e94c6567b073278
base_revision: cd41fdd495f6944ecd3506c21e94c6567b073278
- platform: macos
create_revision: cd41fdd495f6944ecd3506c21e94c6567b073278
base_revision: cd41fdd495f6944ecd3506c21e94c6567b073278

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
22 changes: 17 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
.PHONY: bindings
bindings: bindings-android bindings-ios

.PHONY: bindings-android
bindings-android:
mkdir -p android/app/src/libs
gomobile bind -o android/app/src/libs/kubenav.aar -target=android github.com/kubenav/kubenav/cmd/kubenav
gomobile bind -o android/app/src/libs/kubenav.aar -target=android github.com/kubenav/kubenav/cmd/mobile

.PHONY: bindings-ios
bindings-ios:
mkdir -p ios/Runner/libs
gomobile bind -o ios/Runner/libs/Kubenav.xcframework -target=ios github.com/kubenav/kubenav/cmd/kubenav
gomobile bind -o ios/Runner/libs/Kubenav.xcframework -target=ios github.com/kubenav/kubenav/cmd/mobile

.PHONY: library-macos
library-macos:
GOARCH=amd64 GOOS=darwin CGO_ENABLED=1 go build -buildmode c-shared -o macos/kubenav.x64.dylib github.com/kubenav/kubenav/cmd/desktop
GOARCH=arm64 GOOS=darwin CGO_ENABLED=1 go build -buildmode c-shared -o macos/kubenav.arm64.dylib github.com/kubenav/kubenav/cmd/desktop
lipo -create macos/kubenav.x64.dylib macos/kubenav.arm64.dylib -output macos/kubenav.dylib

.PHONY: library-linux
library-linux:
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -buildmode c-shared -o linux/kubenav.so github.com/kubenav/kubenav/cmd/desktop

.PHONY: library-windows
library-windows:
mkdir -p tmp
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 go build -buildmode c-shared -o windows/kubenav.dll github.com/kubenav/kubenav/cmd/desktop
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ storeFile=

- Update the `version` key in the `pubspec.yaml` file

- Run `make bindings` to build the Go code
- Run `make bindings-android` and `make bindings-ios` to build the Go code

- Delete old builds `rm -rf build`

Expand Down
11 changes: 11 additions & 0 deletions cmd/desktop/cerror/cerror.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package cerror

import (
"fmt"
"strings"
)

// New returns a new error string, which can be returned by a function to interop with the c code.
func New(err error) string {
return fmt.Sprintf("{\"error\": \"%s\"}", strings.ReplaceAll(err.Error(), "\"", "'"))
}
33 changes: 33 additions & 0 deletions cmd/desktop/dart_api_dl/dart_api_dl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package dart_api_dl

// #include <stdlib.h>
// #include "stdint.h"
// #include "include/dart_api_dl.c"
//
// bool GoDart_PostCObject(Dart_Port_DL port, Dart_CObject* obj) {
// return Dart_PostCObject_DL(port, obj);
// }
import "C"

import (
"unsafe"
)

func Init(api unsafe.Pointer) {
if C.Dart_InitializeApiDL(api) != 0 {
panic("Failed to initialize Dart DL C API: Version mismatch. Must update \"include/\" to match Dart SDK version")
}
}

func SendToPort(port int64, data string) {
ret := C.CString(data)

var obj C.Dart_CObject
obj._type = C.Dart_CObject_kString

// cgo does not support unions so we are forced to do this
*(**C.char)(unsafe.Pointer(&obj.value)) = ret
C.GoDart_PostCObject(C.int64_t(port), &obj)

C.free(unsafe.Pointer(ret))
}
Loading

0 comments on commit 6c138ea

Please sign in to comment.