Skip to content

Build your personal knowledge base with Trilium Notes

entrypoint: add missing login entry point and port to TS

Panagiotis Papadopoulosdde24785b8f3
diff --git a/src/public/app/login.ts b/src/public/app/login.ts
new file mode 100644
index 0000000000..ed37e9e954
--- /dev/null
+++ b/src/public/app/login.ts
@@ -0,0 +1,32 @@
+import "../stylesheets/bootstrap.scss";
+
+// @ts-ignore - module = undefined
+// Required for correct loading of scripts in Electron
+if (typeof module === 'object') {window.module = module; module = undefined;}
+
+const device = getDeviceType()
+console.log("Setting device cookie to:", device);
+setCookie("trilium-device", device);
+
+function setCookie(name: string, value?: string) {
+ const date = new Date(Date.now() + 10 * 365 * 24 * 60 * 60 * 1000);
+ const expires = "; expires=" + date.toUTCString();
+
+ document.cookie = name + "=" + (value || "") + expires + "; path=/";
+}
+
+function getDeviceType() {
+ if (window.location.search === '?desktop') return "desktop";
+ if (window.location.search === '?mobile') return "mobile";
+ return isMobile() ? "mobile" : "desktop";
+}
+
+// https://stackoverflow.com/a/73731646/944162
+function isMobile() {
+ const mQ = matchMedia?.('(pointer:coarse)');
+ if (mQ?.media === '(pointer:coarse)') return !!mQ.matches;
+
+ if ('orientation' in window) return true;
+ const userAgentsRegEx = /\b(Android|iPhone|iPad|iPod|Windows Phone|BlackBerry|webOS|IEMobile)\b/i
+ return userAgentsRegEx.test(navigator.userAgent)
+}
\ No newline at end of file
diff --git a/src/views/login.ejs b/src/views/login.ejs
index 63d7fa252b..53b2a94ce8 100644
--- a/src/views/login.ejs
+++ b/src/views/login.ejs
@@ -46,36 +46,6 @@
</div>
<script src="<%= appPath %>/login.js" crossorigin type="module"></script>
-<script>
- // Required for correct loading of scripts in Electron
- if (typeof module === 'object') {window.module = module; module = undefined;}
- const device = getDeviceType()
- console.log("Setting device cookie to:", device);
- setCookie("trilium-device", device);
-
- function setCookie(name, value) {
- const date = new Date(Date.now() + 10 * 365 * 24 * 60 * 60 * 1000);
- const expires = "; expires=" + date.toUTCString();
-
- document.cookie = name + "=" + (value || "") + expires + "; path=/";
- }
-
- function getDeviceType() {
- if (window.location.search === '?desktop') return "desktop";
- if (window.location.search === '?mobile') return "mobile";
- return isMobile() ? "mobile" : "desktop";
- }
-
- // https://stackoverflow.com/a/73731646/944162
- function isMobile() {
- const mQ = matchMedia?.('(pointer:coarse)');
- if (mQ?.media === '(pointer:coarse)') return !!mQ.matches;
-
- if ('orientation' in window) return true;
- const userAgentsRegEx = /\b(Android|iPhone|iPad|iPod|Windows Phone|BlackBerry|webOS|IEMobile)\b/i
- return userAgentsRegEx.test(navigator.userAgent)
- }
-</script>
</body>
</html>
diff --git a/webpack.config.ts b/webpack.config.ts
index 69a22c7c3e..a6c01424c9 100644
--- a/webpack.config.ts
+++ b/webpack.config.ts
@@ -10,6 +10,7 @@ const config: Configuration = {
mode: "production",
entry: {
setup: "./src/public/app/setup.js",
+ login: "./src/public/app/login.js",
mobile: "./src/public/app/mobile.js",
desktop: "./src/public/app/desktop.js",
share: "./src/public/app/share.js",