Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

Commit

Permalink
README: Updated screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
diamondburned committed May 16, 2020
1 parent 45cce77 commit 59907e0
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 130 deletions.
Binary file removed .readme-resources/images/screenshot2.png
Binary file not shown.
Binary file removed .readme-resources/images/screenshot3.png
Binary file not shown.
Binary file added .readme-resources/images/screenshot6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<h1 align="center">gtkcord</h1>
<p align="center">A lightweight Discord client which uses GTK3 for the user interface.</p>

<img src=".readme-resources/images/screenshot5.png" />
<img src=".readme-resources/images/screenshot6.png" />

</p>

Expand Down
2 changes: 2 additions & 0 deletions gtkcord/components/channel/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/diamondburned/gtkcord3/gtkcord/gtkutils"
"github.com/diamondburned/gtkcord3/gtkcord/ningen"
"github.com/diamondburned/gtkcord3/gtkcord/semaphore"
"github.com/diamondburned/gtkcord3/gtkcord/variables"
"github.com/diamondburned/gtkcord3/internal/log"
"github.com/gotk3/gotk3/gtk"
"github.com/pkg/errors"
Expand Down Expand Up @@ -44,6 +45,7 @@ func NewChannels(state *ningen.State, onSelect func(ch *Channel)) (chs *Channels

cs, _ := gtk.ScrolledWindowNew(nil, nil)
cs.Show()
cs.SetSizeRequest(variables.ChannelWidth, -1)
cs.Add(main)

cl, _ := gtk.ListBoxNew()
Expand Down
2 changes: 2 additions & 0 deletions gtkcord/components/channel/privates.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/diamondburned/gtkcord3/gtkcord/gtkutils"
"github.com/diamondburned/gtkcord3/gtkcord/ningen"
"github.com/diamondburned/gtkcord3/gtkcord/semaphore"
"github.com/diamondburned/gtkcord3/gtkcord/variables"
"github.com/diamondburned/gtkcord3/internal/log"
"github.com/gotk3/gotk3/gtk"
)
Expand Down Expand Up @@ -38,6 +39,7 @@ func NewPrivateChannels(s *ningen.State, onSelect func(pm *PrivateChannel)) (pcs

cs, _ := gtk.ScrolledWindowNew(nil, nil)
cs.Show()
cs.SetSizeRequest(variables.ChannelWidth, -1)
cs.SetVExpand(true)
cs.Add(l)

Expand Down
104 changes: 17 additions & 87 deletions gtkcord/components/overview/members/members.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package members

import (
"sort"
"strings"

"github.com/diamondburned/arikawa/discord"
"github.com/diamondburned/arikawa/gateway"
"github.com/diamondburned/gtkcord3/gtkcord/components/popup"
"github.com/diamondburned/gtkcord3/gtkcord/gtkutils"
"github.com/diamondburned/gtkcord3/gtkcord/ningen"
"github.com/diamondburned/gtkcord3/gtkcord/semaphore"
"github.com/diamondburned/gtkcord3/internal/log"
"github.com/gotk3/gotk3/gtk"
"github.com/sasha-s/go-deadlock"
)

type Container struct {
Expand All @@ -20,11 +18,10 @@ type Container struct {

GuildID discord.Snowflake

mutex deadlock.Mutex
state *ningen.State
}

// thread-safe
// thread-unsafe
func New(s *ningen.State) (m *Container) {
list, _ := gtk.ListBoxNew()
list.Show()
Expand All @@ -35,7 +32,8 @@ func New(s *ningen.State) (m *Container) {
state: s,
Rows: []gtkutils.ExtendedWidget{},
}
s.MemberList.OnOP = m.handle
// TODO
// s.MemberList.OnOP = m.handle
s.MemberList.OnSync = m.handleSync

// unreference these things
Expand Down Expand Up @@ -65,9 +63,6 @@ func New(s *ningen.State) (m *Container) {
}

func (m *Container) handleSync(ml *ningen.MemberList, guildID discord.Snowflake) {
m.mutex.Lock()
defer m.mutex.Unlock()

if m.GuildID != guildID {
return
}
Expand All @@ -78,25 +73,25 @@ func (m *Container) handleSync(ml *ningen.MemberList, guildID discord.Snowflake)
return
}

m.cleanup()
m.reset(ml, *guild)
semaphore.Async(func() {
m.cleanup()
m.reset(ml, *guild)
})
}

func (m *Container) handle(
ml *ningen.MemberList, guildID discord.Snowflake, op gateway.GuildMemberListOp) {
// TODO
// func (m *Container) handleUnsafe(
// ml *ningen.MemberList, guildID discord.Snowflake, op gateway.GuildMemberListOp) {

if m.GuildID != guildID {
return
}
// if m.GuildID != guildID {
// return
// }

m.mutex.Lock()
defer m.mutex.Unlock()
}
// m.mutex.Lock()
// defer m.mutex.Unlock()
// }

func (m *Container) cleanup() {
m.mutex.Lock()
defer m.mutex.Unlock()

for i, r := range m.Rows {
m.ListBox.Remove(r)
m.Rows[i] = nil
Expand All @@ -106,9 +101,6 @@ func (m *Container) cleanup() {

// LoadGuild is thread-safe.
func (m *Container) LoadGuild(guild discord.Guild) {
m.mutex.Lock()
defer m.mutex.Unlock()

m.GuildID = guild.ID

// Borrow MemberList's mutex
Expand Down Expand Up @@ -187,65 +179,3 @@ func (m *Container) reset(ml *ningen.MemberList, guild discord.Guild) {
// }
// return
// }

func GetTopRole(roles []discord.Role) *discord.Role {
var pos, ind = -1, -1

for i, r := range roles {
if r.Position < pos || pos == -1 {
ind = i
pos = r.Position
}
}

if ind < 0 {
return nil
}
return &roles[ind]
}

func GetTopRoleID(
ids []discord.Snowflake, roles map[discord.Snowflake]*discord.Role) *discord.Role {

var pos, ind = -1, -1

for i, id := range ids {
if r := roles[id]; r.Position < pos || pos == -1 {
ind = i
pos = r.Position
}
}

if ind < 0 {
return nil
}

return roles[ids[ind]]
}

func FilterHoistRoles(roles []discord.Role) []discord.Role {
filtered := roles[:0]

for i, r := range roles {
if r.Hoist {
filtered = append(filtered, roles[i])
}
}

return filtered
}

func SortRoles(roles []discord.Role) {
sort.Slice(roles, func(i, j int) bool {
return roles[i].Position > roles[j].Position
})
}

func MapRoles(roles []discord.Role) map[discord.Snowflake]*discord.Role {
var mapped = make(map[discord.Snowflake]*discord.Role, len(roles))
for i, r := range roles {
mapped[r.ID] = &roles[i]
}

return mapped
}
68 changes: 68 additions & 0 deletions gtkcord/config/lastread/lastread.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package lastread

import (
"sync"

"github.com/diamondburned/arikawa/discord"
"github.com/diamondburned/gtkcord3/gtkcord/config"
"github.com/diamondburned/gtkcord3/internal/log"
)

type State struct {
path string
store *store
}

type store struct {
sync.Mutex `json:"-"`

// GuildID -> ChannelID; if GuildID == 0 then DM
Access map[discord.Snowflake]discord.Snowflake
}

func New(file string) State {
store := &store{
Access: make(map[discord.Snowflake]discord.Snowflake),
}

if err := store.load(file); err != nil {
log.Errorln("Failed to load config:", err)
}

return State{
path: file,
store: store,
}
}

func (store *store) load(file string) error {
store.Lock()
defer store.Unlock()

return config.UnmarshalFromFile(file, store)
}

func (store *store) save(file string) error {
store.Lock()
defer store.Unlock()

return config.MarshalToFile(file, store)
}

func (s *State) Access(guild discord.Snowflake) discord.Snowflake {
s.store.Lock()
defer s.store.Unlock()

id, _ := s.store.Access[guild]
return id
}

func (s *State) SetAccess(guild, channel discord.Snowflake) {
s.store.Lock()
s.store.Access[guild] = channel
s.store.Unlock()

if err := s.store.save(s.path); err != nil {
log.Errorln("Failed to save config:", err)
}
}
37 changes: 13 additions & 24 deletions gtkcord/gtkcord.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/diamondburned/gtkcord3/gtkcord/components/quickswitcher"
"github.com/diamondburned/gtkcord3/gtkcord/components/singlebox"
"github.com/diamondburned/gtkcord3/gtkcord/components/window"
"github.com/diamondburned/gtkcord3/gtkcord/config/lastread"
"github.com/diamondburned/gtkcord3/gtkcord/gtkutils"
"github.com/diamondburned/gtkcord3/gtkcord/gtkutils/gdbus"
"github.com/diamondburned/gtkcord3/gtkcord/ningen"
Expand All @@ -28,7 +29,6 @@ import (
"github.com/gotk3/gotk3/glib"
"github.com/gotk3/gotk3/gtk"
"github.com/pkg/errors"
"github.com/sasha-s/go-deadlock"
)

var HTTPClient = http.Client{
Expand All @@ -50,10 +50,8 @@ func discordSettings() {
}
}

const (
SpinnerSize = 56
ChannelWidth = 240
)
const SettingsFile = "settings.json"
const LastReadFile = "lastread.json"

type Application struct {
*gtk.Application
Expand Down Expand Up @@ -89,9 +87,9 @@ type Application struct {
Channels *channel.Channels
Messages *message.Messages

// GuildID -> ChannelID; if GuildID == 0 then DM
LastAccess map[discord.Snowflake]discord.Snowflake
lastAccMut deadlock.Mutex
// LastRead contains the persistent state of the latest channels mapped from
// guilds.
LastRead lastread.State

busy moreatomic.BusyMutex
// done chan int // exit code
Expand All @@ -103,11 +101,13 @@ func New(app *gtk.Application) *Application {
if err != nil {
log.Fatalln("Failed to load plugins:", err)
}
discordSettings()

discordSettings()
return &Application{
Application: app,
Plugins: plugins,
LastRead: lastread.New(LastReadFile),
Settings: MakeSettings(),
}
}

Expand All @@ -134,15 +134,14 @@ func (a *Application) Activate() {
a.Window = window.Window

a.leftCols = map[int]gtk.IWidget{}
a.LastAccess = map[discord.Snowflake]discord.Snowflake{}

// Set the window specs:
window.Resize(variables.WindowWidth, variables.WindowHeight)
window.SetTitle("gtkcord")

// Create the preferences/settings window, which applies settings as a side
// effect:
a.Settings = a.makeSettings()
a.Settings.InitWidgets(a)
}

func (a *Application) init() {
Expand Down Expand Up @@ -319,10 +318,6 @@ func (a *Application) Ready(s *ningen.State) error {
}
})

// Set widths:
a.Channels.SetSizeRequest(ChannelWidth, -1)
a.Privates.SetSizeRequest(ChannelWidth, -1)

// Guilds and Channels grid:
g1, _ := gtk.GridNew()
g1.Show()
Expand Down Expand Up @@ -407,17 +402,11 @@ func (a *Application) LogOut() {
}

func (a *Application) lastAccess(guild, ch discord.Snowflake) discord.Snowflake {
a.lastAccMut.Lock()
defer a.lastAccMut.Unlock()

// read
if !ch.Valid() {
if id, ok := a.LastAccess[guild]; ok {
return id
}
return 0
return a.LastRead.Access(guild)
}

a.LastAccess[guild] = ch
a.LastRead.SetAccess(guild, ch)
return ch
}

Expand Down
Loading

0 comments on commit 59907e0

Please sign in to comment.