Store and restore window state on startup

This commit is contained in:
Christian Muehlhaeuser 2019-05-19 04:33:37 +02:00
parent deaae7beab
commit 53855adda8
No known key found for this signature in database
GPG key ID: 3CF9FA45CA1EBB7E
4 changed files with 37 additions and 6 deletions

View file

@ -78,6 +78,10 @@ type ConfigBridge struct {
_ string `property:"redirectURL"`
_ string `property:"theme"`
_ string `property:"style"`
_ int `property:"positionX"`
_ int `property:"positionY"`
_ int `property:"width"`
_ int `property:"height"`
}
var (

View file

@ -17,10 +17,14 @@ type Account struct {
// Config holds telephant's config settings
type Config struct {
Account []Account
Theme string
Style string
FirstRun bool
Account []Account
Theme string
Style string
PositionX int
PositionY int
Width int
Height int
FirstRun bool
}
// LoadConfig returns the current config as a Config struct

View file

@ -18,14 +18,29 @@ ApplicationWindow {
minimumWidth: 364
minimumHeight: 590
width: minimumWidth * 2
height: minimumWidth * 1.5
width: settings.width > 0 ? settings.width : minimumWidth * 2
height: settings.height > 0 ? settings.height : minimumWidth * 1.5
Binding on x {
when: settings.positionX > 0
value: settings.positionX
}
Binding on y {
when: settings.positionY > 0
value: settings.positionY
}
Component.onCompleted: {
if (settings.firstRun) {
connectDialog.open()
}
}
onClosing: function() {
console.log("Closing mainWindow")
settings.positionX = mainWindow.x
settings.positionY = mainWindow.y
settings.width = mainWindow.width
settings.height = mainWindow.height
}
Item {
AboutDialog {

View file

@ -342,6 +342,10 @@ func main() {
configBridge.SetTheme(config.Theme)
configBridge.SetStyle(config.Style)
configBridge.SetFirstRun(config.FirstRun)
configBridge.SetPositionX(config.PositionX)
configBridge.SetPositionY(config.PositionY)
configBridge.SetWidth(config.Width)
configBridge.SetHeight(config.Height)
setupMastodon(config.Account[0])
runApp(config)
@ -349,6 +353,10 @@ func main() {
// save config
config.Theme = configBridge.Theme()
config.Style = configBridge.Style()
config.PositionX = configBridge.PositionX()
config.PositionY = configBridge.PositionY()
config.Width = configBridge.Width()
config.Height = configBridge.Height()
config.FirstRun = false
SaveConfig(configFile, config)
}