diff --git a/cfg/loader.go b/cfg/loader.go index 974ef38..d8c5329 100644 --- a/cfg/loader.go +++ b/cfg/loader.go @@ -1,8 +1,11 @@ package cfg import ( + "fmt" + "io" "io/ioutil" "log" + "net/http" "os" "path/filepath" "regexp" @@ -34,6 +37,8 @@ var CONFIG_FULL_PATH string = "" // rename/refactor due here too! var configDirAbsPath string = "" +var ICON_DIR_PATH string = "" + // TODO we only had double key combos // e.g. cmd+s. we want to handle things // like cmd+alt+s @@ -198,6 +203,57 @@ func Setup() TomlConfig { } } + // ---- + // downloads the icon from github + // and puts it into the phi-editor config folder. + ICON_DIR_PATH = filepath.Join(CONFIG_DIR, "icons") + if _, err := os.Stat(ICON_DIR_PATH); os.IsNotExist(err) { + if err := os.Mkdir(ICON_DIR_PATH, 0775); err != nil { + panic(err) + } + + log.Println("setting up the icons folder") + + // https://raw.githubusercontent.com/felixangell/phi/gh-pages/images/icon128.png + downloadIcon := func(iconSize int) { + log.Println("downloading the phi icon ", iconSize, "x", iconSize, " png image.") + + file, err := os.Create(filepath.Join(ICON_DIR_PATH, fmt.Sprintf("icon%d.png", iconSize))) + defer file.Close() + if err != nil { + log.Println(err.Error()) + return + } + + // Generated by curl-to-Go: https://mholt.github.io/curl-to-go + resp, err := http.Get(fmt.Sprintf("https://raw.githubusercontent.com/felixangell/phi/gh-pages/images/icon%d.png", iconSize)) + if err != nil { + log.Println("Failed to download icon", iconSize, "!", err.Error()) + return + } + defer resp.Body.Close() + + _, err = io.Copy(file, resp.Body) + if err != nil { + log.Println(err.Error()) + } + } + + size := 16 + switch runtime.GOOS { + case "windows": + size = 64 + case "darwin": + size = 512 + case "linux": + size = 96 + } + + // download the icon and + // write it to the phi-editor folder. + downloadIcon(size) + } + // try make the syntax config folder. if _, err := os.Stat(SYNTAX_CONFIG_DIR); os.IsNotExist(err) { if err := os.Mkdir(SYNTAX_CONFIG_DIR, 0775); err != nil { diff --git a/main.go b/main.go index 86bc388..f6fee36 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "io/ioutil" "log" "os" + "path/filepath" "runtime" "time" @@ -86,19 +87,20 @@ func main() { window.Create() { - size := "16" + size := 16 switch runtime.GOOS { case "windows": - size = "64" + size = 64 case "darwin": - size = "512" + size = 512 case "linux": - size = "96" + size = 96 default: log.Println("unrecognized runtime ", runtime.GOOS) } - icon, err := strife.LoadImage("./res/icons/icon" + size + ".png") + iconFile := fmt.Sprintf("icon%d.png", size) + icon, err := strife.LoadImage(filepath.Join(cfg.ICON_DIR_PATH, iconFile)) if err != nil { log.Println("Failed to load icon ", err.Error()) } else { diff --git a/res/firacode.ttf b/res/firacode.ttf deleted file mode 100644 index 575c21b..0000000 Binary files a/res/firacode.ttf and /dev/null differ diff --git a/res/icons/icon128.png b/res/icons/icon128.png deleted file mode 100644 index a87652c..0000000 Binary files a/res/icons/icon128.png and /dev/null differ diff --git a/res/icons/icon16.png b/res/icons/icon16.png deleted file mode 100644 index 957d6c7..0000000 Binary files a/res/icons/icon16.png and /dev/null differ diff --git a/res/icons/icon256.png b/res/icons/icon256.png deleted file mode 100644 index e14314a..0000000 Binary files a/res/icons/icon256.png and /dev/null differ diff --git a/res/icons/icon32.png b/res/icons/icon32.png deleted file mode 100644 index 7edbd33..0000000 Binary files a/res/icons/icon32.png and /dev/null differ diff --git a/res/icons/icon512.png b/res/icons/icon512.png deleted file mode 100644 index 7bbc628..0000000 Binary files a/res/icons/icon512.png and /dev/null differ diff --git a/res/icons/icon64.png b/res/icons/icon64.png deleted file mode 100644 index f8242aa..0000000 Binary files a/res/icons/icon64.png and /dev/null differ diff --git a/res/icons/icon96.png b/res/icons/icon96.png deleted file mode 100644 index f625306..0000000 Binary files a/res/icons/icon96.png and /dev/null differ