gingko / client

Gingko Writer. Tree-based writing software, written in Elm.
https://gingkowriter.com
MIT License
361 stars 49 forks source link

With Gingko open, double-clicking `*.gko` files gives the Home Screen instead of opening the file #213

Open am01264 opened 3 years ago

am01264 commented 3 years ago

Describe the bug When Gingko is already open, and I open a *.gko file, it opens a new window with the home screen instead of the intended file.

To Reproduce Steps to reproduce the behavior:

  1. Open a first file in Gingko
  2. Open your chosen file explorer
  3. Attempt to open a second file in Gingko (in your file explorer)
  4. New Gingko window appears with "Home Screen" instead of file

Expected behavior I would expect a second window to appear with the second file.

Screenshots Home Screen shown on second file open 20201228 Gingko Multiple Open Bug

Software info:

Additional context I've not had a chance to test this solution myself, but it might be to do with how app.on("second-instance", ...) is handled.

https://github.com/gingko/client/blob/ba6e49edc0948c14e453b20036b75bf88dc42af1/src/electron/main.js#L39-L57

Line 47 checks if the first CLI argument commandLine[0] ends with "electron" in the name. This is true if you use npm run electron so likely it'll work in testing & debugging. However, on a windows system the first argument is "C:...\Gingko.exe". The means the code to open another document is never opened

image

A hacky solution might be as follows, however it doesn't account for Mac or Linux users.

   app.on("second-instance", (event, commandLine) => { 
     if ( 
       commandLine[0].endsWith("electron") && 
       typeof commandLine[2] == "string" 
     ) { 
       openDocument(commandLine[2]); 

     // new part
     } else if (
       commandLine[0].toLowerCase().endsWith("gingko.exe") &&
       typeof commandLine[1] == "string"
     ) {
       openDocument(commandLine[1]);
     // end new part

     } else if (winHome) { 
       winHome.show(); 
     } else { 
       createHomeWindow(); 
     } 
   });