🎉 init

This commit is contained in:
Tw93
2022-10-14 17:34:22 +08:00
commit cabf8dfe74
16 changed files with 4193 additions and 0 deletions

3
src-tauri/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
# Generated by Cargo
# will have compiled files and executables
/target/

3696
src-tauri/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

30
src-tauri/Cargo.toml Normal file
View File

@@ -0,0 +1,30 @@
[package]
name = "app"
version = "0.1.0"
description = "Pake打包工具"
authors = ["Tw93"]
license = ""
repository = ""
default-run = "app"
edition = "2021"
rust-version = "1.61.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies]
tauri-build = { version = "1.0.2", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0.2", features = ["derive"] }
tauri = { version = "1.0.2", features = ["api-all"] }
wry = "0.19.0"
tauri-utils = "1.0.2"
[features]
# by default Tauri runs in production mode
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL
default = [ "custom-protocol" ]
# this feature is used used for production builds where `devPath` points to the filesystem
# DO NOT remove this
custom-protocol = [ "tauri/custom-protocol" ]

3
src-tauri/build.rs Normal file
View File

@@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}

BIN
src-tauri/icons/fone.icns Normal file

Binary file not shown.

BIN
src-tauri/icons/jdread.icns Normal file

Binary file not shown.

Binary file not shown.

BIN
src-tauri/icons/weRead.icns Normal file

Binary file not shown.

BIN
src-tauri/icons/yuque.icns Normal file

Binary file not shown.

139
src-tauri/src/main.rs Normal file
View File

@@ -0,0 +1,139 @@
fn main() -> wry::Result<()> {
use wry::{
application::{
accelerator::{Accelerator, SysMods},
event::{Event, StartCause, WindowEvent},
event_loop::{ControlFlow, EventLoop},
keyboard::KeyCode,
menu::{MenuBar as Menu, MenuItem, MenuItemAttributes, MenuType},
platform::macos::WindowBuilderExtMacOS,
window::{Window, WindowBuilder},
},
webview::WebViewBuilder,
};
let mut menu_bar_menu = Menu::new();
let mut first_menu = Menu::new();
first_menu.add_native_item(MenuItem::Hide);
first_menu.add_native_item(MenuItem::EnterFullScreen);
first_menu.add_native_item(MenuItem::Minimize);
first_menu.add_native_item(MenuItem::Separator);
first_menu.add_native_item(MenuItem::Copy);
first_menu.add_native_item(MenuItem::Cut);
first_menu.add_native_item(MenuItem::Paste);
first_menu.add_native_item(MenuItem::Undo);
first_menu.add_native_item(MenuItem::Redo);
first_menu.add_native_item(MenuItem::SelectAll);
first_menu.add_native_item(MenuItem::Separator);
let close_item = first_menu.add_item(
MenuItemAttributes::new("CloseWindow")
.with_accelerators(&Accelerator::new(SysMods::Cmd, KeyCode::KeyW)),
);
first_menu.add_native_item(MenuItem::Quit);
menu_bar_menu.add_submenu("App", true, first_menu);
let script = r#"
(function () {
window.addEventListener('DOMContentLoaded', (event) => {
const style = document.createElement('style');
.c-swiper-container{
display:none;
}
.panel.give_me .nav_view {
top: 154px !important;
}
.download_entry,
.lang,
.copyright {
display: none !important;
}
#pack-top-dom:active {
cursor: grabbing;
cursor: -webkit-grabbing;
}
#pack-top-dom{
position:fixed;
background:transparent;
top:0;
width:100%;
height:30px;
cursor: move;
cursor: grab;
cursor: -webkit-grab;
}
`;
document.head.append(style);
const topDom = document.createElement("div");
topDom.id = "pack-top-dom"
document.body.appendChild(topDom);
const domEl = document.getElementById('pack-top-dom');
domEl.addEventListener('mousedown', (e) => {
if (e.buttons === 1 && e.detail !== 2) {
window.ipc.postMessage('drag_window');
}
})
domEl.addEventListener('touchstart', (e) => {
window.ipc.postMessage('drag_window');
})
});
})();
"#;
let event_loop = EventLoop::new();
let window = WindowBuilder::new()
.with_title("WeRead")
.with_resizable(true)
.with_titlebar_transparent(true)
.with_fullsize_content_view(true)
.with_titlebar_buttons_hidden(false)
.with_title_hidden(true)
.with_menu(menu_bar_menu)
.with_inner_size(wry::application::dpi::LogicalSize::new(1200.00, 728.00))
.build(&event_loop)
.unwrap();
let handler = move |window: &Window, req: String| {
if req == "drag_window" {
println!("drag_window on");
let _ = window.drag_window();
}
};
let _webview = WebViewBuilder::new(window)?
.with_url("https://weread.qq.com/")?
// .with_devtools(true)
.with_initialization_script(script)
.with_ipc_handler(handler)
.build()?;
// _webview.open_devtools();
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
match event {
Event::NewEvents(StartCause::Init) => println!("Wry has started!"),
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => *control_flow = ControlFlow::Exit,
Event::MenuEvent {
menu_id,
origin: MenuType::MenuBar,
..
} => {
if menu_id == close_item.clone().id() {
_webview.window().set_minimized(true);
}
println!("Clicked on {:?}", menu_id);
}
_ => (),
}
});
}

59
src-tauri/tauri.conf.json Normal file
View File

@@ -0,0 +1,59 @@
{
"package": {
"productName": "WeRead",
"version": "0.1.0"
},
"build": {
"beforeBuildCommand": "",
"beforeDevCommand": "",
"devPath": "../dist",
"distDir": "../dist"
},
"tauri": {
"allowlist": {
"all": true
},
"bundle": {
"icon": ["icons/weRead.icns"],
"active": true,
"category": "DeveloperTool",
"copyright": "",
"deb": {
"depends": []
},
"externalBin": [],
"identifier": "com.tw93.weRead",
"longDescription": "",
"macOS": {
"entitlements": null,
"exceptionDomain": "",
"frameworks": [],
"providerShortName": null,
"signingIdentity": null
},
"resources": [],
"shortDescription": "",
"targets": "all",
"windows": {
"certificateThumbprint": null,
"digestAlgorithm": "sha256",
"timestampUrl": ""
}
},
"security": {
"csp": null
},
"updater": {
"active": false
},
"windows": [
{
"fullscreen": false,
"height": 728,
"resizable": true,
"title": "WeRead",
"width": 1200
}
]
}
}