diff --git a/README.md b/README.md index 4a8f5f895..13ae8ff67 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,18 @@ npm install npm run dev ``` +### Testing + +Each part has its own tests: + +```bash +cargo test # the engine (gpx-rs), from the root of the repository +(cd wasm && wasm-pack test --node) # the WebAssembly bindings +npm test --prefix website # the website, once the WebAssembly engine is built +``` + +See [`tauri`](tauri/README.md) for the tests of the desktop app. + ## Credits This project has been made possible thanks to the following open source projects: @@ -59,6 +71,7 @@ This project has been made possible thanks to the following open source projects - Development: - [Svelte](https://github.com/sveltejs/svelte) and [SvelteKit](https://github.com/sveltejs/kit) — seamless development experience - [MDsveX](https://github.com/pngwn/MDsveX) — allowing a Markdown-based documentation + - [Tauri](https://github.com/tauri-apps/tauri) – making a desktop app possible - Design: - [shadcn-svelte](https://github.com/huntabyte/shadcn-svelte) — beautiful components - [@lucide/svelte](https://github.com/lucide-icons/lucide/tree/main/packages/svelte) — beautiful icons diff --git a/gpx-rs/src/core/io/parse.rs b/gpx-rs/src/core/io/parse.rs index 492db04e9..684846805 100644 --- a/gpx-rs/src/core/io/parse.rs +++ b/gpx-rs/src/core/io/parse.rs @@ -3,11 +3,11 @@ use crate::{ TrackpointCategories, TrackpointChunk, Waypoint, WaypointChunk, distance, }; use chrono::DateTime; -use quick_xml::{Error, XmlVersion}; use quick_xml::escape::resolve_predefined_entity; use quick_xml::events::Event; use quick_xml::events::attributes::{Attribute, Attributes}; use quick_xml::reader::Reader; +use quick_xml::{Error, XmlVersion}; enum GPXElement { Metadata, @@ -213,16 +213,21 @@ fn apply_text( } Some(GPXElement::Time) => { stack.pop(); - if let Some(GPXElement::Trackpoint(trkpt)) = stack.last_mut() { - trkpt.time = DateTime::parse_from_rfc3339(e) - .ok() - .map(|time| time.timestamp_millis()); + let time = DateTime::parse_from_rfc3339(e) + .ok() + .map(|time| time.timestamp_millis()); + match stack.last_mut() { + Some(GPXElement::Trackpoint(trkpt)) => trkpt.time = time, + Some(GPXElement::Waypoint(wpt)) => wpt.time = time, + Some(GPXElement::Metadata) => gpx.info.time = time, + _ => (), } } Some(GPXElement::Temperature) => { stack.pop(); if let Some(GPXElement::Trackpoint(trkpt)) = stack.last_mut() { - trkpt.atemp = e.parse().ok(); + // Garmin Connect writes whole degrees as "21.0" + trkpt.atemp = e.parse::().ok().map(|t| t.round() as i16); } } Some(GPXElement::Heartrate) => { @@ -1142,6 +1147,20 @@ mod tests { assert!(wpt.type_.as_ref().is_some_and(|t| t == "Bike Trail")); } + #[test] + fn test_parse_waypoint_time() { + let data = r#""#; + let gpx = parse(data.as_bytes(), &mut Default::default()).unwrap(); + assert_eq!(gpx.wpt[0].time, Some(1714543800000)); + } + + #[test] + fn test_parse_metadata_time() { + let data = r#""#; + let gpx = parse(data.as_bytes(), &mut Default::default()).unwrap(); + assert_eq!(gpx.info.time, Some(1714543800000)); + } + #[test] fn test_parse_trackpoint_time() { let gpx = parse_data("with_time"); @@ -1325,6 +1344,14 @@ mod tests { assert!(trkpt.atemp.is_some_and(|t| t == 21)); } + #[test] + fn test_parse_trackpoint_decimal_atemp() { + let data = r#" + 21.0"#; + let gpx = parse(data.as_bytes(), &mut Default::default()).unwrap(); + assert_eq!(gpx.trk[0].trkseg[0][0].atemp, Some(21)); + } + #[test] fn test_parse_track_style() { let gpx = parse_data("with_style"); diff --git a/tauri/README.md b/tauri/README.md new file mode 100644 index 000000000..3d53c25f5 --- /dev/null +++ b/tauri/README.md @@ -0,0 +1,38 @@ +# tauri + +The desktop app of gpx.studio, built with [Tauri 2](https://v2.tauri.app/). +Its UI is the website ([`../website`](../website)), and it runs the engine of [`../gpx-rs`](../gpx-rs) natively instead of in WebAssembly. + +## Development + +You will need the same tools as for the website: [Node.js](https://nodejs.org/), [Rust](https://rustup.rs/) and [wasm-pack](https://rustwasm.github.io/wasm-pack/). +To run the app in development mode, you will also need to install the [system dependencies of Tauri](https://v2.tauri.app/start/prerequisites/) for your platform and the Tauri CLI: + +```bash +cargo install tauri-cli --version "^2" +``` + +### Setting up the frontend + +The desktop app does not use the WebAssembly engine, but the website depends on its package. +From the root of the repository, build it once and install the website’s dependencies: + +```bash +cd wasm && wasm-pack build --target bundler && cd .. +npm install --prefix website +``` + +For the MapTiler layers, add your key to `website/.env`, as explained in the [main README](../README.md#running-the-website). + +### Running the app + +```bash +cd tauri +cargo tauri dev +``` + +### Testing + +```bash +cargo test -p gpx-studio-desktop +``` diff --git a/website/package-lock.json b/website/package-lock.json index 709701346..a2da57f4f 100644 --- a/website/package-lock.json +++ b/website/package-lock.json @@ -18,7 +18,7 @@ "gpx-wasm": "file:../wasm/pkg", "jszip": "^3.10.1", "mapillary-js": "^4.1.2", - "maplibre-gl": "^6.15.0", + "maplibre-gl": "^6.18.0", "sanitize-html": "^2.17.0", "sortablejs": "^1.15.7" }, @@ -1788,9 +1788,9 @@ } }, "node_modules/@maplibre/maplibre-gl-style-spec": { - "version": "26.4.4", - "resolved": "https://registry.npmjs.org/@maplibre/maplibre-gl-style-spec/-/maplibre-gl-style-spec-26.4.4.tgz", - "integrity": "sha512-hG4RZR4PBd/+6A3ODdZ3AnQRF106ZQk1y3bhwDg8bH/A4Oz2tnRUJVVWs9BZa6gXZ1d3UKe89C+Mm+olGBELvA==", + "version": "26.7.0", + "resolved": "https://registry.npmjs.org/@maplibre/maplibre-gl-style-spec/-/maplibre-gl-style-spec-26.7.0.tgz", + "integrity": "sha512-9d7hK1zk1WRx/AFvq7NtmlTlaOGPXS2r+FZXsrMv8453Xy14bnXBpVCPJDBupCfQs/p8FL0/kb0ygbEWTufN0g==", "license": "ISC", "dependencies": { "@mapbox/jsonlint-lines-primitives": "^2.0.3", @@ -1816,14 +1816,14 @@ } }, "node_modules/@maplibre/vt-pbf": { - "version": "4.3.2", - "resolved": "https://registry.npmjs.org/@maplibre/vt-pbf/-/vt-pbf-4.3.2.tgz", - "integrity": "sha512-j6p0AdjvAR19Z3XaCysle7A4ZSo08tYOzxD0Y9NQylwPAkwJJeYub5b2eVucdeDh7erhv69DahoLOevDRERRUw==", + "version": "4.3.3", + "resolved": "https://registry.npmjs.org/@maplibre/vt-pbf/-/vt-pbf-4.3.3.tgz", + "integrity": "sha512-dEe5XUd64RQbxNxy2OzIkJnwNDWjVmSXjCd0A7zLirm7QJ/WWbmtDFIkfsiM4yt1cplqzG6oSivRYeWx1SM1yg==", "license": "MIT", "dependencies": { "@mapbox/point-geometry": "^1.1.0", "@types/geojson": "^7946.0.16", - "pbf": "^5.1.0" + "pbf": "^5.1.2" } }, "node_modules/@maplibre/vt-pbf/node_modules/pbf": { @@ -4674,9 +4674,9 @@ "license": "(MIT AND Zlib)" }, "node_modules/maplibre-gl": { - "version": "6.15.0", - "resolved": "https://registry.npmjs.org/maplibre-gl/-/maplibre-gl-6.15.0.tgz", - "integrity": "sha512-kxFetbvUHDOVaAP1CYb226Mdk2QhzIPddqM0xJTFD35wu78Mpd6NM7+H68ALjc6Oa0kAOX5EAdMKyvD2u3qfcg==", + "version": "6.18.0", + "resolved": "https://registry.npmjs.org/maplibre-gl/-/maplibre-gl-6.18.0.tgz", + "integrity": "sha512-8ucT+RhJtEZGFvWGPioVQwvOPMAIuUehEgxl2dELw9aJmX4SpUi+OCHHAD33B9EuohNC7kC/gccJacUgTMQfQQ==", "license": "BSD-3-Clause", "dependencies": { "@mapbox/point-geometry": "^1.1.0", @@ -4684,9 +4684,9 @@ "@mapbox/unitbezier": "^1.0.0", "@mapbox/vector-tile": "^3.0.0", "@maplibre/geojson-vt": "^6.3.0", - "@maplibre/maplibre-gl-style-spec": "^26.4.4", + "@maplibre/maplibre-gl-style-spec": "^26.6.0", "@maplibre/mlt": "^1.3.0", - "@maplibre/vt-pbf": "^4.3.2", + "@maplibre/vt-pbf": "^4.3.3", "@types/geojson": "^7946.0.16", "bidi-js": "^1.1.0", "earcut": "^3.2.4", diff --git a/website/package.json b/website/package.json index 6f8bb7aca..6911ffff3 100644 --- a/website/package.json +++ b/website/package.json @@ -82,7 +82,7 @@ "gpx-wasm": "file:../wasm/pkg", "jszip": "^3.10.1", "mapillary-js": "^4.1.2", - "maplibre-gl": "^6.15.0", + "maplibre-gl": "^6.18.0", "sanitize-html": "^2.17.0", "sortablejs": "^1.15.7" } diff --git a/website/src/lib/docs/zh/files-and-stats.mdx b/website/src/lib/docs/zh/files-and-stats.mdx index 3ff9d037f..06f1bb19a 100644 --- a/website/src/lib/docs/zh/files-and-stats.mdx +++ b/website/src/lib/docs/zh/files-and-stats.mdx @@ -45,8 +45,7 @@ title: 文件和统计 ### 树形布局 -正如 [显示](./menu/view) 中所述,文件列表可切换为树形布局。此布局非常适合管理大量已打开的文件,文件将被组织成一个纵向列表并显示在地图右侧。 -In addition, the file tree view enables you to inspect the [tracks, segments, routes, and points of interest](./gpx) contained inside the files through collapsible sections. +正如 [显示](./menu/view) 中所述,文件列表可切换为树形布局。此布局非常适合管理大量已打开的文件,文件将被组织成一个纵向列表并显示在地图右侧。在文件树中,展开可折叠部分可检查其中所包含的 [轨迹、分段、路线和兴趣点](./gpx) 等要素。 [编辑](./menu/edit) 和 [工具](./toolbar) 亦可被用于文件内部要素。此外,拖拽内部要素可对其重新排序,或将它们移动到其他层级甚至另一个文件中。 diff --git a/website/src/lib/docs/zh/gpx.mdx b/website/src/lib/docs/zh/gpx.mdx index 4bce75240..5f17c28c5 100644 --- a/website/src/lib/docs/zh/gpx.mdx +++ b/website/src/lib/docs/zh/gpx.mdx @@ -9,8 +9,7 @@ title: GPX 文件格式 # { title } -GPX 文件格式 是应用程序和 GPS 设备之间交换 GPS 数据的一种开放标准。它本质上由一系列 GPS 点组成,用以编码形成一条或多条轨迹,以及兴趣点(可选)。 -These traces can be stored either as tracks or as routes. +GPX 文件格式 是应用程序和 GPS 设备之间交换 GPS 数据的一种开放标准。它本质上由一系列 GPS 点组成,用以编码形成一条或多条轨迹,以及兴趣点(可选)。这些连线可以储存为轨迹或路线。 还可以包含元数据,其中 **名称(name)** 和 **描述(description)** 字段对用户最有用。 @@ -26,14 +25,13 @@ GPX 文件通常只包含一条轨迹,且该轨迹仅有一个路段。不过 ### Routes -A **route** is a single continuous path made of a sequence of **route points**. +**路线**是一个由**路线点**序列组成的单一连续路径。 These are mandatory checkpoints, which correspond to the anchor points of the [routing tool](./toolbar/routing). -The points in between are only a suggested path connecting the route points. -Like a track, a route can have a **name**, a **description**, and **appearance properties**. +两者之间的点只是一条连接路线点的建议路径。像轨迹一样,路线可以有**名称**、**描述**和**路线属性**。 -Nowadays, most apps and GPS devices work perfectly well with tracks, even for navigation. +现在,大多数应用和 GPS 设备都与轨迹完全兼容,甚至用于导航。 However, some of them only work with routes: in that case, you can [convert](./menu/edit) your tracks to routes, or [create](./menu/file) a route file from the start. diff --git a/website/src/lib/docs/zh/menu/edit.mdx b/website/src/lib/docs/zh/menu/edit.mdx index 1bb97968e..b00732737 100644 --- a/website/src/lib/docs/zh/menu/edit.mdx +++ b/website/src/lib/docs/zh/menu/edit.mdx @@ -37,7 +37,7 @@ Moreover, when the tree layout of the files list is enabled (see [Files and stat ### New route -Create a new route in the selected file. +在所选文件项中创建一条新路线。 @@ -57,10 +57,10 @@ Create a new route in the selected file. ### Convert to route/track -Convert the selected routes to tracks, or the selected tracks or segments to routes. +将选中的路线转换为轨迹,或将选中的轨迹或分段转换为路线。 Since a route has a single segment, a track with multiple segments is converted into one route per segment. -When the selected files contain only routes, or only tracks, you can also convert all of them at once. +当选中的文件只包含路线,或只包含轨迹时,你也可以一次性转换所有路线。 ### 全选 diff --git a/website/src/lib/docs/zh/toolbar/merge.mdx b/website/src/lib/docs/zh/toolbar/merge.mdx index df25f2c56..b17b324a2 100644 --- a/website/src/lib/docs/zh/toolbar/merge.mdx +++ b/website/src/lib/docs/zh/toolbar/merge.mdx @@ -14,7 +14,7 @@ To use this tool, you need to [select](../files-and-stats) multiple files, [trac - 若要生成一条连续轨迹,请选择 **合并为一条连续轨迹**; - The second option can be used to create or manage files with multiple [tracks, segments or routes](../gpx). - Merging files (or tracks) will result in a single file (or track) containing all tracks and routes (or segments) from the selection. + 并将所有内容存储在一个文件(或轨迹)中,请选择 **合并但保持轨迹和路线(或分段)独立**。 diff --git a/website/src/lib/docs/zh/toolbar/scissors.mdx b/website/src/lib/docs/zh/toolbar/scissors.mdx index c0abfbb9a..73990fc93 100644 --- a/website/src/lib/docs/zh/toolbar/scissors.mdx +++ b/website/src/lib/docs/zh/toolbar/scissors.mdx @@ -22,6 +22,6 @@ title: 裁剪和拆分 若要将轨迹拆分为两部分,请点击轨迹上显示的任意分割标记。若要在指定位置进行拆分,请将鼠标悬停在轨迹上,光标位置将出现剪刀图标,表明可在该处拆分。 -You can choose to split the trace into two GPX files, or to keep the split parts in the same file as [tracks, segments or routes](../gpx). +支持将轨迹拆分为两个 GPX 文件,或将它们作为不同的 [轨迹或分段](../gpx) 保留在同一个文件中。 diff --git a/website/src/locales/zh.json b/website/src/locales/zh.json index 0341c357c..8ad6662f0 100644 --- a/website/src/locales/zh.json +++ b/website/src/locales/zh.json @@ -9,42 +9,42 @@ }, "menu": { "new_file": "新建文件", - "new_route_file": "New route file", + "new_route_file": "新建路线文件", "new_track": "新建轨迹", - "new_route": "New route", - "convert_to_route": "Convert to route", - "convert_to_track": "Convert to track", - "convert_to_routes": "Convert to route file", - "convert_to_tracks": "Convert to track file", + "new_route": "新路线", + "convert_to_route": "转换为路径", + "convert_to_track": "转换为轨迹", + "convert_to_routes": "转换为路径文件", + "convert_to_tracks": "转换为轨迹文件", "new_segment": "新建路段", "open": "打开...", - "open_folder": "Open folder...", - "explorer": "Explorer", + "open_folder": "打开文件夹……", + "explorer": "资源管理器", "explorer_menu": { - "open": "Open", - "new_file": "New file...", - "new_route_file": "New route file...", - "new_folder": "New folder...", - "rename": "Rename...", - "reveal_finder": "Reveal in Finder", - "reveal": "Reveal in file explorer", - "delete_failed": "The files could not be moved to the trash." + "open": "打开", + "new_file": "新建文件……", + "new_route_file": "新建路线文件……", + "new_folder": "新建文件夹……", + "rename": "重命名……", + "reveal_finder": "在 Finder 中查看", + "reveal": "在资源管理器中显示文件", + "delete_failed": "无法将文件移动到回收站。" }, - "workspace": "Workspace", - "save": "Save", - "save_all": "Save all", - "save_as": "Save as...", + "workspace": "工作区", + "save": "保存", + "save_all": "全部保存", + "save_as": "另存为……", "close": "关闭", "close_all": "关闭全部", - "close_folder": "Close folder", - "reload": "Reload from disk", - "discard": "Discard", - "cancel": "Cancel", - "overwrite": "Overwrite", - "unsaved_title": "Unsaved changes", - "unsaved_description": "These files have changes that are not saved:", - "overwrite_title": "Overwrite changes made elsewhere?", - "overwrite_description": "These files have changes, and were also changed on the disk. Overwrite what is on the disk, or reload it and lose your changes?", + "close_folder": "关闭文件夹", + "reload": "从硬盘重新加载", + "discard": "丢弃", + "cancel": "取消", + "overwrite": "覆盖", + "unsaved_title": "未保存的更改", + "unsaved_description": "这些文件的更改未保存:", + "overwrite_title": "覆盖其他地方的更改?", + "overwrite_description": "这些文件有更改,也在磁盘上被更改。覆盖磁盘上的内容,或重新加载它并丢失您的更改?", "duplicate": "创建副本", "copy": "复制", "paste": "粘贴", @@ -102,9 +102,9 @@ "name": "名称", "description": "说明", "save": "保存", - "rename_file": "Rename the file on disk", - "name_taken": "A file with this name already exists in the folder.", - "rename_failed": "The file could not be renamed." + "rename_file": "重命名硬盘上的文件", + "name_taken": "此文件夹中已存在具有该名称的文件。", + "rename_failed": "无法重命名文件。" }, "style": { "button": "外观...", @@ -468,8 +468,8 @@ "gpx": { "file": "文件", "files": "文件", - "route": "Route", - "routes": "Routes", + "route": "路线", + "routes": "路线", "track": "轨迹", "tracks": "轨迹", "segment": "路段", @@ -595,15 +595,15 @@ "enable_webgl2": "学习如何在浏览器中启用 WebGL 2", "page_not_found": "无法找到页面", "outdated": { - "title": "This page is out of date", - "description": "Your files were saved by a newer version of gpx.studio, which this page cannot read. Reload the page to get the latest version.", - "reload": "Reload" + "title": "此页面已过期", + "description": "你的文件已被新版本的 gpx.studio 保存,这个页面无法读取该文件。重新加载页面以获取最新版本的页面。", + "reload": "重新加载" }, "desktop": { - "update_available": "gpx.studio {version} is available", - "update_restart": "Update and restart", - "update_download": "Download", - "update_installing": "Installing the update...", - "update_failed": "The update could not be installed" + "update_available": "gpx.studio {version} 现已可用", + "update_restart": "更新并重启", + "update_download": "下载", + "update_installing": "正在安装更新……", + "update_failed": "无法安装更新" } }