1.0.0 • Published 6 months ago

electron-drop-text-on-dock v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

electron-drop-text-on-dock

Detect dropped text on the app's dock icon in Electron on macOS

See demo code

Installing

npm install electron-drop-text-on-dock

info.plist Requirement

You must include the NSServices entry in your app's info.plist.

If you're using Electron Forge, you can set this in your forge.config.js file:

module.exports = {
    packagerConfig: {
        extendInfo: {
            NSServices: [
                {
                    NSSendTypes: ["NSStringPboardType"],
                    NSMessage: "handleTextDropOnDock", // this value must be exact
                    NSMenuItem: {
                        default: "Open in Drop Text Demo", // edit this for your app
                    },
                },
            ],
        },
    },
    ...
};

API

onDropText(callback) (macOS only)

  • callback Function
    • text String - The dropped text.

Usage

In main process:

const { BrowserWindow } = require("electron");
const dropText = require("electron-drop-text-on-dock");

function createWindow() {
    const mainWindow = new BrowserWindow({
        height: 500,
        width: 800,
    });
    dropText.onDropText((text) => {
        console.log("text dropped:", text);
    });
    mainWindow.webContents.loadFile("index.html");
}

app.whenReady().then(() => createWindow());

How to Run Demo

After cloning this repository, run:

npm install
cd demo
npm install
npm run make

License

MIT License