Skip to content

Commit

Permalink
Do not show auth_token while printing Config in Alfred's window.
Browse files Browse the repository at this point in the history
- Add debugging info to Runner::upgrade
- Show alfred's env var in debug window.
- Relax version requirements for alfred-rs
  • Loading branch information
spamwax committed Jul 10, 2022
1 parent 868d163 commit 16391cd
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 21 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/macos-universal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ jobs:
outputs:
istagged: ${{ steps.master_is_tagged.outputs.tagged }}
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Check if commit is tagged
id: master_is_tagged
run: |
cd ${{ github.workspace }}
value=$(git describe --tags --abbrev=0 --exact-match ${{ github.sha }}) || true
[ -n "$value" ] && value=1 || value=0
echo "::set-output name=tagged::$value"
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.16.10] - 2022-07-10
### Fixed
- Don't print auth_token when printing Config

## [0.16.9] - 2022-07-10
### Fixed
- Workaround for #143. Alfred early access has prerelease in its version. It breaks the logic of checking for minimum Alfred version with json support. (Since SemVer doesn't like comparing non-prerelease versions with standard ones)
Expand Down
4 changes: 2 additions & 2 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ env_logger = "0.9"
[features]

[dependencies.alfred-rs]
version = "0.7.0"
version = "0.7"

[dependencies.rusty-pin]
git = "https://github.com/spamwax/rusty-pin"
Expand Down
2 changes: 1 addition & 1 deletion create_alfred_workflow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ if ! cargo +nightly clippy; then
exit
fi

echo "Building new release..."
cd "$alfred_pinboard_rs" || exit

# Bump Cargo.toml version
echo "Bumping Cargo.toml version to $version_tag"
python res/fix_cargo_version.py "$version_tag"
echo "Building new release..."
cargo build --release > build.log 2>&1

echo "Copying resoursces from Alfred's workflow dir..."
Expand Down
38 changes: 22 additions & 16 deletions src/commands/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,27 @@ impl<'api, 'pin> Runner<'api, 'pin> {
let json_format = self.config.as_ref().unwrap().can_use_json();
if check {
let none: Option<Vec<(&str, &str)>> = None;
if let Ok(item) = self.get_upgrade_item() {
let upgrade_item = if let Some(item) = item {
item
} else {
alfred::ItemBuilder::new("You have the latest version of workflow!")
.icon_path("auto_update.png")
.variable("workflow_update_ready", "0")
.arg("update")
.into_item()
};
crate::write_to_alfred(vec![upgrade_item], json_format, none);
} else {
let item =
alfred::ItemBuilder::new("Error in getting upgrade info!").into_item();
crate::write_to_alfred(vec![item], json_format, none);
match self.get_upgrade_item() {
Ok(item) => {
let upgrade_item = if let Some(item) = item {
debug!("Created item to show workflow upgrade is available.");
item
} else {
debug!("Created item to show NO upgrade is available.");
alfred::ItemBuilder::new("You have the latest version of workflow!")
.icon_path("auto_update.png")
.variable("workflow_update_ready", "0")
.arg("update")
.into_item()
};
crate::write_to_alfred(vec![upgrade_item], json_format, none);
}
Err(e) => {
debug!("Error in fetching update status {:?}", e);
let item = alfred::ItemBuilder::new("Error in getting upgrade info")
.into_item();
crate::write_to_alfred(vec![item], json_format, none);
}
}
} else if download {
let filename = self.updater.as_ref().unwrap().download_latest();
Expand All @@ -38,7 +44,7 @@ impl<'api, 'pin> Runner<'api, 'pin> {
.expect("Couldn't write to output!");
} else {
io::stdout()
.write_all(b"Download OK, issue with its file name!")
.write_all(b"Error: Download OK, issue with its file name!")
.expect("Couldn't write to output!");
}
} else {
Expand Down
12 changes: 12 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ fn main() {
process::exit(1);
}
}
debug!(
"alfred_workflow_version: {:?}",
var_os("alfred_workflow_version")
);
debug!("alfred_workflow_data: {:?}", var_os("alfred_workflow_data"));
debug!(
"alfred_workflow_cache: {:?}",
var_os("alfred_workflow_cache")
);
debug!("alfred_workflow_uid: {:?}", var_os("alfred_workflow_uid"));
debug!("alfred_workflow_name: {:?}", var_os("alfred_workflow_name"));
debug!("alfred_version: {:?}", var_os("alfred_version"));

let pinboard;
let config;
Expand Down
25 changes: 24 additions & 1 deletion src/workflow_config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use chrono::prelude::*;
use core::fmt;
use dirs::home_dir;
use std::fs::{create_dir_all, File};
use std::io::BufReader;
Expand All @@ -15,7 +16,29 @@ pub(crate) const CONFIG_KEY_NAME: &str = "settings";

const FILE_BUF_SIZE: usize = 4 * 1024 * 1024;

#[derive(Debug, Serialize, Deserialize)]
/// Debug is directly implemented so that we do not show the auth_token in Alfred's debug window.
impl fmt::Debug for Config {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Config")
.field("alfred_version", &self.alfred_version)
.field("pins_to_show", &self.pins_to_show)
.field("tags_to_show", &self.tags_to_show)
.field("tags_only_search", &self.tag_only_search)
.field("fuzzy_search", &self.fuzzy_search)
.field("private_new_pin", &self.private_new_pin)
.field("toread_new_pin", &self.toread_new_pin)
.field("suggest_tags", &self.suggest_tags)
.field("page_is_bookmarked", &self.page_is_bookmarked)
.field("show_url_vs_tags", &self.show_url_vs_tags)
.field("auto_update_cache", &self.auto_update_cache)
.field("update_time", &self.update_time)
.field("workflow_data_dir", &self.workflow_data_dir)
.field("workflow_cache_dir", &self.workflow_cache_dir)
.finish()
}
}

#[derive(Serialize, Deserialize)]
pub struct Config {
/// Which version of Alfred we are being executed under
#[serde(skip, default = "get_alfred_version")]
Expand Down

0 comments on commit 16391cd

Please sign in to comment.