-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature]<main>: finish v2 wallpaper flow ✨✨
- Loading branch information
Showing
7 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
build: | ||
mkdir -p output | ||
CCO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -o output/wallpaper-bin_arm main.go | ||
CCO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -o output/wallpaper-bin_amd main.go | ||
makefat ./output/wallpaper-bin ./output/wallpaper-bin_* | ||
rm -rf ./output/wallpaper-bin_* | ||
|
||
clean: | ||
rm -rf ./output | ||
rm -rf ./wallpaper | ||
|
||
|
||
run: build | ||
./output/wallpaper-bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,18 @@ | ||
# wallpaper-switch | ||
👊 Macos wallpaper switch alfred flow 👊 | ||
|
||
## Usage | ||
1. Very simple, input `cim` will be ok. | ||
 | ||
2. Enter to select the wallpaper. | ||
 | ||
|
||
## History version | ||
If you want use v1 version, you can find it from https://github.com/o98k-ok/cim-flow | ||
|
||
Compare to v1 version, this version has more features: | ||
1. support `GridView` to select history images. | ||
2. v2 code is easy to understand. | ||
|
||
## Thanks | ||
That's all, enjoy it! |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module github.com/o98k-ok/wallpaper-switch | ||
|
||
go 1.22.0 | ||
|
||
require github.com/duke-git/lancet/v2 v2.3.2 | ||
|
||
require ( | ||
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect | ||
github.com/russross/blackfriday/v2 v2.1.0 // indirect | ||
github.com/urfave/cli/v2 v2.4.0 // indirect | ||
howett.net/plist v1.0.0 // indirect | ||
) | ||
|
||
require ( | ||
github.com/o98k-ok/lazy v0.2.51 | ||
golang.org/x/exp v0.0.0-20221208152030-732eee02a75a // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= | ||
github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU= | ||
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||
github.com/duke-git/lancet/v2 v2.3.2 h1:Cv+uNkx5yGqDSvGc5Vu9eiiZobsPIf0Ng7NGy5hEdow= | ||
github.com/duke-git/lancet/v2 v2.3.2/go.mod h1:zGa2R4xswg6EG9I6WnyubDbFO/+A/RROxIbXcwryTsc= | ||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= | ||
github.com/o98k-ok/lazy v0.2.51 h1:3fqQ/5Ge1R5z2Gu18GyZTYsng4xW0hZ90gI/3D4kzjc= | ||
github.com/o98k-ok/lazy v0.2.51/go.mod h1:HK7ZPdg1JSNmQcRrL/prUeT135oHdPGKnopRmFQuuXk= | ||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= | ||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
github.com/urfave/cli/v2 v2.4.0 h1:m2pxjjDFgDxSPtO8WSdbndj17Wu2y8vOT86wE/tjr+I= | ||
github.com/urfave/cli/v2 v2.4.0/go.mod h1:NX9W0zmTvedE5oDoOMs2RTC8RvdK98NTYZE5LbaEYPg= | ||
golang.org/x/exp v0.0.0-20221208152030-732eee02a75a h1:4iLhBPcpqFmylhnkbY3W0ONLUYYkDAW9xMFLfxgsvCw= | ||
golang.org/x/exp v0.0.0-20221208152030-732eee02a75a/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg= | ||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||
howett.net/plist v1.0.0 h1:7CrbWYbPPO/PyNy38b2EB/+gYbjCe2DXBxgtOOZbSQM= | ||
howett.net/plist v1.0.0/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"flag" | ||
"fmt" | ||
"os" | ||
"path" | ||
"sync" | ||
|
||
"github.com/duke-git/lancet/v2/netutil" | ||
"github.com/o98k-ok/lazy/v2/alfred" | ||
) | ||
|
||
var ( | ||
HOST = "bing.com" | ||
) | ||
|
||
type BingImg struct { | ||
Startdate string `json:"startdate"` | ||
Fullstartdate string `json:"fullstartdate"` | ||
Enddate string `json:"enddate"` | ||
URL string `json:"url"` | ||
Urlbase string `json:"urlbase"` | ||
Copyright string `json:"copyright"` | ||
Copyrightlink string `json:"copyrightlink"` | ||
Title string `json:"title"` | ||
Quiz string `json:"quiz"` | ||
Wp bool `json:"wp"` | ||
Hsh string `json:"hsh"` | ||
Drk int `json:"drk"` | ||
Top int `json:"top"` | ||
Bot int `json:"bot"` | ||
Hs []any `json:"hs"` | ||
} | ||
|
||
type BingResponse struct { | ||
Images []BingImg `json:"images"` | ||
} | ||
|
||
func main() { | ||
var dir string | ||
var count int | ||
flag.StringVar(&dir, "dir", "", "wallpaper dir") | ||
flag.IntVar(&count, "count", 9, "wallpaper count") | ||
flag.Parse() | ||
if len(dir) == 0 { | ||
pwd, _ := os.Getwd() | ||
dir = path.Join(pwd, "wallpaper") | ||
} | ||
|
||
{ | ||
os.MkdirAll(dir, 0755) | ||
} | ||
|
||
{ | ||
url := fmt.Sprintf("https://%s/HPImageArchive.aspx?format=js&idx=0&n=%d&mkt=en-US", HOST, count) | ||
resp, err := netutil.HttpGet(url) | ||
if err != nil { | ||
alfred.Log("get %s err %v", url, err) | ||
return | ||
} | ||
|
||
var bing BingResponse | ||
if err = json.NewDecoder(resp.Body).Decode(&bing); err != nil { | ||
alfred.Log("decode %s response err %v", url, err) | ||
return | ||
} | ||
|
||
items := alfred.NewItems() | ||
items.Items = make([]*alfred.Item, len(bing.Images)) | ||
groups := sync.WaitGroup{} | ||
for i, v := range bing.Images { | ||
groups.Add(1) | ||
go func(idx int, val BingImg) { | ||
defer groups.Done() | ||
|
||
filename := path.Join(dir, fmt.Sprintf("%s_%s.jpg", val.Startdate, val.Hsh)) | ||
item := alfred.NewItem(val.Title, "", filename) | ||
item.Icon = &alfred.Icon{ | ||
Path: filename, | ||
} | ||
items.Items[idx] = item | ||
|
||
{ | ||
_, err := os.Stat(filename) | ||
if err == nil { | ||
return | ||
} | ||
} | ||
|
||
err = netutil.DownloadFile(filename, fmt.Sprintf("https://%s/%s", HOST, val.URL)) | ||
if err != nil { | ||
alfred.Log("download %s err %v", val.URL, err) | ||
} | ||
}(i, v) | ||
} | ||
groups.Wait() | ||
items.Show() | ||
} | ||
} |