-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mw.emit() bug? #17
Comments
I think I figured out a way around this... maybe I was just using it improperly before. In the new window I send the main window a timestamp, then listen for a response named with that timestamp like this: var timestamp = Date.now();
mw.emit("addswatchwindowready", timestamp);
mw.on(timestamp, function(message) {
console.log("message recieved");
console.log(message)
}); and in my main window something like this: mw.on("addswatchwindowready", function(timestamp) {
console.log(timestamp);
setTimeout(function(){
mw.emit(timestamp, JSON.stringify(myobjecttosend));
},500);
}); That looks to be working good, if a bit weird. Could the open window function have a callback or "loaded" event sent back to the opener window instead? That might be a better way of knowing when the window is open. |
Got your point. |
I too ran into the problem with using the emit/on with the new window issue. Ive narrowed the problem down to the way the new window is spawned. I see two possible solutions Im trying a few things and well see if i can come up with a proper solution. |
@codewise-nicolas: Actually we still want to implement #18 to allow multiple new windows. |
Fixed part of the problem, it was that the subscribeMessage() call was incorrectly setting up the messageSubscribers dictionary with an NSArray (which you cant add objects too after the fact). This meant that the old/closed windows registered subscriber was the only one being added and called. Changed the code so that it creates a NSMutableArray instead. Works great. There is still a slight problem that when a window is closed, there is still subscribers in the array - so those need to be removed when the window is closed. |
Hi @acketon, can you confirm that this issue was fixed? |
I was testing the mw.on() and mw.emit() functions. I wanted the new window to send a message back to the main menubar window and the main window to send a message back to the new window. I was going to use this to send data to the new window after it is opened.
The first message works good, just like your example. if I do this:
mw.emit("replymessage", "I can't Dave");
does not work unless I put it in a setTimeout of about half a second... Then it works.But after that I ran into a problem. If I close the New Window and then reopen it and run everything a second time, I get an error in the main window when trying to call mw.emit("replymessage", "I can't Dave") a second time. I removed the setTimeout stuff and just manually ran mw.emit() in the console and it also gave the error so it seems to be that mw.emit() can't be called to send a message to the new window anytime AFTER the first time the window is opened and closed.
Does that description make sense?
The text was updated successfully, but these errors were encountered: