dorukkilitcioglu / persistd

Persist your virtual desktop over multiple reboots
GNU Affero General Public License v3.0
0 stars 0 forks source link

Add support for Google Chrome on Windows #5

Closed dorukkilitcioglu closed 6 years ago

dorukkilitcioglu commented 6 years ago

Google Chrome is my browser of choice. There needs to be support for the following actions:

There might also be a need to find the windows that are in the current desktop, but that is in the back-burner for now.

dorukkilitcioglu commented 6 years ago

Ideas

Open a new window with tabs

  1. Command line:
    • The --new-window option launches a new Chrome window. We might run into the same problem as with SublimeText #3.
  2. Write a Chrome Extension
    • You can launch the extension from the command-line, there is a flag called --app-id [APP ID] or even --load-extension. The second sounds more applicable.
    • In the extension, you can create a window, which gives you a window id so you can do stuff with it.
    • Then you can load in the tabs. Tab API.
      chrome.windows.getAll({populate:true}, getAllOpenWindows);
      function getAllOpenWindows(winData) {
      var tabs = [];
       for (var i in winData) {
           if (winData[i].focused === true) {
               var winTabs = winData[i].tabs;
               var totTabs = winTabs.length;
               for (var j=0; j<totTabs;j++) {
                   tabs.push(winTabs[j].url);
               }
          }
      }
      // do stuff with tabs
      }

      Get current tabs in windows inside a window

      I'm pretty sure an extension can do this too.

Close multiple windows

  1. Chrome Extension
    • Launch it from command line
      window = get(id)
      window.close()

Ideally, there are some weird CLI options, but after browsing them a bit that does not seem feasible. A very wild idea is to use communicate with Google API directly through Python, but that probably wouldn't be as flexible as a Chrome extension. Then again, I really don't want to build a Chrome extension...

dorukkilitcioglu commented 6 years ago

Opening a window with new tabs

So as expected, this was not a walk in the park. Or at least, it looks like the very simple way of just navigating to a desktop and opening up a new Chrome instance using the --new-window option seems to work. However the pid that returns is the process id of the tab that was created, and not of the window.

The reason seems to be that Chrome is technically a single "window", according to Windows. All "windowed" applications seem to be under a global explorer.exe according to Process Explorer, which reminds me of the days when explorer.exe used to crash so I had to restart it...

Anyways, under explorer.exe, there is a single chrome.exe level, and under that chrome.exe level are the tabs. There is a pid associated with that global chrome.exe, which can be moved using VirtualDesktop. However, what that global chrome.exe process points to changes dynamically when you browse through the tabs.

Specifically, that process points to the active tab in the active window. You can check it through the tasklist command.

# tasklist /nh /v /fi "imagename eq chrome.exe"

chrome.exe                    6160 Console                    1    231,736 K Running         DESKTOP-M0A49CK\doruk
                 0:25:20 chrome instant process - Google Search - Google Chrome
chrome.exe                    1260 Console                    1      5,848 K Running         DESKTOP-M0A49CK\doruk
                 0:00:00 N/A

The first entry, which contains a window name instead of N/A like all the others, is the global chrome.exe. Since its pid is 6160 in this case, I can move the process with pid=6160 to any VirtualDesktop. In practice, this only moves the active window, which is actually good for our use case.

What's bad is the fact that I don't think I can kill 6160 without taking down the whole thing, which brings us back to the whole Chrome extension thing.

dorukkilitcioglu commented 6 years ago

Huh, doing taskkill /PID 6160 actually worked. It only killed the active window, which is nice. However, I wouldn't want to leave that to change (what if the user looked at another window before calling close on a project?)

Anyways, for persisting the tabs, using an extension seems like the only way to go. What we need is a way of passing the name of the project to the said extension.

A couple of ideas:

dorukkilitcioglu commented 6 years ago

This is now implemented using the URL approach above. Also as mentioned above, simply doing a --new-window does open Chrome in the current virtual desktop, so it seems safe (for now).

I can probably move the window right after it is opened, since it will be the active window at that time. For that, I just need to find the pid (as above). If that becomes necessary, the issue can be opened again.