Skip to content

Commit

Permalink
fix: timestamp will update when fetching new data (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelkristiansson authored Dec 12, 2022
1 parent e6aba13 commit d2f5e11
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 115 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.4.2

# Fix
* update timestamp every time new fetch is called

## 0.4.1

### Fix
Expand Down
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gitbar",
"private": true,
"version": "0.4.1",
"version": "0.4.2",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -27,5 +27,13 @@
"tslib": "^2.4.1",
"typescript": "^4.8.2",
"vite": "^3.0.9"
},
"prettier": {
"tabWidth": 4,
"trailingComma": "es5",
"semi": true,
"singleQuote": true,
"printWidth": 120,
"arrowParens": "avoid"
}
}
}
49 changes: 25 additions & 24 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gitbar"
version = "0.4.1"
version = "0.4.2"
description = "Github review counter"
authors = ["mikael.kristiansson"]
license = "MIT"
Expand Down
156 changes: 75 additions & 81 deletions src-tauri/src/auto_start.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use auto_launch::{AutoLaunch, AutoLaunchBuilder};
use serde::{ser::Serializer, Serialize};
use tauri::{
command,
plugin::{Builder, TauriPlugin},
Manager, Runtime, State,
command,
plugin::{Builder, TauriPlugin},
Manager, Runtime, State,
};

use std::env::current_exe;
Expand All @@ -12,113 +12,107 @@ type Result<T> = std::result::Result<T, Error>;

#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error(transparent)]
Io(#[from] std::io::Error),
#[error("{0}")]
Anyhow(String),
#[error(transparent)]
Io(#[from] std::io::Error),
#[error("{0}")]
Anyhow(String),
}

impl Serialize for Error {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(self.to_string().as_ref())
}
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(self.to_string().as_ref())
}
}

pub struct AutoLaunchManager(AutoLaunch);

impl AutoLaunchManager {
pub fn enable(&self) -> Result<()> {
self
.0
.enable()
.map_err(|e| e.to_string())
.map_err(Error::Anyhow)
}

pub fn disable(&self) -> Result<()> {
self
.0
.disable()
.map_err(|e| e.to_string())
.map_err(Error::Anyhow)
}

pub fn is_enabled(&self) -> Result<bool> {
self
.0
.is_enabled()
.map_err(|e| e.to_string())
.map_err(Error::Anyhow)
}
pub fn enable(&self) -> Result<()> {
self.0
.enable()
.map_err(|e| e.to_string())
.map_err(Error::Anyhow)
}

pub fn disable(&self) -> Result<()> {
self.0
.disable()
.map_err(|e| e.to_string())
.map_err(Error::Anyhow)
}

pub fn is_enabled(&self) -> Result<bool> {
self.0
.is_enabled()
.map_err(|e| e.to_string())
.map_err(Error::Anyhow)
}
}

pub trait ManagerExt<R: Runtime> {
fn autolaunch(&self) -> State<'_, AutoLaunchManager>;
fn autolaunch(&self) -> State<'_, AutoLaunchManager>;
}

impl<R: Runtime, T: Manager<R>> ManagerExt<R> for T {
fn autolaunch(&self) -> State<'_, AutoLaunchManager> {
self.state::<AutoLaunchManager>()
}
fn autolaunch(&self) -> State<'_, AutoLaunchManager> {
self.state::<AutoLaunchManager>()
}
}

#[command]
async fn enable(manager: State<'_, AutoLaunchManager>) -> Result<()> {
manager.enable()
manager.enable()
}

#[command]
async fn disable(manager: State<'_, AutoLaunchManager>) -> Result<()> {
manager.disable()
manager.disable()
}

#[command]
async fn is_enabled(manager: State<'_, AutoLaunchManager>) -> Result<bool> {
manager.is_enabled()
manager.is_enabled()
}

/// Initializes the plugin.
///
/// `args` - are passed to your app on startup.
pub fn init<R: Runtime>(
args: Option<Vec<&'static str>>,
) -> TauriPlugin<R> {
Builder::new("autostart")
.invoke_handler(tauri::generate_handler![enable, disable, is_enabled])
.setup(move |app| {
let mut builder = AutoLaunchBuilder::new();
let app_name = &app.package_info().name;
builder.set_app_name(app_name);
if let Some(args) = args {
builder.set_args(&args);
}


let current_exe = current_exe()?;

#[cfg(windows)]
builder.set_app_path(&current_exe.display().to_string());
#[cfg(target_os = "macos")]
builder.set_use_launch_agent(true);
builder.set_app_path(&current_exe.canonicalize()?.display().to_string());
#[cfg(target_os = "linux")]
if let Some(appimage) = app
.env()
.appimage
.and_then(|p| p.to_str().map(|s| s.to_string()))
{
builder.set_app_path(&appimage);
} else {
builder.set_app_path(&current_exe.display().to_string());
}

app.manage(AutoLaunchManager(
builder.build().map_err(|e| e.to_string())?,
));
Ok(())
})
.build()
pub fn init<R: Runtime>(args: Option<Vec<&'static str>>) -> TauriPlugin<R> {
Builder::new("autostart")
.invoke_handler(tauri::generate_handler![enable, disable, is_enabled])
.setup(move |app| {
let mut builder = AutoLaunchBuilder::new();
let app_name = &app.package_info().name;
builder.set_app_name(app_name);
if let Some(args) = args {
builder.set_args(&args);
}

let current_exe = current_exe()?;

#[cfg(windows)]
builder.set_app_path(&current_exe.display().to_string());
#[cfg(target_os = "macos")]
builder.set_use_launch_agent(true);
builder.set_app_path(&current_exe.canonicalize()?.display().to_string());
#[cfg(target_os = "linux")]
if let Some(appimage) = app
.env()
.appimage
.and_then(|p| p.to_str().map(|s| s.to_string()))
{
builder.set_app_path(&appimage);
} else {
builder.set_app_path(&current_exe.display().to_string());
}

app.manage(AutoLaunchManager(
builder.build().map_err(|e| e.to_string())?,
));
Ok(())
})
.build()
}
Loading

0 comments on commit d2f5e11

Please sign in to comment.