From aa007e53457231ea7e591829a8ee7f32ca7ab7b3 Mon Sep 17 00:00:00 2001 From: Erik Tank Date: Tue, 31 Oct 2023 06:40:56 -0700 Subject: [PATCH] set bundleid and add CHANGELOG.md - set bundleid for proper updates - add CHANGELOG.md - misc cleanup - provide error information --- .github/workflows/create_alfredworkflow.yml | 6 ++--- CHANGELOG.md | 12 +++++++++ Joplin.pm | 11 +++++++++ info.plist | 4 +-- search_notes.pl | 27 +++++++++++---------- 5 files changed, 42 insertions(+), 18 deletions(-) create mode 100644 CHANGELOG.md diff --git a/.github/workflows/create_alfredworkflow.yml b/.github/workflows/create_alfredworkflow.yml index 1e6ca82..179c5df 100644 --- a/.github/workflows/create_alfredworkflow.yml +++ b/.github/workflows/create_alfredworkflow.yml @@ -18,11 +18,11 @@ jobs: uses: thedoctor0/zip-release@main with: type: 'zip' - filename: 'link-opener.alfredworkflow' + filename: 'joplin.alfredworkflow' exclusions: '*.git*' - uses: actions/upload-artifact@main with: - name: link-opener.alfredworkflow - path: link-opener.alfredworkflow + name: joplin.alfredworkflow + path: joplin.alfredworkflow diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e454e17 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,12 @@ +# Changelog + +## 0.0.1 + +- add `js` search + +## 0.0.2 + +- set bundleid; this should allow for upgrading the workflow properly +- add CHANGELOG.md +- some error handling to provide feedback to user +- misc code clean up to standardize naming diff --git a/Joplin.pm b/Joplin.pm index cb1499c..eb0321a 100644 --- a/Joplin.pm +++ b/Joplin.pm @@ -25,4 +25,15 @@ sub get_data { return decode_json($resp); } +sub parse_error { + my $data = shift || warn("parse_error called without data\n"); + + warn("no error element found in data\n") unless exists $data->{error}; + + my @lines = split(/\n/, $data->{error}); + $lines[0] =~ s/"/'/g; + + return $lines[0]; +} + 1; \ No newline at end of file diff --git a/info.plist b/info.plist index 9dbe39b..0df7a33 100644 --- a/info.plist +++ b/info.plist @@ -3,7 +3,7 @@ bundleid - + com.github/skeletonkey/joplin_alfred_workflow category Productivity connections @@ -142,7 +142,7 @@ Report issues here: https://github.com/skeletonkey/joplin_alfred_workflow/issues JOPLIN_TOKEN version - 0.0.1 + 0.0.2 webaddress https://github.com/skeletonkey/joplin_alfred_workflow diff --git a/search_notes.pl b/search_notes.pl index da19a9e..d5e1d36 100755 --- a/search_notes.pl +++ b/search_notes.pl @@ -5,20 +5,21 @@ use Joplin; -find_link(@ARGV); +my $find = join(' ', @ARGV); -sub find_link { - my $find = join(' ', @ARGV); +my $tmpl = '"title":"%s","subtitle":"%s","arg":"%s"'; - my $tmpl = '"title":"%s","subtitle":"%s","arg":"%s"'; +my $data = Joplin::get_data(["search"], { "query" => $find }); - my $data = Joplin::get_data(["search"], { "query" => $find }); - - if (@{$data->{items}}) { - my @items = @{$data->{items}}; - print '{"items":[{' . join('},{', map({ sprintf($tmpl, $_->{"title"},$_->{"title"},$_->{"id"}) } @items)) . '}]}'; - } - else { - print '{"items":[{"title":"No links found","subtitle":"Please try a different search"}]}'; - } +if (exists $data->{items} && @{$data->{items}}) { + my @items = @{$data->{items}}; + print '{"items":[{' . join('},{', map({ sprintf($tmpl, $_->{"title"},$_->{"title"},$_->{"id"}) } @items)) . '}]}'; +} +elsif (exists $data->{error}) { + my @lines = split(/\n/, $data->{error}); + $lines[0] =~ s/"/'/g; + print '{"items":[{' . sprintf($tmpl, 'Error', Joplin::parse_error($data), 0) . '}]}'; +} +else { + print '{"items":[{"title":"No notes found","subtitle":"Please try a different search"}]}'; } \ No newline at end of file