|
1 |
| -use cargo_metadata::MetadataCommand; |
2 | 1 | use self_update::self_replace;
|
3 | 2 | use self_update::update::Release;
|
4 | 3 | use semver::Version;
|
5 | 4 | use std::path::Path;
|
6 | 5 | use std::{env, fs, io};
|
7 | 6 |
|
| 7 | +const REPO_OWNER: &str = "hacknus"; |
| 8 | +const REPO_NAME: &str = "serial-monitor-rust"; |
| 9 | +const MACOS_APP_NAME: &str = "Serial Monitor.app"; |
| 10 | + |
8 | 11 | /// method to copy the complete directory `src` to `dest` but skipping the binary `binary_name`
|
9 | 12 | /// since we have to use `self-replace` for that.
|
10 | 13 | fn copy_dir(src: &Path, dest: &Path, binary_name: &str) -> io::Result<()> {
|
@@ -35,17 +38,9 @@ fn copy_dir(src: &Path, dest: &Path, binary_name: &str) -> io::Result<()> {
|
35 | 38 |
|
36 | 39 | /// Function to check for updates and return the latest one, if it is more recent than the current version
|
37 | 40 | pub fn check_update() -> Option<Release> {
|
38 |
| - let metadata = MetadataCommand::new().exec().ok()?; |
39 |
| - let url = metadata.root_package()?.clone().homepage?; |
40 |
| - let parts: Vec<&str> = url.split('/').collect(); |
41 |
| - let (repo_owner, repo_name) = if parts.len() >= 5 && parts[2] == "github.com" { |
42 |
| - (parts[3].to_string(), parts[4].to_string()) |
43 |
| - } else { |
44 |
| - return None; |
45 |
| - }; |
46 | 41 | if let Ok(builder) = self_update::backends::github::ReleaseList::configure()
|
47 |
| - .repo_owner(&repo_owner) |
48 |
| - .repo_name(&repo_name) |
| 42 | + .repo_owner(REPO_OWNER) |
| 43 | + .repo_name(REPO_NAME) |
49 | 44 | .build()
|
50 | 45 | {
|
51 | 46 | if let Ok(releases) = builder.fetch() {
|
@@ -126,24 +121,9 @@ pub fn update(release: Release) -> Result<(), Box<dyn std::error::Error>> {
|
126 | 121 | // extracted archive, but we cannot just assume that the parent directory of the
|
127 | 122 | // currently running executable is equal to the app name - this is especially not
|
128 | 123 | // the case if we run the code with `cargo run`.
|
129 |
| - |
130 |
| - // Fetch the metadata of the current Cargo project |
131 |
| - let metadata = MetadataCommand::new().exec()?; |
132 |
| - |
133 |
| - // Access the package metadata |
134 |
| - let mac_os_app_name = metadata |
135 |
| - .root_package() |
136 |
| - .ok_or("Unable to get cargo metadata!")? |
137 |
| - .metadata |
138 |
| - .get("bundle") |
139 |
| - .ok_or("Unable to get cargo bundle metadata!")? |
140 |
| - .get("name") |
141 |
| - .ok_or("Unable to get cargo bundle metadata name!")? |
142 |
| - .as_str() |
143 |
| - .unwrap(); |
144 | 124 | tmp_archive_dir
|
145 | 125 | .path()
|
146 |
| - .join(format!("{}.app/Contents/MacOS/{}", mac_os_app_name, binary)) |
| 126 | + .join(format!("{}/Contents/MacOS/{}", MACOS_APP_NAME, binary)) |
147 | 127 | } else if cfg!(target_os = "linux") {
|
148 | 128 | let binary = env::current_exe()?
|
149 | 129 | .file_name()
|
|
0 commit comments