chore: build

This commit is contained in:
lencx
2022-12-07 20:02:31 +08:00
parent 6fe765dafa
commit 65442f4489
13 changed files with 87 additions and 38 deletions

View File

@@ -1,5 +1,41 @@
// *** Core Script ***
document.addEventListener('DOMContentLoaded', async () => {
const uid = () => window.crypto.getRandomValues(new Uint32Array(1))[0];
function transformCallback(callback = () => {}, once = false) {
const identifier = uid();
const prop = `_${identifier}`;
Object.defineProperty(window, prop, {
value: (result) => {
if (once) {
Reflect.deleteProperty(window, prop);
}
return callback(result)
},
writable: false,
configurable: true,
})
return identifier;
}
async function invoke(cmd, args) {
return new Promise((resolve, reject) => {
if (!window.__TAURI_POST_MESSAGE__) reject('__TAURI_POST_MESSAGE__ does not exist!');
const callback = transformCallback((e) => {
resolve(e);
Reflect.deleteProperty(window, `_${error}`);
}, true)
const error = transformCallback((e) => {
reject(e);
Reflect.deleteProperty(window, `_${callback}`);
}, true)
window.__TAURI_POST_MESSAGE__({
cmd,
callback,
error,
...args
});
});
}
const topStyleDom = document.createElement("style");
topStyleDom.innerHTML = `#chatgpt-app-window-top{position:fixed;top:0;z-index:999999999;width:100%;height:24px;background:transparent;cursor:grab;cursor:-webkit-grab;user-select:none;-webkit-user-select:none;}#chatgpt-app-window-top:active {cursor:grabbing;cursor:-webkit-grabbing;}`;
document.head.appendChild(topStyleDom);
@@ -7,9 +43,9 @@ document.addEventListener('DOMContentLoaded', async () => {
topDom.id = "chatgpt-app-window-top";
document.body.appendChild(topDom);
topDom.addEventListener("mousedown", () => __TAURI_INVOKE__("drag_window"));
topDom.addEventListener("touchstart", () => __TAURI_INVOKE__("drag_window"));
topDom.addEventListener("dblclick", () => __TAURI_INVOKE__("fullscreen"));
topDom.addEventListener("mousedown", () => invoke("drag_window"));
topDom.addEventListener("touchstart", () => invoke("drag_window"));
topDom.addEventListener("dblclick", () => invoke("fullscreen"));
document.addEventListener("click", (e) => {
const origin = e.target.closest("a");

View File

@@ -13,7 +13,7 @@ fn main() {
let context = tauri::generate_context!();
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![cmd::drag_window, cmd::fullscreen,])
.invoke_handler(tauri::generate_handler![cmd::drag_window, cmd::fullscreen])
.setup(setup::init)
.menu(menu::init(&context))
.system_tray(SystemTray::new())

View File

@@ -10,18 +10,6 @@ pub fn get_tauri_conf() -> Option<Config> {
Some(config)
}
#[derive(serde::Serialize, serde::Deserialize, Debug)]
pub struct WaJson {
pub url: String,
pub resizable: bool,
pub theme: tauri::Theme,
pub mode: String,
pub title: String,
pub always_on_top: bool,
pub hidden_title: bool,
pub hide_title_bar: bool,
}
pub fn exists(path: &Path) -> bool {
Path::new(path).exists()
}