Compare commits

..

No commits in common. "ece744aafe7e7eba049fb706a0d16a2f9fa8799b" and "5da22eed8e6fc9305d311bd469d03d085c628f62" have entirely different histories.

2 changed files with 438 additions and 479 deletions

View File

@ -3,8 +3,7 @@
# @date 2023/08/08 14:07:26
import gi, os, sys, json
import webbrowser, shutil, hashlib, random
import gi, os, sys, json, shutil, hashlib, random
gi.require_version('Gtk', '3.0')
gi.require_version("WebKit2", "4.1")
@ -289,25 +288,6 @@ class WebEngine(WebKit2.WebView):
return (_error, output)
def _shell_handler(self, params = {}):
_error = None
output = None
path = params.get('path')
match(params.get('action')):
case 'openExternal':
webbrowser.open(params.get('url'))
case 'showItemInFolder':
os.system(f"xdg-open '{path}'")
case 'openPath':
os.system(f"xdg-open '{path}'")
case 'trashItem':
pass
def _fs_handler(self, params = {}):
_error = None

View File

@ -3,8 +3,8 @@
* @author yutent<yutent.io@gmail.com>
* @date 2023/07/21 17:38:11
*/
!(function () {
const MIME_TYPES = {
const MIME_TYPES = {
html: 'text/html',
json: 'application/json',
js: 'application/javascript',
@ -37,33 +37,31 @@
doc: 'application/msword',
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
}
const KEYS_MAP = {
}
const KEYS_MAP = {
shift: '<Shift>',
ctrl: '<Ctrl>',
alt: '<Alt>',
super: '<Super>'
}
}
const NO_CALLBACK = false
const CALL_ONCE = true
const NO_CALLBACK = false
const CALL_ONCE = true
const __events__ = Symbol('events')
function defer() {
function defer() {
let obj = {}
obj.promise = new Promise((resolve, reject) => {
obj.resolve = resolve
obj.reject = reject
})
return obj
}
}
function rand(prefix = 'cb_') {
function rand(prefix = 'cb_') {
return prefix + Math.random().toString().slice(2)
}
}
function handler(event, data = {}, need = CALL_ONCE) {
function handler(event, data = {}, need = CALL_ONCE) {
let _ = defer()
let callback
@ -86,13 +84,13 @@
callback
})
return _.promise
}
}
function base64(str = '') {
function base64(str = '') {
return btoa(str).replace(/[+=\/]/g, '')
}
}
function _postMessage(data = {}, uuid = null) {
function _postMessage(data = {}, uuid = null) {
let ev = new Event('message')
Object.assign(ev, {
data,
@ -103,24 +101,18 @@
}
})
window.dispatchEvent(ev)
}
}
function readonly(obj, key, value) {
function readonly(obj, key, value) {
Object.defineProperty(obj, key, {
get() {
return value
},
enumerable: false
})
}
}
function _extend(origin, options = {}) {
for (let k in options) {
readonly(origin, k, options[k])
}
}
class NativeImage {
class NativeImage {
#origin
constructor(obj) {
@ -171,17 +163,17 @@
toDataURL(type) {
return this.export(type, true)
}
}
}
class Native {
class EventEmitter {
//
[__events__] = Object.create(null)
__events__ = Object.create(null)
$on(name, fn) {
if (this[__events__][name]) {
this[__events__][name].push(fn)
if (this.__events__[name]) {
this.__events__[name].push(fn)
} else {
this[__events__][name] = [fn]
this.__events__[name] = [fn]
}
}
@ -191,20 +183,18 @@
}
$off(name, fn) {
if (this[__events__][name]) {
if (this.__events__[name]) {
if (fn) {
this[__events__][name] = this[__events__][name].filter(
it => it !== fn
)
this.__events__[name] = this.__events__[name].filter(it => it !== fn)
} else {
this[__events__][name] = []
this.__events__[name] = []
}
}
}
$emit(name, ...args) {
if (this[__events__][name]) {
for (let fn of this[__events__][name]) {
if (this.__events__[name]) {
for (let fn of this.__events__[name]) {
try {
fn.apply(this, args)
if (fn.__once__) {
@ -218,15 +208,15 @@
}
$destroy() {
this[__events__] = Object.create(null)
}
this.__events__ = Object.create(null)
}
}
readonly(window, 'native', new Native())
readonly(window, 'native', new EventEmitter())
native.$on('opener_message', (data, uuid) => _postMessage(data, uuid))
native.$on('opener_message', (data, uuid) => _postMessage(data, uuid))
_extend(native, {
Object.assign(native, {
env: '{{env}}',
app: {
name: '{{app_name}}',
@ -241,12 +231,6 @@
return native.env.LANG
}
},
shell: {
openExternal(url) {},
showItemInFolder(path) {},
openPath(path) {},
trashItem(path) {}
},
fs: {
access(filepath, mode = 'r') {
return handler('fs', { action: 'access', mode, filepath })
@ -456,11 +440,7 @@
handler('window', { action: 'move', value: { x, y } }, NO_CALLBACK)
},
setOpacity(opacity = 1) {
handler(
'window',
{ action: 'set_opacity', value: opacity },
NO_CALLBACK
)
handler('window', { action: 'set_opacity', value: opacity }, NO_CALLBACK)
},
alwayOnTop(setting = true) {
handler(
@ -507,5 +487,4 @@
},
handler
})
})()
})