初始化代码

This commit is contained in:
2023-08-21 16:28:25 +08:00
parent 10b05ac359
commit fc6dca918c
39 changed files with 4470 additions and 72 deletions

24
.gitignore vendored Normal file
View File

@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 Hugo ATTAL
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

117
README.md
View File

@@ -1,92 +1,65 @@
# milky-warp
# 🌌 Milky Warp
<p align="center"><i>Navigate the galaxy of pixels with Milky Warp!</i></p>
Milky Warp is an open-source tool that displays a magnifier when pressing a shortcut. It's built with Tauri, Vite, Vue, and Typescript.
## Getting started
## Features
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
- Displays a magnifier when pressing a configurable shortcut
- Supports zoom in and zoom out using the mouse scroll wheel
- Cross-platform: runs on Windows, macOS, and Linux
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Preview
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin http://gitlab.nightb.cn/milky-warp/milky-warp.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](http://gitlab.nightb.cn/milky-warp/milky-warp/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
<p align="center"><img src="https://user-images.githubusercontent.com/4563971/236351314-0082007d-e740-47b3-8505-7e79fec0b653.gif" alt="preview"></p>
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
### Windows
Download the latest release from the [releases page](https://github.com/hugoattal/milky-warp/releases)
### macOS
There is no release for macOS yet. You can build the application from source.
### Linux
There is no release for Linux yet. You can build the application from source.
## Build
1. Clone the repository: `git clone https://github.com/hugoattal/milky-warp.git`
2. Install the dependencies: `pnpm install`
3. Build the application: `pnpm run tauri build`
4. Get the executable from the `src-tauri/target` folder
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
1. Press the shortcut key (default: `Ctrl+Alt+A`) to activate the magnifier
2. Use the mouse to move the magnifier around the screen
3. Use the mouse scroll wheel to zoom in and out
4. Click to fix the magnifier position, and click again to release it
5. Press the shortcut key again to deactivate the magnifier
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
### Experimental
You can also use the shortcut holder. Due to some limitation, it's not as smooth as I would like it to be.
1. Press the shortcut key (default: `Ctrl+Alt+A`) to activate the magnifier
2. Then you can hold and release the hold shortcut (default: `Ctrl+Shift+A`)
3. While the magnifier is hidden using the hold shortcut, you can't click
4. To close this mode, close the magnifier with the normal shortcut (default: `Ctrl+Alt+A`)
## Configuration
You can customize the shortcut key by editing the `src/config.ts` file.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
Contributions are welcome!
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Sponsors
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
- [**Roller Coaster** 🎢](https://roller-coaster.app): Fast track your automations with visual scripting
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
Milky Warp is released under the [MIT License](LICENSE).

14
index.html Normal file
View File

@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tauri + Vue + TS</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>

26
package.json Normal file
View File

@@ -0,0 +1,26 @@
{
"name": "milky-warp",
"private": true,
"version": "1.3.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"tauri": "tauri"
},
"dependencies": {
"@tauri-apps/api": "^1.3.0",
"@vueuse/core": "^10.1.2",
"vue": "^3.3.4"
},
"devDependencies": {
"@tauri-apps/cli": "^1.3.1",
"@types/node": "^20.3.1",
"@vitejs/plugin-vue": "^4.2.3",
"sass": "^1.63.3",
"typescript": "^5.1.3",
"vite": "^4.3.9",
"vue-tsc": "^1.6.5"
}
}

6
public/tauri.svg Normal file
View File

@@ -0,0 +1,6 @@
<svg width="206" height="231" viewBox="0 0 206 231" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M143.143 84C143.143 96.1503 133.293 106 121.143 106C108.992 106 99.1426 96.1503 99.1426 84C99.1426 71.8497 108.992 62 121.143 62C133.293 62 143.143 71.8497 143.143 84Z" fill="#FFC131"/>
<ellipse cx="84.1426" cy="147" rx="22" ry="22" transform="rotate(180 84.1426 147)" fill="#24C8DB"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M166.738 154.548C157.86 160.286 148.023 164.269 137.757 166.341C139.858 160.282 141 153.774 141 147C141 144.543 140.85 142.121 140.558 139.743C144.975 138.204 149.215 136.139 153.183 133.575C162.73 127.404 170.292 118.608 174.961 108.244C179.63 97.8797 181.207 86.3876 179.502 75.1487C177.798 63.9098 172.884 53.4021 165.352 44.8883C157.82 36.3744 147.99 30.2165 137.042 27.1546C126.095 24.0926 114.496 24.2568 103.64 27.6274C92.7839 30.998 83.1319 37.4317 75.8437 46.1553C74.9102 47.2727 74.0206 48.4216 73.176 49.5993C61.9292 50.8488 51.0363 54.0318 40.9629 58.9556C44.2417 48.4586 49.5653 38.6591 56.679 30.1442C67.0505 17.7298 80.7861 8.57426 96.2354 3.77762C111.685 -1.01901 128.19 -1.25267 143.769 3.10474C159.348 7.46215 173.337 16.2252 184.056 28.3411C194.775 40.457 201.767 55.4101 204.193 71.404C206.619 87.3978 204.374 103.752 197.73 118.501C191.086 133.25 180.324 145.767 166.738 154.548ZM41.9631 74.275L62.5557 76.8042C63.0459 72.813 63.9401 68.9018 65.2138 65.1274C57.0465 67.0016 49.2088 70.087 41.9631 74.275Z" fill="#FFC131"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M38.4045 76.4519C47.3493 70.6709 57.2677 66.6712 67.6171 64.6132C65.2774 70.9669 64 77.8343 64 85.0001C64 87.1434 64.1143 89.26 64.3371 91.3442C60.0093 92.8732 55.8533 94.9092 51.9599 97.4256C42.4128 103.596 34.8505 112.392 30.1816 122.756C25.5126 133.12 23.9357 144.612 25.6403 155.851C27.3449 167.09 32.2584 177.598 39.7906 186.112C47.3227 194.626 57.153 200.784 68.1003 203.846C79.0476 206.907 90.6462 206.743 101.502 203.373C112.359 200.002 122.011 193.568 129.299 184.845C130.237 183.722 131.131 182.567 131.979 181.383C143.235 180.114 154.132 176.91 164.205 171.962C160.929 182.49 155.596 192.319 148.464 200.856C138.092 213.27 124.357 222.426 108.907 227.222C93.458 232.019 76.9524 232.253 61.3736 227.895C45.7948 223.538 31.8055 214.775 21.0867 202.659C10.3679 190.543 3.37557 175.59 0.949823 159.596C-1.47592 143.602 0.768139 127.248 7.41237 112.499C14.0566 97.7497 24.8183 85.2327 38.4045 76.4519ZM163.062 156.711L163.062 156.711C162.954 156.773 162.846 156.835 162.738 156.897C162.846 156.835 162.954 156.773 163.062 156.711Z" fill="#24C8DB"/>
</svg>

After

Width:  |  Height:  |  Size: 2.5 KiB

1
public/vite.svg Normal file
View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

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

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

3759
src-tauri/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

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

@@ -0,0 +1,29 @@
[package]
name = "milky-warp"
version = "1.0.0"
description = "Milky Warp"
authors = ["hugoattal"]
license = "MIT"
repository = "https://github.com/hugoattal/milky-warp"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies]
tauri-build = { version = "1.3", features = [] }
[patch.crates-io]
tao = { git = "https://github.com/tauri-apps/tao", branch = "v0.16" }
[dependencies]
tauri = { version = "1.3", features = ["global-shortcut-all", "protocol-asset", "shell-open", "system-tray", "window-hide", "window-set-ignore-cursor-events", "window-set-position", "window-set-size", "window-show"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
enigo = "0.1.2"
screenshots = "0.5.4"
winapi = { version = "0.3.9", features = ["winuser"] }
[features]
# this feature is used for production builds or when `devPath` points to the filesystem
# DO NOT REMOVE!!
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/128x128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

BIN
src-tauri/icons/32x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 974 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 903 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

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

Binary file not shown.

BIN
src-tauri/icons/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

BIN
src-tauri/icons/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

56
src-tauri/src/lib.rs Normal file
View File

@@ -0,0 +1,56 @@
#[cfg(target_os = "windows")]
extern crate winapi;
#[cfg(target_os = "windows")]
pub fn get_screen_index_from_cursor_pos(cursor_pos: (i32, i32)) -> u32 {
use winapi::shared::windef::{POINT, HMONITOR, HDC, LPRECT};
use winapi::shared::minwindef::{LPARAM, BOOL};
use winapi::um::winuser::{MonitorFromPoint, MONITOR_DEFAULTTONEAREST, EnumDisplayMonitors};
let point = POINT { x: cursor_pos.0, y: cursor_pos.1 };
let monitor = unsafe { MonitorFromPoint(point, MONITOR_DEFAULTTONEAREST) };
let mut index = 0;
static mut GLOBAL_MONITOR: HMONITOR = std::ptr::null_mut();
static mut GLOBAL_INDEX: u32 = 0;
unsafe {
GLOBAL_MONITOR = monitor;
GLOBAL_INDEX = index;
}
unsafe extern "system" fn monitor_enum_proc(hmonitor: HMONITOR, _: HDC, _: LPRECT, _: LPARAM) -> BOOL {
if hmonitor == GLOBAL_MONITOR {
return 0;
}
GLOBAL_INDEX += 1;
1
}
unsafe {
EnumDisplayMonitors(
std::ptr::null_mut(),
std::ptr::null_mut(),
Some(monitor_enum_proc),
0,
)
};
unsafe {
index = GLOBAL_INDEX;
}
return index;
}
#[cfg(target_os = "linux")]
pub fn get_screen_index_from_cursor_pos(cursor_pos: (i32, i32)) -> u32 {
return 0;
}
#[cfg(target_os = "macos")]
pub fn get_screen_index_from_cursor_pos(cursor_pos: (i32, i32)) -> u32 {
return 0;
}

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

@@ -0,0 +1,78 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use std::fs;
use enigo::Enigo;
use enigo::MouseControllable;
use screenshots::Screen;
static mut SCREENSHOT_PATH: String = String::new();
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
#[tauri::command]
fn get_mouse_location() -> String {
let enigo = Enigo::new();
let cursor_location: (i32, i32) = enigo.mouse_location();
format!("{};{}", cursor_location.0, cursor_location.1)
}
fn capture_screen() -> String {
let enigo = Enigo::new();
let cursor_location: (i32, i32) = enigo.mouse_location();
let screen_index = milky_warp::get_screen_index_from_cursor_pos(cursor_location);
let display = Screen::all().expect("Couldn't find primary display.");
let image = display[screen_index as usize].capture().expect("Couldn't capture display.");
let buffer = image.buffer();
let temp_dir = std::env::temp_dir();
let file_path = temp_dir.join("screenshot.png");
fs::write(file_path.clone(), buffer).unwrap();
file_path.to_str().unwrap().to_owned()
}
#[tauri::command]
fn update_screenshot() -> String {
unsafe {
SCREENSHOT_PATH = capture_screen();
SCREENSHOT_PATH.clone()
}
}
#[tauri::command]
fn get_screenshot_path() -> String {
unsafe {
SCREENSHOT_PATH.clone()
}
}
fn make_tray() -> tauri::SystemTray {
let tray_menu = tauri::SystemTrayMenu::new()
.add_item(tauri::CustomMenuItem::new("quit".to_string(), "Quit"));
return tauri::SystemTray::new()
.with_menu(tray_menu);
}
fn handle_tray_event(app: &tauri::AppHandle, event: tauri::SystemTrayEvent) {
if let tauri::SystemTrayEvent::MenuItemClick { id, .. } = event {
if id.as_str() == "quit" {
app.exit(0);
}
}
}
fn main() {
update_screenshot();
tauri::Builder::default()
.system_tray(make_tray())
.on_system_tray_event(handle_tray_event)
.invoke_handler(tauri::generate_handler![get_mouse_location, get_screenshot_path, update_screenshot])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

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

@@ -0,0 +1,72 @@
{
"build": {
"beforeDevCommand": "pnpm dev",
"beforeBuildCommand": "pnpm build",
"devPath": "http://localhost:1420",
"distDir": "../dist",
"withGlobalTauri": false
},
"package": {
"productName": "milky-warp",
"version": "../package.json"
},
"tauri": {
"allowlist": {
"all": false,
"shell": {
"all": false,
"open": true
},
"window": {
"setPosition": true,
"setIgnoreCursorEvents": true,
"setSize": true,
"show": true,
"hide": true
},
"protocol": {
"asset": true,
"assetScope": ["**"]
},
"globalShortcut": {
"all": true
}
},
"bundle": {
"active": true,
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"identifier": "com.milky-warp.app",
"targets": "all"
},
"security": {
"csp": "default-src 'self'; img-src 'self' asset: https://asset.localhost"
},
"updater": {
"active": false
},
"windows": [
{
"fullscreen": false,
"resizable": false,
"title": "Milky Warp",
"width": 256,
"height": 256,
"transparent": true,
"decorations": false,
"alwaysOnTop": true,
"center": true,
"visible": false
}
],
"systemTray": {
"iconPath": "icons/icon.png",
"iconAsTemplate": true
}
}
}

78
src/App.vue Normal file
View File

@@ -0,0 +1,78 @@
<template>
<MZoom :screenshot-path="screenshotPath" :is-active="isWindowDisplayed" :class="{hide: holdHide}"/>
</template>
<script setup lang="ts">
import MZoom from "./components/Zoom.vue";
import { register } from "@tauri-apps/api/globalShortcut";
import { window } from "@tauri-apps/api";
import { convertFileSrc, invoke } from "@tauri-apps/api/tauri";
import { nextTick, onMounted, ref, watch } from "vue";
import { config } from "./config";
import { useMagicKeys } from "@vueuse/core";
const keys = useMagicKeys();
const holdShortcut = keys[config.holdShortcut];
const isWindowDisplayed = ref(false);
const screenshotPath = ref("");
const holdHide = ref(false);
onMounted(async () => {
screenshotPath.value = convertFileSrc((await invoke("get_screenshot_path", {})).replaceAll("\\", "/"));
});
register(config.shortcut, async () => {
isWindowDisplayed.value = !isWindowDisplayed.value;
await nextTick(); // Needed to avoid position flickering
if (!isWindowDisplayed.value) {
await window.getCurrent().hide();
}
else {
holdHide.value = false;
screenshotPath.value = convertFileSrc((await invoke("update_screenshot", {})).replaceAll("\\", "/")) + "?" + Date.now();
await window.getCurrent().show();
//await window.getCurrent().setFocus();
}
});
watch(holdShortcut, async (value) => {
if (value) {
if (isWindowDisplayed.value) {
return
}
isWindowDisplayed.value = true;
await nextTick(); // Needed to avoid position flickering
screenshotPath.value = convertFileSrc((await invoke("update_screenshot", {})).replaceAll("\\", "/")) + "?" + Date.now();
holdHide.value = false;
}
else {
holdHide.value = true;
isWindowDisplayed.value = false;
}
});
</script>
<style lang="scss" scoped>
.hide {
display: none;
}
</style>
<style lang="scss">
html, body {
margin: 0;
background-color: transparent;
#app {
height: 100vh;
overflow-y: auto;
}
}
</style>

1
src/assets/vue.svg Normal file
View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>

After

Width:  |  Height:  |  Size: 496 B

184
src/components/Zoom.vue Normal file
View File

@@ -0,0 +1,184 @@
<template>
<div class="wrapper" @wheel="updateZoom" @click="toggleMove">
<div class="screen" :style="screenStyle"></div>
</div>
</template>
<script setup lang="ts">
import {computed, onBeforeMount, watch, reactive, ref} from "vue";
import {invoke} from "@tauri-apps/api/tauri";
import {window} from "@tauri-apps/api";
import {LogicalPosition, LogicalSize} from "@tauri-apps/api/window";
const props = defineProps<{
screenshotPath: string;
isActive: boolean;
}>();
const WINDOW_SIZE_X = 256;
const WINDOW_SIZE_Y = 128;
const move = ref(true);
const lockOnScreen = ref(false);
const zoomLevel = ref(0);
const targetZoomLevel = ref(0);
const scale = computed(() => Math.pow(1.5, targetZoomLevel.value));
const cursor = {x: 0, y: 0};
const savedLocation = reactive({x: 0, y: 0});
const targetLocation = {x: 0, y: 0};
const monitor = {
size: {x: 0, y: 0},
position: {x: 0, y: 0},
scale: 1
}
let forceInstantMove = false;
const screenStyle = computed(() => {
return {
backgroundImage: `url(${props.screenshotPath})`,
backgroundPosition: `${-savedLocation.x + monitor.position.x / monitor.scale}px ${-savedLocation.y + monitor.position.y / monitor.scale}px`,
backgroundSize: `${monitor.size.x / monitor.scale}px ${monitor.size.y / monitor.scale}px`,
};
});
onBeforeMount(updateWindowSize);
watch(() => scale.value, updateWindowSize);
watch(() => props.isActive, async () => {
if (props.isActive) {
forceInstantMove = true;
move.value = true;
lockOnScreen.value = false;
await moveLoop();
await updateMonitor();
lockOnScreen.value = true;
}
}, {
immediate: true
});
async function updateMonitor() {
const currentMonitor = await window.currentMonitor();
if (!currentMonitor) {
return;
}
const position = currentMonitor.position;
const size = currentMonitor.size;
const scaleFactor = currentMonitor.scaleFactor
monitor.position = {x: position.x, y: position.y};
monitor.size = {x: size.width, y: size.height};
monitor.scale = scaleFactor;
}
async function updateZoom(event: WheelEvent) {
zoomLevel.value -= event.deltaY / 100;
zoomLevel.value = Math.max(0, zoomLevel.value);
zoomLevel.value = Math.min(4, zoomLevel.value);
}
async function updateWindowSize() {
await window.getCurrent().setSize(
new LogicalSize(
scale.value * WINDOW_SIZE_X,
scale.value * WINDOW_SIZE_Y
)
);
}
async function windowMove() {
const mouseLocation = await invoke("get_mouse_location", {});
const location = mouseLocation.split(";").map(v => parseInt(v) / monitor.scale);
cursor.x = location[0];
cursor.y = location[1];
targetLocation.x = cursor.x - (scale.value * WINDOW_SIZE_X) / 2;
targetLocation.y = cursor.y - (scale.value * WINDOW_SIZE_Y) / 2;
const moveWindow = async () => {
await window.appWindow.setPosition(getWindowPosition());
};
await Promise.all([
updateSavedLocation(),
moveWindow()
]);
}
function getWindowPosition() {
if (!lockOnScreen.value) {
return new LogicalPosition(
targetLocation.x,
targetLocation.y
);
}
return new LogicalPosition(
clamp(targetLocation.x, monitor.position.x, monitor.position.x + monitor.size.x / monitor.scale - scale.value * WINDOW_SIZE_X),
clamp(targetLocation.y, monitor.position.y, monitor.position.y + monitor.size.y / monitor.scale - scale.value * WINDOW_SIZE_Y)
);
function clamp(value: number, min: number, max: number) {
return Math.min(Math.max(value, min), max);
}
}
async function updateSavedLocation() {
const alpha = forceInstantMove ? 1 : 0.3;
forceInstantMove = false;
targetZoomLevel.value = lerp(targetZoomLevel.value, zoomLevel.value, alpha);
savedLocation.x = lerp(savedLocation.x, targetLocation.x, alpha);
savedLocation.y = lerp(savedLocation.y, targetLocation.y, alpha);
function lerp(a: number, b: number, alpha: number) {
return a * (1 - alpha) + b * alpha;
}
}
async function moveLoop() {
await windowMove();
if (props.isActive && move.value) {
requestAnimationFrame(moveLoop);
}
}
async function toggleMove() {
move.value = !move.value;
await moveLoop();
}
</script>
<style scoped lang="scss">
.wrapper {
border-radius: 16px;
width: 100%;
height: 100%;
overflow: hidden;
display: flex;
position: relative;
&::after {
content: "";
position: absolute;
inset: 0;
border-radius: 16px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
}
.screen {
image-rendering: pixelated;
opacity: 1;
width: 100%;
height: 100%;
transform: scale(v-bind(scale));
background-repeat: no-repeat;
}
}
</style>

4
src/config.ts Normal file
View File

@@ -0,0 +1,4 @@
export const config = {
"shortcut": "Ctrl+Shift+E",
"holdShortcut": "Shift+Ctrl+W",
}

4
src/main.ts Normal file
View File

@@ -0,0 +1,4 @@
import { createApp } from "vue";
import App from "./App.vue";
createApp(App).mount("#app");

7
src/vite-env.d.ts vendored Normal file
View File

@@ -0,0 +1,7 @@
/// <reference types="vite/client" />
declare module "*.vue" {
import type { DefineComponent } from "vue";
const component: DefineComponent<{}, {}, any>;
export default component;
}

18
tsconfig.json Normal file
View File

@@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"module": "ESNext",
"moduleResolution": "Node",
"strict": true,
"jsx": "preserve",
"sourceMap": true,
"resolveJsonModule": true,
"isolatedModules": true,
"esModuleInterop": true,
"lib": ["ESNext", "DOM"],
"skipLibCheck": true
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"references": [{ "path": "./tsconfig.node.json" }]
}

9
tsconfig.node.json Normal file
View File

@@ -0,0 +1,9 @@
{
"compilerOptions": {
"composite": true,
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}

27
vite.config.ts Normal file
View File

@@ -0,0 +1,27 @@
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
// https://vitejs.dev/config/
export default defineConfig(async () => ({
plugins: [vue()],
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
// prevent vite from obscuring rust errors
clearScreen: false,
// tauri expects a fixed port, fail if that port is not available
server: {
port: 1420,
strictPort: true,
},
// to make use of `TAURI_DEBUG` and other env variables
// https://tauri.studio/v1/api/config#buildconfig.beforedevcommand
envPrefix: ["VITE_", "TAURI_"],
build: {
// Tauri supports es2021
target: process.env.TAURI_PLATFORM == "windows" ? "chrome105" : "safari13",
// don't minify for debug builds
minify: !process.env.TAURI_DEBUG ? "esbuild" : false,
// produce sourcemaps for debug builds
sourcemap: !!process.env.TAURI_DEBUG,
},
}));