Skip to content

Commit

Permalink
add icon package
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex222222222222 committed Mar 13, 2023
1 parent 0817efa commit decf9b8
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type UserConfig struct {
TesseractExecutablePath string
CacheDir string
TerminalNotifierExecutablePath string
DarkMode bool
}

type Language struct {
Expand Down Expand Up @@ -149,6 +150,7 @@ func GenerateDefaultConfig() (*UserConfig, error) {
Tesseract: "eng",
},
},
DarkMode: false,
}

if _, err := os.Stat(c.CacheDir); errors.Is(err, os.ErrNotExist) {
Expand Down
3 changes: 3 additions & 0 deletions files/IconDark.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions files/QuitIconDark.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions files/ScanBarCodeIconDark.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions files/ScanDataMatrixIconDark.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions files/ScanOcrIconDark.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions files/ScanQRCodeIconDark.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions files/ScreenshotIconDark.go

Large diffs are not rendered by default.

87 changes: 87 additions & 0 deletions icons/icons.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package icons

import (
"encoding/base64"
"errors"

"github.com/Alex222222222222/AppOcr/files"
)

type IconType int64

const (
IconTypeApp IconType = iota
IconTypeCaptureScreenShot
IconTypeScanQRCode
IconTypeOCR
IconTypeQuit
IconTypeChangeTheme
IconTypeScanBarCode
IconTYpeScanDataMatrix
)

func GetIcon(iconType IconType, darkMode bool) ([]byte, error) {
iconRaw, err := GetIconRaw(iconType, darkMode)
if err != nil {
return nil, err
}

return base64.StdEncoding.DecodeString(iconRaw)
}

func GetIconRaw(iconType IconType, darkMode bool) (string, error) {
switch iconType {
case IconTypeApp:
if darkMode {
return files.IconDark, nil
} else {
return files.Icon, nil
}
case IconTypeCaptureScreenShot:
if darkMode {
return files.ScreenshotIconDark, nil
} else {
return files.ScreenshotIcon, nil
}
case IconTypeScanQRCode:
if darkMode {
return files.ScanQRCodeIconDark, nil
} else {
return files.ScanQRCodeIcon, nil
}
case IconTypeOCR:
if darkMode {
return files.ScanOcrIconDark, nil
} else {
return files.ScanOcrIcon, nil
}
case IconTypeQuit:
if darkMode {
return files.QuitIconDark, nil
} else {
return files.QuitIcon, nil
}
/*
case IconTypeChangeTheme:
if darkMode {
return files.ChangeThemeIconDark, nil
} else {
return files.ChangeThemeIcon, nil
}
*/
case IconTypeScanBarCode:
if darkMode {
return files.ScanBarCodeIconDark, nil
} else {
return files.ScanBarCodeIcon, nil
}
case IconTYpeScanDataMatrix:
if darkMode {
return files.ScanDataMatrixIconDark, nil
} else {
return files.ScanDataMatrixIcon, nil
}
default:
return "", errors.New("invalid icon type")
}
}
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ func onReady() {
bOCR := systray.AddMenuItem("OCR", "OCR")
bOCR.SetIcon(icon)

// quit the app
icon, err = base64.StdEncoding.DecodeString(files.QuitIcon)
if err != nil {
panic(err)
}
bChangeTheme := systray.AddMenuItem("Change Icon Theme", "Change Icon Theme")
bChangeTheme.SetIcon(icon)

// quit the app
icon, err = base64.StdEncoding.DecodeString(files.QuitIcon)
if err != nil {
Expand Down Expand Up @@ -286,6 +294,12 @@ func onReady() {
}
}
}
case <-bChangeTheme.ClickedCh:
c.DarkMode = !c.DarkMode
err = config.SaveConfig(c)
if err != nil {
panic(err)
}
}
}
}()
Expand Down

0 comments on commit decf9b8

Please sign in to comment.