Migrate to the Meta backend and bump to swift 6
This commit is contained in:
parent
9e2cf0b30e
commit
f8f51911dc
@ -1,10 +1,10 @@
|
||||
// swift-tools-version: 5.10
|
||||
// swift-tools-version: 6.0
|
||||
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "adwitaweb",
|
||||
name: "AdwaitaWebViewSwift",
|
||||
platforms: [
|
||||
.macOS(.v10_15)
|
||||
],
|
||||
|
||||
@ -46,7 +46,7 @@ struct ContentView: View {
|
||||
}
|
||||
```
|
||||
|
||||
Take a look at the simple [sample app](Tests/program.swift).
|
||||
Take a look at the simple [sample app](Tests/main.swift).
|
||||
Check out the [Adwaita](https://github.com/AparokshaUI/Adwaita) packages.
|
||||
|
||||
## Thanks
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import Adwaita
|
||||
import Meta
|
||||
import CWebView
|
||||
import Foundation
|
||||
|
||||
public struct WebView: Widget {
|
||||
public struct WebView: AdwaitaWidget {
|
||||
@Binding var url: String
|
||||
var width: Int = 800
|
||||
var height: Int = 600
|
||||
@ -10,17 +11,19 @@ public struct WebView: Widget {
|
||||
self._url = url
|
||||
}
|
||||
|
||||
public func container(modifiers: [(View) -> View]) -> ViewStorage {
|
||||
let webView = ViewStorage(webkit_web_view_new()?.opaque())
|
||||
update(webView, modifiers: modifiers, updateProperties: true)
|
||||
return webView
|
||||
public func container<Data>(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData {
|
||||
let storage = ViewStorage(webkit_web_view_new()?.opaque())
|
||||
update(storage, data: data, updateProperties: true, type: type)
|
||||
return storage
|
||||
}
|
||||
|
||||
public func update(_ storage: ViewStorage, modifiers: [(View) -> View], updateProperties: Bool) {
|
||||
if updateProperties {
|
||||
webkit_web_view_load_uri(storage.pointer?.cast(), url)
|
||||
gtk_widget_set_size_request(storage.pointer?.cast(), width.cInt, height.cInt)
|
||||
}
|
||||
public func update<Data>(_ storage: ViewStorage, data: WidgetData, updateProperties: Bool, type: Data.Type) where Data: ViewRenderData {
|
||||
guard updateProperties else { return }
|
||||
|
||||
webkit_web_view_load_uri(storage.opaquePointer?.cast(), url)
|
||||
gtk_widget_set_size_request(storage.opaquePointer?.cast(), Int32(width), Int32(height))
|
||||
|
||||
storage.previousState = self
|
||||
}
|
||||
|
||||
public func setSize(width: Int, height: Int) -> Self {
|
||||
@ -29,4 +32,4 @@ public struct WebView: Widget {
|
||||
view.height = height
|
||||
return view
|
||||
}
|
||||
}
|
||||
}
|
||||
19
Tests/main.swift
Normal file
19
Tests/main.swift
Normal file
@ -0,0 +1,19 @@
|
||||
import Adwaita
|
||||
import WebView
|
||||
|
||||
@main
|
||||
struct Test: App{
|
||||
let id = "xyz.zaph.webview"
|
||||
var app: AdwaitaApp!
|
||||
|
||||
@State private var url: String = "https://github.com/AparokshaUI/adwaita-swift"
|
||||
|
||||
var scene: Scene {
|
||||
Window(id: "main"){ window in
|
||||
WebView(url: $url)
|
||||
.setSize(width: 800, height: 600)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,64 +0,0 @@
|
||||
import Adwaita
|
||||
import WebView
|
||||
|
||||
@main
|
||||
struct Test: App{
|
||||
let id = "xyz.zaph.webview"
|
||||
var app: GTUIApp!
|
||||
|
||||
@State private var url: String = "https://google.com"
|
||||
|
||||
var scene: Scene {
|
||||
Window(id: "main"){ window in
|
||||
WebView(url: $url)
|
||||
.setSize(width: 800, height: 600)
|
||||
.topToolbar {
|
||||
ToolbarView(app: app, window: window)
|
||||
}
|
||||
.onAppear {
|
||||
print("Loading url: \(url)")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct ToolbarView: View {
|
||||
|
||||
@State private var about = false
|
||||
var app: GTUIApp
|
||||
var window: GTUIApplicationWindow
|
||||
|
||||
var view: Body {
|
||||
HeaderBar.end {
|
||||
Menu(icon: .default(icon: .openMenu), app: app, window: window) {
|
||||
MenuButton("New Window", window: false) {
|
||||
app.addWindow("main")
|
||||
}
|
||||
.keyboardShortcut("n".ctrl())
|
||||
MenuButton("Close Window") {
|
||||
window.close()
|
||||
}
|
||||
.keyboardShortcut("w".ctrl())
|
||||
MenuSection {
|
||||
MenuButton("About me", window: false) {
|
||||
about = true
|
||||
}
|
||||
}
|
||||
}
|
||||
.primary()
|
||||
.tooltip("Main Menu")
|
||||
.aboutDialog(
|
||||
visible: $about,
|
||||
app: "WebViewAdwaita",
|
||||
developer: "zaph",
|
||||
version: "dev",
|
||||
icon: .custom(name: "xyz.zaph.webview"),
|
||||
website: .init(string: "https://google.com")!,
|
||||
issues: .init(string: "https://google.com")!
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user