forked from tiny-craft/tiny-rdm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add preferencesStore to manager preferences
- Loading branch information
1 parent
16c0967
commit dd88c61
Showing
6 changed files
with
217 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package services | ||
|
||
import ( | ||
"sync" | ||
storage2 "tinyrdm/backend/storage" | ||
"tinyrdm/backend/types" | ||
) | ||
|
||
type preferencesService struct { | ||
pref *storage2.PreferencesStorage | ||
} | ||
|
||
var preferences *preferencesService | ||
var oncePreferences sync.Once | ||
|
||
func Preferences() *preferencesService { | ||
if preferences == nil { | ||
oncePreferences.Do(func() { | ||
preferences = &preferencesService{ | ||
pref: storage2.NewPreferences(), | ||
} | ||
}) | ||
} | ||
return preferences | ||
} | ||
|
||
func (p *preferencesService) GetPreferences() (resp types.JSResp) { | ||
resp.Data = p.pref.GetPreferences() | ||
resp.Success = true | ||
return | ||
} | ||
|
||
func (p *preferencesService) SetPreferences(values map[string]any) (resp types.JSResp) { | ||
err := p.pref.SetPreferencesN(values) | ||
if err != nil { | ||
resp.Msg = err.Error() | ||
return | ||
} | ||
|
||
resp.Success = true | ||
return | ||
} | ||
|
||
func (p *preferencesService) RestorePreferences() (resp types.JSResp) { | ||
defaultPref := p.pref.RestoreDefault() | ||
resp.Data = map[string]any{ | ||
"pref": defaultPref, | ||
} | ||
resp.Success = true | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.