Skip to content

Commit

Permalink
Add a 0.5 second sleep and that appears to fix the browser launch issue
Browse files Browse the repository at this point in the history
  • Loading branch information
quirkey committed Aug 27, 2014
1 parent 85e046f commit 69e8ec0
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 62 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
pkg/
.DS_Store
test.log
debug.log
*webcache*
cef2go
main_linux
21 changes: 5 additions & 16 deletions cef/cef.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import "C"
import (
"log"
"os"
"time"
"unsafe"
)

Expand Down Expand Up @@ -99,16 +100,7 @@ func _InitializeGlobalCStructures() {
C.initialize_client_handler(_ClientHandler)
}

var args []string

// Appends args that get attached to each subprocess. Must be
// called before ExecuteProcess
func AppendArgToSubprocess(arg string) {
args = append(args, arg)
}

func ExecuteProcess(appHandle unsafe.Pointer) int {
os.Args = append(os.Args, args...)
Logger.Println("ExecuteProcess, args=", os.Args)

_InitializeGlobalCStructures()
Expand Down Expand Up @@ -165,8 +157,10 @@ func Initialize(settings Settings) int {

globalLifespanHandler = &LifeSpanHandler{make(chan *Browser)}
ret := C.cef_initialize(_MainArgs, settings.ToCStruct(), _AppHandler, _SandboxInfo)
Logger.Println("Waiting for onContextInitialized")
WaitForContextInitialized()
// Sleep for 500ms to let cef _really_ initialize
// https://code.google.com/p/cefpython/issues/detail?id=131#c2
time.Sleep(500 * time.Millisecond)

return int(ret)
}

Expand All @@ -186,11 +180,6 @@ func Shutdown() {
// OFF: cef_sandbox_info_destroy(_SandboxInfo)
}

func WaitForContextInitialized() {
Logger.Println("WaitForContextInitialized")
// <-contextInitialized
}

func OnUIThread() bool {
return C.cef_currently_on(C.TID_UI) == 1
}
6 changes: 0 additions & 6 deletions cef/cef_callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ package cef
*/
import "C"

//export go_OnContextInitialized
func go_OnContextInitialized() {
Logger.Println("go_OnContextInitialized")
contextInitialized <- 1
}

//export go_OnAfterCreated
func go_OnAfterCreated(self *C.struct__cef_life_span_handler_t, browser *C.cef_browser_t) {
if globalLifespanHandler != nil {
Expand Down
2 changes: 1 addition & 1 deletion cef/cef_life_span_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (l *LifeSpanHandler) RegisterAndWaitForBrowser(url string) (browser *Browse
case b := <-l.browser:
return b, nil
// browser couldnt be created
case <-time.After(10 * time.Second):
case <-time.After(5 * time.Second):
return nil, errors.New("Timedout waiting for browser to be created")
}
}
Expand Down
32 changes: 0 additions & 32 deletions debug.log

This file was deleted.

1 change: 0 additions & 1 deletion lib/handlers/cef_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ void CEF_CALLBACK on_register_custom_schemes(

void CEF_CALLBACK on_context_initialized(
struct _cef_browser_process_handler_t* self) {
go_OnContextInitialized();
DEBUG_CALLBACK("on_context_initialized!\n");
}

Expand Down
17 changes: 11 additions & 6 deletions main_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,25 @@ import (
)

func main() {
cwd, _ := os.Getwd()
var releasePath = os.Getenv("RELEASE_PATH")
if releasePath == "" {
releasePath = cwd
}
fmt.Printf("RELEASE PATH %s", releasePath)
// TODO: It should be executable's directory use
// rather than working directory.
cwd, _ := os.Getwd()
logger := log.New(os.Stdout, fmt.Sprintf("[%d] ", os.Getpid()), log.Lshortfile)
cef.SetLogger(logger)
// CEF subprocesses.
cef.ExecuteProcess(nil)

// CEF initialize.
settings := cef.Settings{}
settings.ResourcesDirPath = cwd + "/Release"
settings.LocalesDirPath = cwd + "/Release/locales"
settings.CachePath = cwd + "/webcache" // Set to empty to disable
settings.LogSeverity = cef.LOGSEVERITY_VERBOSE // LOGSEVERITY_VERBOSE
settings.ResourcesDirPath = releasePath
settings.LocalesDirPath = releasePath + "/locales"
settings.CachePath = cwd + "/webcache" // Set to empty to disable
settings.LogSeverity = cef.LOGSEVERITY_INFO // LOGSEVERITY_VERBOSE
settings.LogFile = cwd + "/debug.log"
settings.RemoteDebuggingPort = 7000
cef.Initialize(settings)
Expand All @@ -39,7 +44,7 @@ func main() {

// Create browser.
browserSettings := &cef.BrowserSettings{}
url := "file://" + cwd + "/example.html"
url := "file://" + cwd + "/Release/example.html"
go func() {
browser := cef.CreateBrowser(window, browserSettings, url)
browser.ExecuteJavaScript("console.log('we outchea');", "sup.js", 1)
Expand Down

0 comments on commit 69e8ec0

Please sign in to comment.