This repository has been archived by the owner on Feb 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 344
/
session.go
56 lines (49 loc) · 1.82 KB
/
session.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package astilectron
import (
"context"
)
// Session event names
const (
EventNameSessionCmdClearCache = "session.cmd.clear.cache"
EventNameSessionEventClearedCache = "session.event.cleared.cache"
EventNameSessionCmdFlushStorage = "session.cmd.flush.storage"
EventNameSessionEventFlushedStorage = "session.event.flushed.storage"
EventNameSessionCmdLoadExtension = "session.cmd.load.extension"
EventNameSessionEventLoadedExtension = "session.event.loaded.extension"
EventNameSessionEventWillDownload = "session.event.will.download"
)
// Session represents a session
// TODO Add missing session methods
// TODO Add missing session events
// https://github.com/electron/electron/blob/v1.8.1/docs/api/session.md
type Session struct {
*object
}
// newSession creates a new session
func newSession(ctx context.Context, d *dispatcher, i *identifier, w *writer) *Session {
return &Session{object: newObject(ctx, d, i, w, i.new())}
}
// ClearCache clears the Session's HTTP cache
func (s *Session) ClearCache() (err error) {
if err = s.ctx.Err(); err != nil {
return
}
_, err = synchronousEvent(s.ctx, s, s.w, Event{Name: EventNameSessionCmdClearCache, TargetID: s.id}, EventNameSessionEventClearedCache)
return
}
// FlushStorage writes any unwritten DOMStorage data to disk
func (s *Session) FlushStorage() (err error) {
if err = s.ctx.Err(); err != nil {
return
}
_, err = synchronousEvent(s.ctx, s, s.w, Event{Name: EventNameSessionCmdFlushStorage, TargetID: s.id}, EventNameSessionEventFlushedStorage)
return
}
// Loads a chrome extension
func (s *Session) LoadExtension(path string) (err error) {
if err = s.ctx.Err(); err != nil {
return
}
_, err = synchronousEvent(s.ctx, s, s.w, Event{Name: EventNameSessionCmdLoadExtension, Path: path, TargetID: s.id}, EventNameSessionEventLoadedExtension)
return
}