Skip to content

Commit

Permalink
✨ Add automatic upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
techouse committed Mar 19, 2022
1 parent 98c1a1f commit 973cce8
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ build/

bin/query_cache/
bin/image_cache/
bin/update_cache/
Binary file added assets/alfredhatcog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/question.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 49 additions & 11 deletions bin/main.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
import 'dart:io' show File, exitCode, stdout;
import 'dart:convert';
import 'dart:convert' show HtmlEscape;

import 'package:alfred_workflow/alfred_workflow.dart'
show
AlfredCache,
AlfredItem,
AlfredItemIcon,
AlfredItemText,
AlfredItems,
AlfredUpdater,
AlfredWorkflow;
import 'package:algolia/algolia.dart' show AlgoliaQuerySnapshot;
import 'package:args/args.dart' show ArgParser, ArgResults;
import 'package:stash/stash_api.dart' show CreatedExpiryPolicy;

import 'src/constants/config.dart';
import 'src/models/search_result.dart' show SearchResult;
import 'src/services/algolia_search.dart' show AlgoliaSearch;
import 'src/services/emoji_downloader.dart';
import 'src/services/emoji_downloader.dart' show EmojiDownloader;

const HtmlEscape htmlEscape = HtmlEscape();

final AlfredWorkflow workflow = AlfredWorkflow();

final AlfredWorkflow workflow = AlfredWorkflow(
cache: AlfredCache<AlfredItems>(
fromEncodable: (Map<String, dynamic> json) => AlfredItems.fromJson(json),
maxEntries: 1024,
expiryPolicy: const CreatedExpiryPolicy(
Duration(days: 7),
),
),
);
final AlfredUpdater updater = AlfredUpdater(
githubRepositoryUrl: Config.githubRepositoryUrl,
currentVersion: Config.version,
updateInterval: Duration(days: 7),
);
bool verbose = false;
bool upgrade = false;

void main(List<String> arguments) async {
try {
Expand All @@ -28,10 +44,18 @@ void main(List<String> arguments) async {
workflow.clearItems();

final ArgParser parser = ArgParser()
..addOption('query', abbr: 'q', mandatory: true)
..addFlag('verbose', abbr: 'v', defaultsTo: false);
..addOption('query', abbr: 'q', defaultsTo: '')
..addFlag('verbose', abbr: 'v', defaultsTo: false)
..addFlag('upgrade', abbr: 'u', defaultsTo: false);
final ArgResults args = parser.parse(arguments);

upgrade = args['upgrade'];
if (upgrade) {
stdout.writeln('Upgrading workflow...');

return await updater.update();
}

verbose = args['verbose'];

final String query = args['query'].replaceAll(RegExp(r'\s+'), ' ').trim();
Expand All @@ -52,14 +76,28 @@ void main(List<String> arguments) async {
} catch (err) {
exitCode = 1;
workflow.addItem(AlfredItem(title: err.toString()));
if (verbose) {
rethrow;
}
if (verbose) rethrow;
} finally {
workflow.run();
if (!upgrade) {
if (await updater.updateAvailable()) {
workflow.run(addToBeginning: upgradeItem);
} else {
workflow.run();
}
}
}
}

const upgradeItem = AlfredItem(
title: 'Auto-Update available!',
subtitle: 'Press <enter> to auto-update to a new version of this workflow.',
arg: 'update:workflow',
match:
'Auto-Update available! Press <enter> to auto-update to a new version of this workflow.',
icon: AlfredItemIcon(path: 'alfredhatcog.png'),
valid: true,
);

void _showPlaceholder() {
workflow.addItem(
const AlfredItem(
Expand Down
3 changes: 3 additions & 0 deletions bin/src/constants/config.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
class Config {
Config._();

static const String version = '1.0.3';
static final Uri githubRepositoryUrl =
Uri.https('github.com', '/techouse/alfred-gitmoji');
static const String algoliaApplicationId = 'WODHKE4WZG';
static const String algoliaSearchOnlyApiKey =
'7456cdd91ba8d4f87846549697397759';
Expand Down
2 changes: 1 addition & 1 deletion bin/src/services/algolia_search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class AlgoliaSearch {
.query(queryString)
.setAttributesToRetrieve(SearchResult.attributesToRetrieve)
.setPage(0)
.setHitsPerPage(10)
.setHitsPerPage(20)
.getObjects();
}
11 changes: 8 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
if [ -d "build/dist" ]; then
rm -rf build/dist
fi
mkdir -p build/dist
cp -r info.plist assets/* LICENSE README.md version build/dist
dart compile exe bin/main.dart -o build/dist/docs -S /dev/null --verbosity error

if [ -d "build/debug_info" ]; then
rm -rf build/debug_info
fi

mkdir -p build/dist build/debug_info
cp -r info.plist assets/* LICENSE README.md build/dist
dart compile exe bin/main.dart -o build/dist/gm -S build/debug_info/gitmojis
108 changes: 100 additions & 8 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,20 @@
<string>Productivity</string>
<key>connections</key>
<dict>
<key>F6F9BD70-3218-4D80-A4D2-63C6A77142CA</key>
<key>E50F9D21-04DF-4185-A2CB-40B7111F31C0</key>
<array>
<dict>
<key>destinationuid</key>
<string>F404D930-F17D-43D0-B06B-28D6A000A93F</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>sourceoutputuid</key>
<string>D850B7E1-B6F7-4A5E-8EF6-522CBF4E0A21</string>
<key>vitoclose</key>
<false/>
</dict>
<dict>
<key>destinationuid</key>
<string>B1E797A8-B1C1-4A07-A340-67D2AC741B3C</string>
Expand All @@ -20,6 +32,19 @@
<key>vitoclose</key>
<false/>
</dict>
</array>
<key>F6F9BD70-3218-4D80-A4D2-63C6A77142CA</key>
<array>
<dict>
<key>destinationuid</key>
<string>E50F9D21-04DF-4185-A2CB-40B7111F31C0</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
<dict>
<key>destinationuid</key>
<string>D6793604-058B-4867-A1EA-BF8C2B8B3733</string>
Expand All @@ -42,6 +67,59 @@
<string>Gitmoji</string>
<key>objects</key>
<array>
<dict>
<key>config</key>
<dict>
<key>concurrently</key>
<false/>
<key>escaping</key>
<integer>102</integer>
<key>script</key>
<string>./gm --upgrade</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>type</key>
<integer>0</integer>
</dict>
<key>type</key>
<string>alfred.workflow.action.script</string>
<key>uid</key>
<string>F404D930-F17D-43D0-B06B-28D6A000A93F</string>
<key>version</key>
<integer>2</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>conditions</key>
<array>
<dict>
<key>inputstring</key>
<string>{query}</string>
<key>matchcasesensitive</key>
<false/>
<key>matchmode</key>
<integer>0</integer>
<key>matchstring</key>
<string>update:workflow</string>
<key>outputlabel</key>
<string>Update Workflow</string>
<key>uid</key>
<string>D850B7E1-B6F7-4A5E-8EF6-522CBF4E0A21</string>
</dict>
</array>
<key>elselabel</key>
<string>Copy to Clipboard</string>
</dict>
<key>type</key>
<string>alfred.workflow.utility.conditional</string>
<key>uid</key>
<string>E50F9D21-04DF-4185-A2CB-40B7111F31C0</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -89,7 +167,7 @@
<key>runningsubtext</key>
<string>Fetching gitmojis ...</string>
<key>script</key>
<string>./docs -q "{query}"</string>
<string>./gm -q "{query}"</string>
<key>scriptargtype</key>
<integer>0</integer>
<key>scriptfile</key>
Expand Down Expand Up @@ -137,29 +215,43 @@
<key>B1E797A8-B1C1-4A07-A340-67D2AC741B3C</key>
<dict>
<key>xpos</key>
<integer>285</integer>
<integer>845</integer>
<key>ypos</key>
<integer>220</integer>
<integer>205</integer>
</dict>
<key>D6793604-058B-4867-A1EA-BF8C2B8B3733</key>
<dict>
<key>xpos</key>
<integer>290</integer>
<integer>580</integer>
<key>ypos</key>
<integer>395</integer>
</dict>
<key>E50F9D21-04DF-4185-A2CB-40B7111F31C0</key>
<dict>
<key>xpos</key>
<integer>580</integer>
<key>ypos</key>
<integer>105</integer>
</dict>
<key>F404D930-F17D-43D0-B06B-28D6A000A93F</key>
<dict>
<key>xpos</key>
<integer>845</integer>
<key>ypos</key>
<integer>365</integer>
<integer>10</integer>
</dict>
<key>F6F9BD70-3218-4D80-A4D2-63C6A77142CA</key>
<dict>
<key>xpos</key>
<integer>55</integer>
<integer>325</integer>
<key>ypos</key>
<integer>220</integer>
</dict>
</dict>
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>1.0.2</string>
<string>1.0.3</string>
<key>webaddress</key>
<string>https://github.com/techouse</string>
</dict>
Expand Down
8 changes: 4 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ packages:
description:
path: "."
ref: master
resolved-ref: f00676352fc5979de0cc9dd7f83a72bbbca298d8
resolved-ref: "3bcaed9a5848e962ece41074eebbe07d236cad18"
url: "[email protected]:techouse/alfred_workflow.git"
source: git
version: "0.0.4"
version: "0.0.5"
algolia:
dependency: "direct main"
description:
Expand Down Expand Up @@ -198,7 +198,7 @@ packages:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "4.4.0"
version: "5.0.0"
pub_semver:
dependency: transitive
description:
Expand Down Expand Up @@ -275,7 +275,7 @@ packages:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "5.3.1"
version: "5.4.1"
yaml:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Search for gitmojis and copy them to the clipboard easily.
# Prevent accidental publishing to pub.dev.
publish_to: 'none'

version: 1.0.0
version: 1.0.2

environment:
sdk: '>=2.16.1 <3.0.0'
Expand Down
1 change: 0 additions & 1 deletion version

This file was deleted.

0 comments on commit 973cce8

Please sign in to comment.