-
-
Notifications
You must be signed in to change notification settings - Fork 560
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
Fix preferences opening on startup #1552
Fix preferences opening on startup #1552
Conversation
Hi @meszarosdezso. I think this is not a good way to go about fixing this. In this case you stop preferences window being open on startup which is needed in order to set some settings (mute notifications). By doing this, the user defined settings are not respected since we don't set them, we just avoid opening preference window all together. I'd rather resolve the root of the problem which i think is that preferences window is not being closed at all. Check Line 280 in 0e5175b
It seems that in the old design, preferences window would be closed automatically or some thing like that since we don't call |
Thanks, I'll take a look later today! |
Okay, so after some professional I couldn't find where the props for |
This seems to happen because when { isNewDesign } where isNewDesing holds a boolean value. On line 493, config value is passed as a parameter when an object should be passed: { isNewDesign, defaultStatus: config.get('notificationsMuted') }
const isNewDesign = await ipcMain.callRenderer<undefined, boolean>(mainWindow, 'check-new-ui'); and it should be added on line 382 (after createMainWindow call) and updateAppMenu call should be moved below isNewDesign since the real value could be passed then. The final result should look something like this: await Promise.all([ensureOnline(), app.whenReady()]);
mainWindow = createMainWindow();
const isNewDesign = await ipcMain.callRenderer<undefined, boolean>(mainWindow, 'check-new-ui');
await updateAppMenu({isNewDesign}); In that case I think there is no need to have the same code on 445 since we could use the variable from outside of The thing that actually makes all of this work look quite pointless (but I hope you'll go through with this pr) is that the
To sum everything up, wrong parameters are being passed in index.ts which can be fixed by getting information about new design earlier in the code and passing it to renderer calls. Options for muting notifications should not be visible on new design. Preferences window can be fixed by adding a utility class for hiding the window if class is added to body tag #1552 (comment). Also there is no need to execute the logic in This is quite a long comment so feel free to ask for clarifications if there is any need. Edit: |
await Promise.all([ensureOnline(), app.whenReady()]);
mainWindow = createMainWindow();
const isNewDesign = await ipcMain.callRenderer<undefined, boolean>(mainWindow, 'check-new-ui');
await updateAppMenu({isNewDesign}); Calling 'check-new-ui' there never resolves the promise, making the app stuck before even opening the window. /: Putting that call right before calling After opening it manually from the menu the checkbox is there.
true, lol.
I don't see any errors related to
The preferences window is now hidden automatically, would this make it not even flash for a second? Where should I add/remove the class to/from the body? EDIT: I guess I misunderstood your comment, I see now that the updated async function updateDoNotDisturb(isNewDesign: boolean): Promise<void> {
const shouldClosePreferences = await openHiddenPreferences(isNewDesign);
if (shouldClosePreferences) {
closePreferences(isNewDesign);
}
if (!isNewDesign) {
const soundsCheckbox = document.querySelector<HTMLInputElement>(messengerSoundsSelector)!;
toggleSounds(await ipc.callMain('update-dnd-mode', soundsCheckbox.checked));
}
} |
Okay, now I think we've got the best solution. We should leave the Line 396 in 0e5175b
This way we will check for new ui on each button click which is not ideal but it is the cleanest solution. If this is what you meant by adding
Here we have two problems.
That is basically it, except in order for this to work on old design, the logic must be between opening and closing of preferences window. Just move
I'm not really sure what you mean by preferences window is now hidden automatically. You'll need to first add that utility class to /* A utility class for temporarily hiding preferences window */
html.hide-preferences-window [data-pagelet=root] > div > div:last-child {
display: none;
} This will hide the preferences window and overlay when |
This still does not work, as I mentioned above, that call for some reason never resolves, and the app doesn't start (the window is not appearing, terminal is stuck at
Oh, of course, that makes sense 😅
It opens for a split second, and disappears. The fix with the utility class works, tho I still see only the opaque white overlay flashing for a bit. |
447e620
to
3d4dc6b
Compare
I'd just like to clarify this. I meant to revert to what is being done on main branch regarding index.ts, except with passing correct parameters to setMuteNotifications. Caprine should open when calling
I guess that's not what we want since preference window should not be shown at all. I'll check that out later today. |
I guess we need to target the element's parent element. afaik, there's no way to do that with css, I guess something like document.querySelector('[data-pagelet=root] > div > div:last-child').parentElement.style.display = 'none'; |
That line actually hides all elements in the app since parent element of overlay is the wrapper around the whole ui. The utility class should be doing all the work but for some reason it showing the overlay for a split second. I've added a review on that par since I've just now realized that order of the calls was wrong. You should first close the preferences and only then remove the utility class. What might also make a problem is that once close preferences action is done (clicking the close button) there is some time between click() function returning and preferences actually closing. You'll need to track if preference window is actually closed and only then remove the utility class. Here is how it is done with a mutation observer on another element. Line 176 in 0e5175b
Instead of observing the sidebar, you should observe the wrapper for overlay |
That was it! Now it seems to work just fine, thanks! |
Check new ui call now returns a boolean instead of an element. There is no need to receive an element and convert it's value into boolean now.
An error was thrown every time Caprine starts because JS couldn't get property 'checked' of object null since notification checkbox was not found in preferences window. This avoids it until notifications are implemented.
There is no need to cast a boolean to boolean :)
This look good to me. I've just refactored a few things. Thanks for the fix @meszarosdezso! Sorry for all the back and forth about tiny bugs 😅. |
No probs, thanks for your help, I way too underestimated the problem, but it was fun to work on this and get to know the internals better(: Sorry for the unnecessary Boolean castings I saw it somewhere in the code, thought it's for typescript :p |
This PR adds a boolean flag for the
updateDoNotDisturb
andopenHiddenPreferences
functions, to prevent the preferences window from opening on startup. I know its not the best solution, but gets the job done for now(:fixes #1547