-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: trunk
Are you sure you want to change the base?
Conversation
service: .init(client: Client()) | ||
) | ||
// viewController.developmentEnvironmentUrl = URL(string: "http://localhost:5173/")! | ||
viewController.isDebuggingEnabled = true |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
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:This PR probably isn't ready yet – there's a bunch of compatibility things that are unaddressed, but it's a start.