-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
68 lines (60 loc) · 1.56 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const electron = require('electron')
const { BrowserWindow, ipcMain: ipc } = electron
const { join: pathJoin } = require('path')
const draggableFile = async (file, { title }) => {
const { bounds } = electron.screen.getPrimaryDisplay()
const height = 200
const width = 300
let win = new BrowserWindow({
width,
height,
x: bounds.width / 2 + bounds.width / 4 - width / 2,
y: bounds.width.height / 2 - height / 2,
alwaysOnTop: true,
acceptFirstMouse: true,
webPreferences: {
webSecurity: false,
},
enableLargerThanScreen: true,
movable: true,
title,
resizable: true,
backgroundColor: 'black',
show: false,
})
win.setAlwaysOnTop(true, 'screen-saver')
win.loadURL(`file://${__dirname}/index.html#${encodeURIComponent(file)}`)
win.once('ready-to-show', () => {
win.show()
})
ipc.once('size', (event, { width, height }) => {
const padding = 15
if (win) win.setSize(width, height + padding, true)
})
ipc.once('ondragstart', event => {
win.capturePage(icon => {
win.close()
event.sender.startDrag({
file,
icon,
})
})
})
win.once('closed', () => {
ipc.removeAllListeners('ondragstart')
ipc.removeAllListeners('size')
win = null
})
}
const action = async context => {
const file = await context.filePath()
const title = context.defaultFileName
draggableFile(file, { title })
}
const draggable = {
title: 'Drag and Drop',
formats: ['gif', 'mp4', 'webm', 'apng'],
action,
}
exports.action = action
exports.shareServices = [draggable]