Make some basic timer functionality
9
.vscode/launch.json
vendored
@ -23,10 +23,15 @@
|
||||
"request": "launch",
|
||||
"name": "Tauri Production Debug",
|
||||
"cargo": {
|
||||
"args": ["build", "--release", "--manifest-path=./src-tauri/Cargo.toml"]
|
||||
"args": [
|
||||
"build",
|
||||
"--release",
|
||||
"--manifest-path=./src-tauri/Cargo.toml"
|
||||
]
|
||||
},
|
||||
// task for the `beforeBuildCommand` if used, must be configured in `.vscode/tasks.json`
|
||||
"preLaunchTask": "ui:build"
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
|
43
.vscode/tasks.json
vendored
@ -3,30 +3,43 @@
|
||||
// for the documentation about the tasks.json format
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "tauri:dev",
|
||||
"type": "shell",
|
||||
"command": "cargo",
|
||||
"problemMatcher": [],
|
||||
"args": [
|
||||
"tauri",
|
||||
"dev"
|
||||
],
|
||||
"icon": {
|
||||
"id": "run"
|
||||
},
|
||||
},
|
||||
{
|
||||
"label": "ui:dev",
|
||||
"type": "shell",
|
||||
// `dev` keeps running in the background
|
||||
// ideally you should also configure a `problemMatcher`
|
||||
// see https://code.visualstudio.com/docs/editor/tasks#_can-a-background-task-be-used-as-a-prelaunchtask-in-launchjson
|
||||
"isBackground": true,
|
||||
// change this to your `beforeDevCommand`:
|
||||
"command": "npm",
|
||||
"args": ["run", "dev"]
|
||||
"problemMatcher": [],
|
||||
"args": [
|
||||
"run",
|
||||
"dev",
|
||||
"--",
|
||||
"--clearScreen",
|
||||
"false"
|
||||
]
|
||||
},
|
||||
{
|
||||
"label": "ui:build",
|
||||
"group": "build",
|
||||
"type": "shell",
|
||||
// change this to your `beforeBuildCommand`:
|
||||
"command": "npm",
|
||||
"args": ["run", "build"],
|
||||
},
|
||||
{
|
||||
"label": "full:dev",
|
||||
"type": "shell",
|
||||
"isBackground": true,
|
||||
"command": "cargo",
|
||||
"args": ["tauri", "dev"]
|
||||
"problemMatcher": [],
|
||||
"args": [
|
||||
"run",
|
||||
"build"
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
}
|
@ -2,6 +2,14 @@
|
||||
|
||||
A basic timer for my broken brain.
|
||||
|
||||
## Acknowledgements
|
||||
|
||||
- Potato icon from https://github.com/googlefonts/noto-emoji
|
||||
|
||||
## Forking
|
||||
|
||||
I'm developing this for myself, and have limited goals.
|
||||
|
||||
## License
|
||||
|
||||
Copyright (C) 2022 ModZero
|
||||
|
@ -2,9 +2,9 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<link rel="icon" type="image/svg+xml" href="/potato.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite + Svelte + TS</title>
|
||||
<title>Ziemniak</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
|
30
package-lock.json
generated
@ -7,6 +7,7 @@
|
||||
"": {
|
||||
"name": "ziemniak",
|
||||
"version": "0.0.0",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^1.0.2"
|
||||
},
|
||||
@ -14,6 +15,8 @@
|
||||
"@sveltejs/vite-plugin-svelte": "^1.0.1",
|
||||
"@tauri-apps/cli": "^1.0.5",
|
||||
"@tsconfig/svelte": "^3.0.0",
|
||||
"@types/luxon": "^3.0.0",
|
||||
"luxon": "^3.0.1",
|
||||
"svelte": "^3.49.0",
|
||||
"svelte-check": "^2.8.0",
|
||||
"svelte-preprocess": "^4.10.7",
|
||||
@ -313,6 +316,12 @@
|
||||
"integrity": "sha512-pYrtLtOwku/7r1i9AMONsJMVYAtk3hzOfiGNekhtq5tYBGA7unMve8RvUclKLMT3PrihvJqUmzsRGh0RP84hKg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/luxon": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/luxon/-/luxon-3.0.0.tgz",
|
||||
"integrity": "sha512-Lx+EZoJxUKw4dp8uei9XiUVNlgkYmax5+ovqt6Xf3LzJOnWhlfJw/jLBmqfGVwOP/pDr4HT8bI1WtxK0IChMLw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "18.6.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.6.1.tgz",
|
||||
@ -1045,6 +1054,15 @@
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/luxon": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/luxon/-/luxon-3.0.1.tgz",
|
||||
"integrity": "sha512-hF3kv0e5gwHQZKz4wtm4c+inDtyc7elkanAsBq+fundaCdUBNJB1dHEGUZIM6SfSBUlbVFduPwEtNjFK8wLtcw==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/magic-string": {
|
||||
"version": "0.26.2",
|
||||
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.26.2.tgz",
|
||||
@ -1789,6 +1807,12 @@
|
||||
"integrity": "sha512-pYrtLtOwku/7r1i9AMONsJMVYAtk3hzOfiGNekhtq5tYBGA7unMve8RvUclKLMT3PrihvJqUmzsRGh0RP84hKg==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/luxon": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/luxon/-/luxon-3.0.0.tgz",
|
||||
"integrity": "sha512-Lx+EZoJxUKw4dp8uei9XiUVNlgkYmax5+ovqt6Xf3LzJOnWhlfJw/jLBmqfGVwOP/pDr4HT8bI1WtxK0IChMLw==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "18.6.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.6.1.tgz",
|
||||
@ -2245,6 +2269,12 @@
|
||||
"integrity": "sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ==",
|
||||
"dev": true
|
||||
},
|
||||
"luxon": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/luxon/-/luxon-3.0.1.tgz",
|
||||
"integrity": "sha512-hF3kv0e5gwHQZKz4wtm4c+inDtyc7elkanAsBq+fundaCdUBNJB1dHEGUZIM6SfSBUlbVFduPwEtNjFK8wLtcw==",
|
||||
"dev": true
|
||||
},
|
||||
"magic-string": {
|
||||
"version": "0.26.2",
|
||||
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.26.2.tgz",
|
||||
|
@ -15,6 +15,8 @@
|
||||
"@sveltejs/vite-plugin-svelte": "^1.0.1",
|
||||
"@tauri-apps/cli": "^1.0.5",
|
||||
"@tsconfig/svelte": "^3.0.0",
|
||||
"@types/luxon": "^3.0.0",
|
||||
"luxon": "^3.0.1",
|
||||
"svelte": "^3.49.0",
|
||||
"svelte-check": "^2.8.0",
|
||||
"svelte-preprocess": "^4.10.7",
|
||||
|
23
public/potato.svg
Normal file
@ -0,0 +1,23 @@
|
||||
<svg width="128" height="128" style="enable-background:new 0 0 128 128;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<g id="Layer_2" style="display:none;">
|
||||
<path d=" M71.52,44.35c-6.36-3.15-15.04-9.52-16.33-11.23" style="display:inline;fill:none;stroke:#330000;stroke-width:1.8115;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;"/>
|
||||
<path d=" M100.93,47.54c-15.84-1.92-37.94-15.19-39.85-16.57" style="display:inline;fill:none;stroke:#330000;stroke-width:1.8115;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;"/>
|
||||
<path d=" M106.25,41.12C86.91,39.26,66.33,28.38,65.9,27.88" style="display:inline;fill:none;stroke:#330000;stroke-width:1.8115;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;"/>
|
||||
<path d=" M114.28,34.86c-15.82-0.36-42.16-9.41-43.57-10.08" style="display:inline;fill:none;stroke:#330000;stroke-width:1.8115;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;"/>
|
||||
<path d=" M113.84,26.83c-12.91,1.05-38.1-5.93-38.94-6.04" style="display:inline;fill:none;stroke:#330000;stroke-width:1.8115;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;"/>
|
||||
<path d=" M105.04,19.23c-9.5,1-26.01-3.26-27.3-3.53" style="display:inline;fill:none;stroke:#330000;stroke-width:1.8115;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;"/>
|
||||
</g>
|
||||
<g id="图层_1">
|
||||
<path d="M112.51,21.82c-4.8-3.07-10.15-5.51-15.56-7.61c-7.7-2.99-15.42-3.67-23.2-2.18 c-6.89,1.32-13.39,4.5-18.93,8.9c-3.46,2.74-6.92,5.49-10.13,8.47c-7.74,7.2-15.59,14.39-22.55,22.25 C16.01,58.56,10.52,66.11,5.7,73.88c-4.14,6.67-4.63,13.99-2.16,21.24c5.5,16.09,31.28,26.36,47.4,19.42 c5.88-2.53,11.69-5.27,17.48-8.01c6.66-3.15,13.16-6.7,19.94-9.56c20.74-8.77,32.83-24.01,36.89-44.51 C127.77,39.74,123.59,28.9,112.51,21.82z M60.63,33.33c0.11,0.42-0.25-0.01-0.14,0.41c-0.03-0.11-0.06-0.23-0.09-0.34 C60.48,33.37,60.56,33.35,60.63,33.33z" style="fill:#B89278;"/>
|
||||
<g>
|
||||
<path d="M104.36,70.22c-0.09,0-0.18-0.02-0.26-0.07c-0.17-0.1-0.27-0.3-0.24-0.51 c0.35-2.25,0.79-4.52,1.21-6.72c0.99-5.12,1.93-9.96,1.89-14.8c-0.06-7.2-5.06-12.89-9.47-17.92c-0.16-0.19-0.17-0.46-0.01-0.65 c0.1-0.12,0.24-0.18,0.38-0.18c0.09,0,0.18,0.02,0.26,0.08c6.85,4.25,12.58,15.13,13.04,24.77c0.23,4.82-0.71,11.5-6.51,15.9 C104.58,70.19,104.47,70.22,104.36,70.22z" style="fill:#855C52;"/>
|
||||
<path d="M97.88,29.88c10.73,6.66,19.12,30.24,6.49,39.85c1.14-7.31,3.16-14.54,3.11-21.6 C107.41,40.85,102.55,35.21,97.88,29.88 M97.88,28.88c-0.29,0-0.57,0.12-0.76,0.35c-0.32,0.38-0.32,0.93,0.01,1.31 c4.35,4.96,9.29,10.58,9.35,17.59c0.04,4.8-0.89,9.61-1.88,14.71c-0.43,2.2-0.87,4.47-1.22,6.73c-0.06,0.4,0.13,0.8,0.48,1.01 c0.16,0.09,0.34,0.14,0.51,0.14c0.21,0,0.43-0.07,0.61-0.2c4.72-3.59,7.04-9.24,6.71-16.32c-0.46-9.78-6.29-20.84-13.27-25.17 C98.24,28.93,98.06,28.88,97.88,28.88L97.88,28.88z" style="fill:#855C52;"/>
|
||||
</g>
|
||||
<g>
|
||||
<path d="M45.54,82.39c-0.13,0-0.25-0.05-0.35-0.14c-0.41-0.4-0.81-0.8-1.21-1.2 c-3.82-3.82-7.44-7.43-13.7-7.43c-0.18,0-0.36,0-0.55,0.01c-0.01,0-0.01,0-0.02,0c-0.23,0-0.42-0.15-0.48-0.37 c-0.06-0.23,0.04-0.46,0.25-0.57c1.41-0.75,2.97-1.13,4.64-1.13c5.99,0,11.45,4.71,11.92,10.29c0.02,0.21-0.1,0.41-0.29,0.49 C45.68,82.38,45.61,82.39,45.54,82.39z" style="fill:#855C52;"/>
|
||||
<path d="M34.11,72.06c5.42,0,10.96,4.28,11.42,9.83c-4.28-4.2-8.11-8.77-15.26-8.77 c-0.19,0-0.38,0-0.57,0.01C31.09,72.39,32.6,72.06,34.11,72.06 M34.11,71.06L34.11,71.06c-1.75,0-3.39,0.4-4.87,1.18 c-0.41,0.22-0.62,0.69-0.5,1.14c0.12,0.44,0.51,0.74,0.97,0.74c0.01,0,0.02,0,0.03,0c0.18-0.01,0.36-0.01,0.53-0.01 c6.06,0,9.6,3.54,13.35,7.28c0.4,0.4,0.8,0.8,1.21,1.2c0.19,0.19,0.44,0.29,0.7,0.29c0.14,0,0.29-0.03,0.43-0.1 c0.38-0.18,0.61-0.57,0.57-0.99C46.04,75.98,40.35,71.06,34.11,71.06L34.11,71.06z" style="fill:#855C52;"/>
|
||||
</g>
|
||||
<path d="M32.88,40.51c7.74-3.96,25.52-9.94,25.85-8.17c0.01,2.75-4.2,4.47-5.5,4.94 c-10.07,3.67-21.63,9.32-31.09,14.36C24.61,48.92,30.35,42.7,32.88,40.51z" style="fill:#855C52;"/>
|
||||
<path d="M71,97.58c-3.38,0.27-8.02,0.27-11.41,0.27c-3.16,0-2.13,1.91-1.22,2.19 c4.24,1.29,7.86,1.95,12.29,2.15c0.89,0.04,5.96,0.29,6.76-0.1c6.58-3.18,10.54-5.01,14.01-6.51C84.67,96.75,76.57,97.13,71,97.58z " style="fill:#855C52;"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 4.2 KiB |
@ -1 +0,0 @@
|
||||
<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>
|
Before Width: | Height: | Size: 1.5 KiB |
18
src-tauri/Cargo.lock
generated
@ -263,6 +263,19 @@ version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "chrono"
|
||||
version = "0.4.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
"serde",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cocoa"
|
||||
version = "0.24.0"
|
||||
@ -3130,6 +3143,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd6469f4314d5f1ffec476e05f17cc9a78bc7a27a6a857842170bdf8d6f98d2f"
|
||||
dependencies = [
|
||||
"getrandom 0.2.7",
|
||||
"rand 0.8.5",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3707,8 +3722,11 @@ checksum = "d2d7d3948613f75c98fd9328cfdcc45acc4d360655289d0a7d4ec931392200a3"
|
||||
name = "ziemniak"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tauri",
|
||||
"tauri-build",
|
||||
"tokio",
|
||||
"uuid 1.1.2",
|
||||
]
|
||||
|
@ -15,9 +15,12 @@ rust-version = "1.57"
|
||||
tauri-build = { version = "1.0.4", features = [] }
|
||||
|
||||
[dependencies]
|
||||
serde_json = "1.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
tauri = { version = "1.0.5", features = ["api-all"] }
|
||||
chrono = { version = "0.4.19", default-features = false, features = [ "std", "clock", "serde" ] }
|
||||
tokio = { version = "1.19", features = [ "rt", "rt-multi-thread", "sync", "fs", "io-util", "time" ] }
|
||||
uuid = { version = "1.1.2", features = [ "v4", "fast-rng", "serde" ] }
|
||||
|
||||
[features]
|
||||
# by default Tauri runs in production mode
|
||||
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 6.3 KiB |
Before Width: | Height: | Size: 974 B After Width: | Height: | Size: 824 B |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.4 KiB |
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 7.1 KiB |
Before Width: | Height: | Size: 903 B After Width: | Height: | Size: 782 B |
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 7.8 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 85 KiB After Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
@ -1,16 +1,84 @@
|
||||
#![cfg_attr(
|
||||
all(not(debug_assertions), target_os = "windows"),
|
||||
windows_subsystem = "windows"
|
||||
all(not(debug_assertions), target_os = "windows"),
|
||||
windows_subsystem = "windows"
|
||||
)]
|
||||
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use chrono::{DateTime, FixedOffset, Local};
|
||||
use tauri::{async_runtime::spawn, Window};
|
||||
use tokio::time::interval;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Clone, Default, serde::Serialize)]
|
||||
struct Timer {
|
||||
id: Uuid,
|
||||
started: Option<DateTime<FixedOffset>>,
|
||||
duration: Duration,
|
||||
elapsed: Option<Duration>,
|
||||
message: String,
|
||||
}
|
||||
|
||||
impl Timer {
|
||||
fn new(message: &str, duration: Duration) -> Self {
|
||||
return Self {
|
||||
id: Uuid::new_v4(),
|
||||
duration: duration,
|
||||
message: message.to_string(),
|
||||
..Default::default()
|
||||
};
|
||||
}
|
||||
|
||||
fn complete(self: &Self) -> bool {
|
||||
return self.elapsed.map_or(false, |e| e >= self.duration);
|
||||
}
|
||||
|
||||
async fn run(self: &mut Self, window: Window) {
|
||||
self.started = Some(Local::now().into());
|
||||
let mut elapsed = Duration::from_secs(0);
|
||||
self.elapsed = Some(elapsed);
|
||||
let mut last_checked = Instant::now();
|
||||
|
||||
let mut interval = interval(Duration::from_secs(1) / 60);
|
||||
loop {
|
||||
interval.tick().await;
|
||||
let now = Instant::now();
|
||||
let duration = now - last_checked;
|
||||
|
||||
elapsed = elapsed + duration;
|
||||
self.elapsed = Some(elapsed);
|
||||
|
||||
if self.complete() {
|
||||
break;
|
||||
}
|
||||
|
||||
if let Err(_) = window.emit("timer-tick", self.clone()) {
|
||||
break;
|
||||
}
|
||||
last_checked = now;
|
||||
}
|
||||
|
||||
window
|
||||
.emit("timer-done", self.clone())
|
||||
.expect("Our window went away?");
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn greet(name: &str) -> String {
|
||||
format!("Hello, {}!", name)
|
||||
fn start_timer(window: Window, duration: Duration, message: &str) -> Uuid {
|
||||
let mut timer = Timer::new(message, duration);
|
||||
let timer_id = timer.id.clone();
|
||||
|
||||
spawn(async move {
|
||||
timer.run(window).await;
|
||||
});
|
||||
|
||||
timer_id
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![greet])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![start_timer])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
@ -16,8 +16,8 @@
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"category": "DeveloperTool",
|
||||
"copyright": "",
|
||||
"category": "Lifestyle",
|
||||
"copyright": "2022 ModZero",
|
||||
"deb": {
|
||||
"depends": []
|
||||
},
|
||||
@ -29,8 +29,8 @@
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
],
|
||||
"identifier": "com.tauri.dev",
|
||||
"longDescription": "",
|
||||
"identifier": "xyz.modzero.ziemniak",
|
||||
"longDescription": "A bit more flexible interval timer",
|
||||
"macOS": {
|
||||
"entitlements": null,
|
||||
"exceptionDomain": "",
|
||||
|
@ -1,5 +1,26 @@
|
||||
<script>
|
||||
let seconds = 5;
|
||||
import { onDestroy } from 'svelte'
|
||||
import { invoke } from '@tauri-apps/api'
|
||||
import { listen, once } from '@tauri-apps/api/event'
|
||||
|
||||
let seconds = 5
|
||||
|
||||
function start_timer() {
|
||||
invoke('start_timer', {
|
||||
duration: { secs: seconds, nanos: 0 },
|
||||
message: "Hi!",
|
||||
})
|
||||
|
||||
let timer_tick_unlisten = listen('timer-tick', (event) => {
|
||||
console.log("Tick!", event.payload.id, event.payload.elapsed)
|
||||
})
|
||||
|
||||
once('timer-done', (event) => {
|
||||
console.log("Done!", event.payload.id)
|
||||
|
||||
timer_tick_unlisten.then(ttu => ttu())
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<main>
|
||||
@ -7,5 +28,5 @@
|
||||
Fire after
|
||||
<input type="number" bind:value={seconds} />
|
||||
</label>
|
||||
<button>Fire!</button>
|
||||
<button on:click="{start_timer}">Fire!</button>
|
||||
</main>
|
||||
|
23
src/assets/potato.svg
Normal file
@ -0,0 +1,23 @@
|
||||
<svg width="128" height="128" style="enable-background:new 0 0 128 128;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<g id="Layer_2" style="display:none;">
|
||||
<path d=" M71.52,44.35c-6.36-3.15-15.04-9.52-16.33-11.23" style="display:inline;fill:none;stroke:#330000;stroke-width:1.8115;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;"/>
|
||||
<path d=" M100.93,47.54c-15.84-1.92-37.94-15.19-39.85-16.57" style="display:inline;fill:none;stroke:#330000;stroke-width:1.8115;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;"/>
|
||||
<path d=" M106.25,41.12C86.91,39.26,66.33,28.38,65.9,27.88" style="display:inline;fill:none;stroke:#330000;stroke-width:1.8115;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;"/>
|
||||
<path d=" M114.28,34.86c-15.82-0.36-42.16-9.41-43.57-10.08" style="display:inline;fill:none;stroke:#330000;stroke-width:1.8115;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;"/>
|
||||
<path d=" M113.84,26.83c-12.91,1.05-38.1-5.93-38.94-6.04" style="display:inline;fill:none;stroke:#330000;stroke-width:1.8115;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;"/>
|
||||
<path d=" M105.04,19.23c-9.5,1-26.01-3.26-27.3-3.53" style="display:inline;fill:none;stroke:#330000;stroke-width:1.8115;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;"/>
|
||||
</g>
|
||||
<g id="图层_1">
|
||||
<path d="M112.51,21.82c-4.8-3.07-10.15-5.51-15.56-7.61c-7.7-2.99-15.42-3.67-23.2-2.18 c-6.89,1.32-13.39,4.5-18.93,8.9c-3.46,2.74-6.92,5.49-10.13,8.47c-7.74,7.2-15.59,14.39-22.55,22.25 C16.01,58.56,10.52,66.11,5.7,73.88c-4.14,6.67-4.63,13.99-2.16,21.24c5.5,16.09,31.28,26.36,47.4,19.42 c5.88-2.53,11.69-5.27,17.48-8.01c6.66-3.15,13.16-6.7,19.94-9.56c20.74-8.77,32.83-24.01,36.89-44.51 C127.77,39.74,123.59,28.9,112.51,21.82z M60.63,33.33c0.11,0.42-0.25-0.01-0.14,0.41c-0.03-0.11-0.06-0.23-0.09-0.34 C60.48,33.37,60.56,33.35,60.63,33.33z" style="fill:#B89278;"/>
|
||||
<g>
|
||||
<path d="M104.36,70.22c-0.09,0-0.18-0.02-0.26-0.07c-0.17-0.1-0.27-0.3-0.24-0.51 c0.35-2.25,0.79-4.52,1.21-6.72c0.99-5.12,1.93-9.96,1.89-14.8c-0.06-7.2-5.06-12.89-9.47-17.92c-0.16-0.19-0.17-0.46-0.01-0.65 c0.1-0.12,0.24-0.18,0.38-0.18c0.09,0,0.18,0.02,0.26,0.08c6.85,4.25,12.58,15.13,13.04,24.77c0.23,4.82-0.71,11.5-6.51,15.9 C104.58,70.19,104.47,70.22,104.36,70.22z" style="fill:#855C52;"/>
|
||||
<path d="M97.88,29.88c10.73,6.66,19.12,30.24,6.49,39.85c1.14-7.31,3.16-14.54,3.11-21.6 C107.41,40.85,102.55,35.21,97.88,29.88 M97.88,28.88c-0.29,0-0.57,0.12-0.76,0.35c-0.32,0.38-0.32,0.93,0.01,1.31 c4.35,4.96,9.29,10.58,9.35,17.59c0.04,4.8-0.89,9.61-1.88,14.71c-0.43,2.2-0.87,4.47-1.22,6.73c-0.06,0.4,0.13,0.8,0.48,1.01 c0.16,0.09,0.34,0.14,0.51,0.14c0.21,0,0.43-0.07,0.61-0.2c4.72-3.59,7.04-9.24,6.71-16.32c-0.46-9.78-6.29-20.84-13.27-25.17 C98.24,28.93,98.06,28.88,97.88,28.88L97.88,28.88z" style="fill:#855C52;"/>
|
||||
</g>
|
||||
<g>
|
||||
<path d="M45.54,82.39c-0.13,0-0.25-0.05-0.35-0.14c-0.41-0.4-0.81-0.8-1.21-1.2 c-3.82-3.82-7.44-7.43-13.7-7.43c-0.18,0-0.36,0-0.55,0.01c-0.01,0-0.01,0-0.02,0c-0.23,0-0.42-0.15-0.48-0.37 c-0.06-0.23,0.04-0.46,0.25-0.57c1.41-0.75,2.97-1.13,4.64-1.13c5.99,0,11.45,4.71,11.92,10.29c0.02,0.21-0.1,0.41-0.29,0.49 C45.68,82.38,45.61,82.39,45.54,82.39z" style="fill:#855C52;"/>
|
||||
<path d="M34.11,72.06c5.42,0,10.96,4.28,11.42,9.83c-4.28-4.2-8.11-8.77-15.26-8.77 c-0.19,0-0.38,0-0.57,0.01C31.09,72.39,32.6,72.06,34.11,72.06 M34.11,71.06L34.11,71.06c-1.75,0-3.39,0.4-4.87,1.18 c-0.41,0.22-0.62,0.69-0.5,1.14c0.12,0.44,0.51,0.74,0.97,0.74c0.01,0,0.02,0,0.03,0c0.18-0.01,0.36-0.01,0.53-0.01 c6.06,0,9.6,3.54,13.35,7.28c0.4,0.4,0.8,0.8,1.21,1.2c0.19,0.19,0.44,0.29,0.7,0.29c0.14,0,0.29-0.03,0.43-0.1 c0.38-0.18,0.61-0.57,0.57-0.99C46.04,75.98,40.35,71.06,34.11,71.06L34.11,71.06z" style="fill:#855C52;"/>
|
||||
</g>
|
||||
<path d="M32.88,40.51c7.74-3.96,25.52-9.94,25.85-8.17c0.01,2.75-4.2,4.47-5.5,4.94 c-10.07,3.67-21.63,9.32-31.09,14.36C24.61,48.92,30.35,42.7,32.88,40.51z" style="fill:#855C52;"/>
|
||||
<path d="M71,97.58c-3.38,0.27-8.02,0.27-11.41,0.27c-3.16,0-2.13,1.91-1.22,2.19 c4.24,1.29,7.86,1.95,12.29,2.15c0.89,0.04,5.96,0.29,6.76-0.1c6.58-3.18,10.54-5.01,14.01-6.51C84.67,96.75,76.57,97.13,71,97.58z " style="fill:#855C52;"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 4.2 KiB |
@ -1 +0,0 @@
|
||||
<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="26.6" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 308"><path fill="#FF3E00" d="M239.682 40.707C211.113-.182 154.69-12.301 113.895 13.69L42.247 59.356a82.198 82.198 0 0 0-37.135 55.056a86.566 86.566 0 0 0 8.536 55.576a82.425 82.425 0 0 0-12.296 30.719a87.596 87.596 0 0 0 14.964 66.244c28.574 40.893 84.997 53.007 125.787 27.016l71.648-45.664a82.182 82.182 0 0 0 37.135-55.057a86.601 86.601 0 0 0-8.53-55.577a82.409 82.409 0 0 0 12.29-30.718a87.573 87.573 0 0 0-14.963-66.244"></path><path fill="#FFF" d="M106.889 270.841c-23.102 6.007-47.497-3.036-61.103-22.648a52.685 52.685 0 0 1-9.003-39.85a49.978 49.978 0 0 1 1.713-6.693l1.35-4.115l3.671 2.697a92.447 92.447 0 0 0 28.036 14.007l2.663.808l-.245 2.659a16.067 16.067 0 0 0 2.89 10.656a17.143 17.143 0 0 0 18.397 6.828a15.786 15.786 0 0 0 4.403-1.935l71.67-45.672a14.922 14.922 0 0 0 6.734-9.977a15.923 15.923 0 0 0-2.713-12.011a17.156 17.156 0 0 0-18.404-6.832a15.78 15.78 0 0 0-4.396 1.933l-27.35 17.434a52.298 52.298 0 0 1-14.553 6.391c-23.101 6.007-47.497-3.036-61.101-22.649a52.681 52.681 0 0 1-9.004-39.849a49.428 49.428 0 0 1 22.34-33.114l71.664-45.677a52.218 52.218 0 0 1 14.563-6.398c23.101-6.007 47.497 3.036 61.101 22.648a52.685 52.685 0 0 1 9.004 39.85a50.559 50.559 0 0 1-1.713 6.692l-1.35 4.116l-3.67-2.693a92.373 92.373 0 0 0-28.037-14.013l-2.664-.809l.246-2.658a16.099 16.099 0 0 0-2.89-10.656a17.143 17.143 0 0 0-18.398-6.828a15.786 15.786 0 0 0-4.402 1.935l-71.67 45.674a14.898 14.898 0 0 0-6.73 9.975a15.9 15.9 0 0 0 2.709 12.012a17.156 17.156 0 0 0 18.404 6.832a15.841 15.841 0 0 0 4.402-1.935l27.345-17.427a52.147 52.147 0 0 1 14.552-6.397c23.101-6.006 47.497 3.037 61.102 22.65a52.681 52.681 0 0 1 9.003 39.848a49.453 49.453 0 0 1-22.34 33.12l-71.664 45.673a52.218 52.218 0 0 1-14.563 6.398"></path></svg>
|
Before Width: | Height: | Size: 1.9 KiB |
@ -1,11 +0,0 @@
|
||||
<script lang="ts">
|
||||
let count: number = 0
|
||||
$: doubled = count * 2
|
||||
const increment = () => {
|
||||
count += 1
|
||||
}
|
||||
</script>
|
||||
|
||||
<button on:click={increment}>
|
||||
count is {count} and doubled is {doubled}
|
||||
</button>
|
@ -1,8 +1,6 @@
|
||||
import './app.css'
|
||||
import App from './App.svelte'
|
||||
|
||||
import { invoke } from '@tauri-apps/api'
|
||||
|
||||
const app = new App({
|
||||
target: document.getElementById('app')
|
||||
})
|
||||
|
@ -3,5 +3,8 @@ import { svelte } from '@sveltejs/vite-plugin-svelte'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [svelte()]
|
||||
plugins: [svelte()],
|
||||
build: {
|
||||
write: true
|
||||
}
|
||||
})
|
||||
|