Coder Social home page Coder Social logo

Comments (12)

simonw avatar simonw commented on May 28, 2024

I tried adding this:

app.on("open-file", (event, path) => {
  console.log("open-file:", event, path)
});
// Directly before this line:
app.whenReady().then(() => {

But the icon in the Dock (at least when running in npm start dev mode) doesn't accept dropped files. There must be something special I need to do to tell macOS that this icon accepts dropped files, but I don't know what that is.

from datasette-app.

simonw avatar simonw commented on May 28, 2024

This might turn out to be part of the work on #54.

from datasette-app.

simonw avatar simonw commented on May 28, 2024

Maybe this will start working if I add the 'open-file' event handler and run a proper build of the application?

No, tried that and it didn't make the icon a drop target.

from datasette-app.

simonw avatar simonw commented on May 28, 2024

On Windows it sounds like dragging a file to the icon will work differently - it will call the application itself and pass that file path as process.argv argument: https://stackoverflow.com/questions/57900693/electron-drag-and-drop-a-file-on-the-icon

I only care about macOS for the moment though.

from datasette-app.

simonw avatar simonw commented on May 28, 2024

This might be the answer! electron/electron#4403 (comment)

Second, I added a CFBundleDocumentTypes section to Mac app's Info.plist and listed the acceptable file types. (See https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html )

from datasette-app.

simonw avatar simonw commented on May 28, 2024

From electron-userland/electron-builder#3732 (comment) it looks like you can add things to Info.plist by populating the "extendInfo" key used by electrion-builder: https://www.electron.build/configuration/mac

GitHub code search has some examples: https://github.com/search?l=JSON&q=extendInfo+CFBundleDocumentTypes&type=Code

These examples look useful:

from datasette-app.

simonw avatar simonw commented on May 28, 2024

This worked:

diff --git a/package.json b/package.json
index 9aa3db1..7ee237e 100644
--- a/package.json
+++ b/package.json
@@ -14,6 +14,16 @@
     "appId": "io.datasette.app",
     "mac": {
       "category": "public.app-category.developer-tools",
+      "extendInfo": {
+        "CFBundleDocumentTypes": [
+          {
+            "CFBundleTypeExtensions": [
+              "csv", "tsv", "db"
+            ],
+            "LSHandlerRank": "Alternate"
+          }
+        ]
+      },
       "hardenedRuntime" : true,
       "gatekeeperAssess": false,
       "entitlements": "build/entitlements.mac.plist",

from datasette-app.

simonw avatar simonw commented on May 28, 2024

From #88 (comment)

One remaining catch: once I add the CFBundleDocumentTypes configuration from #40 it will be possible to drag a CSV or DB file onto the Datasette icon to launch the application and fire the event.

But... the current event code assumes that the server has already started up:

datasette-app/main.js

Lines 822 to 860 in 78b86be

app.on("open-file", async (event, filepath) => {
const first16 = await firstBytes(filepath, 16);
if (first16.equals(SQLITE_HEADER)) {
const response = await datasette.apiRequest("/-/open-database-file", {
path: filepath,
});
const responseJson = await response.json();
if (!responseJson.ok) {
console.log(responseJson);
dialog.showMessageBox({
type: "error",
message: "Error opening database file",
detail: responseJson.error,
});
} else {
setTimeout(() => {
datasette.openPath(responseJson.path);
});
}
return;
}
const response = await datasette.apiRequest("/-/open-csv-file", {
path: filepath,
});
const responseJson = await response.json();
if (!responseJson.ok) {
console.log(responseJson);
dialog.showMessageBox({
type: "error",
message: "Error opening CSV file",
detail: responseJson.error,
});
} else {
pathToOpen = responseJson.path;
}
setTimeout(() => {
datasette.openPath(pathToOpen);
});
});

Need to handle the case where that event is fired before the server has had a chance to start.

from datasette-app.

simonw avatar simonw commented on May 28, 2024

After that last commit (and doing a proper application install) .db files on my computer are now showing the Datasette icon and double-clicking them opens them in Datasette!

(But only if Datasette is already open, I still need to fix it so the open-file event works if the server hasn't yet started).

Also .csv files are now showing Datasette in their "Open with" menu.

Open_With_and_contextMenu_and_tmp_and_Support__db_or__csv__tsv_files_being_dragged_and_dropped_onto_the_app__or_app_icon__ยท_Issue__40_ยท_simonw_datasette-app_and_Uniform_Type_Identifiers___Apple_Developer_Documentation_and_Library

from datasette-app.

mnckapilan avatar mnckapilan commented on May 28, 2024

Tangential to this issue but relevant to Windows (#71), Application Registration needs to be done on Windows in order for Datasette to be a viable .csv handler โ€“ and also for native recent files functionality in Windows Explorer to work.

Filed away for later when you look into Windows I guess.

from datasette-app.

simonw avatar simonw commented on May 28, 2024

Tested with this build https://github.com/simonw/datasette-app/actions/runs/1225528995 and while double-clicking a .db file or "Open in Datasette"-ing a CSV file did cause the Datasette application to open, the files were NOT attached once it had started up.

With Datasette open double-clicking or using "Open in Datasette" did work.

from datasette-app.

simonw avatar simonw commented on May 28, 2024

The build from https://github.com/simonw/datasette-app/actions/runs/1225558655 works!

from datasette-app.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.