2021-09-07 17:36:50 +03:00
|
|
|
package rui
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
_ "embed"
|
2026-07-28 12:26:03 +03:00
|
|
|
"strconv"
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
"strings"
|
2021-09-07 17:36:50 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//go:embed app_scripts.js
|
|
|
|
|
var defaultScripts string
|
|
|
|
|
|
|
|
|
|
//go:embed app_styles.css
|
|
|
|
|
var appStyles string
|
|
|
|
|
|
|
|
|
|
//go:embed defaultTheme.rui
|
|
|
|
|
var defaultThemeText string
|
|
|
|
|
|
2024-09-12 14:05:11 +03:00
|
|
|
// Application represent generic application interface, see also [Session]
|
2021-09-07 17:36:50 +03:00
|
|
|
type Application interface {
|
2024-09-12 14:05:11 +03:00
|
|
|
// Finish finishes the application
|
2021-09-07 17:36:50 +03:00
|
|
|
Finish()
|
2024-09-12 14:05:11 +03:00
|
|
|
|
|
|
|
|
// Params returns application parameters set by StartApp function
|
2024-04-27 16:16:30 +03:00
|
|
|
Params() AppParams
|
2024-09-12 14:05:11 +03:00
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
removeSession(id int)
|
2026-07-28 12:26:03 +03:00
|
|
|
getCreateContentFunc() func(Session) SessionContent
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
2022-01-30 00:25:46 +03:00
|
|
|
// AppParams defines parameters of the app
|
|
|
|
|
type AppParams struct {
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
// Title - title of the app window/tab
|
|
|
|
|
Title string
|
2024-04-27 16:16:30 +03:00
|
|
|
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
// TitleColor - background color of the app window/tab (applied only for Safari and Chrome for Android)
|
2022-01-30 00:25:46 +03:00
|
|
|
TitleColor Color
|
2024-04-27 16:16:30 +03:00
|
|
|
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
// Icon - the icon file name
|
|
|
|
|
Icon string
|
2024-04-27 16:16:30 +03:00
|
|
|
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
// CertFile - path of a certificate for the server must be provided
|
|
|
|
|
// if neither the Server's TLSConfig.Certificates nor TLSConfig.GetCertificate are populated.
|
|
|
|
|
// If the certificate is signed by a certificate authority, the certFile should be the concatenation
|
|
|
|
|
// of the server's certificate, any intermediates, and the CA's certificate.
|
|
|
|
|
CertFile string
|
2024-04-27 16:16:30 +03:00
|
|
|
|
2024-06-11 15:03:13 +03:00
|
|
|
AutoCertDomain string
|
|
|
|
|
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
// KeyFile - path of a private key for the server must be provided
|
|
|
|
|
// if neither the Server's TLSConfig.Certificates nor TLSConfig.GetCertificate are populated.
|
|
|
|
|
KeyFile string
|
2024-04-27 16:16:30 +03:00
|
|
|
|
Added some properties and functions
* Added "resize", "grid-auto-flow", "caret-color", and "backdrop-filter" properties
* Added BlurView, BlurViewByID, GetResize, GetGridAutoFlow, GetCaretColor, GetBackdropFilter functions
* The "warp" property for ListView and ListLayout renamed to "list-warp"
* The "warp" property for EditView renamed to "edit-warp"
* Added CertFile and KeyFile optional fields to the AppParams struct.If they are set, then an https connection is created, otherwise http.
2022-06-07 13:07:10 +03:00
|
|
|
// Redirect80 - if true then the function of redirect from port 80 to 443 is created
|
|
|
|
|
Redirect80 bool
|
2024-04-27 16:16:30 +03:00
|
|
|
|
2024-03-12 19:32:22 +03:00
|
|
|
// NoSocket - if true then WebSockets will not be used and information exchange
|
|
|
|
|
// between the client and the server will be carried out only via http.
|
|
|
|
|
NoSocket bool
|
2024-04-27 16:16:30 +03:00
|
|
|
|
|
|
|
|
// SocketAutoClose - time in seconds after which the socket is automatically closed for an inactive session.
|
|
|
|
|
// The countdown begins after the OnPause event arrives.
|
|
|
|
|
// If the value of this property is less than or equal to 0 then the socket is not closed.
|
|
|
|
|
SocketAutoClose int
|
2026-04-13 15:38:32 +03:00
|
|
|
|
|
|
|
|
// GoogleFonts - url of Google fonts included in the application. For example, adding two fonts: "Open Sans" and "Roboto"
|
|
|
|
|
//
|
|
|
|
|
// GoogleFonts : "https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300..800;1,300..800&family=Roboto:ital,wght@0,100..900;1,100..900&display=swap"
|
|
|
|
|
GoogleFonts string
|
2022-01-30 00:25:46 +03:00
|
|
|
}
|
|
|
|
|
|
2026-07-28 12:26:03 +03:00
|
|
|
func getStartPage(buffer *strings.Builder, sessionID int, params AppParams) {
|
2026-09-03 12:39:07 +03:00
|
|
|
writeStrings(buffer, `<head>
|
|
|
|
|
<meta charset="utf-8">
|
|
|
|
|
<title>`, params.Title, "</title>")
|
|
|
|
|
|
2022-10-27 16:14:30 +03:00
|
|
|
if params.Icon != "" {
|
2026-09-03 12:39:07 +03:00
|
|
|
writeStrings(buffer, `
|
|
|
|
|
<link rel="icon" href="`, params.Icon, `">`)
|
2022-01-30 00:25:46 +03:00
|
|
|
}
|
|
|
|
|
|
2022-10-27 16:14:30 +03:00
|
|
|
if params.TitleColor != 0 {
|
2026-09-03 12:39:07 +03:00
|
|
|
writeStrings(buffer, `
|
|
|
|
|
<meta name="theme-color" content="`, params.TitleColor.cssString(), `">`)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buffer.WriteString(`
|
2026-09-03 12:39:07 +03:00
|
|
|
<base target="_blank" rel="noopener">
|
|
|
|
|
<meta name="viewport" content="width=device-width">`)
|
2026-04-13 15:38:32 +03:00
|
|
|
|
|
|
|
|
if params.GoogleFonts != "" {
|
2026-09-03 12:39:07 +03:00
|
|
|
writeStrings(buffer, `
|
|
|
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
|
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
|
|
|
<link href="`, params.GoogleFonts, `" rel="stylesheet">`)
|
2026-04-13 15:38:32 +03:00
|
|
|
}
|
|
|
|
|
|
2026-09-03 12:39:07 +03:00
|
|
|
writeStrings(buffer, `
|
|
|
|
|
<style>`, appStyles, `</style>
|
|
|
|
|
<style id="ruiAnimations"></style>
|
|
|
|
|
<script>
|
|
|
|
|
const sessionID = `, strconv.Itoa(sessionID), `;
|
2026-07-28 12:26:03 +03:00
|
|
|
</script>
|
|
|
|
|
<script src="/script.js"></script>
|
2026-09-03 12:39:07 +03:00
|
|
|
</head>
|
|
|
|
|
<body id="body" onkeydown="keyDownEvent(this, event)">
|
|
|
|
|
<div class="ruiRoot" id="ruiRootView"></div>
|
|
|
|
|
<div class="ruiPopupLayer" id="ruiPopupLayer" style="visibility: hidden; isolation: isolate; z-index: 10001;"></div>
|
2026-11-02 14:13:08 +03:00
|
|
|
<div class="ruiTooltip" id="ruiTooltip" style="visibility: hidden; opacity: 0; z-index: 10002;">
|
2026-09-03 12:39:07 +03:00
|
|
|
<div id="ruiTooltipText" class="ruiTooltipText"></div>
|
|
|
|
|
<div id="ruiTooltipTopArrow" class="ruiTooltipTopArrow"></div>
|
|
|
|
|
<div id="ruiTooltipBottomArrow" class="ruiTooltipBottomArrow"></div>
|
|
|
|
|
</div>
|
2023-04-25 17:20:47 +03:00
|
|
|
|
2026-09-03 12:39:07 +03:00
|
|
|
<a id="ruiDownloader" download style="display: none;"></a>
|
|
|
|
|
</body>`)
|
2021-11-07 09:43:13 +03:00
|
|
|
}
|