-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
ad2fbd7
commit 3ef5760
Showing
3 changed files
with
62 additions
and
32 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
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() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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