Skip to content
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

Yad gui speed improvements #2370

Merged
merged 12 commits into from
Aug 24, 2023
Merged

Yad gui speed improvements #2370

merged 12 commits into from
Aug 24, 2023

Conversation

Botspot
Copy link
Owner

@Botspot Botspot commented Jun 27, 2023

Avoids running a gui script subprocess every time a category or app is clicked. This has long been the behavior of the xlunch mode but I've had plans to extend it to yad. My past attempts failed but this time around it looks pretty solid. The interface is noticeably smoother and more snappy. I have not benchmarked it.
The other major benefit from these changes is that the app details window no longer vanishes when you try to drag it around the screen, resize it, or when you bring another window into focus. The details window will now close only when the user begins to do something else.

I have completed basic testing of the interface and have corrected all bugs found. It is entirely possible that edge cases have gone untested. While debugging, I found a lot of cases where a dialog (app list, details window, search) was supposed to close but no longer does, so I would not be too surprised if there are a couple more cases where that particular issue crops up.

I'm interested in feedback from @theofficialgman and maybe some testing from @Rak1ta if possible. (Rak1ta you seem to find a lot of bugs!)

@theofficialgman
Copy link
Collaborator

theofficialgman commented Jun 27, 2023

I am currently out of town. Will take a look mid/late next week.

Edit: marking as draft just so I don't accidentally click the merge button on mobile.

@theofficialgman theofficialgman marked this pull request as draft June 27, 2023 03:33
@Rak1ta
Copy link
Contributor

Rak1ta commented Jun 28, 2023

@Botspot i checked it all out. I noticed such a bug, I attach a video. If I write the text, you will not be able to understand me.
Pi-apps does not open programs while the update menu hangs, but captures all clicks. The same with the search.
I haven't found anything else.

Until updated:
https://github.com/Botspot/pi-apps/assets/88277343/2a1df3c4-b728-451d-be91-c25bb64af84a

After the update:
https://github.com/Botspot/pi-apps/assets/88277343/3620da3e-6514-4d69-8d15-6625754fb863
https://github.com/Botspot/pi-apps/assets/88277343/e058746b-c56f-41e5-a90a-f1b239b30730

@Rak1ta
Copy link
Contributor

Rak1ta commented Jun 28, 2023

Previously, an additional window was tied to the menu of the list of programs (although it was not taken into account that this could go outside the screen). Now as I understand it, you have made a reference to a certain place on the screen.
Is it possible to make it clear to all windows that they should be with the main menu? And taking into account the boundaries of the screen.

Безымянный

I write about the fact that I cannot control the position of the pop-up menu, which can close other windows.
Безымянный2

@Rak1ta
Copy link
Contributor

Rak1ta commented Jun 28, 2023

I managed to make two windows, but it's hard to replicate. I have an ssd, pi-apps manage to open and close all windows quickly.
Безымянный3

@Botspot
Copy link
Owner Author

Botspot commented Jun 28, 2023

The main issue uncovered by Rak1ta is that this implementation breaks how the get_positions function works. It needs the app list's window ID, provided by Yad's $YAD_XID variable that is sent to subprocesses. Now that yad is not starting each details window as a subprocess, the $YAD_XID variable remains unknown to the responses loop.

@Botspot
Copy link
Owner Author

Botspot commented Jun 28, 2023

Previously, an additional window was tied to the menu of the list of programs (although it was not taken into account that this could go outside the screen). Now as I understand it, you have made a reference to a certain place on the screen. Is it possible to make it clear to all windows that they should be with the main menu? And taking into account the boundaries of the screen.

I write about the fact that I cannot control the position of the pop-up menu, which can close other windows.

I have solved this issue. I am still looking for a way to prevent clicks from stacking up when clicking the Search button multiple times.

@theofficialgman
Copy link
Collaborator

theofficialgman commented Jul 3, 2023

@Botspot the major issue I forsee with this has to do with the update to this change. I have not tested these changes but I know that on update, the old GUI script will be running. Clicking on any app/settings/etc will call the gui script with the 3rd argument which functionality you have removed. this will either result in the wrong thing executing or nothing happening at all.

If we want to keep these changes, I think we will need to bump GUI_FORMAT_VERSION to 3 and provide a simple backwards compatibility layer if GUI_FORMAT_VERSION is currently set to <=2 (from the previously running GUI)

gui Outdated
if [ "$1" != 0 ];then
sleep 1.5
fi
pkill -P "$detailspid" 2>/dev/null
Copy link
Collaborator

@theofficialgman theofficialgman Jul 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this kills child PIDs of the parent process (the backgrounded details_window function)
this (I think) will kill any running or backgrounded terminal_manage calls spawned from that detailspid

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had not considered this possibility, but it does not seem to kill the terminal in practice. Not sure why not.

Copy link
Collaborator

@theofficialgman theofficialgman Jul 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in practice this is impossible to hit because in order to kill the detailspid that has the manage child process, you would need to click uninstall/install and another app name in the list at the exact same time.

Since the partent process (the details window) pid disappears once the yad details window closes on clicking the install/uninstall button, the kill_details pkill does nothing since that pid does not exist anymore (even though it has child PIDs, eg: the manage daemon, still active).

@Botspot
Copy link
Owner Author

Botspot commented Jul 3, 2023

@theofficialgman I think it was unintentional to push a snapdrop commit to this branch.

@theofficialgman
Copy link
Collaborator

theofficialgman commented Jul 3, 2023

@theofficialgman I think it was unintentional to push a snapdrop commit to this branch.

what snapdrop commit 😆 ? yes it was unintentional. thought I had master checked out

@Botspot
Copy link
Owner Author

Botspot commented Jul 3, 2023

@Botspot the major issue I forsee with this has to do with the update to this change. I have not tested these changes but I know that on update, the old GUI script will be running. Clicking on any app/settings/etc will call the gui script with the 3rd argument which functionality you have removed. this will either result in the wrong thing executing or nothing happening at all.

If we want to keep these changes, I think we will need to bump GUI_FORMAT_VERSION to 3 and provide a simple backwards compatibility layer if GUI_FORMAT_VERSION is currently set to <=2 (from the previously running GUI)

I just tried simulating an update from old to new. When I clicked on a category in the old gui, the new gui launched, covering the old with an identical app list. From there it worked fine. I'm inclined to leave it like this - it seems less unexpected than having updater kill the gui the way it did for GUI_FORMAT_VERSION=2.

@Botspot
Copy link
Owner Author

Botspot commented Jul 3, 2023

After thinking about it more, I went ahead with GUI_FORMAT_VERSION=3.

@Botspot Botspot marked this pull request as ready for review July 4, 2023 15:17
@theofficialgman
Copy link
Collaborator

theofficialgman commented Jul 6, 2023

After thinking about it more, I went ahead with GUI_FORMAT_VERSION=3.

hmm... the old GUI did not close. something changed to make this runonce not affective anymore. it did execute, but it didn't close the GUI

edit: yeah so the gui process gets killed (the script gui) but the yad window remains and is non-functional.

@theofficialgman theofficialgman marked this pull request as draft July 7, 2023 00:19
@theofficialgman
Copy link
Collaborator

I found a way to kill the yad windows (by using the knowledge we have of what arguments it was started with to get the pid from ps). this kills both the old gui script and the old yad window, however the new yad window pops up in the top left with a strange size and it closes after 30 seconds (the timer from the terminal-manage script that I guess the new gui got spawned as a child PID from)

@theofficialgman
Copy link
Collaborator

theofficialgman commented Jul 7, 2023

The benifits of these changes are clear. However I don't think there is a way to integrate them without asking the user to re-start pi-apps. We can do that easily by adding an if statement near the top of the GUI script that checks the GUI_FORMAT_VERSION that is currently set (so from the old gui it will be set to 2) and prompt the user to close and re-start pi-apps.

I tried setsid as well which creates a new session and that does resolve the close after 30 seconds issue. But the new problems are, it struggles to get the window size and doesn't seem to be able to launch its own terminal-run processes (so installing/uninstalling/etc all fail)

@theofficialgman
Copy link
Collaborator

theofficialgman commented Jul 7, 2023

also I'm going to be honest I don't see any speed differences with this PR compared to master (both are instant for me). If you see any that must mean you are pretty IO limited (on your storage). Since the only difference is this PR has all of the functions already in bash, while master has to read from storage (or a cache) and execute the gui script again.

@theofficialgman
Copy link
Collaborator

theofficialgman commented Jul 7, 2023

I've tried every iteration of forking (&), disown, nohup, setsid. everything either dies when the timer ends (still a child process) or fails to run terminal-run (like mentioned before because the process gets sent to init and that can't run basically any GUI stuff)

@theofficialgman
Copy link
Collaborator

outside of the outright removal of the mange, api, settings, or other fundamental scripts I see no reason why we would ever need to close or restart the GUI on the user ever again from now on. Since the GUI is a self contained running script now (it does not call itself) an update can not cause a break in functionality.

@theofficialgman theofficialgman marked this pull request as ready for review July 7, 2023 02:00
@theofficialgman
Copy link
Collaborator

theofficialgman commented Jul 7, 2023

I am still looking for a way to prevent clicks from stacking up when clicking the Search button multiple times.

@Botspot solved with 37fe8aa

@Botspot
Copy link
Owner Author

Botspot commented Jul 7, 2023

I am still looking for a way to prevent clicks from stacking up when clicking the Search button multiple times.

@Botspot solved with 37fe8aa

Well done. That is quite a genius way of doing it.

@Botspot
Copy link
Owner Author

Botspot commented Jul 7, 2023

I found a better way to transition to the new gui, hold on...

@theofficialgman
Copy link
Collaborator

Took a WHILE but I figured out the issue stems from the how yad is calling the commands. yad was directly calling another yad window before this PR. now the gui script is calling the secondary yad commands.

yad doesn't like that and won't raise if you do that.

the while loop is unnecessary, so I got rid of it :)

@theofficialgman
Copy link
Collaborator

theofficialgman commented Jul 7, 2023

ah crap this breaks killing the windows ofc...
will look into this tomorrow or later. probably going to have to change the detailspid to a pipe so that anything can read it.

@Botspot
Copy link
Owner Author

Botspot commented Jul 7, 2023

ah crap this breaks killing the windows ofc... will look into this tomorrow or later. probably going to have to change the detailspid to a pipe so that anything can read it.

It also introduces possible issues if multiple action threads are running concurrently. A while loop has more control over what is being run, and when, and can easily pass information forward from previous iterations. I'm hoping you can find another way to fix the window focusing issue that only seems to be happening on your system.
Have you tried experimenting with different --class and --name values?
Have you tried a more recent version of yad?

@theofficialgman
Copy link
Collaborator

theofficialgman commented Jul 7, 2023

I'm hoping you can find another way to fix the window focusing issue that only seems to be happening on your system.

Two systems. Different hardware. Different DEs. Different OS. Make sure to test yourself from the . desktop file since it doesn't happen when running pi-apps/gui from terminal.

I have yet to test on piOS buster/bullseye and will do tonight but I bet it happens there as well.

@theofficialgman
Copy link
Collaborator

theofficialgman commented Jul 7, 2023

@Botspot before the PR, before dc1fa20 , and after dc1fa20 on piOS bullseye with the default DE (64bit on a pi3), the updater window is not focused on launch. So this DE does not work regardless of what we do and always has this issue #2370 (comment)

@theofficialgman
Copy link
Collaborator

It also introduces possible issues if multiple action threads are running concurrently.

the gui functioned this way before the PR and there were no issues.

@theofficialgman
Copy link
Collaborator

theofficialgman commented Jul 7, 2023

@Botspot I have tested more systems. in summary

has the issue (updater not focused on launch) before the PR:
piOS 64bit bullseye with default DE, raspberry pi3

has the issue (updater not focused on launch) with the PR but before my fix (dc1fa20):
piOS 64bit bullseye with default DE, raspberry pi3
Ubuntu Bionic 18.04 (xorg) with mutter on Budgie DE (yad 0.38.2) Nintendo Switch
Ubuntu Focal 20.04 (xorg) with mutter on Ubuntu/Gnome DE (yad 0.40) Jetson Orin Nano Devkit
Ubuntu Lunar 23.04 (xorg) with kwin on KDE Plasma (yad 0.40) x86_64 Desktop PC

has the issue (updater not focused on launch) with the PR but after my fix (dc1fa20):
piOS 64bit bullseye with default DE, raspberry pi3

So my fix corrects all DEs (3) that have the bug as a result of this change and does nothing for the broken DEs (piOS) that never properly raised the window in the first place

@theofficialgman
Copy link
Collaborator

Have you tried experimenting with different --class and --name values?

no affect.

@theofficialgman
Copy link
Collaborator

ah crap this breaks killing the windows ofc... will look into this tomorrow or later. probably going to have to change the detailspid to a pipe so that anything can read it.

solved with 212e539

Botspot and others added 11 commits July 22, 2023 17:36
relaunch gui on update
if the user is running GUI_FORMAT_VERSION unset or 1, then they have the old updater that was not part of the manage daemon. so spawning a new GUI will not be part of the manage daemon and will succeed.

if the user is on GUI_FORMAT_VERSION 2 then the likelyhood that they have the new manage daemon updater is high so we can not simply respawn the GUI since it would be a child process of the manage daemon (and would be killed after the 30 second timeout). So we are forced to detect this and kill the GUI process and yad window and tell the user to restart pi-apps themselves.
`app_search_gui` and details_window are now part of the same `detailspid`. so kill_details to kill any GUI window spawned by these functions. In addition, `app_search_gui` is no longer blocking so `kill_details` can kill it if the user slicks search again.
yad now calls the `run_user_selection` function directly which allows for DEs to properly handle window focusing. also modify the parsing of yad output in app_search_gui since that strangely changed as a side affect of this change

workaround array variables not being passed to `bash -c`

bash -c specifically does not pass the contents of array variables. we use an array variable to set the default yadflags and it is the only variable that need to be set that we don't have access to inside bash -c

without this the spawned yad windows from app_search_gui, the details window, and updater will be missing the default flags

this also affects the settings yad GUI which spawns other scripts with bash -c, however all of those scripts don't rely on the yadflags (or re-set them internally) so the issue doesn't occur there
`kill_details` is a blocking function and part of it is sent to the background so as to not block further execution. To prevent accidentally reading the new detailspid that gets added to the list, make sure to read the current contents first in a blocking manner and then send the kill loop to the background.
@Botspot Botspot merged commit 7600ab2 into master Aug 24, 2023
@Botspot Botspot deleted the gui-speedup branch August 24, 2023 04:43
Botspot added a commit that referenced this pull request Aug 24, 2023
@theofficialgman
Copy link
Collaborator

theofficialgman commented Aug 24, 2023

@Botspot I really would have preferred that do a rebase. It's impossible to have issues if you do one since you get forced to resolve conflicts manually during the process. Using github actions with vscode as the editor its a breeze to resolve any

@Botspot
Copy link
Owner Author

Botspot commented Aug 24, 2023

@Botspot I really would have preferred that do a rebase. It's impossible to have issues if you do one since you get forced to resolve conflicts manually during the process. Using github actions with vscode as the editor its a breeze to resolve any

I actually was forced to resolve conflicts, but I did it incorrectly. I should have tested gui after resolving the conflicts, not before.

@theofficialgman
Copy link
Collaborator

theofficialgman commented Aug 24, 2023

fyi, the github actions check should have been an indication for you not to merge
shellcheck failed

you are welcome to add a rule to prevent merging unless all checks pass. I can't do that since I don't have permissions on this repo to edit settings. https://stackoverflow.com/questions/60776412/github-actions-is-there-a-way-to-make-it-mandatory-for-pull-request-to-merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants