Added self updates

This commit is contained in:
Djkato 2023-05-09 00:30:44 +02:00
parent 3d1bee87b6
commit 11fcca4a78
5 changed files with 1142 additions and 49 deletions

1098
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,16 +1,16 @@
[package] [package]
name = "DRP_Creative" name = "drp_creative"
version = "0.1.3" version = "0.1.4"
edition = "2021" edition = "2021"
author = "https://djkato.net" author = "https://djkato.net"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
discord-rich-presence = "0.2.2" discord-rich-presence = "0.2.2"
regex = "1.6.0" regex = "1.6.0"
tray-item = "0.7.0" tray-item = "0.7.0"
lazy_static = "1.4.0" lazy_static = "1.4.0"
self_update = {version= "0.36.0", features= ["archive-zip"]}
win-msgbox = "0.1.2"
[dependencies.windows] [dependencies.windows]
version = "0.39.0" version = "0.39.0"
@ -24,3 +24,8 @@ features = [
[target.'cfg(windows)'.build-dependencies] [target.'cfg(windows)'.build-dependencies]
windres = "0.2.2" windres = "0.2.2"
# prefix binary with x86_64-pc-windows-msvc for self_updater
[[bin]]
name = "DRP_Creative--x86_64-pc-windows-msvc"
path = "src/main.rs"

View file

@ -15,12 +15,31 @@ Examples:
6. Enjoy! 6. Enjoy!
## How to use: ## How to use:
- App updates will be notified and suggested on startup via popup window.
- When it's running, you'll notice a new icon appear on your Taskbar. If you want to exclude the **currently open project** from showing up, click on the icon and click on `Don't show current project`. - When it's running, you'll notice a new icon appear on your Taskbar. If you want to exclude the **currently open project** from showing up, click on the icon and click on `Don't show current project`.
![icon showcase](https://i.imgur.com/nADffGB.png) ![icon showcase](https://i.imgur.com/nADffGB.png)
- To change the portfolio website or remove excluded projects and words from the program, run the program at least once, and a `.drp_config` file will appear. You can open this with any text editor and rewrite the lines there. be gentle though, program expects a certain format for the file ^^' - To change the portfolio website or remove excluded projects and words from the program, run the program at least once, and a `.drp_config` file will appear. You can open this with any text editor and rewrite the lines there. be gentle though, program expects a certain format for the file ^^'
- To disable the portfolio row, there's a "HIDE_PORTFOLIO_ROW" setting.
Example `.drp_config`:
```json
SHOULD_EXCLUDE_BE_ANONYMOUS:{
n
}
PORTFOLIO_LINK:{
djkato.net
}
EXCLUDE_CHARACTERS_LIST:{
no_drp
}
HIDE_PORTFOLIO_ROW:{
no
}
```
### Currently supported programs: ### Currently supported programs:
**Full support:** **Full support:**
- Cinema 4D - Cinema 4D

View file

@ -1,15 +1,24 @@
#![windows_subsystem = "windows"] //UNCOMMENT ONLY WHEN BUILDING FOR RELEASE TO NOT SHOW TERMINAL WINDOW! #![windows_subsystem = "windows"] //UNCOMMENT ONLY WHEN BUILDING FOR RELEASE TO NOT SHOW TERMINAL WINDOW!
#[macro_use]
extern crate self_update;
pub mod app; pub mod app;
pub mod config; pub mod config;
pub mod program_status; pub mod program_status;
pub mod self_updater;
pub mod tray_icon; pub mod tray_icon;
use crate::config::Config; use crate::config::Config;
use crate::program_status::*; use crate::program_status::*;
use crate::self_updater::try_update;
use app::{App, Apps}; use app::{App, Apps};
use discord_rich_presence::{activity, DiscordIpc, DiscordIpcClient}; use discord_rich_presence::{activity, DiscordIpc, DiscordIpcClient};
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
use std::{thread, time}; use std::{thread, time};
fn main() { fn main() {
match try_update() {
Ok(_) => {}
Err(e) => println!("Failed to update! {e}"),
}
let apps = Apps::construct_apps(); let apps = Apps::construct_apps();
let mut config = Config::load(); let mut config = Config::load();

46
src/self_updater.rs Normal file
View file

@ -0,0 +1,46 @@
use windows::w;
pub fn try_update() -> Result<(), Box<dyn std::error::Error>> {
let build = self_update::backends::github::Update::configure()
.repo_owner("djkato")
.repo_name("DRP_Creative")
.bin_name("DRP_Creative")
.no_confirm(true)
.current_version(cargo_crate_version!())
.build()?;
let latest_release = build.get_latest_release()?;
if self_update::version::bump_is_greater(
build.current_version().as_str(),
latest_release.version.as_str(),
)? {
let body: windows::core::HSTRING = format!(
"Found update! \nCurrent version: {}\nFound Version: {}\nUpdate?",
build.current_version(),
latest_release.version
)
.into();
if let Ok(response) = win_msgbox::MessageBox::<win_msgbox::OkayCancel>::new(body.as_ptr())
.title(w!("DRP Creative Updater").as_ptr())
.show()
{
match response {
win_msgbox::OkayCancel::Cancel => {}
win_msgbox::OkayCancel::Okay => {
build.update()?;
win_msgbox::MessageBox::<win_msgbox::Okay>::new(
w!("Update successful, restart app to apply").as_ptr(),
)
.title(w!("DRP Creative").as_ptr())
.icon(win_msgbox::Icon::Information)
.show()
.expect("Failed to show update successful window");
return Ok(());
}
}
};
} else {
return Err("No updates found".into());
}
Err("Something got skipped".into())
}