Skip to content

Commit

Permalink
Add Gitea updater
Browse files Browse the repository at this point in the history
  • Loading branch information
deanishe committed Apr 7, 2019
1 parent 0cf061c commit 5c81958
Show file tree
Hide file tree
Showing 31 changed files with 1,071 additions and 310 deletions.
77 changes: 4 additions & 73 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,86 +1,17 @@

# Godep
# Deps
/vendor/*

# Tests that actually call Alfred
*_private_test.go

# Created by test
/coverage.*
/testenv
/info.plist

# Created by https://www.gitignore.io/api/go,atom,sublimetext,vim

### Go ###
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
coverage.out

# Folders
_obj
_test

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

_testmain.go

*.exe
*.test
*.prof


#!! ERROR: atom is undefined. Use list command to see defined gitignore types !!#

### SublimeText ###
# cache files for sublime text
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache

# workspace files are user-specific
*.sublime-workspace

# project files should be checked into the repository, unless a significant
# proportion of contributors will probably not be using SublimeText
# *.sublime-project

# sftp configuration file
sftp-config.json

# Package control specific files
Package Control.last-run
Package Control.ca-list
Package Control.ca-bundle
Package Control.system-ca-bundle
Package Control.cache/
Package Control.ca-certs/
bh_unicode_properties.cache

# Sublime-github package stores a github token in this file
# https://packagecontrol.io/packages/sublime-github
GitHub.sublime-settings


### Vim ###
# swap
# vim turds
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
# session
Session.vim
# temporary
.netrwhist
*~
# auto-generated tag files
tags
.tags
.tags1
/tags
35 changes: 0 additions & 35 deletions .gitlab-ci.yml

This file was deleted.

22 changes: 0 additions & 22 deletions Gopkg.lock

This file was deleted.

34 changes: 0 additions & 34 deletions Gopkg.toml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

<div align="center">
<img src="./Icon.png" alt="AwGo Logo" title="AwGo Logo">
<img src="https://raw.githubusercontent.com/deanishe/alfred-safari-assistant/master/icons/icon.png" alt="AwGo Logo" title="AwGo Logo">
</div>

AwGo — A Go library for Alfred workflows
Expand Down
2 changes: 1 addition & 1 deletion _examples/bookmarks/bookmarks.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"net/url"
"os"

"github.com/DHowett/go-plist"
"github.com/deanishe/awgo/fuzzy"
"howett.net/plist"
)

var (
Expand Down
69 changes: 47 additions & 22 deletions alfred.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,25 @@ package aw

import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/deanishe/awgo/util"
)


// JXA scripts to call Alfred.
const (
scriptSearch = "Application(%s).search(%s);"
scriptAction = "Application(%s).action(%s);"
scriptBrowse = "Application(%s).browse(%s);"
scriptSetTheme = "Application(%s).setTheme(%s);"
scriptTrigger = "Application(%s).runTrigger(%s, %s);"
scriptSetConfig = "Application(%s).setConfiguration(%s, %s);"
scriptRmConfig = "Application(%s).removeConfiguration(%s, %s);"
)

/*
Alfred wraps Alfred's AppleScript API, allowing you to open Alfred in
various modes or call External Triggers.
Expand All @@ -28,6 +42,10 @@ various modes or call External Triggers.
*/
type Alfred struct {
Env
// For testing. Set to true to save JXA script to lastScript
// instead of running it.
noRunScripts bool
lastScript string
}

// NewAlfred creates a new Alfred from the environment.
Expand All @@ -44,13 +62,12 @@ func NewAlfred(env ...Env) *Alfred {
e = sysEnv{}
}

return &Alfred{e}
return &Alfred{Env: e}
}

// Search runs Alfred with the given query. Use an empty query to just open Alfred.
func (a *Alfred) Search(query string) error {
_, err := util.RunJS(fmt.Sprintf(scriptSearch, util.QuoteJS(query)))
return err
return a.runScript(scriptSearch, query)
}

// Browse tells Alfred to open path in navigation mode.
Expand All @@ -62,14 +79,12 @@ func (a *Alfred) Browse(path string) error {
return err
}

_, err = util.RunJS(fmt.Sprintf(scriptBrowse, util.QuoteJS(path)))
return err
return a.runScript(scriptBrowse, path)
}

// SetTheme tells Alfred to use the specified theme.
func (a *Alfred) SetTheme(name string) error {
_, err := util.RunJS(fmt.Sprintf(scriptSetTheme, util.QuoteJS(name)))
return err
return a.runScript(scriptSetTheme, name)
}

// Action tells Alfred to show File Actions for path(s).
Expand All @@ -91,8 +106,7 @@ func (a *Alfred) Action(path ...string) error {
paths = append(paths, p)
}

_, err := util.RunJS(fmt.Sprintf(scriptAction, util.QuoteJS(paths)))
return err
return a.runScript(scriptAction, paths)
}

// RunTrigger runs an External Trigger in the given workflow. Query may be empty.
Expand All @@ -117,19 +131,30 @@ func (a *Alfred) RunTrigger(name, query string, bundleID ...string) error {
opts["withArgument"] = query
}

_, err := util.RunJS(fmt.Sprintf(scriptTrigger, util.QuoteJS(name), util.QuoteJS(opts)))
return a.runScript(scriptTrigger, name, opts)
}

func (a *Alfred) runScript(script string, arg ...interface{}) error {
quoted := []interface{}{util.QuoteJS(scriptAppName())}
for _, v := range arg {
quoted = append(quoted, util.QuoteJS(v))
}
script = fmt.Sprintf(script, quoted...)

if a.noRunScripts {
a.lastScript = script
return nil
}

_, err := util.RunJS(script)
return err
}

// JXA scripts to call Alfred
var (
// Simple scripts require one or no string
scriptSearch = "Application('Alfred 3').search(%s)"
scriptAction = "Application('Alfred 3').action(%s)"
scriptBrowse = "Application('Alfred 3').browse(%s)"
scriptSetTheme = "Application('Alfred 3').setTheme(%s)"
// These scripts require a string and an object of options
scriptTrigger = "Application('Alfred 3').runTrigger(%s, %s)"
scriptSetConfig = "Application('Alfred 3').setConfiguration(%s, %s)"
scriptRmConfig = "Application('Alfred 3').removeConfiguration(%s, %s)"
)
// Name of JXA Application for running Alfred
func scriptAppName() string {
if strings.HasPrefix(os.Getenv(EnvVarAlfredVersion), "3") {
return "Alfred 3"
}
return "com.runningwithcrayons.Alfred"
}

Loading

0 comments on commit 5c81958

Please sign in to comment.