electron-drop-text-on-dock
v1.0.0
Published
Detect dropped text on the app's dock icon in Electron on macOS
Downloads
1
Maintainers
Readme
electron-drop-text-on-dock
Detect dropped text on the app's dock icon in Electron on macOS
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
Functiontext
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