Skip to content

Commit

Permalink
Merge pull request #3 from ErikKalkoken/add-theme-setting
Browse files Browse the repository at this point in the history
Add theme setting
  • Loading branch information
ErikKalkoken authored Jul 25, 2024
2 parents 102c51b + 9f40105 commit 41bf3be
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 17 deletions.
2 changes: 1 addition & 1 deletion FyneApp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ Website = "https://github.com/ErikKalkoken/janice"
Icon = "icon.png"
Name = "Janice"
ID = "io.github.erikkalkoken.janice"
Version = "0.1.1"
Version = "0.2.0"
Build = 1
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ Janice is a desktop app for viewing large JSON files. It's key features are:
- Copy values to clipboard
- Single executable file, no installation required
- Desktop app that runs on Windows, Linux and macOS (experimental)
- Automatic dark and light mode
- Automatic dark and light theme

## Screenshots

![screenshot](https://cdn.imgpile.com/f/bdQBc3q_xl.png)
### Light theme

![light](https://cdn.imgpile.com/f/0IrYBjJ_xl.png)

### Dark theme

![dark](https://cdn.imgpile.com/f/bdQBc3q_xl.png)

## How to run

Expand Down
10 changes: 0 additions & 10 deletions internal/ui/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ const (
websiteURL = "https://github.com/ErikKalkoken/janice"
)

// setting keys and defaults
const (
settingExtensionDefault = true
settingExtensionFilter = "extension-filter"
settingNotifyUpdates = "notify-updates"
settingNotifyUpdatesDefault = true
settingRecentFileCount = "recent-file-count"
settingRecentFileCountDefault = 5
)

func (u *UI) makeMenu() *fyne.MainMenu {
recentItem := fyne.NewMenuItem("Open Recent", nil)
recentItem.ChildMenu = fyne.NewMenu("")
Expand Down
30 changes: 30 additions & 0 deletions internal/ui/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ import (
"fyne.io/fyne/v2/widget"
)

const (
themeAuto = "auto"
themeDark = "dark"
themeLight = "light"
)

// setting keys and defaults
const (
settingExtensionDefault = true
settingExtensionFilter = "extension-filter"
settingNotifyUpdates = "notify-updates"
settingNotifyUpdatesDefault = true
settingRecentFileCount = "recent-file-count"
settingRecentFileCountDefault = 5
settingTheme = "theme"
settingThemeDefault = themeAuto
)

func (u *UI) showSettingsDialog() {
recentEntry := widget.NewEntry()
x := u.app.Preferences().IntWithFallback(settingRecentFileCount, settingRecentFileCountDefault)
Expand All @@ -24,10 +42,17 @@ func (u *UI) showSettingsDialog() {
z := u.app.Preferences().BoolWithFallback(settingNotifyUpdates, settingNotifyUpdatesDefault)
notifyUpdates.SetChecked(z)

themeChoice := widget.NewRadioGroup(
[]string{themeAuto, themeDark, themeLight}, func(s string) {},
)
initialTheme := u.app.Preferences().StringWithFallback(settingTheme, settingThemeDefault)
themeChoice.SetSelected(initialTheme)

items := []*widget.FormItem{
{Text: "Max recent files", Widget: recentEntry, HintText: "Maximum number of recent files remembered"},
{Text: "JSON file filter", Widget: extFilter, HintText: "Wether to show files with .json extension only"},
{Text: "Notify about updates", Widget: notifyUpdates, HintText: "Wether to notify when an update is available (requires restart)"},
{Text: "Theme", Widget: themeChoice, HintText: "Choose the preferred theme (requires restart)"},
}
d := dialog.NewForm(
"Settings", "Apply", "Cancel", items, func(applied bool) {
Expand All @@ -42,6 +67,11 @@ func (u *UI) showSettingsDialog() {
u.app.Preferences().SetInt(settingRecentFileCount, x)
u.app.Preferences().SetBool(settingExtensionFilter, extFilter.Checked)
u.app.Preferences().SetBool(settingNotifyUpdates, notifyUpdates.Checked)
newTheme := themeChoice.Selected
if newTheme != initialTheme {
u.app.Preferences().SetString(settingTheme, newTheme)
u.setTheme(themeChoice.Selected)
}
}, u.window)
d.Show()
}
Expand Down
16 changes: 13 additions & 3 deletions internal/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ func NewUI(app fyne.App) (*UI, error) {
welcomeText := widget.NewLabel(
"Welcome to " + appName + ".\n" +
"Open a JSON file through the File Open menu\n" +
"or drag and drop the file on this window" +
"or import it from clipboard.\n",
"or drag and drop the file on this window\n" +
"or import from the clipboard.\n",
)
welcomeText.Importance = widget.LowImportance
welcomeText.Importance = widget.MediumImportance
welcomeText.Alignment = fyne.TextAlignCenter
u.welcomeMessage = container.NewCenter(welcomeText)

Expand Down Expand Up @@ -105,6 +105,7 @@ func NewUI(app fyne.App) (*UI, error) {
Height: float32(app.Preferences().FloatWithFallback(preferenceLastWindowHeight, 600)),
}
u.window.Resize(s)
u.setTheme(app.Preferences().StringWithFallback(settingTheme, settingThemeDefault))
u.window.SetOnClosed(func() {
app.Preferences().SetFloat(preferenceLastWindowWidth, float64(u.window.Canvas().Size().Width))
app.Preferences().SetFloat(preferenceLastWindowHeight, float64(u.window.Canvas().Size().Height))
Expand Down Expand Up @@ -243,6 +244,15 @@ func (u *UI) setTitle(fileName string) {
u.window.SetTitle(s)
}

func (u *UI) setTheme(themeName string) {
switch themeName {
case themeDark:
u.app.Settings().SetTheme(theme.DarkTheme())
case themeLight:
u.app.Settings().SetTheme(theme.LightTheme())
}
}

// loadDocument loads a JSON file
// Shows a loader modal while loading
func (u *UI) loadDocument(reader fyne.URIReadCloser) {
Expand Down
2 changes: 1 addition & 1 deletion io.github.erikkalkoken.janice.appdata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<launchable type="desktop-id">io.github.erikkalkoken.janice.desktop</launchable>
<screenshots>
<screenshot type="default">
<image>https://cdn.imgpile.com/f/bdQBc3q_xl.png</image>
<image>https://cdn.imgpile.com/f/0IrYBjJ_xl.png</image>
</screenshot>
</screenshots>

Expand Down

0 comments on commit 41bf3be

Please sign in to comment.