Exemple #1
0
func (window *GhAuthWindow) build() {
	window.bindKeys()
	window.SetModal(true)
	window.SetTitle("Readmill Authentication")
	window.Connect("destroy", func() {
		config := models.Config()

		if config.AccessToken == "" {
			gtk.MainQuit()
		}
	})

	scrolledWindow := gtk.ScrolledWindow(nil, nil)
	scrolledWindow.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)
	scrolledWindow.SetShadowType(gtk.GTK_SHADOW_IN)

	webview := webkit.WebView()
	webview.Connect("load-committed", func() {
		uri := webview.GetUri()
		matched, _ := regexp.MatchString(`^`+constants.READMILL_REDIRECT_URI+`/\?code=`, uri)

		if matched {
			webview.StopLoading()
			codeRegex, _ := regexp.Compile(`\?code=([^&]*)`)
			result := codeRegex.FindStringSubmatch(uri)
			code := result[1]
			token := readmilloauth.GetToken(constants.READMILL_CLIENT_ID, constants.READMILL_CLIENT_SECRET, constants.READMILL_REDIRECT_URI, code)
			userId := readmilloauth.GetUserId(token)

			config := models.Config()
			config.AccessToken = token
			config.UserId = userId
			config.Write()

			window.Destroy()
		}
	})
	scrolledWindow.Add(webview)

	authorizeUri := readmilloauth.AuthorizeUri(constants.READMILL_CLIENT_ID, constants.READMILL_REDIRECT_URI)
	webview.LoadUri(authorizeUri)

	window.Add(scrolledWindow)
	window.SetSizeRequest(500, 650)
}
Exemple #2
0
func Startup() {
	gdk.ThreadsInit()
	gdk.ThreadsEnter()
	initializeEnvironment()
	gtk.Init(nil)

	window := windows.MainWindow()
	window.ShowAll()

	config := models.Config()
	if config.AccessToken == "" {
		authWindow := windows.AuthWindow()
		authWindow.ShowAll()
	}

	gtk.Main()
}
Exemple #3
0
func Sync() {
	config := models.Config()

	syncHighlights(config.AccessToken)
	syncReadings(config.UserId, config.AccessToken)
}