-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
37 lines (26 loc) · 1.08 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
'use strict';
require('./scripts/set-permissions');
const tempWrite = require('temp-write');
const { exec } = require('child_process');
const isWayland = () => process.env.XDG_SESSION_TYPE === 'wayland';
const run = (cmd) => new Promise((done) => exec(cmd, { cwd: __dirname }, (...args) => done(args)));
const copyX11 = (file) => run(`xclip -sel clip -t image/png -i "${file}"`);
const copyWayland = (file) => run(`wl-copy < "${file}"`);
const copyLinux = (file) => (isWayland() ? copyWayland(file) : copyX11(file));
const copyOsx = (file) => run(`./scripts/osx-copy-image "${file}"`);
const copyWindows = (file) =>
run(
`powershell.exe -ExecutionPolicy Bypass Start-Process -NoNewWindow -FilePath ./scripts/file2clip.exe -ArgumentList "${file}"`
);
const copyImg = (img) => {
const file = Buffer.isBuffer(img) ? tempWrite.sync(img) : img;
return process.platform === 'win32'
? copyWindows(file)
: process.platform === 'darwin'
? copyOsx(file)
: copyLinux(file);
};
const ErrorCodes = {
COMMAND_NOT_FOUND: 127
};
module.exports = { copyImg, ErrorCodes, isWayland };