Init commit
This commit is contained in:
commit
c93a588d93
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
.DS_Store
|
||||
/.build
|
||||
/Packages
|
||||
xcuserdata/
|
||||
DerivedData/
|
||||
.swiftpm/configuration/registries.json
|
||||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
|
||||
.netrc
|
||||
40
.vscode/launch.json
vendored
Normal file
40
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"type": "swift-lldb",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder:adwitaweb}",
|
||||
"name": "Debug adwitaweb",
|
||||
"program": "${workspaceFolder:adwitaweb}/.build/debug/adwitaweb",
|
||||
"preLaunchTask": "swift: Build Debug adwitaweb"
|
||||
},
|
||||
{
|
||||
"type": "swift-lldb",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder:adwitaweb}",
|
||||
"name": "Release adwitaweb",
|
||||
"program": "${workspaceFolder:adwitaweb}/.build/release/adwitaweb",
|
||||
"preLaunchTask": "swift: Build Release adwitaweb"
|
||||
},
|
||||
{
|
||||
"type": "swift-lldb",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder:adwitaweb}",
|
||||
"name": "Debug Test",
|
||||
"program": "${workspaceFolder:adwitaweb}/.build/debug/Test",
|
||||
"preLaunchTask": "swift: Build Debug Test"
|
||||
},
|
||||
{
|
||||
"type": "swift-lldb",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder:adwitaweb}",
|
||||
"name": "Release Test",
|
||||
"program": "${workspaceFolder:adwitaweb}/.build/release/Test",
|
||||
"preLaunchTask": "swift: Build Release Test"
|
||||
}
|
||||
]
|
||||
}
|
||||
24
Package.resolved
Normal file
24
Package.resolved
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"originHash" : "496c63bc49c50cbe6b86167e8d0b9463e27ba13de73667d4e8f9cc29ec185222",
|
||||
"pins" : [
|
||||
{
|
||||
"identity" : "adwaita",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/AparokshaUI/Adwaita",
|
||||
"state" : {
|
||||
"branch" : "main",
|
||||
"revision" : "c6d0fa508011281569f5985a0bcbc6b0d4428711"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "levenshteintransformations",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/david-swift/LevenshteinTransformations",
|
||||
"state" : {
|
||||
"revision" : "002c3ae5c48f30d61c96045fd3ceb9928aa778d2",
|
||||
"version" : "0.1.3"
|
||||
}
|
||||
}
|
||||
],
|
||||
"version" : 3
|
||||
}
|
||||
31
Package.swift
Normal file
31
Package.swift
Normal file
@ -0,0 +1,31 @@
|
||||
// swift-tools-version: 5.10
|
||||
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "adwitaweb",
|
||||
products: [
|
||||
.library(name: "WebView", targets: ["WebView"]),
|
||||
.library(name: "CWebView", targets: ["CWebView"]),
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/AparokshaUI/Adwaita", branch: "main"),
|
||||
],
|
||||
targets: [
|
||||
// Targets are the basic building blocks of a package, defining a module or a test suite.
|
||||
// Targets can depend on other targets in this package and products from dependencies.
|
||||
|
||||
.target(name: "WebView",
|
||||
dependencies: [
|
||||
.product(name: "Adwaita", package: "Adwaita"),
|
||||
"CWebView"
|
||||
]),
|
||||
.systemLibrary(name: "CWebView",
|
||||
pkgConfig: "webkitgtk-6.0"),
|
||||
.executableTarget(
|
||||
name: "Test",
|
||||
dependencies: ["WebView", "Adwaita"],
|
||||
path: "Tests")
|
||||
]
|
||||
)
|
||||
5
Sources/CWebView/module.modulemap
Normal file
5
Sources/CWebView/module.modulemap
Normal file
@ -0,0 +1,5 @@
|
||||
module CWebView [system] {
|
||||
header "shim.h"
|
||||
link "webkitgtk-6.0"
|
||||
export *
|
||||
}
|
||||
1
Sources/CWebView/shim.h
Normal file
1
Sources/CWebView/shim.h
Normal file
@ -0,0 +1 @@
|
||||
#include <webkit/webkit.h>
|
||||
32
Sources/WebView/WebView.swift
Normal file
32
Sources/WebView/WebView.swift
Normal file
@ -0,0 +1,32 @@
|
||||
import Adwaita
|
||||
import CWebView
|
||||
|
||||
public struct WebView: Widget {
|
||||
@Binding var url: String
|
||||
var width: Int = 800
|
||||
var height: Int = 600
|
||||
|
||||
public init(url: Binding<String>) {
|
||||
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 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 setSize(width: Int, height: Int) -> Self {
|
||||
var view = self
|
||||
view.width = width
|
||||
view.height = height
|
||||
return view
|
||||
}
|
||||
}
|
||||
4
Sources/main.swift
Normal file
4
Sources/main.swift
Normal file
@ -0,0 +1,4 @@
|
||||
// The Swift Programming Language
|
||||
// https://docs.swift.org/swift-book
|
||||
|
||||
print("Hello, world!")
|
||||
64
Tests/program.swift
Normal file
64
Tests/program.swift
Normal file
@ -0,0 +1,64 @@
|
||||
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