{"action":"created","issue":{"url":"https://api.github.com/repos/getlantern/systray/issues/5","labels_url":"https://api.github.com/repos/getlantern/systray/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/getlantern/systray/issues/5/comments","events_url":"https://api.github.com/repos/getlantern/systray/issues/5/events","html_url":"https://github.com/getlantern/systray/issues/5","id":102756363,"number":5,"title":"Run(...)/nativeloop blocks forever on all platforms","user":{"login":"thomasf","id":330847,"avatar_url":"https://avatars.githubusercontent.com/u/330847?v=3","gravatar_id":"","url":"https://api.github.com/users/thomasf","html_url":"https://github.com/thomasf","followers_url":"https://api.github.com/users/thomasf/followers","following_url":"https://api.github.com/users/thomasf/following{/other_user}","gists_url":"https://api.github.com/users/thomasf/gists{/gist_id}","starred_url":"https://api.github.com/users/thomasf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thomasf/subscriptions","organizations_url":"https://api.github.com/users/thomasf/orgs","repos_url":"https://api.github.com/users/thomasf/repos","events_url":"https://api.github.com/users/thomasf/events{/privacy}","received_events_url":"https://api.github.com/users/thomasf/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-08-24T10:04:58Z","updated_at":"2015-08-27T11:11:32Z","closed_at":null,"body":"None of the platform specific implementations obey this description since they all block forever:\r\n\r\n```\r\n// Run initializes GUI and starts the event loop, then invokes the onReady\r\n// callback.\r\n// It blocks until systray.Quit() is called.\r\n// Should be called at the very beginning of main() to lock at main thread.\r\nfunc Run(onReady func()) {}\r\n```\r\n\r\n\r\nI'm not sure if some or all of these just moves the race condition I'm trying to avoid (program exists before teardown of native GUI finishes) but It works much better now... I'm in a bit of a hurry so I will recheck these solutions at a later point.\r\n\r\n### possible gtk solution\r\n\r\nAdding this call to the `do_quit` function:\r\n```\r\n    gtk_main_quit();\r\n```\r\n\r\n\r\n### possible objc solution\r\n\r\n\r\nAdding this call to the `quit` function:\r\n\r\n```objc\r\n  [NSApp terminate:self];\r\n```\r\n\r\n\r\n### possible windows solution\r\n\r\nSomething like this for windows, maybe, I just did it as fast as I could and I don't speak winapi at all.\r\n\r\n```c\r\n#define WM_DONE (WM_USER + 2)\r\n\r\n\r\nint nativeLoop(void) {\r\n    HINSTANCE hInstance = GetModuleHandle(NULL);\r\n    TCHAR* szWindowClass = TEXT(\"SystrayClass\");\r\n    MSG msg;\r\n    MyRegisterClass(hInstance, szWindowClass);\r\n    hWnd = InitInstance(hInstance, FALSE, szWindowClass); // Don't show window\r\n    if (!hWnd) {\r\n        return EXIT_FAILURE;\r\n    }\r\n    if (!createMenu() || !addNotifyIcon()) {\r\n        return EXIT_FAILURE;\r\n    }\r\n    systray_ready(0);\r\n\r\n    while (GetMessage(&msg, NULL, 0, 0)) {\r\n        TranslateMessage(&msg);\r\n        if (msg.message == WM_DONE) {\r\n          return EXIT_SUCCESS;\r\n        };\r\n        DispatchMessage(&msg);\r\n    }\r\n    return EXIT_SUCCESS;\r\n}\r\n\r\nvoid quit() {\r\n    Shell_NotifyIcon(NIM_DELETE, &nid);\r\n    PostMessage (hWnd, WM_DONE, 0,  0);\r\n\r\n}\r\n\r\n\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/getlantern/systray/issues/comments/135388087","html_url":"https://github.com/getlantern/systray/issues/5#issuecomment-135388087","issue_url":"https://api.github.com/repos/getlantern/systray/issues/5","id":135388087,"user":{"login":"thomasf","id":330847,"avatar_url":"https://avatars.githubusercontent.com/u/330847?v=3","gravatar_id":"","url":"https://api.github.com/users/thomasf","html_url":"https://github.com/thomasf","followers_url":"https://api.github.com/users/thomasf/followers","following_url":"https://api.github.com/users/thomasf/following{/other_user}","gists_url":"https://api.github.com/users/thomasf/gists{/gist_id}","starred_url":"https://api.github.com/users/thomasf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thomasf/subscriptions","organizations_url":"https://api.github.com/users/thomasf/orgs","repos_url":"https://api.github.com/users/thomasf/repos","events_url":"https://api.github.com/users/thomasf/events{/privacy}","received_events_url":"https://api.github.com/users/thomasf/received_events","type":"User","site_admin":false},"created_at":"2015-08-27T11:11:32Z","updated_at":"2015-08-27T11:11:32Z","body":"A large part of my recent \"race condition\" problems was  a go 1.5 cgo stack frame which caused lot's of issues  here and there..(  https://github.com/golang/go/issues/12238 )\r\n\r\nThe osx code above just exits the application immediately but the other two OS solutions seems to work."}}