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

Research "setRepresentedFilename" API #57

Closed
simonw opened this issue Sep 7, 2021 · 2 comments
Closed

Research "setRepresentedFilename" API #57

simonw opened this issue Sep 7, 2021 · 2 comments
Labels
electron-wrapper Features that go in the Node.js/Electron code research

Comments

@simonw
Copy link
Owner

simonw commented Sep 7, 2021

Described in https://www.electronjs.org/docs/latest/tutorial/represented-file - can be used to tell Electron that a specific window corresponds to a specific file on disk.

@simonw simonw added electron-wrapper Features that go in the Node.js/Electron code research labels Sep 7, 2021
@simonw
Copy link
Owner Author

simonw commented Sep 7, 2021

I tried it out like this (against https://github.com/simonw/datasette-app/tree/0e4436bf8222725ac26b6c32ae007d5bc36ab392):

diff --git a/main.js b/main.js
index cd26592..ea6b370 100644
--- a/main.js
+++ b/main.js
@@ -203,6 +203,9 @@ class DatasetteServer {
         newWindow.show();
       });
       configureWindow(newWindow);
+      if (opts.representedFilename) {
+        newWindow.setRepresentedFilename(opts.representedFilename);
+      }
     }
   }
 }
@@ -386,6 +389,7 @@ async function initializeApp() {
             if (!selectedFiles) {
               return;
             }
+            let filepath2 = null;
             let pathToOpen = null;
             for (const filepath of selectedFiles) {
               const response = await datasette.apiRequest("/-/open-csv-file", {
@@ -401,10 +405,13 @@ async function initializeApp() {
                 });
               } else {
                 pathToOpen = responseJson.path;
+                filepath2 = filepath;
               }
             }
             setTimeout(() => {
-              datasette.openPath(pathToOpen);
+              datasette.openPath(pathToOpen, {
+                representedFilename: filepath2
+              });
             }, 500);
           },
         },

@simonw
Copy link
Owner Author

simonw commented Sep 7, 2021

If I do decide to use this, one trick I'll have to solve is that if the user navigates to a different page the title bar needs to be updated to reflect that the new page they are viewing doesn't represent that specific file any more:

setRepresentedFilename.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
electron-wrapper Features that go in the Node.js/Electron code research
Projects
None yet
Development

No branches or pull requests

1 participant