Compare commits

..

2 Commits

Author SHA1 Message Date
479fdba9f6 feat: 改进配置方式,重写逻辑。 2022-11-28 00:09:18 +08:00
7e1c4dd245 feat: 屏幕跟随改为多线程执行。
性能没有提升。
2022-11-26 10:17:42 +08:00
11 changed files with 595 additions and 323 deletions

View File

@ -1,12 +1,12 @@
lockfileVersion: 5.4
specifiers:
'@tauri-apps/api': ^1.1.0
'@tauri-apps/cli': ^1.1.0
'@types/node': ^18.7.10
'@types/react': ^18.0.15
'@types/react-dom': ^18.0.6
'@vitejs/plugin-react': ^2.0.0
'@tauri-apps/api': ^1.2.0
'@tauri-apps/cli': ^1.2.1
'@types/node': ^18.11.9
'@types/react': ^18.0.25
'@types/react-dom': ^18.0.9
'@vitejs/plugin-react': ^2.2.0
autoprefixer: ^10.4.13
clsx: ^1.2.1
eslint-config-prettier: ^8.5.0
@ -15,12 +15,12 @@ specifiers:
eslint-plugin-prettier: ^4.2.1
eslint-plugin-simple-import-sort: ^8.0.0
postcss: ^8.4.19
prettier: ^2.7.1
prettier: ^2.8.0
react: ^18.2.0
react-dom: ^18.2.0
tailwindcss: ^3.2.4
typescript: ^4.6.4
vite: ^3.0.2
typescript: ^4.9.3
vite: ^3.2.4
dependencies:
'@tauri-apps/api': 1.2.0
@ -29,22 +29,22 @@ dependencies:
react-dom: 18.2.0_react@18.2.0
devDependencies:
'@tauri-apps/cli': 1.2.0
'@tauri-apps/cli': 1.2.1
'@types/node': 18.11.9
'@types/react': 18.0.25
'@types/react-dom': 18.0.8
'@vitejs/plugin-react': 2.2.0_vite@3.2.3
'@types/react-dom': 18.0.9
'@vitejs/plugin-react': 2.2.0_vite@3.2.4
autoprefixer: 10.4.13_postcss@8.4.19
eslint-config-prettier: 8.5.0
eslint-plugin-import: 2.26.0
eslint-plugin-jsx-a11y: 6.6.1
eslint-plugin-prettier: 4.2.1_5ipovlnpea62s4232hvmwuqmsm
eslint-plugin-prettier: 4.2.1_woggxqa3l645ufel4grhxgids4
eslint-plugin-simple-import-sort: 8.0.0
postcss: 8.4.19
prettier: 2.7.1
prettier: 2.8.0
tailwindcss: 3.2.4_postcss@8.4.19
typescript: 4.8.4
vite: 3.2.3_@types+node@18.11.9
typescript: 4.9.3
vite: 3.2.4_@types+node@18.11.9
packages:
@ -330,8 +330,8 @@ packages:
to-fast-properties: 2.0.0
dev: true
/@esbuild/android-arm/0.15.13:
resolution: {integrity: sha512-RY2fVI8O0iFUNvZirXaQ1vMvK0xhCcl0gqRj74Z6yEiO1zAUa7hbsdwZM1kzqbxHK7LFyMizipfXT3JME+12Hw==}
/@esbuild/android-arm/0.15.15:
resolution: {integrity: sha512-JJjZjJi2eBL01QJuWjfCdZxcIgot+VoK6Fq7eKF9w4YHm9hwl7nhBR1o2Wnt/WcANk5l9SkpvrldW1PLuXxcbw==}
engines: {node: '>=12'}
cpu: [arm]
os: [android]
@ -339,8 +339,8 @@ packages:
dev: true
optional: true
/@esbuild/linux-loong64/0.15.13:
resolution: {integrity: sha512-+BoyIm4I8uJmH/QDIH0fu7MG0AEx9OXEDXnqptXCwKOlOqZiS4iraH1Nr7/ObLMokW3sOCeBNyD68ATcV9b9Ag==}
/@esbuild/linux-loong64/0.15.15:
resolution: {integrity: sha512-lhz6UNPMDXUhtXSulw8XlFAtSYO26WmHQnCi2Lg2p+/TMiJKNLtZCYUxV4wG6rZMzXmr8InGpNwk+DLT2Hm0PA==}
engines: {node: '>=12'}
cpu: [loong64]
os: [linux]
@ -412,8 +412,8 @@ packages:
engines: {node: '>= 14.6.0', npm: '>= 6.6.0', yarn: '>= 1.19.1'}
dev: false
/@tauri-apps/cli-darwin-arm64/1.2.0:
resolution: {integrity: sha512-f3LR2RvTU2ulxYdK9Nc3vKaSpDChu52pz0BMWNrSs3dxs4WTVioie98Ufz+GorifkUp3sYXcJte3HzX6wH/QxQ==}
/@tauri-apps/cli-darwin-arm64/1.2.1:
resolution: {integrity: sha512-WiAxSON52owFI65Whd3NjcKjXdO1zJfafBVZ3v+Y3F2zlXhRPiirXbtefAc3mvN56zDz/pfi018Qb4XesuVzHA==}
engines: {node: '>= 10'}
cpu: [arm64]
os: [darwin]
@ -421,8 +421,8 @@ packages:
dev: true
optional: true
/@tauri-apps/cli-darwin-x64/1.2.0:
resolution: {integrity: sha512-m07QZaAZCtyobrjddfz/Rxf9GGutnBOpRMbNqVqCk0qKRJzHG1fIsLqkgZh6+qPv0zHpu7xi/FPcqTec72Cp8w==}
/@tauri-apps/cli-darwin-x64/1.2.1:
resolution: {integrity: sha512-jfumnrn7RYKVtDmHgrQhImoxpqT51bDrO4KxgpIXaYSaf6MdG2JT72dwUovPrURw0JX2Z/Elihq+dYbrsKoV/w==}
engines: {node: '>= 10'}
cpu: [x64]
os: [darwin]
@ -430,8 +430,8 @@ packages:
dev: true
optional: true
/@tauri-apps/cli-linux-arm-gnueabihf/1.2.0:
resolution: {integrity: sha512-Id9eF1JtthZRFVtXAAVtSlI3uMT8cJ7LYmCSIl3mAXEUeaPBxnUs1i9X6/J+2Ho3yLEuuOxJ7PaJd+4v8wnEeg==}
/@tauri-apps/cli-linux-arm-gnueabihf/1.2.1:
resolution: {integrity: sha512-n4p6Ekn6Wa9X/klUGevEGgoWAGApGGsLrJYE4c8bKTbAUfQ9Nyzjh8gK/GDii1dg9oRW0FdXDa6BJa7aEEj9sA==}
engines: {node: '>= 10'}
cpu: [arm]
os: [linux]
@ -439,8 +439,8 @@ packages:
dev: true
optional: true
/@tauri-apps/cli-linux-arm64-gnu/1.2.0:
resolution: {integrity: sha512-NtfPkkpeMPl+i/tB/Fc8ST2rKO2vV8int/RkOvNGLCkhWcl4sbzKBol7tc4q8c8h0X7FXDcF1l/EOuGsZUAA5Q==}
/@tauri-apps/cli-linux-arm64-gnu/1.2.1:
resolution: {integrity: sha512-oAHkQQGfNCh8pQQHuDzzqt+S5sOj3tiUkySaquR2z/AQEHeDGAMrRGLZwOiDw9Xvu7qxFiF9H0e5OMK7BkncDw==}
engines: {node: '>= 10'}
cpu: [arm64]
os: [linux]
@ -448,8 +448,8 @@ packages:
dev: true
optional: true
/@tauri-apps/cli-linux-arm64-musl/1.2.0:
resolution: {integrity: sha512-tz+mOOVsy/TMdq2WJVIJl/iwW3OCWCyD5Fls3fhyJ4XpLfjn4G+C+oU0awXD/0se0ko81aq4D+r8eDx6oBRi0A==}
/@tauri-apps/cli-linux-arm64-musl/1.2.1:
resolution: {integrity: sha512-1dEZ5fdFYkMyB1U7ZkDJUlwYwCeqy9Y3vXmtZ6pCxrvgs844s8+RIFDuMU42pTN+lUxfFeQARmv0LpS4eF/QWQ==}
engines: {node: '>= 10'}
cpu: [arm64]
os: [linux]
@ -457,8 +457,8 @@ packages:
dev: true
optional: true
/@tauri-apps/cli-linux-x64-gnu/1.2.0:
resolution: {integrity: sha512-FH/wU+OWZjRQvrq/oequScr72I84XgOuRuMEpt/GqGD341cBJ8ithpoyzuiKsvjS6K0qMyRFzy3eyhQ7gwX+4Q==}
/@tauri-apps/cli-linux-x64-gnu/1.2.1:
resolution: {integrity: sha512-wkgCD3s5P6tgBPnn0/gDx7MXMx2Hx+jdA+JP8zdCq4cIeYXlxdZG/zXbHb5ldPadNh582lzHiGg+Pmc+wDg2fA==}
engines: {node: '>= 10'}
cpu: [x64]
os: [linux]
@ -466,8 +466,8 @@ packages:
dev: true
optional: true
/@tauri-apps/cli-linux-x64-musl/1.2.0:
resolution: {integrity: sha512-nLg30aBT9fI83sjIqaGPN7twbtE5LJy2DbKzxIlw59F+GT8HBdiM/2mZdTLB3AQb52yVHuGB1TVtWDsl0JHqCA==}
/@tauri-apps/cli-linux-x64-musl/1.2.1:
resolution: {integrity: sha512-zD+a+5cSlYVU0ECOojWp71ok/9jE0DJufzb9oky17XIKV/oiOAG60z4OYRe+oqxYS1TcBt+pUa1/2zlu/6SRdA==}
engines: {node: '>= 10'}
cpu: [x64]
os: [linux]
@ -475,8 +475,8 @@ packages:
dev: true
optional: true
/@tauri-apps/cli-win32-ia32-msvc/1.2.0:
resolution: {integrity: sha512-eXtgIgY0fawgcOuUjH8Y6PxwPxbK87Zl9XmA7Q0m58T7pIz+gcbgvtH8Bb+liYHoRYItIhQxVm+ui7Y59rI7Cg==}
/@tauri-apps/cli-win32-ia32-msvc/1.2.1:
resolution: {integrity: sha512-nEgdRd8czaKL1RQfj946dsfzlk6atmD95Fm7NVTVOe77PFHTS3ztHeWK7X6jirCaOF3h/F7qpJVCU6JMnq2tfA==}
engines: {node: '>= 10'}
cpu: [ia32]
os: [win32]
@ -484,8 +484,8 @@ packages:
dev: true
optional: true
/@tauri-apps/cli-win32-x64-msvc/1.2.0:
resolution: {integrity: sha512-egyM66R05AIbkaUDptpHurFTIYp3VM4H5OrRd3O2b0oXf8SoiXiyrHbQsHVHHDYyytKmwkdNqjdy+Vev/Vq25Q==}
/@tauri-apps/cli-win32-x64-msvc/1.2.1:
resolution: {integrity: sha512-ceWiQkmNNRrnfgbLMnndT4QF1IyLK7aOJsMqS/HueshAwmVQWnC1DUE0C58Taetgq38Cavc4gGnZOCHuH6ZuTw==}
engines: {node: '>= 10'}
cpu: [x64]
os: [win32]
@ -493,20 +493,20 @@ packages:
dev: true
optional: true
/@tauri-apps/cli/1.2.0:
resolution: {integrity: sha512-DgUnk4p/atWHq2HUx9Vt+/LuRsx4iFlkzdZIUxtFWvpcZih2k0TzmHJbrhM1evh1/7a+SqiwDawmyf3Hz1HxXA==}
/@tauri-apps/cli/1.2.1:
resolution: {integrity: sha512-JrFFT1/4V+AGSRjKdgszZwOr+/a1519LDhNxBkbsIg6D/kFK+3kk1qImaQBY9DvvIWK6IV4whc8OAkgxm+Sl3w==}
engines: {node: '>= 10'}
hasBin: true
optionalDependencies:
'@tauri-apps/cli-darwin-arm64': 1.2.0
'@tauri-apps/cli-darwin-x64': 1.2.0
'@tauri-apps/cli-linux-arm-gnueabihf': 1.2.0
'@tauri-apps/cli-linux-arm64-gnu': 1.2.0
'@tauri-apps/cli-linux-arm64-musl': 1.2.0
'@tauri-apps/cli-linux-x64-gnu': 1.2.0
'@tauri-apps/cli-linux-x64-musl': 1.2.0
'@tauri-apps/cli-win32-ia32-msvc': 1.2.0
'@tauri-apps/cli-win32-x64-msvc': 1.2.0
'@tauri-apps/cli-darwin-arm64': 1.2.1
'@tauri-apps/cli-darwin-x64': 1.2.1
'@tauri-apps/cli-linux-arm-gnueabihf': 1.2.1
'@tauri-apps/cli-linux-arm64-gnu': 1.2.1
'@tauri-apps/cli-linux-arm64-musl': 1.2.1
'@tauri-apps/cli-linux-x64-gnu': 1.2.1
'@tauri-apps/cli-linux-x64-musl': 1.2.1
'@tauri-apps/cli-win32-ia32-msvc': 1.2.1
'@tauri-apps/cli-win32-x64-msvc': 1.2.1
dev: true
/@types/json5/0.0.29:
@ -521,8 +521,8 @@ packages:
resolution: {integrity: sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==}
dev: true
/@types/react-dom/18.0.8:
resolution: {integrity: sha512-C3GYO0HLaOkk9dDAz3Dl4sbe4AKUGTCfFIZsz3n/82dPNN8Du533HzKatDxeUYWu24wJgMP1xICqkWk1YOLOIw==}
/@types/react-dom/18.0.9:
resolution: {integrity: sha512-qnVvHxASt/H7i+XG1U1xMiY5t+IHcPGUK7TDMDzom08xa7e86eCeKOiLZezwCKVxJn6NEiiy2ekgX8aQssjIKg==}
dependencies:
'@types/react': 18.0.25
dev: true
@ -539,7 +539,7 @@ packages:
resolution: {integrity: sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==}
dev: true
/@vitejs/plugin-react/2.2.0_vite@3.2.3:
/@vitejs/plugin-react/2.2.0_vite@3.2.4:
resolution: {integrity: sha512-FFpefhvExd1toVRlokZgxgy2JtnBOdp4ZDsq7ldCWaqGSGn9UhWMAVm/1lxPL14JfNS5yGz+s9yFrQY6shoStA==}
engines: {node: ^14.18.0 || >=16.0.0}
peerDependencies:
@ -552,7 +552,7 @@ packages:
'@babel/plugin-transform-react-jsx-source': 7.19.6_@babel+core@7.20.2
magic-string: 0.26.7
react-refresh: 0.14.0
vite: 3.2.3_@types+node@18.11.9
vite: 3.2.4_@types+node@18.11.9
transitivePeerDependencies:
- supports-color
dev: true
@ -583,8 +583,8 @@ packages:
color-convert: 1.9.3
dev: true
/anymatch/3.1.2:
resolution: {integrity: sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg==}
/anymatch/3.1.3:
resolution: {integrity: sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==}
engines: {node: '>= 8'}
dependencies:
normalize-path: 3.0.0
@ -636,7 +636,7 @@ packages:
postcss: ^8.1.0
dependencies:
browserslist: 4.21.4
caniuse-lite: 1.0.30001431
caniuse-lite: 1.0.30001434
fraction.js: 4.2.0
normalize-range: 0.1.2
picocolors: 1.0.0
@ -681,7 +681,7 @@ packages:
engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7}
hasBin: true
dependencies:
caniuse-lite: 1.0.30001431
caniuse-lite: 1.0.30001434
electron-to-chromium: 1.4.284
node-releases: 2.0.6
update-browserslist-db: 1.0.10_browserslist@4.21.4
@ -699,8 +699,8 @@ packages:
engines: {node: '>= 6'}
dev: true
/caniuse-lite/1.0.30001431:
resolution: {integrity: sha512-zBUoFU0ZcxpvSt9IU66dXVT/3ctO1cy4y9cscs1szkPlcWb6pasYM144GqrUygUbT+k7cmUCW61cvskjcv0enQ==}
/caniuse-lite/1.0.30001434:
resolution: {integrity: sha512-aOBHrLmTQw//WFa2rcF1If9fa3ypkC1wzqqiKHgfdrXTWcU8C4gKVZT77eQAPWN1APys3+uQ0Df07rKauXGEYA==}
dev: true
/chalk/2.4.2:
@ -716,7 +716,7 @@ packages:
resolution: {integrity: sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==}
engines: {node: '>= 8.10.0'}
dependencies:
anymatch: 3.1.2
anymatch: 3.1.3
braces: 3.0.2
glob-parent: 5.1.2
is-binary-path: 2.1.0
@ -792,7 +792,7 @@ packages:
supports-color:
optional: true
dependencies:
ms: 2.1.2
ms: 2.1.3
dev: true
/debug/4.3.4:
@ -897,8 +897,8 @@ packages:
is-symbol: 1.0.4
dev: true
/esbuild-android-64/0.15.13:
resolution: {integrity: sha512-yRorukXBlokwTip+Sy4MYskLhJsO0Kn0/Fj43s1krVblfwP+hMD37a4Wmg139GEsMLl+vh8WXp2mq/cTA9J97g==}
/esbuild-android-64/0.15.15:
resolution: {integrity: sha512-F+WjjQxO+JQOva3tJWNdVjouFMLK6R6i5gjDvgUthLYJnIZJsp1HlF523k73hELY20WPyEO8xcz7aaYBVkeg5Q==}
engines: {node: '>=12'}
cpu: [x64]
os: [android]
@ -906,8 +906,8 @@ packages:
dev: true
optional: true
/esbuild-android-arm64/0.15.13:
resolution: {integrity: sha512-TKzyymLD6PiVeyYa4c5wdPw87BeAiTXNtK6amWUcXZxkV51gOk5u5qzmDaYSwiWeecSNHamFsaFjLoi32QR5/w==}
/esbuild-android-arm64/0.15.15:
resolution: {integrity: sha512-attlyhD6Y22jNyQ0fIIQ7mnPvDWKw7k6FKnsXlBvQE6s3z6s6cuEHcSgoirquQc7TmZgVCK5fD/2uxmRN+ZpcQ==}
engines: {node: '>=12'}
cpu: [arm64]
os: [android]
@ -915,8 +915,8 @@ packages:
dev: true
optional: true
/esbuild-darwin-64/0.15.13:
resolution: {integrity: sha512-WAx7c2DaOS6CrRcoYCgXgkXDliLnFv3pQLV6GeW1YcGEZq2Gnl8s9Pg7ahValZkpOa0iE/ojRVQ87sbUhF1Cbg==}
/esbuild-darwin-64/0.15.15:
resolution: {integrity: sha512-ohZtF8W1SHJ4JWldsPVdk8st0r9ExbAOSrBOh5L+Mq47i696GVwv1ab/KlmbUoikSTNoXEhDzVpxUR/WIO19FQ==}
engines: {node: '>=12'}
cpu: [x64]
os: [darwin]
@ -924,8 +924,8 @@ packages:
dev: true
optional: true
/esbuild-darwin-arm64/0.15.13:
resolution: {integrity: sha512-U6jFsPfSSxC3V1CLiQqwvDuj3GGrtQNB3P3nNC3+q99EKf94UGpsG9l4CQ83zBs1NHrk1rtCSYT0+KfK5LsD8A==}
/esbuild-darwin-arm64/0.15.15:
resolution: {integrity: sha512-P8jOZ5zshCNIuGn+9KehKs/cq5uIniC+BeCykvdVhx/rBXSxmtj3CUIKZz4sDCuESMbitK54drf/2QX9QHG5Ag==}
engines: {node: '>=12'}
cpu: [arm64]
os: [darwin]
@ -933,8 +933,8 @@ packages:
dev: true
optional: true
/esbuild-freebsd-64/0.15.13:
resolution: {integrity: sha512-whItJgDiOXaDG/idy75qqevIpZjnReZkMGCgQaBWZuKHoElDJC1rh7MpoUgupMcdfOd+PgdEwNQW9DAE6i8wyA==}
/esbuild-freebsd-64/0.15.15:
resolution: {integrity: sha512-KkTg+AmDXz1IvA9S1gt8dE24C8Thx0X5oM0KGF322DuP+P3evwTL9YyusHAWNsh4qLsR80nvBr/EIYs29VSwuA==}
engines: {node: '>=12'}
cpu: [x64]
os: [freebsd]
@ -942,8 +942,8 @@ packages:
dev: true
optional: true
/esbuild-freebsd-arm64/0.15.13:
resolution: {integrity: sha512-6pCSWt8mLUbPtygv7cufV0sZLeylaMwS5Fznj6Rsx9G2AJJsAjQ9ifA+0rQEIg7DwJmi9it+WjzNTEAzzdoM3Q==}
/esbuild-freebsd-arm64/0.15.15:
resolution: {integrity: sha512-FUcML0DRsuyqCMfAC+HoeAqvWxMeq0qXvclZZ/lt2kLU6XBnDA5uKTLUd379WYEyVD4KKFctqWd9tTuk8C/96g==}
engines: {node: '>=12'}
cpu: [arm64]
os: [freebsd]
@ -951,8 +951,8 @@ packages:
dev: true
optional: true
/esbuild-linux-32/0.15.13:
resolution: {integrity: sha512-VbZdWOEdrJiYApm2kkxoTOgsoCO1krBZ3quHdYk3g3ivWaMwNIVPIfEE0f0XQQ0u5pJtBsnk2/7OPiCFIPOe/w==}
/esbuild-linux-32/0.15.15:
resolution: {integrity: sha512-q28Qn5pZgHNqug02aTkzw5sW9OklSo96b5nm17Mq0pDXrdTBcQ+M6Q9A1B+dalFeynunwh/pvfrNucjzwDXj+Q==}
engines: {node: '>=12'}
cpu: [ia32]
os: [linux]
@ -960,8 +960,8 @@ packages:
dev: true
optional: true
/esbuild-linux-64/0.15.13:
resolution: {integrity: sha512-rXmnArVNio6yANSqDQlIO4WiP+Cv7+9EuAHNnag7rByAqFVuRusLbGi2697A5dFPNXoO//IiogVwi3AdcfPC6A==}
/esbuild-linux-64/0.15.15:
resolution: {integrity: sha512-217KPmWMirkf8liO+fj2qrPwbIbhNTGNVtvqI1TnOWJgcMjUWvd677Gq3fTzXEjilkx2yWypVnTswM2KbXgoAg==}
engines: {node: '>=12'}
cpu: [x64]
os: [linux]
@ -969,8 +969,8 @@ packages:
dev: true
optional: true
/esbuild-linux-arm/0.15.13:
resolution: {integrity: sha512-Ac6LpfmJO8WhCMQmO253xX2IU2B3wPDbl4IvR0hnqcPrdfCaUa2j/lLMGTjmQ4W5JsJIdHEdW12dG8lFS0MbxQ==}
/esbuild-linux-arm/0.15.15:
resolution: {integrity: sha512-RYVW9o2yN8yM7SB1yaWr378CwrjvGCyGybX3SdzPHpikUHkME2AP55Ma20uNwkNyY2eSYFX9D55kDrfQmQBR4w==}
engines: {node: '>=12'}
cpu: [arm]
os: [linux]
@ -978,8 +978,8 @@ packages:
dev: true
optional: true
/esbuild-linux-arm64/0.15.13:
resolution: {integrity: sha512-alEMGU4Z+d17U7KQQw2IV8tQycO6T+rOrgW8OS22Ua25x6kHxoG6Ngry6Aq6uranC+pNWNMB6aHFPh7aTQdORQ==}
/esbuild-linux-arm64/0.15.15:
resolution: {integrity: sha512-/ltmNFs0FivZkYsTzAsXIfLQX38lFnwJTWCJts0IbCqWZQe+jjj0vYBNbI0kmXLb3y5NljiM5USVAO1NVkdh2g==}
engines: {node: '>=12'}
cpu: [arm64]
os: [linux]
@ -987,8 +987,8 @@ packages:
dev: true
optional: true
/esbuild-linux-mips64le/0.15.13:
resolution: {integrity: sha512-47PgmyYEu+yN5rD/MbwS6DxP2FSGPo4Uxg5LwIdxTiyGC2XKwHhHyW7YYEDlSuXLQXEdTO7mYe8zQ74czP7W8A==}
/esbuild-linux-mips64le/0.15.15:
resolution: {integrity: sha512-PksEPb321/28GFFxtvL33yVPfnMZihxkEv5zME2zapXGp7fA1X2jYeiTUK+9tJ/EGgcNWuwvtawPxJG7Mmn86A==}
engines: {node: '>=12'}
cpu: [mips64el]
os: [linux]
@ -996,8 +996,8 @@ packages:
dev: true
optional: true
/esbuild-linux-ppc64le/0.15.13:
resolution: {integrity: sha512-z6n28h2+PC1Ayle9DjKoBRcx/4cxHoOa2e689e2aDJSaKug3jXcQw7mM+GLg+9ydYoNzj8QxNL8ihOv/OnezhA==}
/esbuild-linux-ppc64le/0.15.15:
resolution: {integrity: sha512-ek8gJBEIhcpGI327eAZigBOHl58QqrJrYYIZBWQCnH3UnXoeWMrMZLeeZL8BI2XMBhP+sQ6ERctD5X+ajL/AIA==}
engines: {node: '>=12'}
cpu: [ppc64]
os: [linux]
@ -1005,8 +1005,8 @@ packages:
dev: true
optional: true
/esbuild-linux-riscv64/0.15.13:
resolution: {integrity: sha512-+Lu4zuuXuQhgLUGyZloWCqTslcCAjMZH1k3Xc9MSEJEpEFdpsSU0sRDXAnk18FKOfEjhu4YMGaykx9xjtpA6ow==}
/esbuild-linux-riscv64/0.15.15:
resolution: {integrity: sha512-H5ilTZb33/GnUBrZMNJtBk7/OXzDHDXjIzoLXHSutwwsLxSNaLxzAaMoDGDd/keZoS+GDBqNVxdCkpuiRW4OSw==}
engines: {node: '>=12'}
cpu: [riscv64]
os: [linux]
@ -1014,8 +1014,8 @@ packages:
dev: true
optional: true
/esbuild-linux-s390x/0.15.13:
resolution: {integrity: sha512-BMeXRljruf7J0TMxD5CIXS65y7puiZkAh+s4XFV9qy16SxOuMhxhVIXYLnbdfLrsYGFzx7U9mcdpFWkkvy/Uag==}
/esbuild-linux-s390x/0.15.15:
resolution: {integrity: sha512-jKaLUg78mua3rrtrkpv4Or2dNTJU7bgHN4bEjT4OX4GR7nLBSA9dfJezQouTxMmIW7opwEC5/iR9mpC18utnxQ==}
engines: {node: '>=12'}
cpu: [s390x]
os: [linux]
@ -1023,8 +1023,8 @@ packages:
dev: true
optional: true
/esbuild-netbsd-64/0.15.13:
resolution: {integrity: sha512-EHj9QZOTel581JPj7UO3xYbltFTYnHy+SIqJVq6yd3KkCrsHRbapiPb0Lx3EOOtybBEE9EyqbmfW1NlSDsSzvQ==}
/esbuild-netbsd-64/0.15.15:
resolution: {integrity: sha512-aOvmF/UkjFuW6F36HbIlImJTTx45KUCHJndtKo+KdP8Dhq3mgLRKW9+6Ircpm8bX/RcS3zZMMmaBLkvGY06Gvw==}
engines: {node: '>=12'}
cpu: [x64]
os: [netbsd]
@ -1032,8 +1032,8 @@ packages:
dev: true
optional: true
/esbuild-openbsd-64/0.15.13:
resolution: {integrity: sha512-nkuDlIjF/sfUhfx8SKq0+U+Fgx5K9JcPq1mUodnxI0x4kBdCv46rOGWbuJ6eof2n3wdoCLccOoJAbg9ba/bT2w==}
/esbuild-openbsd-64/0.15.15:
resolution: {integrity: sha512-HFFX+WYedx1w2yJ1VyR1Dfo8zyYGQZf1cA69bLdrHzu9svj6KH6ZLK0k3A1/LFPhcEY9idSOhsB2UyU0tHPxgQ==}
engines: {node: '>=12'}
cpu: [x64]
os: [openbsd]
@ -1041,8 +1041,8 @@ packages:
dev: true
optional: true
/esbuild-sunos-64/0.15.13:
resolution: {integrity: sha512-jVeu2GfxZQ++6lRdY43CS0Tm/r4WuQQ0Pdsrxbw+aOrHQPHV0+LNOLnvbN28M7BSUGnJnHkHm2HozGgNGyeIRw==}
/esbuild-sunos-64/0.15.15:
resolution: {integrity: sha512-jOPBudffG4HN8yJXcK9rib/ZTFoTA5pvIKbRrt3IKAGMq1EpBi4xoVoSRrq/0d4OgZLaQbmkHp8RO9eZIn5atA==}
engines: {node: '>=12'}
cpu: [x64]
os: [sunos]
@ -1050,8 +1050,8 @@ packages:
dev: true
optional: true
/esbuild-windows-32/0.15.13:
resolution: {integrity: sha512-XoF2iBf0wnqo16SDq+aDGi/+QbaLFpkiRarPVssMh9KYbFNCqPLlGAWwDvxEVz+ywX6Si37J2AKm+AXq1kC0JA==}
/esbuild-windows-32/0.15.15:
resolution: {integrity: sha512-MDkJ3QkjnCetKF0fKxCyYNBnOq6dmidcwstBVeMtXSgGYTy8XSwBeIE4+HuKiSsG6I/mXEb++px3IGSmTN0XiA==}
engines: {node: '>=12'}
cpu: [ia32]
os: [win32]
@ -1059,8 +1059,8 @@ packages:
dev: true
optional: true
/esbuild-windows-64/0.15.13:
resolution: {integrity: sha512-Et6htEfGycjDrtqb2ng6nT+baesZPYQIW+HUEHK4D1ncggNrDNk3yoboYQ5KtiVrw/JaDMNttz8rrPubV/fvPQ==}
/esbuild-windows-64/0.15.15:
resolution: {integrity: sha512-xaAUIB2qllE888SsMU3j9nrqyLbkqqkpQyWVkfwSil6BBPgcPk3zOFitTTncEKCLTQy3XV9RuH7PDj3aJDljWA==}
engines: {node: '>=12'}
cpu: [x64]
os: [win32]
@ -1068,8 +1068,8 @@ packages:
dev: true
optional: true
/esbuild-windows-arm64/0.15.13:
resolution: {integrity: sha512-3bv7tqntThQC9SWLRouMDmZnlOukBhOCTlkzNqzGCmrkCJI7io5LLjwJBOVY6kOUlIvdxbooNZwjtBvj+7uuVg==}
/esbuild-windows-arm64/0.15.15:
resolution: {integrity: sha512-ttuoCYCIJAFx4UUKKWYnFdrVpoXa3+3WWkXVI6s09U+YjhnyM5h96ewTq/WgQj9LFSIlABQvadHSOQyAVjW5xQ==}
engines: {node: '>=12'}
cpu: [arm64]
os: [win32]
@ -1077,34 +1077,34 @@ packages:
dev: true
optional: true
/esbuild/0.15.13:
resolution: {integrity: sha512-Cu3SC84oyzzhrK/YyN4iEVy2jZu5t2fz66HEOShHURcjSkOSAVL8C/gfUT+lDJxkVHpg8GZ10DD0rMHRPqMFaQ==}
/esbuild/0.15.15:
resolution: {integrity: sha512-TEw/lwK4Zzld9x3FedV6jy8onOUHqcEX3ADFk4k+gzPUwrxn8nWV62tH0udo8jOtjFodlEfc4ypsqX3e+WWO6w==}
engines: {node: '>=12'}
hasBin: true
requiresBuild: true
optionalDependencies:
'@esbuild/android-arm': 0.15.13
'@esbuild/linux-loong64': 0.15.13
esbuild-android-64: 0.15.13
esbuild-android-arm64: 0.15.13
esbuild-darwin-64: 0.15.13
esbuild-darwin-arm64: 0.15.13
esbuild-freebsd-64: 0.15.13
esbuild-freebsd-arm64: 0.15.13
esbuild-linux-32: 0.15.13
esbuild-linux-64: 0.15.13
esbuild-linux-arm: 0.15.13
esbuild-linux-arm64: 0.15.13
esbuild-linux-mips64le: 0.15.13
esbuild-linux-ppc64le: 0.15.13
esbuild-linux-riscv64: 0.15.13
esbuild-linux-s390x: 0.15.13
esbuild-netbsd-64: 0.15.13
esbuild-openbsd-64: 0.15.13
esbuild-sunos-64: 0.15.13
esbuild-windows-32: 0.15.13
esbuild-windows-64: 0.15.13
esbuild-windows-arm64: 0.15.13
'@esbuild/android-arm': 0.15.15
'@esbuild/linux-loong64': 0.15.15
esbuild-android-64: 0.15.15
esbuild-android-arm64: 0.15.15
esbuild-darwin-64: 0.15.15
esbuild-darwin-arm64: 0.15.15
esbuild-freebsd-64: 0.15.15
esbuild-freebsd-arm64: 0.15.15
esbuild-linux-32: 0.15.15
esbuild-linux-64: 0.15.15
esbuild-linux-arm: 0.15.15
esbuild-linux-arm64: 0.15.15
esbuild-linux-mips64le: 0.15.15
esbuild-linux-ppc64le: 0.15.15
esbuild-linux-riscv64: 0.15.15
esbuild-linux-s390x: 0.15.15
esbuild-netbsd-64: 0.15.15
esbuild-openbsd-64: 0.15.15
esbuild-sunos-64: 0.15.15
esbuild-windows-32: 0.15.15
esbuild-windows-64: 0.15.15
esbuild-windows-arm64: 0.15.15
dev: true
/escalade/3.1.1:
@ -1210,7 +1210,7 @@ packages:
semver: 6.3.0
dev: true
/eslint-plugin-prettier/4.2.1_5ipovlnpea62s4232hvmwuqmsm:
/eslint-plugin-prettier/4.2.1_woggxqa3l645ufel4grhxgids4:
resolution: {integrity: sha512-f/0rXLXUt0oFYs8ra4w49wYZBG5GKZpAYsJSm6rnYL5uVDjd+zowwMwVZHnAjf4edNrKpCDYfXDgmRE/Ak7QyQ==}
engines: {node: '>=12.0.0'}
peerDependencies:
@ -1222,7 +1222,7 @@ packages:
optional: true
dependencies:
eslint-config-prettier: 8.5.0
prettier: 2.7.1
prettier: 2.8.0
prettier-linter-helpers: 1.0.0
dev: true
@ -1570,6 +1570,10 @@ packages:
resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==}
dev: true
/ms/2.1.3:
resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==}
dev: true
/nanoid/3.3.4:
resolution: {integrity: sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==}
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
@ -1687,11 +1691,11 @@ packages:
postcss: ^8.2.14
dependencies:
postcss: 8.4.19
postcss-selector-parser: 6.0.10
postcss-selector-parser: 6.0.11
dev: true
/postcss-selector-parser/6.0.10:
resolution: {integrity: sha512-IQ7TZdoaqbT+LCpShg46jnZVlhWD2w6iQYAcYXfHARZ7X1t/UGhhceQDs5X0cGqKvYlHNOuv7Oa1xmb0oQuA3w==}
/postcss-selector-parser/6.0.11:
resolution: {integrity: sha512-zbARubNdogI9j7WY4nQJBiNqQf3sLS3wCP4WfOidu+p28LofJqDH1tcXypGrcmMHhDk2t9wGhCsYe/+szLTy1g==}
engines: {node: '>=4'}
dependencies:
cssesc: 3.0.0
@ -1718,8 +1722,8 @@ packages:
fast-diff: 1.2.0
dev: true
/prettier/2.7.1:
resolution: {integrity: sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==}
/prettier/2.8.0:
resolution: {integrity: sha512-9Lmg8hTFZKG0Asr/kW9Bp8tJjRVluO8EJQVfY2T7FMw9T5jy4I/Uvx0Rca/XWf50QQ1/SS48+6IJWnrb+2yemA==}
engines: {node: '>=10.13.0'}
hasBin: true
dev: true
@ -1904,7 +1908,7 @@ packages:
postcss-js: 4.0.0_postcss@8.4.19
postcss-load-config: 3.1.4_postcss@8.4.19
postcss-nested: 6.0.0_postcss@8.4.19
postcss-selector-parser: 6.0.10
postcss-selector-parser: 6.0.11
postcss-value-parser: 4.2.0
quick-lru: 5.1.1
resolve: 1.22.1
@ -1933,8 +1937,8 @@ packages:
strip-bom: 3.0.0
dev: true
/typescript/4.8.4:
resolution: {integrity: sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==}
/typescript/4.9.3:
resolution: {integrity: sha512-CIfGzTelbKNEnLpLdGFgdyKhG23CKdKgQPOBc+OUNrkJ2vr+KSzsSV5kq5iWhEQbok+quxgGzrAtGWCyU7tHnA==}
engines: {node: '>=4.2.0'}
hasBin: true
dev: true
@ -1963,8 +1967,8 @@ packages:
resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==}
dev: true
/vite/3.2.3_@types+node@18.11.9:
resolution: {integrity: sha512-h8jl1TZ76eGs3o2dIBSsvXDLb1m/Ec1iej8ZMdz+PsaFUsftZeWe2CZOI3qogEsMNaywc17gu0q6cQDzh/weCQ==}
/vite/3.2.4_@types+node@18.11.9:
resolution: {integrity: sha512-Z2X6SRAffOUYTa+sLy3NQ7nlHFU100xwanq1WDwqaiFiCe+25zdxP1TfCS5ojPV2oDDcXudHIoPnI1Z/66B7Yw==}
engines: {node: ^14.18.0 || >=16.0.0}
hasBin: true
peerDependencies:
@ -1989,7 +1993,7 @@ packages:
optional: true
dependencies:
'@types/node': 18.11.9
esbuild: 0.15.13
esbuild: 0.15.15
postcss: 8.4.19
resolve: 1.22.1
rollup: 2.79.1

1
src-tauri/Cargo.lock generated
View File

@ -573,6 +573,7 @@ dependencies = [
"base64",
"bmp",
"color_space",
"futures",
"hex",
"once_cell",
"paris",

View File

@ -31,6 +31,7 @@ hex = "0.4.3"
rumqttc = "0.17.0"
time = { version = "0.3.17", features = ["formatting"] }
color_space = "0.5.3"
futures = "0.3.25"
[features]
# by default Tauri runs in production mode

View File

@ -1,13 +1,23 @@
use futures::{future::join_all, stream::FuturesUnordered, StreamExt};
use once_cell::sync::OnceCell;
use paris::info;
use serde::{Deserialize, Serialize};
use std::{sync::Arc, time::Duration};
use serde_json::value::Index;
use std::{collections::HashMap, iter::Map, sync::Arc, thread, time::Duration};
use tauri::async_runtime::RwLock;
use tokio::{sync::Mutex, time::sleep};
use tokio::{
join,
sync::mpsc,
task,
time::{sleep, Instant},
};
use tracing::warn;
use crate::{
picker::{led_color::LedColor, manager::Picker},
picker::{
config::DisplayConfig, display_picker::DisplayPicker, led_color::LedColor, manager::Picker,
screenshot::Screenshot,
},
rpc,
};
@ -81,45 +91,100 @@ impl CoreManager {
}
pub async fn play_follow(&self) -> anyhow::Result<()> {
{
info!("Following A");
let lock = self.ambient_light_mode.read().await;
if let AmbientLightMode::Follow = *lock {
Picker::global().refresh_displays().await?;
info!("Following B");
} else {
return Ok(());
}
}
let lock = self.ambient_light_mode.read().await;
let mut futs = vec![];
if let AmbientLightMode::Follow = *lock {
drop(lock);
let configs = Picker::global().display_configs.lock().await;
loop {
info!("Following");
let lock = self.ambient_light_mode.read().await;
if let AmbientLightMode::Follow = *lock {
match Picker::global().take_screenshots_for_all().await {
Ok(_) => {
let colors = Picker::global().get_led_strip_colors().await;
match colors {
Ok(colors) => {
let colors = colors.into_iter().rev().collect();
rpc::manager::Manager::global()
.publish_led_colors(&colors)
.await;
}
Err(error) => {
warn!("get strip colors failed. {}", error);
}
let (tx, mut rx) = mpsc::channel(10);
for config in configs.to_owned() {
let tx = tx.clone();
let fut = tokio::spawn(async move {
match Self::follow_display_by_config(config, tx).await {
Ok(_) => {}
Err(error) => {
warn!("following failed. {}", error);
}
}
Err(error) => {
warn!("take screenshots failed. {}", error);
}
}
} else {
break;
});
futs.push(fut);
}
let configs = configs.clone();
tokio::spawn(async move {
let mut global_colors = HashMap::new();
while let Some(screenshot) = rx.recv().await {
let start_at = Instant::now();
match screenshot.get_top_colors().await {
Ok(colors) => {
let start = screenshot.get_top_of_led_strip_range().min().unwrap_or(0);
let colors_len = colors.len();
for (index, color) in colors.into_iter().enumerate() {
global_colors.insert(index + start, color);
}
if global_colors.len() == 60 {
let mut colors = vec![];
for index in 0..global_colors.len() {
colors.push(*global_colors.get(&index).unwrap());
}
global_colors = HashMap::new();
match rpc::manager::Manager::global()
.publish_led_colors(&colors)
.await
{
Ok(_) => {
info!("publish successful",);
}
Err(error) => {
warn!("publish led colors failed. {}", error);
}
}
}
}
Err(_) => {}
};
}
});
join_all(futs).await;
} else {
drop(lock);
return Ok(());
}
Ok(())
}
async fn follow_display_by_config(
config: DisplayConfig,
tx: mpsc::Sender<Screenshot>,
) -> anyhow::Result<()> {
let mut picker = DisplayPicker::from_config(config)?;
loop {
let start = Instant::now();
let next_tick = start + Duration::from_millis(16);
let lock = Self::global().ambient_light_mode.read().await;
if let AmbientLightMode::Follow = *lock {
drop(lock);
let screenshot = picker.take_screenshot()?;
// info!("Take Screenshot Spend: {:?}", start.elapsed());
tx.send(screenshot).await;
} else {
break;
}
tokio::time::sleep_until(next_tick).await;
}
// // Picker::global().take_screenshots_for_all().await?;
// // let colors = Picker::global().get_led_strip_colors().await?;
// // let colors = colors.into_iter().rev().collect();
Ok(())
}
}

View File

@ -7,12 +7,12 @@ mod core;
mod picker;
mod rpc;
use crate::core::CoreManager;
use crate::core::AmbientLightMode;
use crate::core::CoreManager;
use paris::*;
use picker::led_color::LedColor;
use picker::manager::Picker;
use std::time::Instant;
use std::vec;
#[tauri::command]
async fn refresh_displays() {
@ -26,24 +26,22 @@ async fn refresh_displays() {
#[tauri::command]
async fn take_snapshot() -> Vec<String> {
let start = Instant::now();
let manager = Picker::global();
match manager.take_screenshots_for_all().await {
Ok(screenshots) => {
info!("screenshots len: {}", screenshots.len());
let mut futures = Vec::new();
for screenshot in screenshots {
let future = screenshot.to_webp_base64().await;
futures.push(future);
}
futures
let start = time::Instant::now();
let base64_bitmap_list = match manager.list_displays().await {
Ok(base64_bitmap_list) => {
info!("screenshots len: {}", base64_bitmap_list.len());
base64_bitmap_list
}
Err(error) => {
error!("can not take screenshots for all. {}", error);
vec![]
}
}
};
info!("截图花费 {} s", start.elapsed().as_seconds_f32());
base64_bitmap_list
}
#[tauri::command]

View File

@ -0,0 +1,58 @@
#[derive(Clone, Copy)]
pub struct LedStripConfig {
pub index: usize,
pub global_start_position: usize,
pub global_end_position: usize,
}
#[derive(Clone, Copy)]
pub struct DisplayConfig {
pub index_of_display: usize,
pub display_width: usize,
pub display_height: usize,
pub top_led_strip: LedStripConfig,
pub bottom_led_strip: LedStripConfig,
pub left_led_strip: LedStripConfig,
pub right_led_strip: LedStripConfig,
}
#[derive(Clone, Copy)]
pub enum LedFlowX {
LR, // from left to right
RL, // from right to left
}
#[derive(Clone, Copy)]
pub enum LedFlowY {
TB, // from top to bottom
BT, // from bottom to top
}
impl DisplayConfig {
pub fn default(index_of_display: usize, display_width: usize, display_height: usize) -> Self {
Self {
index_of_display,
display_width,
display_height,
top_led_strip: LedStripConfig {
index: 0,
global_start_position: 0,
global_end_position: 0,
},
bottom_led_strip: LedStripConfig {
index: 0,
global_start_position: 0,
global_end_position: 0,
},
left_led_strip: LedStripConfig {
index: 0,
global_start_position: 0,
global_end_position: 0,
},
right_led_strip: LedStripConfig {
index: 0,
global_start_position: 0,
global_end_position: 0,
},
}
}
}

View File

@ -0,0 +1,51 @@
use paris::info;
use scrap::{Capturer, Display};
use super::{config::DisplayConfig, screen::Screen, screenshot::Screenshot};
pub struct DisplayPicker {
pub screen: Screen,
pub config: DisplayConfig,
}
impl DisplayPicker {
pub fn new(screen: Screen, config: DisplayConfig) -> Self {
Self { screen, config }
}
pub fn from_config(config: DisplayConfig) -> anyhow::Result<Self> {
let displays = Display::all()
.map_err(|error| anyhow::anyhow!("Can not get all of displays. {}", error))?;
let display = displays
.into_iter()
.skip(config.index_of_display)
.next();
match display {
Some(display) => {
let height = display.height();
let width = display.width();
info!("dw: {}, cw: {}", width, config.display_height);
assert_eq!(width, config.display_width);
let capturer = Capturer::new(display)?;
let screen = Screen::new(capturer, width, height);
Ok(Self { screen, config })
}
None => {
anyhow::bail!("Index out of displays range.")
}
}
}
pub fn take_screenshot(&mut self) -> anyhow::Result<Screenshot> {
let bitmap = self
.screen
.take()
.map_err(|error| anyhow::anyhow!("take screenshot for display failed. {}", error))?;
// info!("bitmap size {}", bitmap.len());
let screenshot = Screenshot::new(bitmap, self.config);
Ok(screenshot)
}
}

View File

@ -1,19 +1,24 @@
use futures::{stream::FuturesUnordered, StreamExt};
use once_cell::sync::OnceCell;
use paris::*;
use scrap::{Capturer, Display};
use paris::info;
use scrap::Display;
use std::sync::Arc;
use tokio::sync::Mutex;
use tokio::{sync::Mutex, task};
use crate::picker::screen::Screen;
use crate::picker::{
config::{LedFlowX, LedFlowY, LedStripConfig},
screen::Screen,
};
use super::{
led_color::LedColor,
screenshot::{Screenshot},
config::DisplayConfig, display_picker::DisplayPicker, led_color::LedColor,
screenshot::Screenshot,
};
pub struct Picker {
pub screens: Arc<Mutex<Vec<Screen>>>,
pub screenshots: Arc<Mutex<Vec<Screenshot>>>,
pub display_configs: Arc<Mutex<Vec<DisplayConfig>>>,
}
impl Picker {
@ -23,46 +28,144 @@ impl Picker {
SCREEN_COLOR_PICKER.get_or_init(|| Picker {
screens: Arc::new(Mutex::new(vec![])),
screenshots: Arc::new(Mutex::new(vec![])),
display_configs: Arc::new(Mutex::new(vec![
DisplayConfig {
index_of_display: 1,
display_width: 1920,
display_height: 1200,
top_led_strip: LedStripConfig {
index: 1,
global_start_position: 32,
global_end_position: 60,
},
bottom_led_strip: LedStripConfig {
index: 0,
global_start_position: 0,
global_end_position: 0,
},
left_led_strip: LedStripConfig {
index: 0,
global_start_position: 0,
global_end_position: 0,
},
right_led_strip: LedStripConfig {
index: 0,
global_start_position: 0,
global_end_position: 0,
},
},
DisplayConfig {
index_of_display: 0,
display_width: 3008,
display_height: 1692,
top_led_strip: LedStripConfig {
index: 0,
global_start_position: 0,
global_end_position: 32,
},
bottom_led_strip: LedStripConfig {
index: 0,
global_start_position: 0,
global_end_position: 0,
},
left_led_strip: LedStripConfig {
index: 0,
global_start_position: 0,
global_end_position: 0,
},
right_led_strip: LedStripConfig {
index: 0,
global_start_position: 0,
global_end_position: 0,
},
},
])),
})
}
pub async fn refresh_displays(&self) -> anyhow::Result<()> {
pub async fn list_displays(&self) -> anyhow::Result<Vec<String>> {
let mut configs = self.display_configs.lock().await;
let screenshots = self.screenshots.lock().await;
let displays = Display::all()
.map_err(|error| anyhow::anyhow!("Can not get all of displays. {}", error))?;
let mut screens = self.screens.lock().await;
let mut screenshots = self.screenshots.lock().await;
screens.clear();
info!("number of displays: {}", displays.len());
for display in displays {
configs.clear();
let mut futs = FuturesUnordered::new();
for (index, display) in displays.iter().enumerate() {
let height = display.height();
let width = display.width();
match Capturer::new(display) {
Ok(capturer) => screens.push(Screen::new(capturer, width, height)),
Err(error) => screens.push(Screen::new_failed(
anyhow::anyhow!("{}", error),
width,
height,
)),
};
screenshots.push(Screenshot::new(width, height));
let config = DisplayConfig::default(index, width, height);
configs.push(config);
}
screens.reverse();
screenshots.reverse();
screenshots[0].set_number_of_leds(22, 0);
screenshots[1].set_number_of_leds(38, 0);
for (index, display) in displays.iter().enumerate() {
let height = display.height();
let width = display.width();
let config = configs[index];
futs.push(async move {
let join = task::spawn(Self::preview_display_by_config(config));
join.await?
});
}
let mut bitmap_string_list = vec![];
while let Some(bitmap_string) = futs.next().await {
match bitmap_string {
Ok(bitmap_string) => {
bitmap_string_list.push(bitmap_string);
}
Err(error) => {
anyhow::bail!("can not convert to base64 image. {}", error);
}
}
}
Ok(bitmap_string_list)
}
pub async fn preview_display_by_config(config: DisplayConfig) -> anyhow::Result<String> {
let start = time::Instant::now();
let mut picker = DisplayPicker::from_config(config)?;
let screenshot = picker.take_screenshot()?;
info!("Take Screenshot Spend: {}", start.elapsed());
anyhow::Ok(screenshot.to_webp_base64().await)
}
pub async fn refresh_displays(&self) -> anyhow::Result<()> {
// let displays = Display::all()
// .map_err(|error| anyhow::anyhow!("Can not get all of displays. {}", error))?;
// let mut screens = self.screens.lock().await;
// let mut screenshots = self.screenshots.lock().await;
// screens.clear();
// info!("number of displays: {}", displays.len());
// for display in displays {
// let height = display.height();
// let width = display.width();
// match Capturer::new(display) {
// Ok(capturer) => screens.push(Screen::new(capturer, width, height)),
// Err(error) => screens.push(Screen::new_failed(
// anyhow::anyhow!("{}", error),
// width,
// height,
// )),
// };
// screenshots.push(Screenshot::new(width, height));
// }
// screens.reverse();
// screenshots.reverse();
Ok(())
}
pub async fn take_screenshots_for_all(&self) -> anyhow::Result<Vec<Screenshot>> {
let mut screens = self.screens.lock().await;
let mut screenshots = self.screenshots.lock().await;
let screenshots = self.screenshots.lock().await;
for (index, screen) in screens.iter_mut().enumerate() {
let bitmap = screen.take().map_err(|error| {
anyhow::anyhow!("take screenshot for display failed. {}", error)
})?;
screenshots[index].set_bitmap(bitmap).await
}
Ok(screenshots.to_vec())
}

View File

@ -1,4 +1,6 @@
pub mod led_color;
pub mod screen;
pub mod manager;
pub mod screenshot;
pub mod screenshot;
pub mod display_picker;
pub mod config;

View File

@ -1,5 +1,5 @@
use scrap::Capturer;
use std::{io::ErrorKind::WouldBlock, time::Duration, thread};
pub struct Screen {
capturer: Option<Capturer>,
@ -29,15 +29,24 @@ impl Screen {
pub fn take(&mut self) -> anyhow::Result<Vec<u8>> {
match self.capturer.as_mut() {
Some(capturer) => {
let buffer = capturer
.frame()
.map_err(|error| anyhow::anyhow!("failed to frame of display. {}", error))?;
anyhow::Ok(buffer.to_vec())
}
Some(capturer) => loop {
match capturer.frame() {
Ok(buffer) => {
return anyhow::Ok(buffer.to_vec());
}
Err(error) => {
if error.kind() == WouldBlock {
thread::sleep(Duration::from_millis(16));
continue;
} else {
anyhow::bail!("failed to frame of display. {}", error);
}
}
}
},
None => anyhow::bail!("Do not initialized"),
}
}
}
unsafe impl Send for Screen {}
unsafe impl Send for Screen {}

View File

@ -1,126 +1,106 @@
use color_space::{Hsv, Rgb};
use paris::info;
use std::sync::Arc;
use tokio::sync::Mutex;
use super::led_color::LedColor;
use std::ops::Range;
use color_space::{Hsv, Rgb};
use super::{
config::{DisplayConfig, LedStripConfig},
led_color::LedColor,
};
#[derive(Clone)]
pub struct Screenshot {
bitmap: Arc<Mutex<Option<Vec<u8>>>>,
width: usize,
height: usize,
led_number_of_x: usize,
led_number_of_y: usize,
bitmap: Vec<u8>,
config: DisplayConfig,
}
impl Screenshot {
pub fn new(width: usize, height: usize) -> Self {
Self {
bitmap: Arc::new(Mutex::new(None)),
led_number_of_x: 0,
led_number_of_y: 0,
width,
height,
}
pub fn new(bitmap: Vec<u8>, config: DisplayConfig) -> Self {
Self { bitmap, config }
}
pub fn get_size(&self) -> (usize, usize) {
(self.width, self.height)
}
pub fn get_number_of_leds(&self) -> (usize, usize) {
(self.led_number_of_x, self.led_number_of_y)
}
pub fn set_number_of_leds(&mut self, led_number_of_x: usize, led_number_of_y: usize) {
self.led_number_of_x = led_number_of_x;
self.led_number_of_y = led_number_of_y;
}
pub async fn get_top_colors(&self) -> anyhow::Result<Vec<LedColor>> {
self.get_x_colors(XPosition::Top).await
self.get_x_colors(XPosition::Top, self.config.top_led_strip)
.await
}
pub async fn get_bottom_colors(&self) -> anyhow::Result<Vec<LedColor>> {
self.get_x_colors(XPosition::Bottom).await
self.get_x_colors(XPosition::Bottom, self.config.bottom_led_strip)
.await
}
async fn get_x_colors(&self, position: XPosition) -> anyhow::Result<Vec<LedColor>> {
if self.led_number_of_x == 0 {
return Ok(vec![]);
}
pub fn get_top_of_led_strip_range(&self) -> Range<usize> {
self.config.top_led_strip.global_start_position
..self.config.top_led_strip.global_end_position
}
let bitmap = self.bitmap.lock().await;
match bitmap.as_ref() {
Some(bitmap) => {
let cell_size_x = self.width / self.led_number_of_x;
let cell_size_y = self.height / 5;
let cell_size = cell_size_x * cell_size_y;
let y_range = match position {
XPosition::Top => 0..cell_size_y,
XPosition::Bottom => self.height - cell_size_y..self.height,
};
let mut colors = Vec::new();
let stride = bitmap.len() / self.height;
for pos in 0..self.led_number_of_x {
let mut r = 0.0;
let mut g = 0.0;
let mut b = 0.0;
for x in pos * cell_size_x..(pos + 1) * cell_size_x {
for y in y_range.to_owned() {
let i = stride * y + 4 * x;
r += bitmap[i + 2] as f64;
g += bitmap[i + 1] as f64;
b += bitmap[i] as f64;
}
}
let rgb = Rgb::new(
r / cell_size as f64,
g / cell_size as f64,
b / cell_size as f64,
);
let hsv = Hsv::from(rgb);
// info!("HSV: {:?}", [hsv.h, hsv.s, hsv.v]);
let color = LedColor::from_hsv(hsv.h, hsv.s, hsv.v);
// info!("color: {:?}", color.get_rgb());
colors.push(color);
}
return Ok(colors);
async fn get_x_colors(
&self,
position: XPosition,
strip_config: LedStripConfig,
) -> anyhow::Result<Vec<LedColor>> {
let bitmap = &self.bitmap;
let number_of_leds = strip_config
.global_start_position
.abs_diff(strip_config.global_end_position);
let cell_size_x = self.config.display_width / number_of_leds;
let cell_size_y = self.config.display_height / 8;
let cell_size = cell_size_x * cell_size_y;
let y_range = match position {
XPosition::Top => 20..cell_size_y + 20,
XPosition::Bottom => {
self.config.display_height - 20 - cell_size_y..self.config.display_height - 20
}
None => Ok(vec![]),
}
}
};
pub async fn set_bitmap(&mut self, bitmap: Vec<u8>) {
let mut self_bitmap = self.bitmap.lock().await;
*self_bitmap = Some(bitmap);
let mut colors = Vec::new();
let stride = bitmap.len() / self.config.display_height;
for pos in strip_config.global_start_position..strip_config.global_end_position {
let mut r = 0.0;
let mut g = 0.0;
let mut b = 0.0;
for x in pos * cell_size_x..(pos + 1) * cell_size_x {
for y in y_range.to_owned() {
let i = stride * y + 4 * x;
r += bitmap[i + 2] as f64;
g += bitmap[i + 1] as f64;
b += bitmap[i] as f64;
}
}
let rgb = Rgb::new(
r / cell_size as f64,
g / cell_size as f64,
b / cell_size as f64,
);
let hsv = Hsv::from(rgb);
// info!("HSV: {:?}", [hsv.h, hsv.s, hsv.v]);
let color = LedColor::from_hsv(hsv.h, hsv.s, hsv.v);
// info!("color: {:?}", color.get_rgb());
colors.push(color);
}
return Ok(colors);
}
pub async fn to_webp_base64(&self) -> String {
let bitmap = self.bitmap.lock().await;
match bitmap.to_owned() {
Some(bitmap) => {
let mut bitflipped = Vec::with_capacity(self.width * self.height * 3);
let stride = bitmap.len() / self.height;
let bitmap = &self.bitmap;
let mut bitflipped =
Vec::with_capacity(self.config.display_width * self.config.display_height * 3);
let stride = bitmap.len() / self.config.display_height;
for y in 0..self.height {
for x in 0..self.width {
let i = stride * y + 4 * x;
bitflipped.extend_from_slice(&[bitmap[i + 2], bitmap[i + 1], bitmap[i]]);
}
}
let webp_memory = webp::Encoder::from_rgb(
bitflipped.as_slice(),
self.width as u32,
self.height as u32,
)
.encode(100.0);
return base64::encode(&*webp_memory);
for y in 0..self.config.display_height {
for x in 0..self.config.display_width {
let i = stride * y + 4 * x;
bitflipped.extend_from_slice(&[bitmap[i + 2], bitmap[i + 1], bitmap[i]]);
}
None => "".to_owned(),
}
let webp_memory = webp::Encoder::from_rgb(
bitflipped.as_slice(),
self.config.display_width as u32,
self.config.display_height as u32,
)
.encode(100.0);
return base64::encode(&*webp_memory);
}
}