Problem with imported library

149 views
Skip to first unread message

xilan...@gmail.com

unread,
Feb 12, 2015, 4:22:51 AM2/12/15
to cef...@googlegroups.com
I have imported a library from main_darwin.go example, when i instantiate and create an object from the library the browser window would create but stay frozen without loading the local html page. here is what it looks like :

http://i.imgur.com/kV8YNkq.png

Here is my main_darwin.go :

package main

import (
"cef"
"cocoa"
"os"
"log"
"os/exec"
"fmt"
"github.com/eris-ltd/decerver"
"github.com/eris-ltd/decerver-modules/ipfs"
"github.com/eris-ltd/decerver-modules/legalmarkdown"
"github.com/eris-ltd/decerver-modules/monk"

)

var Logger *log.Logger = log.New(os.Stdout, "[main] ", log.Lshortfile)

func main() {


// Executable's directory
exeDir := cocoa.GetExecutableDir()

// CEF subprocesses.
cef.ExecuteProcess(nil)
// Initialize CEF.
settings := cef.Settings{}
settings.CachePath = exeDir + "/webcache" // Set to empty to disable
settings.LogSeverity = cef.LOGSEVERITY_DEFAULT // LOGSEVERITY_VERBOSE
settings.LogFile = exeDir + "/debug.log"
//settings.LocalesDirPath = cwd + "/cef.framework/Resources"
//settings.ResourcesDirPath = cwd + "/cef.framework/Resources"
cef.Initialize(settings)

// Create Window using Cocoa API.
cocoa.InitializeApp()
window := cocoa.CreateWindow("Snapthereum", 1024, 768)
cocoa.ConnectDestroySignal(window, OnDestroyWindow)
cocoa.ActivateApp()


startMonk()
// Create browser.
browserSettings := cef.BrowserSettings{}
url := "file://" + exeDir + "/example.html"
cef.CreateBrowser(window, browserSettings, url)



focusDapp()
// CEF loop and shutdown.
cef.RunMessageLoop()

cef.Shutdown()
os.Exit(0)
}

func startMonk(){
dc := decerver.NewDeCerver()
fm := ipfs.NewIpfsModule()
lmd := legalmarkdown.NewLmdModule()
mjs := monkjs.NewMonkModule()
//bci := blockchaininfo.NewBlkChainInfo()

dc.LoadModule(fm)
dc.LoadModule(lmd)
//dc.LoadModule(bci)
dc.LoadModule(mjs)

errInit := dc.Init()
if errInit != nil {
fmt.Printf("Module failed to initialize: %s. Shutting down.\n", errInit.Error())
os.Exit(1)
}

//Run decerver
errStart := dc.Start()
if errStart != nil {
fmt.Printf("Module failed to start: %s. Shutting down.\n", errStart.Error())
os.Exit(1)
}

}

func focusDapp(){
focus := exec.Command("curl","http://localhost:3000/admin/switch/monkadmin")
focus.Stdout = os.Stdout
focus.Stderr = os.Stderr
focus.Run()
}

func OnDestroyWindow() {
cef.QuitMessageLoop()
}

Czarek Tomczak

unread,
Feb 12, 2015, 6:38:10 AM2/12/15
to cef...@googlegroups.com, xilan...@gmail.com
Looks like your function focusDapp() hangs it, as this function never returns. Thus cef.RunMessageLoop() is never being called. Try running focusDapp in a separate thread / as a goroutine.

In CEF you can run message loop in three ways:
1) RunMessageLoop on main UI thread (as in example)
2) There is also DoMessageLoopWork that performs a single iteration of CEF message loop processing, this function could be called from a timer
3) Set CefSettings.multi_threaded_message_loop and CEF will run message loop in a separate thread. But then CEF UI thread is no more app main thread, so it needs to be ensured that CEF functions that are supposed to be called on UI thread (as stated in doc comments) are called on that thread. There are utility functions like CefPostTask that let you make calls on UI thread.

xilan...@gmail.com

unread,
Feb 12, 2015, 7:38:52 AM2/12/15
to cef...@googlegroups.com, xilan...@gmail.com
I solved the problem by using goroutine as you suggested. I have another question, how to enable the browser navigation menu ?

Czarek Tomczak

unread,
Feb 12, 2015, 8:05:10 AM2/12/15
to cef...@googlegroups.com, xilan...@gmail.com
There is only mouse context menu available with Back/Forward items. See the cefclient C++ example in upstream CEF that has a navigation bar which was implemented using OS dependent controls (WinApi / Cocoa / Gtk).

xilan...@gmail.com

unread,
Feb 12, 2015, 8:19:27 AM2/12/15
to cef...@googlegroups.com, xilan...@gmail.com
The contextual menu feature isn't working, if i right click the application crashes, here is the output :
get_context_menu_handler
2015-02-12 21:19:41.699 cef2go[3407:507] -[NSApplication isHandlingSendEvent]: unrecognized selector sent to instance 0x9222330
2015-02-12 21:19:41.700 cef2go[3407:507] -[NSApplication isHandlingSendEvent]: unrecognized selector sent to instance 0x9222330
2015-02-12 21:19:41.701 cef2go[3407:507] (
0 CoreFoundation 0x00007fff8785925c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff8ce13e75 objc_exception_throw + 43
2 CoreFoundation 0x00007fff8785c12d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00007fff877b7272 ___forwarding___ + 1010
4 CoreFoundation 0x00007fff877b6df8 _CF_forwarding_prep_0 + 120
5 Chromium Embedded Framework 0x0000000004cc91e2 cef_time_delta + 575330
6 Chromium Embedded Framework 0x0000000004c894b9 cef_time_delta + 313913
7 Chromium Embedded Framework 0x0000000004bfafe0 cef_zip_reader_create + 234368
8 Chromium Embedded Framework 0x0000000004fbbef2 catch_exception_raise + 2767618
9 Chromium Embedded Framework 0x0000000004f4ad99 catch_exception_raise + 2304425
10 Chromium Embedded Framework 0x0000000004f3e13e catch_exception_raise + 2252110
11 Chromium Embedded Framework 0x00000000050b7608 _CTFontManagerUnregisterFontForData + 115640
12 Chromium Embedded Framework 0x0000000004cce8db cef_time_delta + 597595
13 Chromium Embedded Framework 0x0000000004ccedb5 cef_time_delta + 598837
14 Chromium Embedded Framework 0x0000000004c8fb31 cef_time_delta + 340145
15 CoreFoundation 0x00007fff8778a5b1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
16 CoreFoundation 0x00007fff8777bc62 __CFRunLoopDoSources0 + 242
17 CoreFoundation 0x00007fff8777b3ef __CFRunLoopRun + 831
18 CoreFoundation 0x00007fff8777ae75 CFRunLoopRunSpecific + 309
19 HIToolbox 0x00007fff8d0c6a0d RunCurrentEventLoopInMode + 226
20 HIToolbox 0x00007fff8d0c67b7 ReceiveNextEventCommon + 479
21 HIToolbox 0x00007fff8d0c65bc _BlockUntilNextEventMatchingListInModeWithFilter + 65
22 AppKit 0x00007fff8b56024e _DPSNextEvent + 1434
23 AppKit 0x00007fff8b55f89b -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 122
24 AppKit 0x00007fff8b55399c -[NSApplication run] + 553
25 Chromium Embedded Framework 0x0000000004c90031 cef_time_delta + 341425
26 Chromium Embedded Framework 0x0000000004c8f93c cef_time_delta + 339644
27 Chromium Embedded Framework 0x0000000004cce1f0 cef_time_delta + 595824
28 Chromium Embedded Framework 0x0000000004ce729a cef_time_delta + 698394
29 Chromium Embedded Framework 0x0000000004ccdb8d cef_time_delta + 594189
30 Chromium Embedded Framework 0x0000000004be6182 cef_zip_reader_create + 148770
31 cef2go 0x0000000004037a51 runtime.asmcgocall + 97
)

Czarek Tomczak

unread,
Feb 12, 2015, 8:44:37 AM2/12/15
to cef...@googlegroups.com, xilan...@gmail.com
I've created Issue 24 with details on how to fix that. The Objective-C++ code that fixes issue is already available and basically just needs some pasting. Would you like to work on a pull request? See https://github.com/CzarekTomczak/cef2go/issues/24

xilan...@gmail.com

unread,
Feb 12, 2015, 10:45:10 AM2/12/15
to cef...@googlegroups.com, xilan...@gmail.com
I can try, where is the Objective-C++ code you talk about ?

xilan...@gmail.com

unread,
Feb 12, 2015, 1:26:13 PM2/12/15
to cef...@googlegroups.com, xilan...@gmail.com
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.

#import "util_mac.h"
#import <Cocoa/Cocoa.h>
#include <objc/runtime.h>
#include "include/cef_app.h"
#include "include/cef_application_mac.h"

namespace {

BOOL g_handling_send_event = false;

} // namespace

// Add the necessary CrAppControlProtocol
// functionality to NSApplication using categories and swizzling.
@interface NSApplication (CEFPythonApplication)

- (BOOL)isHandlingSendEvent;
- (void)setHandlingSendEvent:(BOOL)handlingSendEvent;
- (void)_swizzled_sendEvent:(NSEvent*)event;
- (void)_swizzled_terminate:(id)sender;

@end

@implementation NSApplication (CEFPythonApplication)

// This selector is called very early during the application initialization.
+ (void)load {
// Swap NSApplication::sendEvent with _swizzled_sendEvent.
Method original = class_getInstanceMethod(self, @selector(sendEvent));
Method swizzled =
class_getInstanceMethod(self, @selector(_swizzled_sendEvent));
method_exchangeImplementations(original, swizzled);

Method originalTerm = class_getInstanceMethod(self, @selector(terminate:));
Method swizzledTerm =
class_getInstanceMethod(self, @selector(_swizzled_terminate:));
method_exchangeImplementations(originalTerm, swizzledTerm);
}

- (BOOL)isHandlingSendEvent {
return g_handling_send_event;
}

- (void)setHandlingSendEvent:(BOOL)handlingSendEvent {
g_handling_send_event = handlingSendEvent;
}

- (void)_swizzled_sendEvent:(NSEvent*)event {
CefScopedSendingEvent sendingEventScoper;
// Calls NSApplication::sendEvent due to the swizzling.
[self _swizzled_sendEvent:event];
}

- (void)_swizzled_terminate:(id)sender {
[self _swizzled_terminate:sender];
}

@end

void MacInitialize() {
[NSApplication sharedApplication];
}

I suppose this is the C++ code, where does it need to be placed ?

Czarek Tomczak

unread,
Feb 12, 2015, 2:39:46 PM2/12/15
to cef...@googlegroups.com, xilan...@gmail.com
Everything was explained in the Issue that was created. I'm sorry but I can't help you any further.

xilan...@gmail.com

unread,
Feb 12, 2015, 4:18:46 PM2/12/15
to cef...@googlegroups.com, xilan...@gmail.com
I have tried paste the C++ code in src/cocoa/cocoa.go but the compilation fails. I don't have knowledge of C++ but it looks like the code needs to be slightly adapted. I need this issue to be addressed badly as i am using cef2go in a important project.

xilan...@gmail.com

unread,
Feb 12, 2015, 4:20:35 PM2/12/15
to cef...@googlegroups.com, xilan...@gmail.com
Specifically, i have pasted the C++ snippet inside the multiline comment containing other C++ as you instructed. There seem to be still Python dependant code in the snippet by the way.
Reply all
Reply to author
Forward
0 new messages