2023-07-21 19:13:51 +08:00
|
|
|
/**
|
|
|
|
* {}
|
|
|
|
* @author yutent<yutent.io@gmail.com>
|
|
|
|
* @date 2023/07/20 14:19:13
|
|
|
|
*/
|
|
|
|
|
|
|
|
import 'es.shim'
|
|
|
|
import { $, bind } from 'wkit'
|
|
|
|
|
2023-07-25 18:53:52 +08:00
|
|
|
async function test1() {
|
|
|
|
let txt = await native.clipboard.readText()
|
|
|
|
$('input').value = txt
|
2023-07-21 19:13:51 +08:00
|
|
|
}
|
|
|
|
|
2023-07-25 18:53:52 +08:00
|
|
|
async function test2() {
|
|
|
|
native.clipboard.writeText('这是一段写进剪切板的文本')
|
|
|
|
// native.handler('blabla', { foo: 'bar' }).then(r => {
|
|
|
|
// $('#output').innerHTML = JSON.stringify(r)
|
|
|
|
// })
|
2023-07-21 19:13:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bind($('.btn1'), 'click', test1)
|
|
|
|
bind($('.btn2'), 'click', test2)
|
2023-07-25 18:53:52 +08:00
|
|
|
bind($('.btn3'), 'click', async function () {
|
|
|
|
// window.open('about:blank')
|
|
|
|
// let img = await native.clipboard.writeImage('/code/gtk/webkit/debian.png')
|
|
|
|
let img = await native.image('/code/gtk/webkit/debian.png')
|
|
|
|
native.clipboard.writeImage(img)
|
|
|
|
// native.clipboard.writeImage('/code/gtk/webkit/debian.png')
|
|
|
|
try {
|
|
|
|
$('img').src = URL.createObjectURL(await img.export())
|
|
|
|
} catch (err) {
|
|
|
|
alert(err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
bind($('.btn4'), 'click', async function () {
|
|
|
|
native.quit()
|
|
|
|
// native.clipboard.clear()
|
|
|
|
})
|
|
|
|
|
2023-07-26 17:55:29 +08:00
|
|
|
bind($('.btn5'), 'click', async function () {
|
|
|
|
native.tray()
|
|
|
|
})
|
|
|
|
|
|
|
|
bind($('.btn6'), 'click', async function () {
|
2023-07-27 20:25:43 +08:00
|
|
|
// console.log(await native.globalShortcut.enabled)
|
|
|
|
|
|
|
|
native.globalShortcut.register('<Ctrl>2', function () {
|
|
|
|
alert('<Ctrl>2被绑定了')
|
|
|
|
})
|
|
|
|
// console.log(await native.screen.getAllDisplays())
|
|
|
|
// console.log(await native.screen.getPrimaryDisplay())
|
2023-07-26 17:55:29 +08:00
|
|
|
})
|
|
|
|
|
2023-07-25 18:53:52 +08:00
|
|
|
bind($('textarea'), 'paste', async function (ev) {
|
|
|
|
let items = ev.clipboardData.items
|
|
|
|
for (let it of items) {
|
|
|
|
let file = it.getAsFile()
|
|
|
|
$('img').src = URL.createObjectURL(file)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
})
|