初始提交:OpenCode Go 用量监控 Tauri 桌面应用
@@ -0,0 +1,7 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
/target/
|
||||
|
||||
# Generated by Tauri
|
||||
# will have schema files for capabilities auto-completion
|
||||
/gen/schemas
|
||||
@@ -0,0 +1,22 @@
|
||||
[package]
|
||||
name = "go-meter"
|
||||
version = "0.1.0"
|
||||
description = "OpenCode Go plan usage monitor"
|
||||
authors = ["you"]
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
name = "go_meter_lib"
|
||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { version = "2", features = [] }
|
||||
tauri-plugin-single-instance = "2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
rusqlite = { version = "0.40", features = ["bundled"] }
|
||||
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls", "gzip"] }
|
||||
regex = "1"
|
||||
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"$schema": "../gen/schemas/desktop-schema.json",
|
||||
"identifier": "default",
|
||||
"description": "Capability for the main window",
|
||||
"windows": ["main"],
|
||||
"permissions": ["core:default"]
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"$schema": "../gen/schemas/desktop-schema.json",
|
||||
"identifier": "remote-console",
|
||||
"description": "Capability for the remote opencode.ai console page (hidden browser window)",
|
||||
"windows": ["browser"],
|
||||
"remote": {
|
||||
"urls": ["https://opencode.ai"]
|
||||
},
|
||||
"permissions": ["core:event:default"]
|
||||
}
|
||||
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 6.8 KiB |
|
After Width: | Height: | Size: 974 B |
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 3.8 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 7.6 KiB |
|
After Width: | Height: | Size: 903 B |
|
After Width: | Height: | Size: 8.4 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 85 KiB |
|
After Width: | Height: | Size: 14 KiB |
@@ -0,0 +1,55 @@
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
fn main() {
|
||||
#[cfg(not(debug_assertions))]
|
||||
fix_invalid_stdio();
|
||||
go_meter_lib::run()
|
||||
}
|
||||
|
||||
// Windows GUI 子系统程序从无控制台的宿主环境(如沙箱、计划任务)启动时,
|
||||
// 标准输入/输出/错误句柄可能无效,导致 WebView2 子进程初始化挂起。
|
||||
// 将无效句柄重定向到 NUL 保证句柄有效。
|
||||
#[cfg(not(debug_assertions))]
|
||||
fn fix_invalid_stdio() {
|
||||
use std::ffi::c_void;
|
||||
unsafe {
|
||||
extern "system" {
|
||||
fn SetStdHandle(n_std_handle: u32, handle: *mut c_void) -> i32;
|
||||
fn CreateFileW(
|
||||
lp_file_name: *const u16,
|
||||
dw_desired_access: u32,
|
||||
dw_share_mode: u32,
|
||||
lp_security_attributes: *mut c_void,
|
||||
dw_creation_disposition: u32,
|
||||
dw_flags_and_attributes: u32,
|
||||
h_template_file: *mut c_void,
|
||||
) -> *mut c_void;
|
||||
}
|
||||
const STD_INPUT_HANDLE: u32 = -10i32 as u32;
|
||||
const STD_OUTPUT_HANDLE: u32 = -11i32 as u32;
|
||||
const STD_ERROR_HANDLE: u32 = -12i32 as u32;
|
||||
const GENERIC_READ: u32 = 0x8000_0000;
|
||||
const GENERIC_WRITE: u32 = 0x4000_0000;
|
||||
const FILE_SHARE_READ: u32 = 1;
|
||||
const FILE_SHARE_WRITE: u32 = 2;
|
||||
const OPEN_EXISTING: u32 = 3;
|
||||
const FILE_ATTRIBUTE_NORMAL: u32 = 0x80;
|
||||
|
||||
let path: Vec<u16> = "NUL".encode_utf16().chain(std::iter::once(0)).collect();
|
||||
let h = CreateFileW(
|
||||
path.as_ptr(),
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
std::ptr::null_mut(),
|
||||
OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
std::ptr::null_mut(),
|
||||
);
|
||||
if !h.is_null() {
|
||||
SetStdHandle(STD_INPUT_HANDLE, h);
|
||||
SetStdHandle(STD_OUTPUT_HANDLE, h);
|
||||
SetStdHandle(STD_ERROR_HANDLE, h);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "OpenCode Go Meter",
|
||||
"version": "0.1.0",
|
||||
"identifier": "com.gometer.app",
|
||||
"build": {
|
||||
"beforeDevCommand": "pnpm dev",
|
||||
"devUrl": "http://localhost:1420",
|
||||
"beforeBuildCommand": "pnpm build",
|
||||
"frontendDist": "../dist"
|
||||
},
|
||||
"app": {
|
||||
"withGlobalTauri": true,
|
||||
"windows": [
|
||||
{
|
||||
"label": "main",
|
||||
"title": "OpenCode Go 用量",
|
||||
"width": 400,
|
||||
"height": 720,
|
||||
"minWidth": 360,
|
||||
"minHeight": 600,
|
||||
"resizable": true,
|
||||
"center": true
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": null
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"targets": "all",
|
||||
"icon": [
|
||||
"icons/32x32.png",
|
||||
"icons/128x128.png",
|
||||
"icons/128x128@2x.png",
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
]
|
||||
}
|
||||
}
|
||||