Skip to content

Commit

Permalink
Switch to SwiftUI
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperisager committed Dec 9, 2024
1 parent ad2fbd7 commit 3ef5760
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 32 deletions.
61 changes: 61 additions & 0 deletions app/App.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import SwiftUI

@main
struct App: SwiftUI.App {
@StateObject private var worklet = Worklet()
@Environment(\.scenePhase) private var scenePhase

var body: some Scene {
WindowGroup {
ContentView()
.onAppear {
worklet.start()
}
.onDisappear {
worklet.terminate()
}
}
.onChange(of: scenePhase) { phase in
switch phase {
case .background:
worklet.suspend()
case .active:
worklet.resume()
default:
break
}
}
}
}

struct ContentView: View {
var body: some View {
Text("Hello SwiftUI!")
}
}

class Worklet: ObservableObject {
private var worklet: BareWorklet?

func start() {
guard let url = Bundle.main.url(forResource: "app", withExtension: "bundle") else {
return
}

worklet = BareWorklet(configuration: nil)

worklet?.start(url.path, source: nil, arguments: nil)
}

func suspend() {
worklet?.suspend()
}

func resume() {
worklet?.resume()
}

func terminate() {
worklet?.terminate()
}
}
31 changes: 0 additions & 31 deletions app/AppDelegate.swift

This file was deleted.

2 changes: 1 addition & 1 deletion project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ targets:
dependencies:
- framework: app/frameworks/BareKit.xcframework
sources:
- path: app/AppDelegate.swift
- path: app/App.swift
- path: app/App-Bridging-Header.h
- path: app/app.js
- path: app/app.bundle
Expand Down

0 comments on commit 3ef5760

Please sign in to comment.