sv-ochis / discoveries

0 stars 0 forks source link

[swift | ✔︎] always on top, webview minimal app #4

Open sv-ochis opened 1 year ago

sv-ochis commented 1 year ago

small app that I use with https://mcam.app for video feed from an iphone/ipad

// swift webcam.swift
// pkill -f webcam to close

import AppKit
import WebKit

class DraggableWKWebView: WKWebView {
    override func mouseDown(with event: NSEvent) {
        if let window = window {
            window.performDrag(with: event)
        }
    }
}

let app = NSApplication.shared

let window = NSWindow(
    contentRect: NSRect(x: 0, y: 0, width: 320, height: 240),
    styleMask: [.closable, .resizable],
    backing: .buffered,
    defer: false
)
window.level = .floating

let webView = DraggableWKWebView(frame: window.contentView!.bounds)
webView.autoresizingMask = [.width, .height]
if let url = URL(string: "<URL of the webpage>") {
    let request = URLRequest(url: url)
    webView.load(request)
}

window.contentView!.addSubview(webView)
window.makeKeyAndOrderFront(nil)

app.run()