Skip to content

Commit

Permalink
create patch
Browse files Browse the repository at this point in the history
  • Loading branch information
MoAlyousef committed Jan 5, 2024
1 parent 96f12cd commit 9149d39
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 13 deletions.
17 changes: 4 additions & 13 deletions fltk-webview-sys/webview/webview.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include <string>

#ifndef WEBVIEW_H
#define WEBVIEW_H

Expand Down Expand Up @@ -718,12 +715,6 @@ inline id operator"" _str(const char *s, std::size_t) {
return objc::msg_send<id>("NSString"_cls, "stringWithUTF8String:"_sel, s);
}

inline std::string unique_name(std::string base) {
static int name_counter = 0;
base += std::to_string(name_counter++);
return base;
}

class cocoa_wkwebview_engine {
public:
cocoa_wkwebview_engine(bool debug, void *window)
Expand Down Expand Up @@ -836,7 +827,7 @@ class cocoa_wkwebview_engine {
// default name in projects created with Xcode, and using the same name
// causes objc_registerClassPair to crash.
auto cls = objc_allocateClassPair((Class) "NSResponder"_cls,
unique_name("WebviewAppDelegate").c_str(), 0);
"WebviewAppDelegate", 0);
class_addProtocol(cls, objc_getProtocol("NSTouchBarProvider"));
class_addMethod(cls, "applicationShouldTerminateAfterLastWindowClosed:"_sel,
(IMP)(+[](id, SEL, id) -> BOOL { return 1; }), "c@:@");
Expand All @@ -859,7 +850,7 @@ class cocoa_wkwebview_engine {
}
id create_script_message_handler() {
auto cls = objc_allocateClassPair((Class) "NSResponder"_cls,
unique_name("WebkitScriptMessageHandler").c_str(), 0);
"WebkitScriptMessageHandler", 0);
class_addProtocol(cls, objc_getProtocol("WKScriptMessageHandler"));
class_addMethod(
cls, "userContentController:didReceiveScriptMessage:"_sel,
Expand All @@ -877,7 +868,7 @@ class cocoa_wkwebview_engine {
}
static id create_webkit_ui_delegate() {
auto cls =
objc_allocateClassPair((Class) "NSObject"_cls, unique_name("WebkitUIDelegate").c_str(), 0);
objc_allocateClassPair((Class) "NSObject"_cls, "WebkitUIDelegate", 0);
class_addProtocol(cls, objc_getProtocol("WKUIDelegate"));
class_addMethod(
cls,
Expand Down Expand Up @@ -2301,4 +2292,4 @@ WEBVIEW_API const webview_version_info_t *webview_version() {

#endif /* WEBVIEW_HEADER */
#endif /* __cplusplus */
#endif /* WEBVIEW_H */
#endif /* WEBVIEW_H */
61 changes: 61 additions & 0 deletions webview.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
diff --git a/fltk-webview-sys/webview/webview.h b/fltk-webview-sys/webview/webview.h
index 01f81e6..622bfdf 100644
--- a/fltk-webview-sys/webview/webview.h
+++ b/fltk-webview-sys/webview/webview.h
@@ -22,6 +22,9 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+
+#include <string>
+
#ifndef WEBVIEW_H
#define WEBVIEW_H

@@ -715,6 +718,12 @@ inline id operator"" _str(const char *s, std::size_t) {
return objc::msg_send<id>("NSString"_cls, "stringWithUTF8String:"_sel, s);
}

+inline std::string unique_name(std::string base) {
+ static int name_counter = 0;
+ base += std::to_string(name_counter++);
+ return base;
+}
+
class cocoa_wkwebview_engine {
public:
cocoa_wkwebview_engine(bool debug, void *window)
@@ -827,7 +836,7 @@ private:
// default name in projects created with Xcode, and using the same name
// causes objc_registerClassPair to crash.
auto cls = objc_allocateClassPair((Class) "NSResponder"_cls,
- "WebviewAppDelegate", 0);
+ unique_name("WebviewAppDelegate").c_str(), 0);
class_addProtocol(cls, objc_getProtocol("NSTouchBarProvider"));
class_addMethod(cls, "applicationShouldTerminateAfterLastWindowClosed:"_sel,
(IMP)(+[](id, SEL, id) -> BOOL { return 1; }), "c@:@");
@@ -850,7 +859,7 @@ private:
}
id create_script_message_handler() {
auto cls = objc_allocateClassPair((Class) "NSResponder"_cls,
- "WebkitScriptMessageHandler", 0);
+ unique_name("WebkitScriptMessageHandler").c_str(), 0);
class_addProtocol(cls, objc_getProtocol("WKScriptMessageHandler"));
class_addMethod(
cls, "userContentController:didReceiveScriptMessage:"_sel,
@@ -868,7 +877,7 @@ private:
}
static id create_webkit_ui_delegate() {
auto cls =
- objc_allocateClassPair((Class) "NSObject"_cls, "WebkitUIDelegate", 0);
+ objc_allocateClassPair((Class) "NSObject"_cls, unique_name("WebkitUIDelegate").c_str(), 0);
class_addProtocol(cls, objc_getProtocol("WKUIDelegate"));
class_addMethod(
cls,
@@ -2292,4 +2301,4 @@ WEBVIEW_API const webview_version_info_t *webview_version() {

#endif /* WEBVIEW_HEADER */
#endif /* __cplusplus */
-#endif /* WEBVIEW_H */
\ No newline at end of file
+#endif /* WEBVIEW_H */

0 comments on commit 9149d39

Please sign in to comment.