Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/davidcann/electron-drop-text-on-dock
Detect dropped text on the app's dock icon in Electron on macOS
https://github.com/davidcann/electron-drop-text-on-dock
drag-and-drop electron macos
Last synced: 1 day ago
JSON representation
Detect dropped text on the app's dock icon in Electron on macOS
- Host: GitHub
- URL: https://github.com/davidcann/electron-drop-text-on-dock
- Owner: davidcann
- License: mit
- Created: 2023-11-04T01:05:00.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2023-11-04T01:34:46.000Z (11 months ago)
- Last Synced: 2024-04-26T12:22:45.851Z (5 months ago)
- Topics: drag-and-drop, electron, macos
- Language: Objective-C++
- Homepage:
- Size: 7.81 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# electron-drop-text-on-dock
> Detect dropped text on the app's dock icon in [Electron](https://electronjs.org/) on macOS
[See demo code](demo)
## 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](https://github.com/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 { onDropText } = require("electron-drop-text-on-dock");onDropText((text) => {
console.log("text dropped:", text);
});function createWindow() {
const mainWindow = new BrowserWindow({
height: 500,
width: 800,
});
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