Show version info in settings

This commit is contained in:
Ken-Håvard Lieng 2018-11-22 12:00:18 +01:00
parent 5d896ae439
commit fbbcf6457e
8 changed files with 275 additions and 174 deletions

File diff suppressed because one or more lines are too long

View File

@ -812,6 +812,11 @@ input.message-input-nick.invalid {
text-align: center;
}
.settings-version {
color: #999;
font-size: 12px;
}
.suspense-fallback {
display: flex;
align-items: center;

View File

@ -7,6 +7,7 @@ import FileInput from 'components/ui/FileInput';
const Settings = ({
settings,
installable,
version,
setSetting,
onCertChange,
onKeyChange,
@ -71,6 +72,13 @@ const Settings = ({
{error ? <p className="error">{error}</p> : null}
</div>
</div>
{version && (
<div className="settings-version">
<p>{version.tag}</p>
<p>Commit: {version.commit}</p>
<p>Build Date: {version.date}</p>
</div>
)}
</div>
</div>
);

View File

@ -12,7 +12,8 @@ import connect from 'utils/connect';
const mapState = createStructuredSelector({
settings: getSettings,
installable: state => state.app.installable
installable: state => state.app.installable,
version: state => state.app.version
});
const mapDispatch = {

View File

@ -11,7 +11,12 @@ import { replace } from 'utils/router';
function loadState({ store }, env) {
store.dispatch(setConnectDefaults(env.defaults));
store.dispatch(appSet('hexIP', env.hexIP));
store.dispatch(
appSet({
hexIP: env.hexIP,
version: env.version
})
);
store.dispatch(setSettings(env.settings, true));
if (env.servers) {

View File

@ -1,3 +1,4 @@
import assign from 'lodash/assign';
import createReducer from 'utils/createReducer';
import * as actions from './actions';
@ -29,7 +30,11 @@ const initialState = {
export default createReducer(initialState, {
[actions.APP_SET](state, { key, value }) {
if (typeof key === 'object') {
assign(state, key);
} else {
state[key] = value;
}
},
[actions.UPDATE_MESSAGE_HEIGHT](state, action) {

View File

@ -6,6 +6,7 @@ import (
"strings"
"github.com/khlieng/dispatch/storage"
"github.com/khlieng/dispatch/version"
"github.com/spf13/viper"
)
@ -20,11 +21,18 @@ type connectDefaults struct {
ShowDetails bool
}
type dispatchVersion struct {
Tag string
Commit string
Date string
}
type indexData struct {
Defaults connectDefaults
Servers []Server
Channels []*storage.Channel
HexIP bool
Version dispatchVersion
Settings *storage.ClientSettings
@ -38,6 +46,11 @@ type indexData struct {
func getIndexData(r *http.Request, path string, state *State) *indexData {
data := indexData{
HexIP: viper.GetBool("hexIP"),
Version: dispatchVersion{
Tag: version.Tag,
Commit: version.Commit,
Date: version.Date,
},
}
data.Defaults = connectDefaults{

View File

@ -99,6 +99,10 @@ func easyjson7e607aefDecodeGithubComKhliengDispatchServer(in *jlexer.Lexer, out
}
case "hexIP":
out.HexIP = bool(in.Bool())
case "version":
if data := in.Raw(); in.Ok() {
in.AddError((out.Version).UnmarshalJSON(data))
}
case "settings":
if in.IsNull() {
in.Skip()
@ -107,7 +111,9 @@ func easyjson7e607aefDecodeGithubComKhliengDispatchServer(in *jlexer.Lexer, out
if out.Settings == nil {
out.Settings = new(storage.ClientSettings)
}
easyjson7e607aefDecodeGithubComKhliengDispatchStorage1(in, &*out.Settings)
if data := in.Raw(); in.Ok() {
in.AddError((*out.Settings).UnmarshalJSON(data))
}
}
case "users":
if in.IsNull() {
@ -209,6 +215,16 @@ func easyjson7e607aefEncodeGithubComKhliengDispatchServer(out *jwriter.Writer, i
}
out.Bool(bool(in.HexIP))
}
if true {
const prefix string = ",\"version\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.Raw((in.Version).MarshalJSON())
}
if in.Settings != nil {
const prefix string = ",\"settings\":"
if first {
@ -217,7 +233,7 @@ func easyjson7e607aefEncodeGithubComKhliengDispatchServer(out *jwriter.Writer, i
} else {
out.RawString(prefix)
}
easyjson7e607aefEncodeGithubComKhliengDispatchStorage1(out, *in.Settings)
out.Raw((*in.Settings).MarshalJSON())
}
if in.Users != nil {
const prefix string = ",\"users\":"
@ -265,53 +281,6 @@ func (v *indexData) UnmarshalJSON(data []byte) error {
func (v *indexData) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson7e607aefDecodeGithubComKhliengDispatchServer(l, v)
}
func easyjson7e607aefDecodeGithubComKhliengDispatchStorage1(in *jlexer.Lexer, out *storage.ClientSettings) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeString()
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "coloredNicks":
out.ColoredNicks = bool(in.Bool())
default:
in.SkipRecursive()
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
func easyjson7e607aefEncodeGithubComKhliengDispatchStorage1(out *jwriter.Writer, in storage.ClientSettings) {
out.RawByte('{')
first := true
_ = first
if in.ColoredNicks {
const prefix string = ",\"coloredNicks\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.Bool(bool(in.ColoredNicks))
}
out.RawByte('}')
}
func easyjson7e607aefDecodeGithubComKhliengDispatchStorage(in *jlexer.Lexer, out *storage.Channel) {
isTopLevel := in.IsStart()
if in.IsNull() {
@ -383,7 +352,102 @@ func easyjson7e607aefEncodeGithubComKhliengDispatchStorage(out *jwriter.Writer,
}
out.RawByte('}')
}
func easyjson7e607aefDecodeGithubComKhliengDispatchServer1(in *jlexer.Lexer, out *connectDefaults) {
func easyjson7e607aefDecodeGithubComKhliengDispatchServer1(in *jlexer.Lexer, out *dispatchVersion) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
in.Consumed()
}
in.Skip()
return
}
in.Delim('{')
for !in.IsDelim('}') {
key := in.UnsafeString()
in.WantColon()
if in.IsNull() {
in.Skip()
in.WantComma()
continue
}
switch key {
case "tag":
out.Tag = string(in.String())
case "commit":
out.Commit = string(in.String())
case "date":
out.Date = string(in.String())
default:
in.SkipRecursive()
}
in.WantComma()
}
in.Delim('}')
if isTopLevel {
in.Consumed()
}
}
func easyjson7e607aefEncodeGithubComKhliengDispatchServer1(out *jwriter.Writer, in dispatchVersion) {
out.RawByte('{')
first := true
_ = first
if in.Tag != "" {
const prefix string = ",\"tag\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Tag))
}
if in.Commit != "" {
const prefix string = ",\"commit\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Commit))
}
if in.Date != "" {
const prefix string = ",\"date\":"
if first {
first = false
out.RawString(prefix[1:])
} else {
out.RawString(prefix)
}
out.String(string(in.Date))
}
out.RawByte('}')
}
// MarshalJSON supports json.Marshaler interface
func (v dispatchVersion) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjson7e607aefEncodeGithubComKhliengDispatchServer1(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v dispatchVersion) MarshalEasyJSON(w *jwriter.Writer) {
easyjson7e607aefEncodeGithubComKhliengDispatchServer1(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *dispatchVersion) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjson7e607aefDecodeGithubComKhliengDispatchServer1(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *dispatchVersion) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson7e607aefDecodeGithubComKhliengDispatchServer1(l, v)
}
func easyjson7e607aefDecodeGithubComKhliengDispatchServer2(in *jlexer.Lexer, out *connectDefaults) {
isTopLevel := in.IsStart()
if in.IsNull() {
if isTopLevel {
@ -449,7 +513,7 @@ func easyjson7e607aefDecodeGithubComKhliengDispatchServer1(in *jlexer.Lexer, out
in.Consumed()
}
}
func easyjson7e607aefEncodeGithubComKhliengDispatchServer1(out *jwriter.Writer, in connectDefaults) {
func easyjson7e607aefEncodeGithubComKhliengDispatchServer2(out *jwriter.Writer, in connectDefaults) {
out.RawByte('{')
first := true
_ = first
@ -548,23 +612,23 @@ func easyjson7e607aefEncodeGithubComKhliengDispatchServer1(out *jwriter.Writer,
// MarshalJSON supports json.Marshaler interface
func (v connectDefaults) MarshalJSON() ([]byte, error) {
w := jwriter.Writer{}
easyjson7e607aefEncodeGithubComKhliengDispatchServer1(&w, v)
easyjson7e607aefEncodeGithubComKhliengDispatchServer2(&w, v)
return w.Buffer.BuildBytes(), w.Error
}
// MarshalEasyJSON supports easyjson.Marshaler interface
func (v connectDefaults) MarshalEasyJSON(w *jwriter.Writer) {
easyjson7e607aefEncodeGithubComKhliengDispatchServer1(w, v)
easyjson7e607aefEncodeGithubComKhliengDispatchServer2(w, v)
}
// UnmarshalJSON supports json.Unmarshaler interface
func (v *connectDefaults) UnmarshalJSON(data []byte) error {
r := jlexer.Lexer{Data: data}
easyjson7e607aefDecodeGithubComKhliengDispatchServer1(&r, v)
easyjson7e607aefDecodeGithubComKhliengDispatchServer2(&r, v)
return r.Error()
}
// UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (v *connectDefaults) UnmarshalEasyJSON(l *jlexer.Lexer) {
easyjson7e607aefDecodeGithubComKhliengDispatchServer1(l, v)
easyjson7e607aefDecodeGithubComKhliengDispatchServer2(l, v)
}