Skip to content

Commit

Permalink
Merge pull request #78 from Beebeeoii/refactor-constants
Browse files Browse the repository at this point in the history
refactor: moved lominus.go into internal constants
  • Loading branch information
Jia Wei Lee authored Aug 14, 2022
2 parents fc4a146 + c7d8802 commit 1018353
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 51 deletions.
4 changes: 2 additions & 2 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (

appDir "github.com/beebeeoii/lominus/internal/app/dir"
appPref "github.com/beebeeoii/lominus/internal/app/pref"
appConstants "github.com/beebeeoii/lominus/internal/constants"
"github.com/beebeeoii/lominus/internal/file"
logs "github.com/beebeeoii/lominus/internal/log"
"github.com/beebeeoii/lominus/internal/lominus"
)

// Init initialises and ensures log and preference files that Lominus requires are available.
Expand Down Expand Up @@ -65,7 +65,7 @@ func Init() error {
}

// TODO Consider moving this to its own module in the future.
gradesPath := filepath.Join(baseDir, lominus.GRADES_FILE_NAME)
gradesPath := filepath.Join(baseDir, appConstants.GRADES_FILE_NAME)

if !file.Exists(gradesPath) {
gradeFileErr := file.EncodeStructToFile(gradesPath, time.Now())
Expand Down
6 changes: 3 additions & 3 deletions internal/app/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"path/filepath"

appDir "github.com/beebeeoii/lominus/internal/app/dir"
"github.com/beebeeoii/lominus/internal/lominus"
appConstants "github.com/beebeeoii/lominus/internal/constants"
)

// GetJwtPath returns the file path to user's JWT data.
Expand All @@ -17,7 +17,7 @@ func GetTokensPath() (string, error) {
return jwtPath, retrieveBaseDirErr
}

jwtPath = filepath.Join(baseDir, lominus.TOKENS_FILE_NAME)
jwtPath = filepath.Join(baseDir, appConstants.TOKENS_FILE_NAME)

return jwtPath, nil
}
Expand All @@ -31,7 +31,7 @@ func GetCredentialsPath() (string, error) {
return credentialsPath, retrieveBaseDirErr
}

credentialsPath = filepath.Join(baseDir, lominus.CREDENTIALS_FILE_NAME)
credentialsPath = filepath.Join(baseDir, appConstants.CREDENTIALS_FILE_NAME)

return credentialsPath, nil
}
4 changes: 2 additions & 2 deletions internal/app/dir/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"path/filepath"

"github.com/beebeeoii/lominus/internal/lominus"
appConstants "github.com/beebeeoii/lominus/internal/constants"
)

// GetBaseDir returns the directory where config files for Lominus will be stored in.
Expand All @@ -23,7 +23,7 @@ func GetBaseDir() (string, error) {
return baseDir, err
}

baseDir = filepath.Join(userConfigDir, lominus.APP_NAME)
baseDir = filepath.Join(userConfigDir, appConstants.APP_NAME)

return baseDir, nil
}
4 changes: 2 additions & 2 deletions internal/app/integrations/telegram/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"path/filepath"

appDir "github.com/beebeeoii/lominus/internal/app/dir"
"github.com/beebeeoii/lominus/internal/lominus"
appConstants "github.com/beebeeoii/lominus/internal/constants"
)

// GetTelegramInfoPath returns the file path to user's telegram config file.
Expand All @@ -17,7 +17,7 @@ func GetTelegramInfoPath() (string, error) {
return telegramInfoPath, retrieveBaseDirErr
}

telegramInfoPath = filepath.Join(baseDir, lominus.TELEGRAM_FILE_NAME)
telegramInfoPath = filepath.Join(baseDir, appConstants.TELEGRAM_FILE_NAME)

return telegramInfoPath, nil
}
4 changes: 2 additions & 2 deletions internal/app/lock/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"path/filepath"

appDir "github.com/beebeeoii/lominus/internal/app/dir"
"github.com/beebeeoii/lominus/internal/lominus"
appConstants "github.com/beebeeoii/lominus/internal/constants"
)

// GetLockPath returns the file path to Lominus lock file.
Expand All @@ -17,7 +17,7 @@ func GetLockPath() (string, error) {
return lockPath, retrieveBaseDirErr
}

lockPath = filepath.Join(baseDir, lominus.LOCK_FILE_NAME)
lockPath = filepath.Join(baseDir, appConstants.LOCK_FILE_NAME)

return lockPath, nil
}
6 changes: 3 additions & 3 deletions internal/app/pref/pref.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"path/filepath"

appDir "github.com/beebeeoii/lominus/internal/app/dir"
appConstants "github.com/beebeeoii/lominus/internal/constants"
"github.com/beebeeoii/lominus/internal/file"
"github.com/beebeeoii/lominus/internal/lominus"
)

const PREFERENCES_FILE_NAME = lominus.PREFERENCES_FILE_NAME
const PREFERENCES_FILE_NAME = appConstants.PREFERENCES_FILE_NAME

// Preferences struct describes the data being stored in the user's preferences file.
type Preferences struct {
Expand All @@ -27,7 +27,7 @@ func GetPreferencesPath() (string, error) {
return preferencesPath, retrieveBaseDirErr
}

preferencesPath = filepath.Join(baseDir, lominus.PREFERENCES_FILE_NAME)
preferencesPath = filepath.Join(baseDir, appConstants.PREFERENCES_FILE_NAME)

return preferencesPath, nil
}
Expand Down
5 changes: 3 additions & 2 deletions internal/lominus/lominus.go → internal/constants/lominus.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Package lominus provides app config constants.
package lominus
// Package constants provide constants to be used internally within Lominus (not exported as API)
// such as UI constants.
package constants

const APP_NAME = "Lominus"
const APP_ID = "com.lominus.beebeeoii"
Expand Down
6 changes: 3 additions & 3 deletions internal/cron/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
appDir "github.com/beebeeoii/lominus/internal/app/dir"
intTelegram "github.com/beebeeoii/lominus/internal/app/integrations/telegram"
appPref "github.com/beebeeoii/lominus/internal/app/pref"
appConstants "github.com/beebeeoii/lominus/internal/constants"
appFiles "github.com/beebeeoii/lominus/internal/file"
"github.com/beebeeoii/lominus/internal/indexing"
logs "github.com/beebeeoii/lominus/internal/log"
"github.com/beebeeoii/lominus/internal/lominus"
"github.com/beebeeoii/lominus/internal/notifications"
"github.com/beebeeoii/lominus/pkg/api"
"github.com/beebeeoii/lominus/pkg/auth"
Expand Down Expand Up @@ -319,7 +319,7 @@ func getGrades(modules []api.Module) ([]api.Grade, error) {
var lastSync time.Time
baseDir, _ := appDir.GetBaseDir()

existingGradeErr := appFiles.DecodeStructFromFile(filepath.Join(baseDir, lominus.GRADES_FILE_NAME), &lastSync)
existingGradeErr := appFiles.DecodeStructFromFile(filepath.Join(baseDir, appConstants.GRADES_FILE_NAME), &lastSync)
if existingGradeErr != nil {
return grades, existingGradeErr
}
Expand All @@ -342,7 +342,7 @@ func getGrades(modules []api.Module) ([]api.Grade, error) {
grades = append(grades, allGrades...)
}

err := appFiles.EncodeStructToFile(filepath.Join(baseDir, lominus.GRADES_FILE_NAME), time.Now())
err := appFiles.EncodeStructToFile(filepath.Join(baseDir, appConstants.GRADES_FILE_NAME), time.Now())
if err != nil {
return []api.Grade{}, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/log/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

appDir "github.com/beebeeoii/lominus/internal/app/dir"
appPref "github.com/beebeeoii/lominus/internal/app/pref"
"github.com/beebeeoii/lominus/internal/lominus"
appConstants "github.com/beebeeoii/lominus/internal/constants"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -91,7 +91,7 @@ func getLogPath() (string, error) {
return logPath, retrieveBaseDirErr
}

logPath = filepath.Join(baseDir, lominus.LOG_FILE_NAME)
logPath = filepath.Join(baseDir, appConstants.LOG_FILE_NAME)

return logPath, nil
}
Expand Down
13 changes: 6 additions & 7 deletions internal/ui/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
appConstants "github.com/beebeeoii/lominus/internal/constants"
"github.com/beebeeoii/lominus/internal/file"
logs "github.com/beebeeoii/lominus/internal/log"
"github.com/beebeeoii/lominus/internal/lominus"
"github.com/beebeeoii/lominus/pkg/auth"
)

Expand Down Expand Up @@ -98,7 +97,7 @@ func getLuminusView(
progressBar := widget.NewProgressBarInfinite()

mainDialog := dialog.NewCustom(
lominus.APP_NAME,
appConstants.APP_NAME,
appConstants.CANCEL_TEXT,
container.NewVBox(status, progressBar),
parentWindow,
Expand All @@ -111,15 +110,15 @@ func getLuminusView(
if err != nil {
logs.Logger.Debugln("verfication failed")
dialog.NewInformation(
lominus.APP_NAME,
appConstants.APP_NAME,
appConstants.VERIFICATION_FAILED_MESSAGE,
parentWindow,
).Show()
} else {
logs.Logger.Debugln("verfication succesful - saving credentials")
luminusCredentials.Save(credentialsPath)
dialog.NewInformation(
lominus.APP_NAME,
appConstants.APP_NAME,
appConstants.VERIFICATION_SUCCESSFUL_MESSAGE,
parentWindow,
).Show()
Expand Down Expand Up @@ -171,7 +170,7 @@ func getCanvasView(
progressBar := widget.NewProgressBarInfinite()

mainDialog := dialog.NewCustom(
lominus.APP_NAME,
appConstants.APP_NAME,
appConstants.CANCEL_TEXT,
container.NewVBox(status, progressBar),
parentWindow,
Expand All @@ -184,7 +183,7 @@ func getCanvasView(
if err != nil {
logs.Logger.Debugln("verfication failed")
dialog.NewInformation(
lominus.APP_NAME,
appConstants.APP_NAME,
appConstants.VERIFICATION_FAILED_MESSAGE,
parentWindow,
).Show()
Expand All @@ -193,7 +192,7 @@ func getCanvasView(
canvasCredentials.Save(credentialsPath)
canvasTokens.Save(tokensPath)
dialog.NewInformation(
lominus.APP_NAME,
appConstants.APP_NAME,
appConstants.VERIFICATION_SUCCESSFUL_MESSAGE,
parentWindow,
).Show()
Expand Down
7 changes: 3 additions & 4 deletions internal/ui/integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
intTelegram "github.com/beebeeoii/lominus/internal/app/integrations/telegram"
"github.com/beebeeoii/lominus/internal/file"
logs "github.com/beebeeoii/lominus/internal/log"
"github.com/beebeeoii/lominus/internal/lominus"
"github.com/beebeeoii/lominus/pkg/integrations/telegram"

appConstants "github.com/beebeeoii/lominus/internal/constants"
Expand Down Expand Up @@ -64,7 +63,7 @@ func getIntegrationsTab(parentWindow fyne.Window) (*container.TabItem, error) {
progressBar := widget.NewProgressBarInfinite()

mainDialog := dialog.NewCustom(
lominus.APP_NAME,
appConstants.APP_NAME,
appConstants.CANCEL_TEXT,
container.NewVBox(status, progressBar),
parentWindow,
Expand All @@ -82,7 +81,7 @@ func getIntegrationsTab(parentWindow fyne.Window) (*container.TabItem, error) {
)
logs.Logger.Errorln(errMessage)
dialog.NewInformation(
lominus.APP_NAME,
appConstants.APP_NAME,
appConstants.TELEGRAM_TESTING_FAILED_MESSAGE,
parentWindow,
).Show()
Expand All @@ -93,7 +92,7 @@ func getIntegrationsTab(parentWindow fyne.Window) (*container.TabItem, error) {
)
logs.Logger.Debugln("telegram test message sent successfully")
dialog.NewInformation(
lominus.APP_NAME,
appConstants.APP_NAME,
appConstants.TELEGRAM_TESTING_SUCCESSFUL_MESSAGE,
parentWindow,
).Show()
Expand Down
19 changes: 9 additions & 10 deletions internal/ui/preferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget"
"github.com/beebeeoii/lominus/internal/lominus"

appDir "github.com/beebeeoii/lominus/internal/app/dir"
appPref "github.com/beebeeoii/lominus/internal/app/pref"
Expand Down Expand Up @@ -79,7 +78,7 @@ func getFileDirectoryView(parentWindow fyne.Window) (fyne.CanvasObject, error) {
if dirErr.Error() != "Cancelled" {
logs.Logger.Debugln("directory selection cancelled")
dialog.NewInformation(
lominus.APP_NAME,
appConstants.APP_NAME,
appConstants.PREFERENCES_FAILED_MESSAGE,
parentWindow,
).Show()
Expand All @@ -95,7 +94,7 @@ func getFileDirectoryView(parentWindow fyne.Window) (fyne.CanvasObject, error) {
preferencesPath, getPreferencesPathErr := appPref.GetPreferencesPath()
if getPreferencesPathErr != nil {
dialog.NewInformation(
lominus.APP_NAME,
appConstants.APP_NAME,
appConstants.PREFERENCES_FAILED_MESSAGE,
parentWindow,
).Show()
Expand All @@ -106,7 +105,7 @@ func getFileDirectoryView(parentWindow fyne.Window) (fyne.CanvasObject, error) {
savePrefErr := appPref.SavePreferences(preferencesPath, preferences)
if savePrefErr != nil {
dialog.NewInformation(
lominus.APP_NAME,
appConstants.APP_NAME,
appConstants.PREFERENCES_FAILED_MESSAGE,
parentWindow,
).Show()
Expand Down Expand Up @@ -164,7 +163,7 @@ func getSyncView(parentWindow fyne.Window) (fyne.CanvasObject, error) {
preferencesPath, getPreferencesPathErr := appPref.GetPreferencesPath()
if getPreferencesPathErr != nil {
dialog.NewInformation(
lominus.APP_NAME,
appConstants.APP_NAME,
appConstants.PREFERENCES_FAILED_MESSAGE,
parentWindow,
).Show()
Expand All @@ -175,7 +174,7 @@ func getSyncView(parentWindow fyne.Window) (fyne.CanvasObject, error) {
savePrefErr := appPref.SavePreferences(preferencesPath, preferences)
if savePrefErr != nil {
dialog.NewInformation(
lominus.APP_NAME,
appConstants.APP_NAME,
appConstants.PREFERENCES_FAILED_MESSAGE,
parentWindow,
).Show()
Expand Down Expand Up @@ -212,7 +211,7 @@ func getAdvancedView(parentWindow fyne.Window) (fyne.CanvasObject, error) {
fmt.Sprintf(
appConstants.DEBUG_CHECKBOX_W_LINK_DESCRIPTION,
filepath.FromSlash(
fmt.Sprintf("file://%s", filepath.Join(baseDir, lominus.LOG_FILE_NAME)),
fmt.Sprintf("file://%s", filepath.Join(baseDir, appConstants.LOG_FILE_NAME)),
),
),
)
Expand All @@ -225,7 +224,7 @@ func getAdvancedView(parentWindow fyne.Window) (fyne.CanvasObject, error) {
preferencesPath, getPreferencesPathErr := appPref.GetPreferencesPath()
if getPreferencesPathErr != nil {
dialog.NewInformation(
lominus.APP_NAME,
appConstants.APP_NAME,
appConstants.PREFERENCES_FAILED_MESSAGE,
parentWindow,
).Show()
Expand All @@ -245,7 +244,7 @@ func getAdvancedView(parentWindow fyne.Window) (fyne.CanvasObject, error) {
savePrefErr := appPref.SavePreferences(preferencesPath, preferences)
if savePrefErr != nil {
dialog.NewInformation(
lominus.APP_NAME,
appConstants.APP_NAME,
appConstants.PREFERENCES_FAILED_MESSAGE,
parentWindow,
).Show()
Expand All @@ -254,7 +253,7 @@ func getAdvancedView(parentWindow fyne.Window) (fyne.CanvasObject, error) {
}

dialog.NewInformation(
lominus.APP_NAME,
appConstants.APP_NAME,
appConstants.DEBUG_TOGGLE_SUCCESSFUL_MESSAGE,
parentWindow,
).Show()
Expand Down
4 changes: 2 additions & 2 deletions internal/ui/systray.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package ui

import (
"fyne.io/fyne/v2"
appConstants "github.com/beebeeoii/lominus/internal/constants"
"github.com/beebeeoii/lominus/internal/cron"
"github.com/beebeeoii/lominus/internal/lominus"
"github.com/beebeeoii/lominus/internal/notifications"
)

// BuildSystemTray creates the system tray icon and its menu options, used to be initialised
// when Lominus starts.
func BuildSystemTray() *fyne.Menu {
return fyne.NewMenu(lominus.APP_NAME,
return fyne.NewMenu(appConstants.APP_NAME,
fyne.NewMenuItem("Sync Now", func() {
preferences := getPreferences()
if preferences.Directory == "" {
Expand Down
Loading

0 comments on commit 1018353

Please sign in to comment.