diff --git a/src/Util.cc b/src/Util.cc index ed18261..a2621f3 100644 --- a/src/Util.cc +++ b/src/Util.cc @@ -2,12 +2,23 @@ #include #include +bool _isWorker() { + // First thread to flip this bool is the main thread + static bool test{true}; + if(test) { + test = false; + return true; + } + return false; +} +thread_local bool isWorker{_isWorker()}; + EM_JS(void, _fireEv, (int index, int typeIdx, int content), { objs[index].dispatchEvent(new CustomEvent(events[typeIdx], { "detail" : content == 0 ? null : UTF8ToString(content) })); }) void fireEv(int index, int typeIdx, const char* content) { int contentAddr{reinterpret_cast(content)}; - if(emscripten_wasm_worker_self_id()) emscripten_wasm_worker_post_function_viii(0, _fireEv, index, typeIdx, contentAddr); + if(isWorker) emscripten_wasm_worker_post_function_viii(0, _fireEv, index, typeIdx, contentAddr); else _fireEv(index, typeIdx, contentAddr); } int untar(unsigned char* tar, int tarSize, const std::string& storepath) {