diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ed8ebf5
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+__pycache__
\ No newline at end of file
diff --git a/app.js b/app.js
index af6677e..650d850 100644
--- a/app.js
+++ b/app.js
@@ -5,58 +5,107 @@
*/
import 'es.shim'
-import { $, bind } from 'wkit'
+import { html, css, Component } from 'wkit'
-async function test1() {
- let txt = await native.clipboard.readText()
- $('input').value = txt
+class App extends Component {
+ static props = {
+ input: '',
+ img: ''
+ }
+
+ static styles = css`
+ .output {
+ max-width: 100%;
+ white-space: pre-wrap;
+ word-break: break-all;
+ }
+ `
+
+ render() {
+ return html`
+
+
+
+ 打开控制台
+
+
loading...
+
+
+
+
+
+
+
+
+
+
+ `
+ }
+
+ async test1() {
+ let txt = await native.clipboard.readText()
+ console.log('<><><>', txt)
+ this.input = txt
+ }
+
+ async test2() {
+ native.clipboard.writeText('这是一段写进剪切板的文本')
+ }
+
+ async writeImage() {
+ // let img = await native.image('/code/gtk/webkit/debian.png')
+ // native.clipboard.writeImage(img)
+ native.clipboard.writeImage('/code/gtk/webkit/red.png')
+ // try {
+ // this.img = URL.createObjectURL(await img.export())
+ // } catch (err) {
+ // alert(err)
+ // }
+ }
+
+ quit() {
+ native.quit()
+ }
+
+ createTray() {
+ native.tray()
+ }
+
+ async register() {
+ // console.log(await native.globalShortcut.enabled)
+
+ native.globalShortcut.register('2', function () {
+ alert('2被绑定了')
+ })
+ // console.log(await native.screen.getAllDisplays())
+ // console.log(await native.screen.getPrimaryDisplay())
+ }
+
+ async pasteImg(ev) {
+ let items = ev.clipboardData.items
+
+ let img = await window?.native?.clipboard?.readImage()
+
+ console.log(img)
+
+ if (img) {
+ this.img = URL.createObjectURL(await img.export())
+ }
+
+ for (let it of items) {
+ let file = it.getAsFile()
+ if (file) {
+ this.img = URL.createObjectURL(file)
+ break
+ }
+ }
+ }
}
-async function test2() {
- native.clipboard.writeText('这是一段写进剪切板的文本')
- // native.handler('blabla', { foo: 'bar' }).then(r => {
- // $('#output').innerHTML = JSON.stringify(r)
- // })
-}
-
-bind($('.btn1'), 'click', test1)
-bind($('.btn2'), 'click', test2)
-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()
-})
-
-bind($('.btn5'), 'click', async function () {
- native.tray()
-})
-
-bind($('.btn6'), 'click', async function () {
- // console.log(await native.globalShortcut.enabled)
-
- native.globalShortcut.register('2', function () {
- alert('2被绑定了')
- })
- // console.log(await native.screen.getAllDisplays())
- // console.log(await native.screen.getPrimaryDisplay())
-})
-
-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
- }
-})
+App.reg('app')
diff --git a/demo.js b/demo.js
deleted file mode 100644
index 3b501dd..0000000
--- a/demo.js
+++ /dev/null
@@ -1,5 +0,0 @@
-import fs from 'iofs'
-
-let buf = fs.cat('./debian.png')
-console.log(buf)
-console.log([...buf], buf.byteLength)
diff --git a/index.html b/index.html
index aca0cc8..e975b38 100644
--- a/index.html
+++ b/index.html
@@ -16,30 +16,11 @@
}
}
-
+
-
-
-
-打开控制台
-
-loading...
-
-
-
-
-
-
-
-
-
-
-
-
+