Skip to content

Commit

Permalink
Make downloading theme files optional
Browse files Browse the repository at this point in the history
  • Loading branch information
yorukot committed May 11, 2024
1 parent 39c1523 commit 7fa775d
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/internal/config_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func loadHotkeysFile() {
func loadThemeFile() {
data, err := os.ReadFile(SuperFileMainDir + themeFolder + "/" + Config.Theme + ".toml")
if err != nil {
log.Fatalf("Theme file doesn't exist: %v", err)
data = []byte(DefaultTheme)
}

err = toml.Unmarshal(data, &theme)
Expand Down
65 changes: 65 additions & 0 deletions src/internal/default_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,71 @@ border_middle_right = "┫"
metadata = false
`

var DefaultTheme string = `# Catpuccin
# Theme create by: https://github.com/AnshumanNeon
# Update by(sort by time):
#
# Thanks for all contributor!!
# If you want to make sidebar border display just set it same as sidebar background color
# ========= Border =========
file_panel_border = "#6c7086"
sidebar_border = "#1e1e2e"
footer_border = "#6c7086"
# ========= Border Active =========
file_panel_border_active = "#b4befe"
sidebar_border_active = "#f38ba8"
footer_border_active = "#a6e3a1"
modal_border_active = "#868686"
# ========= Background (bg) =========
full_screen_bg = "#1e1e2e"
file_panel_bg = "#1e1e2e"
sidebar_bg = "#1e1e2e"
footer_bg = "#1e1e2e"
modal_bg = "#1e1e2e"
# ========= Foreground (fg) =========
full_screen_fg = "#a6adc8"
file_panel_fg = "#a6adc8"
sidebar_fg = "#a6adc8"
footer_fg = "#a6adc8"
modal_fg = "#a6adc8"
# ========= Special Color =========
cursor = "#f5e0dc"
correct = "#a6e3a1"
error = "#f38ba8"
hint = "#73c7ec"
cancel = "#eba0ac"
# Gradient color can only have two color!
gradient_color = ["#89b4fa", "#cba6f7"]
# ========= File Panel Special Items =========
file_panel_top_directory_icon = "#a6e3a1"
file_panel_top_path = "#89b5fa"
file_panel_item_selected_fg = "#98D0FD"
file_panel_item_selected_bg = "#1e1e2e"
# ========= Sidebar Special Items =========
sidebar_title = "#74c7ec"
sidebar_item_selected_fg = "#A6DBF7"
sidebar_item_selected_bg = "#1e1e2e"
sidebar_divider = "#868686"
# ========= Modal Special Items =========
modal_cancel_fg = "#383838"
modal_cancel_bg = "#eba0ac"
modal_confirm_fg = "#383838"
modal_confirm_bg = "#89dceb"
# ========= Help Menu =========
help_menu_hotkey = "#89dceb"
help_menu_title = "#eba0ac"
`
func defaultModelConfig(toggleDotFileBool bool, firstFilePanelDir string) model {
return model{
filePanelFocusIndex: 0,
Expand Down
31 changes: 21 additions & 10 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ func main() {
Description: "Pretty fancy and modern terminal file manager ",
ArgsUsage: "[path]",
Commands: []*cli.Command{
{
Name: "download-theme",
Aliases: []string{"dt"},
Usage: "Download or update theme file from github",
Action: func(c *cli.Context) error {
if err := downloadAndInstallTheme(SuperFileMainDir, themeZipName, themeZip, themeFolder); err != nil {
log.Fatalln("Error downloading theme:", err)
}
fmt.Println(lipgloss.NewStyle().Foreground(lipgloss.Color("#66ff66")).Render("🎉 Successful downloaded themes!"))
fmt.Println(lipgloss.NewStyle().Foreground(lipgloss.Color("#66b2ff")).Render("Now you can change your superfile theme!"))
return nil
},
},
{
Name: "path-list",
Aliases: []string{"pl"},
Expand Down Expand Up @@ -110,8 +123,6 @@ func InitConfigFile() {
LogFile string
ConfigFile string
HotkeysFile string
ThemeFolder string
ThemeZipName string
}{
MainDir: SuperFileMainDir,
DataDir: SuperFileDataDir,
Expand All @@ -121,8 +132,6 @@ func InitConfigFile() {
LogFile: logFile,
ConfigFile: configFile,
HotkeysFile: hotkeysFile,
ThemeFolder: themeFolder,
ThemeZipName: themeZipName,
}

// Create directories
Expand Down Expand Up @@ -162,12 +171,6 @@ func InitConfigFile() {
if err := writeConfigFile(config.MainDir+config.HotkeysFile, internal.HotkeysTomlString); err != nil {
log.Fatalln("Error writing config file:", err)
}

// Download and install theme
if err := downloadAndInstallTheme(config.MainDir, config.ThemeZipName, themeZip, config.ThemeFolder); err != nil {
log.Fatalln("Error downloading theme:", err)
}

}

// Helper functions
Expand Down Expand Up @@ -219,6 +222,9 @@ func writeConfigFile(path, data string) error {
}

func downloadAndInstallTheme(dir, zipName, zipUrl, zipFolder string) error {
if !connected() {
log.Fatalln("You don't have an internet connection!")
}
currentThemeVersion, err := readThemeVersionFromFile(SuperFileDataDir + themeFileVersion)
if err != nil && !os.IsNotExist(err) {
fmt.Println("Error reading from file:", err)
Expand Down Expand Up @@ -392,3 +398,8 @@ func unzip(src, dest string) error {
}
return nil
}

func connected() (ok bool) {
_, err := http.Get("http://clients3.google.com/generate_204")
return err == nil
}

0 comments on commit 7fa775d

Please sign in to comment.