-
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.
- Loading branch information
Showing
9 changed files
with
128 additions
and
5 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,33 @@ | ||
package app | ||
|
||
import ( | ||
"encoding/json" | ||
"path/filepath" | ||
|
||
"github.com/promignis/knack/constants" | ||
"github.com/promignis/knack/fs" | ||
"github.com/promignis/knack/utils" | ||
) | ||
|
||
type Manifest struct { | ||
AppName string | ||
} | ||
|
||
var manifest Manifest | ||
|
||
func parseManifest() Manifest { | ||
if manifest == (Manifest{}) { | ||
root := utils.GetRootPath() | ||
manifestData := fs.GetFileData(filepath.Join(root, constants.Manifest)) | ||
json.Unmarshal(manifestData, &manifest) | ||
} | ||
return manifest | ||
} | ||
|
||
func GetAppName() string { | ||
return parseManifest().AppName | ||
} | ||
|
||
func GetUserDataPath() string { | ||
return globalSettingFolder | ||
} |
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,6 @@ | ||
package app | ||
|
||
import "os" | ||
|
||
var systemSettingFolders = []string{os.Getenv("PROGRAMDATA")} | ||
var globalSettingFolder = os.Getenv("APPDATA") |
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,6 @@ | ||
package app | ||
|
||
import "os" | ||
|
||
var systemSettingFolders = []string{"/Library/Application Support"} | ||
var globalSettingFolder = os.Getenv("HOME") + "/Library/Application Support" |
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,27 @@ | ||
// +build !windows,!darwin | ||
|
||
package app | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html | ||
|
||
var systemSettingFolders []string | ||
var globalSettingFolder string | ||
|
||
func init() { | ||
if os.Getenv("XDG_CONFIG_HOME") != "" { | ||
globalSettingFolder = os.Getenv("XDG_CONFIG_HOME") | ||
} else { | ||
globalSettingFolder = filepath.Join(os.Getenv("HOME"), ".config") | ||
} | ||
if os.Getenv("XDG_CONFIG_DIRS") != "" { | ||
systemSettingFolders = strings.Split(os.Getenv("XDG_CONFIG_DIRS"), ":") | ||
} else { | ||
systemSettingFolders = []string{"/etc/xdg"} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"appName": "test-app" | ||
} |
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,42 @@ | ||
package persistance | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"sync" | ||
|
||
"github.com/promignis/knack/app" | ||
"github.com/promignis/knack/fs" | ||
) | ||
|
||
var lock sync.Mutex | ||
var userdataFilePath = filepath.Join(app.GetUserDataPath(), "/", app.GetAppName()) | ||
|
||
func init() { | ||
|
||
// In case the directory does not exist , create it before we start creating files inside it | ||
if _, err := os.Stat(userdataFilePath); os.IsNotExist(err) { | ||
err = os.MkdirAll(userdataFilePath, os.ModePerm) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} | ||
|
||
func Set(filename string, stringifiedJson string) { | ||
// Putting this here so that read and write on the same file can not happen. Can be clenaed up in future. | ||
lock.Lock() | ||
defer lock.Unlock() | ||
name := filename + ".json" | ||
path := filepath.Join(userdataFilePath, name) | ||
fs.WriteFileData(path, []byte(stringifiedJson)) | ||
} | ||
|
||
func Get(filename string) string { | ||
lock.Lock() | ||
defer lock.Unlock() | ||
name := filename + ".json" | ||
path := filepath.Join(userdataFilePath, name) | ||
stringifiedJson := fs.GetFileData(path) | ||
return string(stringifiedJson) | ||
} |
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,2 @@ | ||
go build -o output-dev.exe | ||
output-dev.exe |
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,2 @@ | ||
go build -ldflags="-H windowsgui" -o output.exe | ||
output.exe |