Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
basic-vue-admin
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-vue-admin
Commits
507a8563
提交
507a8563
authored
11月 14, 2022
作者:
方治民
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 新增移动磁盘(含 U 盘)插拔的监控示例
上级
ae7d6d61
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
358 行增加
和
6 行删除
+358
-6
Cargo.lock
src-tauri/Cargo.lock
+279
-2
Cargo.toml
src-tauri/Cargo.toml
+2
-0
main.rs
src-tauri/src/main.rs
+77
-4
没有找到文件。
src-tauri/Cargo.lock
浏览文件 @
507a8563
...
...
@@ -39,6 +39,15 @@ dependencies = [
]
[[package]]
name = "android_system_properties"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
dependencies = [
"libc",
]
[[package]]
name = "anyhow"
version = "1.0.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
...
...
@@ -48,12 +57,14 @@ checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6"
name = "app"
version = "0.1.0"
dependencies = [
"chrono",
"rusb",
"serde",
"serde_json",
"sysinfo",
"tauri",
"tauri-build",
"tokio",
]
[[package]]
...
...
@@ -144,6 +155,12 @@ dependencies = [
]
[[package]]
name = "bumpalo"
version = "3.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba"
[[package]]
name = "bytemuck"
version = "1.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
...
...
@@ -242,6 +259,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f"
dependencies = [
"iana-time-zone",
"js-sys",
"num-integer",
"num-traits",
"rustc-serialize",
"serde",
"time 0.1.44",
"wasm-bindgen",
"winapi",
]
[[package]]
name = "cocoa"
version = "0.24.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
...
...
@@ -273,6 +307,16 @@ dependencies = [
]
[[package]]
name = "codespan-reporting"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e"
dependencies = [
"termcolor",
"unicode-width",
]
[[package]]
name = "color_quant"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
...
...
@@ -450,6 +494,50 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35"
[[package]]
name = "cxx"
version = "1.0.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97abf9f0eca9e52b7f81b945524e76710e6cb2366aead23b7d4fbf72e281f888"
dependencies = [
"cc",
"cxxbridge-flags",
"cxxbridge-macro",
"link-cplusplus",
]
[[package]]
name = "cxx-build"
version = "1.0.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7cc32cc5fea1d894b77d269ddb9f192110069a8a9c1f1d441195fba90553dea3"
dependencies = [
"cc",
"codespan-reporting",
"once_cell",
"proc-macro2",
"quote",
"scratch",
"syn",
]
[[package]]
name = "cxxbridge-flags"
version = "1.0.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ca220e4794c934dc6b1207c3b42856ad4c302f2df1712e9f8d2eec5afaacf1f"
[[package]]
name = "cxxbridge-macro"
version = "1.0.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b846f081361125bfc8dc9d3940c84e1fd83ba54bbca7b17cd29483c828be0704"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "darling"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
...
...
@@ -1078,6 +1166,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21dec9db110f5f872ed9699c3ecf50cf16f423502706ba5c72462e28d3157573"
[[package]]
name = "iana-time-zone"
version = "0.1.53"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"wasm-bindgen",
"winapi",
]
[[package]]
name = "iana-time-zone-haiku"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca"
dependencies = [
"cxx",
"cxx-build",
]
[[package]]
name = "ico"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
...
...
@@ -1227,6 +1339,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
[[package]]
name = "js-sys"
version = "0.3.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47"
dependencies = [
"wasm-bindgen",
]
[[package]]
name = "json-patch"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
...
...
@@ -1283,6 +1404,15 @@ dependencies = [
]
[[package]]
name = "link-cplusplus"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369"
dependencies = [
"cc",
]
[[package]]
name = "lock_api"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
...
...
@@ -1394,6 +1524,18 @@ dependencies = [
]
[[package]]
name = "mio"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de"
dependencies = [
"libc",
"log",
"wasi 0.11.0+wasi-snapshot-preview1",
"windows-sys",
]
[[package]]
name = "ndk"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
...
...
@@ -1760,7 +1902,7 @@ dependencies = [
"indexmap",
"line-wrap",
"serde",
"time",
"time
0.3.17
",
"xml-rs",
]
...
...
@@ -2039,6 +2181,12 @@ dependencies = [
]
[[package]]
name = "rustc-serialize"
version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
[[package]]
name = "rustc_version"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
...
...
@@ -2096,6 +2244,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "scratch"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898"
[[package]]
name = "selectors"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
...
...
@@ -2259,6 +2413,15 @@ dependencies = [
]
[[package]]
name = "signal-hook-registry"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0"
dependencies = [
"libc",
]
[[package]]
name = "siphasher"
version = "0.3.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
...
...
@@ -2280,6 +2443,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
[[package]]
name = "socket2"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "soup2"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
...
...
@@ -2544,7 +2717,7 @@ dependencies = [
"sha2",
"tauri-utils",
"thiserror",
"time",
"time
0.3.17
",
"uuid 1.2.1",
"walkdir",
]
...
...
@@ -2657,6 +2830,15 @@ dependencies = [
]
[[package]]
name = "termcolor"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
dependencies = [
"winapi-util",
]
[[package]]
name = "thin-slice"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
...
...
@@ -2693,6 +2875,17 @@ dependencies = [
[[package]]
name = "time"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
"winapi",
]
[[package]]
name = "time"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376"
...
...
@@ -2741,9 +2934,27 @@ checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099"
dependencies = [
"autocfg",
"bytes",
"libc",
"memchr",
"mio",
"num_cpus",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"tokio-macros",
"winapi",
]
[[package]]
name = "tokio-macros"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
...
...
@@ -2866,6 +3077,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a"
[[package]]
name = "unicode-width"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
[[package]]
name = "url"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
...
...
@@ -2947,11 +3164,71 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142"
dependencies = [
"bumpalo",
"log",
"once_cell",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c"
dependencies = [
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f"
[[package]]
name = "webkit2gtk"
version = "0.18.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
...
...
src-tauri/Cargo.toml
浏览文件 @
507a8563
...
...
@@ -20,6 +20,8 @@ serde = { version = "1.0", features = ["derive"] }
tauri
=
{
version
=
"1.2.0"
,
features
=
[]
}
rusb
=
"0.9"
sysinfo
=
"0.26.7"
tokio
=
{
version
=
"1.21"
,
features
=
["full"]
}
chrono
=
{
version
=
"0.4.23"
,
features
=
[
"serde"
,
"rustc-serialize"
]
}
[features]
# by default Tauri runs in production mode
...
...
src-tauri/src/main.rs
浏览文件 @
507a8563
...
...
@@ -3,15 +3,88 @@
windows_subsystem
=
"windows"
)]
// 标准库
use
std
::
collections
::
BTreeMap
;
use
std
::
process
::
Command
;
// 系统信息库
use
sysinfo
::{
DiskExt
,
System
,
SystemExt
};
// 异步编程库: https://github.com/tokio-rs/tokio
use
tokio
::
time
::{
self
,
Duration
};
// 时间函数库: https://github.com/chronotope/chrono
// use chrono::prelude::*;
// JSON 序列化库
// use serde::{Deserialize, Serialize};
fn
main
()
{
let
s
=
System
::
new_all
();
for
disk
in
s
.disks
()
{
println!
(
"{:?}: {:?}"
,
disk
.name
(),
disk
.type_
());
fn
find
()
->
BTreeMap
<
String
,
String
>
{
let
system
=
System
::
new_all
();
let
mut
devices
:
BTreeMap
<
String
,
String
>
=
BTreeMap
::
new
();
for
disk
in
system
.disks
()
{
let
point
=
disk
.mount_point
()
.to_str
()
.map
(
str
::
to_string
)
.clone
()
.unwrap
();
let
name
=
disk
.name
()
.to_str
()
.map
(
str
::
to_string
)
.clone
()
.unwrap
();
devices
.insert
(
point
,
name
);
}
return
devices
;
}
async
fn
loop_find
(
mut
devices
:
BTreeMap
<
String
,
String
>
)
{
let
mut
interval
=
time
::
interval
(
Duration
::
from_millis
(
500
));
println!
(
""
);
println!
(
"==========================================="
);
println!
(
"{:?}"
,
devices
);
println!
(
"==========================================="
);
println!
(
""
);
loop
{
interval
.tick
()
.await
;
let
latest_devices
=
find
();
let
size
=
devices
.len
();
let
latest_size
=
latest_devices
.len
();
if
size
!=
latest_size
{
for
(
k
,
v
)
in
&
latest_devices
{
if
!
devices
.contains_key
(
k
)
{
println!
(
"attach: {:?}, {:?}"
,
v
,
k
);
// 打开文件夹
Command
::
new
(
"EXPLORER"
)
.arg
(
k
)
.spawn
()
.unwrap
();
}
}
for
(
k
,
v
)
in
&
devices
{
if
!
latest_devices
.contains_key
(
k
)
{
println!
(
"detach: {:?}, {:?}"
,
v
,
k
);
}
}
devices
=
latest_devices
;
}
}
}
fn
main
()
{
tauri
::
Builder
::
default
()
.setup
(|
_app
|
{
// let app_handle = app.handle();
let
devices
=
find
();
tauri
::
async_runtime
::
spawn
(
async
move
{
// A loop that takes output from the async process and sends it
// to the webview via a Tauri Event
loop_find
(
devices
)
.await
});
Ok
(())
})
.run
(
tauri
::
generate_context!
())
.expect
(
"error while running tauri application"
);
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论