Files
jsowell-charger-web/jsowell-ui/node_modules/clipboardy/lib/linux.js
Lemon f5e6e29f00 Merge branch 'dev-zza' into dev
# Conflicts:
#	jsowell-ui/.env.development
#	jsowell-ui/.env.staging
#	jsowell-ui/bin/build-sit.bat
#	jsowell-ui/bin/build.bat
#	jsowell-ui/src/api/adapayMember/adapayMember.js
#	jsowell-ui/src/api/pile/merchant.js
#	jsowell-ui/src/router/index.js
#	jsowell-ui/src/views/financial/financeDetail.vue
#	jsowell-ui/src/views/financial/merchant.vue
#	jsowell-ui/src/views/homeIndex/homeIndex.vue
#	jsowell-ui/src/views/login.vue
#	jsowell-ui/src/views/pile/basic/detail.vue
#	jsowell-ui/src/views/pile/station/components/SiteInfo.vue
#	jsowell-ui/src/views/pile/station/detail.vue
#	jsowell-ui/src/views/pile/station/orderReport.vue
2025-06-03 14:26:37 +08:00

58 lines
1.5 KiB
JavaScript

'use strict';
const path = require('path');
const execa = require('execa');
const xsel = 'xsel';
const xselFallback = path.join(__dirname, '../fallbacks/linux/xsel');
const copyArguments = ['--clipboard', '--input'];
const pasteArguments = ['--clipboard', '--output'];
const makeError = (xselError, fallbackError) => {
let error;
if (xselError.code === 'ENOENT') {
error = new Error('Couldn\'t find the `xsel` binary and fallback didn\'t work. On Debian/Ubuntu you can install xsel with: sudo apt install xsel');
} else {
error = new Error('Both xsel and fallback failed');
error.xselError = xselError;
}
error.fallbackError = fallbackError;
return error;
};
const xselWithFallback = async (argumentList, options) => {
try {
return await execa.stdout(xsel, argumentList, options);
} catch (xselError) {
try {
return await execa.stdout(xselFallback, argumentList, options);
} catch (fallbackError) {
throw makeError(xselError, fallbackError);
}
}
};
const xselWithFallbackSync = (argumentList, options) => {
try {
return execa.sync(xsel, argumentList, options);
} catch (xselError) {
try {
return execa.sync(xselFallback, argumentList, options);
} catch (fallbackError) {
throw makeError(xselError, fallbackError);
}
}
};
module.exports = {
copy: async options => {
await xselWithFallback(copyArguments, options);
},
copySync: options => {
xselWithFallbackSync(copyArguments, options);
},
paste: options => xselWithFallback(pasteArguments, options),
pasteSync: options => xselWithFallbackSync(pasteArguments, options)
};