Skip to content

Commit

Permalink
feat: add auto-theme switch
Browse files Browse the repository at this point in the history
  • Loading branch information
mishamyrt committed Jan 6, 2024
1 parent 7993841 commit f632f75
Show file tree
Hide file tree
Showing 19 changed files with 143 additions and 148 deletions.
10 changes: 8 additions & 2 deletions frontend/src/app/App.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { SidebarLayout, ThemeProvider } from '@naco-ui/svelte'
import { isDark, SidebarLayout, ThemeProvider } from '@naco-ui/svelte'
import { FeatureSlicedDebug } from 'feature-sliced-svelte'
import { appSettingsStore } from '$entities/app'
Expand All @@ -13,13 +13,19 @@
import Toolbar from './ui/Toolbar.svelte'
$: props = pages[$activePage].layoutProps ?? {}
$: theme = $appSettingsStore.theme
$: scheme = theme === 'auto'
? $isDark
? 'dark'
: 'light'
: theme
const sidebarWidth = 200
</script>

<FeatureSlicedDebug />
<ThemeProvider
os={$appSettingsStore.ui}
scheme={$appSettingsStore.theme}>
{scheme}>
<SidebarLayout {sidebarWidth} macInset={{
show: true
}} toolbar={{
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/entities/app/model/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { ColorScheme, OS } from '@naco-ui/svelte'

export type AppTheme = ColorScheme | 'auto'

export interface AppSettings {
ui: OS
theme: ColorScheme
theme: AppTheme
}
4 changes: 2 additions & 2 deletions frontend/src/features/app/change-settings/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import AppDarkThemeToggle from './ui/AppDarkThemeToggle.svelte'
import AppThemeSelect from './ui/AppThemeSelect.svelte'
import AppUISwitchSegment from './ui/AppUISwitchSegment.svelte'

export {
AppDarkThemeToggle,
AppThemeSelect,
AppUISwitchSegment
}

This file was deleted.

28 changes: 28 additions & 0 deletions frontend/src/features/app/change-settings/ui/AppThemeSelect.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<script lang="ts">
import { Select, type SelectOption } from '@naco-ui/svelte'
import { fsd } from 'feature-sliced-svelte'
import { appSettingsChanged, appSettingsStore, type AppTheme } from '$entities/app'
const themeOptions: SelectOption[] = [
{ title: 'Auto', value: 'auto' },
{ title: 'Light', value: 'light' },
{ title: 'Dark', value: 'dark' }
]
function handleChange (e: CustomEvent<string>) {
appSettingsChanged({
ui: $appSettingsStore.ui,
theme: e.detail as AppTheme
})
}
</script>

<div use:fsd={'features/AppDarkThemeToggle'}>
<Select
options={themeOptions}
value={$appSettingsStore.theme}
on:change={handleChange}
/>
</div>
4 changes: 2 additions & 2 deletions frontend/src/widgets/app/ui/AppDebugModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { Button, FormGroup, FormRow, getTheme, Modal, ModalActions, onHotkey, Stack, Typography } from '@naco-ui/svelte'
import { fsd } from 'feature-sliced-svelte'
import { AppDarkThemeToggle, AppUISwitchSegment, LoggingSwitch, RestartButton } from '$features/app'
import { AppThemeSelect, AppUISwitchSegment, LoggingSwitch, RestartButton } from '$features/app'
import { disconnected } from '$shared/model'
const { os } = getTheme()
Expand Down Expand Up @@ -36,7 +36,7 @@
</Stack>
</FormRow>
<FormRow title="Dark theme">
<AppDarkThemeToggle />
<AppThemeSelect />
</FormRow>
<FormRow
title="Reset connection"
Expand Down
10 changes: 5 additions & 5 deletions internal/application/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package application

import (
"nuga_ui/config"
"nuga_ui/internal/entity"
"nuga_ui/internal/dto"

"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
"github.com/wailsapp/wails/v2/pkg/options/mac"
)

// GetState builds UIState from settings
func (a *Application) getState() (entity.AppTheme, bool) {
func (a *Application) getState() (dto.AppTheme, bool) {
config := a.repo.Settings.GetApp()
currentOS := a.repo.Environment.GetOS()
universal := currentOS != string(config.UI)
Expand All @@ -26,11 +26,11 @@ func (a *Application) GetOptions() *options.App {
}
var macAppearance mac.AppearanceType
switch theme {
case entity.LightUITheme:
case dto.LightUITheme:
macAppearance = mac.NSAppearanceNameVibrantLight
case entity.DarkUITheme:
case dto.DarkUITheme:
macAppearance = mac.NSAppearanceNameDarkAqua
case entity.AutoUITheme:
case dto.AutoUITheme:
default:
macAppearance = mac.DefaultAppearance
}
Expand Down
40 changes: 0 additions & 40 deletions internal/dto/environment.go

This file was deleted.

1 change: 1 addition & 0 deletions internal/dto/files.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package dto contains Nuga.app data transfer objects
package dto

import "github.com/wailsapp/wails/v2/pkg/runtime"
Expand Down
44 changes: 34 additions & 10 deletions internal/entity/config.go → internal/dto/settings.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Package entity contains app entities
package entity
package dto

import "runtime"

// OS represents operating system value
type OS string
Expand All @@ -13,6 +14,17 @@ const (
Linux OS = "linux"
)

// CurrentOS returns... current OS
func CurrentOS() OS {
switch runtime.GOOS {
case "darwin":
return MacOS
case "windows":
return Windows
}
return Linux
}

// OSMode represents keyboard OS mode value
type OSMode string

Expand All @@ -35,20 +47,32 @@ const (
AutoUITheme AppTheme = "auto"
)

// AppConfig represents the configuration for the user interface settings.
type AppConfig struct {
// AppThemeFromString creates AppTheme instance from string
func AppThemeFromString(s string) AppTheme {
switch s {
case "light":
return LightUITheme
case "dark":
return DarkUITheme
default:
return AutoUITheme
}
}

// AppSettings represents the configuration for the user interface settings.
type AppSettings struct {
UI OS `json:"ui"`
Theme AppTheme `json:"theme"`
}

// ModeConfig represents the configuration for the application mode settings.
type ModeConfig struct {
// ModeSettings represents the configuration for the application mode settings.
type ModeSettings struct {
OSMode OSMode `json:"osMode"`
IndividualSettings bool `json:"individual"`
}

// Config represents the overall configuration for the application.
type Config struct {
Mode ModeConfig `json:"mode"`
App AppConfig `json:"app"`
// Settings represents the overall configuration for the application.
type Settings struct {
Mode ModeSettings `json:"mode"`
App AppSettings `json:"app"`
}
9 changes: 4 additions & 5 deletions internal/interfaces/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package interfaces

import (
"nuga_ui/internal/dto"
"nuga_ui/internal/entity"

"github.com/mishamyrt/nuga-lib"
)
Expand All @@ -27,10 +26,10 @@ type DeviceRepository interface {

// SettingsRepository defines the interface for managing application settings.
type SettingsRepository interface {
GetMode() *entity.ModeConfig
SetMode(m entity.ModeConfig) error
GetApp() *entity.AppConfig
SetApp(ui entity.AppConfig) error
GetMode() *dto.ModeSettings
SetMode(m dto.ModeSettings) error
GetApp() *dto.AppSettings
SetApp(ui dto.AppSettings) error
}

// EnvironmentRepository defines the interface for retrieving environment-related information.
Expand Down
9 changes: 4 additions & 5 deletions internal/interfaces/usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package interfaces
import (
"context"
"nuga_ui/internal/dto"
"nuga_ui/internal/entity"

"github.com/mishamyrt/nuga-lib/light"
)
Expand Down Expand Up @@ -51,10 +50,10 @@ type EnvironmentUsecase interface {
// SettingsUsecase defines the interface for managing application settings use cases.
type SettingsUsecase interface {
BasicUsecase
GetModeSettings() entity.ModeConfig
SetModeSettings(m entity.ModeConfig) error
GetAppSettings() entity.AppConfig
SetAppSettings(ui entity.AppConfig) error
GetModeSettings() dto.ModeSettings
SetModeSettings(m dto.ModeSettings) error
GetAppSettings() dto.AppSettings
SetAppSettings(ui dto.AppSettings) error
}

// LightsUsecase defines the interface for lighting-related use cases.
Expand Down
4 changes: 2 additions & 2 deletions internal/repository/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package environment

import (
"nuga_ui/config"
"nuga_ui/internal/entity"
"nuga_ui/internal/dto"
"runtime"
)

Expand All @@ -20,7 +20,7 @@ func New() *Repository {
func (r *Repository) GetOS() string {
os := runtime.GOOS
if os == "darwin" {
return string(entity.MacOS)
return string(dto.MacOS)
}
return os
}
Expand Down
4 changes: 2 additions & 2 deletions internal/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
)

// New creates new repository instance
func New(filePath string) (*interfaces.Repository, error) {
settings, err := settings.New(filePath)
func New(directory string) (*interfaces.Repository, error) {
settings, err := settings.NewAtDirectory(directory)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit f632f75

Please sign in to comment.