Session

Interface to operate on client session parameters. When a client creates a connection to a server, a Session interface is created for that connection. This interface is used to interact with the client. We can get the current Session by calling the Session() method of the View interface

Interface description

App() Application

Return the current application interface

ClientItem(key string) (string, bool)

Reads value by key from the client-side storage

Color(tag string) (Color, bool)

Returns the color with "tag" name or 0 if it is not exists

Constant(tag string) (string, bool)

Returns the constant with "tag" name or "" if it is not exists

Content() SessionContent

Returns the SessionContent of session

DarkTheme() bool

Returns "true" if the dark theme is used

DownloadFile(path string)

Downloads(saves) on the client side the file located at the specified path on the server.

DownloadFileData(filename string, data []byte)

Downloads(saves) on the client side a file with a specified name and specified content.

Get(viewID, tag string) any

Returns a value of the view (with id defined by the first argument) property with name defined by the second argument. The type of return value depends on the property. If the property is not set then nil is returned.

GetString(tag string) (string, bool)

Returns the text for the current language

ID() int

Return the id of the session

ImageConstant(tag string) (string, bool)

Returns the image constant with "tag" name or "" if it is not exists

Language() string

Returns the current session language

OpenURL(url string)

Opens the url in the new browser tab

PixelRatio() float64

Returns the ratio of the resolution in physical pixels to the resolution in logical pixels for the current display device.

RemoteAddr() string

Returns the client address.

RemoveAllClientItems()

Removes all key-value pair from the client-side storage

RemoveClientItem(key string)

Removes a key-value pair from the client-side storage

RootView() View

Returns the root view of the session

Set(viewID, tag string, value any) bool

Sets the value (third argument) of the property (second argument) of the view with id defined by the first argument. Return "true" if the value has been set, in the opposite case "false" are returned and a description of the error is written to the log

SetClientItem(key, value string)

Stores a key-value pair in the client-side storage

SetCustomTheme(name string) bool

Set the custom theme

SetHotKey(keyCode KeyCode, controlKeys ControlKeyMask, fn func(Session))

Sets the function that will be called when the given hotkey is pressed. Invoke SetHotKey(..., ..., nil) for remove hotkey function.

SetLanguage(lang string)

Set the current session language

SetTitle(title string)

Sets the text of the browser title/tab

SetTitleColor(color Color)

Sets the color of the browser navigation bar. Supported only in Safari and Chrome for android

StartTimer(ms int, timerFunc func(Session)) int

Starts a timer on the client side. The first argument specifies the timer period in milliseconds. The second argument specifies a function that will be called on each timer event. The result is the id of the timer, which is used to stop the timer

StopTimer(timerID int)

Stop the timer with the given id

TextDirection() int

Returns the default text direction. Possible values are: 1(LeftToRightDirection) and 2(RightToLeftDirection)

TouchScreen() bool

Returns "true" if current session is displayed on a touch screen device

UserAgent() string

Returns the "user-agent" text of the client browser

func GetLocalIP() string

Return IP address of the machine interface