Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add macOS support #32

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft

Add macOS support #32

wants to merge 1 commit into from

Conversation

jkmassel
Copy link
Contributor

This project already supports iOS, and it's pretty straightforward to support macOS as well – we just need to have NSViewController support as well. This has a two main advantages:

  1. The build/test cycle can be faster because you can run on a real device
  2. The earlier we transition to multi-platform the easier it'll be to ensure support

This PR probably isn't ready yet – there's a bunch of compatibility things that are unaddressed, but it's a start.

service: .init(client: Client())
)
// viewController.developmentEnvironmentUrl = URL(string: "http://localhost:5173/")!
viewController.isDebuggingEnabled = true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this suppose to be hard-coded as true?

func webView(_ webView: GBWebView, didReceiveMessage: EditorJSMessage)
}

public class GBWebView: WKWebView {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this view need to be public?


/// Calls this at any moment before showing the actual editor. The warmup
/// shaves a couple of hundred milliseconds off the first load.
public static func warmup() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this deletion intentional? I don't see a replacement for it.

@@ -1,7 +1,7 @@
import WebKit

/// A type that represents JavaScript messages send from and to the web view.
struct EditorJSMessage {
public struct EditorJSMessage {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably don't need to publicize this struct if GBWebView is not public?

#elseif canImport(AppKit)
import AppKit
public typealias VCRepresentable = NSViewController
#endif

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: There are a few places do similar things. Maybe we can put all of them into one swift file, so that it's easier to read the typealiases that are re-defined for different platforms.

#else
view.layer?.backgroundColor = CGColor(red: 1.0, green: 0, blue: 0, alpha: 1.0)
webView.layer?.backgroundColor = CGColor(red: 0, green: 1.00, blue: 0, alpha: 1.0)
#endif

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these colors for debugging purposes?

}
}

fileprivate func didLoadEditor() {
// guard !_isEditorRendered else { return }
// _isEditorRendered = true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete these code?


let escapedTitle = viewModel.initialTitle.addingPercentEncoding(withAllowedCharacters: .alphanumerics)!
let escapedContent = viewModel.initialContent.addingPercentEncoding(withAllowedCharacters: .alphanumerics)!
let hasThemeStylesEnabled = viewModel.features.contains(.ThemeStyles)

let jsCode = """
window.GBKit = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not for this PR, but it might be good to encode the JSON properly:

let GBKitJSONString = JSONEncode().encode(...)
let jsCode = "window.GBKit = \(GBKitJSONString);"


let escapedString = content.addingPercentEncoding(withAllowedCharacters: .alphanumerics)!
public func setContent(_ newValue: String) {
let escapedString = newValue.addingPercentEncoding(withAllowedCharacters: .alphanumerics)!
evaluate("editor.setContent(decodeURIComponent('\(escapedString)'));", isCritical: true)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR, but we can potentially create a simple wrapper to safely pass any types of arguments to JS. Something like

func callJSFunction(name: String, arguments: [AnyEncodeable]) {
  let args = JSONEncode().encode(arguments)
  evaluate("\(name)(...\(args))")
}


#if(os(iOS))
// This is important so they user can't select anything but text across blocks.
// config.selectionGranularity = WKSelectionGranularity.character

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line supposed to be commented out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants