-
-
Notifications
You must be signed in to change notification settings - Fork 644
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/matryer/xbar into main
- Loading branch information
Showing
9 changed files
with
209 additions
and
48 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
type settings struct { | ||
path string `json:"-"` | ||
|
||
// AutoUpdate indicates that xbar should automatically | ||
// update itself. | ||
AutoUpdate bool `json:"autoupdate"` | ||
} | ||
|
||
func loadSettings(path string) (*settings, error) { | ||
s := &settings{ | ||
path: path, | ||
} | ||
b, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
// file not found - it's ok, just use defaults | ||
return s, nil | ||
} | ||
return nil, errors.Wrap(err, "ReadFile") | ||
} | ||
err = json.Unmarshal(b, s) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "Unmarshal") | ||
} | ||
return s, nil | ||
} | ||
|
||
func (s *settings) save() error { | ||
b, err := json.MarshalIndent(s, "", "\t") | ||
if err != nil { | ||
return errors.Wrap(err, "MarshalIndent") | ||
} | ||
err = os.MkdirAll(filepath.Dir(s.path), 0777) | ||
if err != nil { | ||
return errors.Wrap(err, "MkdirAll") | ||
} | ||
err = ioutil.WriteFile(s.path, b, 0777) | ||
if err != nil { | ||
return errors.Wrap(err, "WriteFile") | ||
} | ||
return nil | ||
} |
Oops, something went wrong.