Skip to content

Build your personal knowledge base with Trilium Notes

mobile detection

azivner458ed1faffda
diff --git a/src/routes/index.js b/src/routes/index.js
index e3e36f845a..c0af0c5f4e 100644
--- a/src/routes/index.js
+++ b/src/routes/index.js
@@ -9,7 +9,9 @@ const optionService = require('../services/options');
async function index(req, res) {
const options = await optionService.getOptionsMap();
- res.render('index', {
+ const view = req.cookies['trilium-device'] === 'mobile' ? 'mobile' : 'desktop';
+
+ res.render(view, {
theme: options.theme,
leftPaneMinWidth: parseInt(options.leftPaneMinWidth),
leftPaneWidthPercent: parseInt(options.leftPaneWidthPercent),
diff --git a/src/views/index.ejs b/src/views/desktop.ejs
similarity index 100%
rename from src/views/index.ejs
rename to src/views/desktop.ejs
diff --git a/src/views/login.ejs b/src/views/login.ejs
index 354e0d17d0..8286c78999 100644
--- a/src/views/login.ejs
+++ b/src/views/login.ejs
@@ -42,8 +42,26 @@
</div>
</div>
-<!-- Required for correct loading of scripts in Electron -->
-<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>
+<script>
+ // Required for correct loading of scripts in Electron
+ if (typeof module === 'object') {window.module = module; module = undefined;}
+
+ let device = "desktop";
+
+ // mobile device detection based on https://stackoverflow.com/a/24600597/944162
+ if (/Mobi/.test(navigator.userAgent) || window.location.search === '?mobile') {
+ device = "mobile";
+ }
+
+ 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=/";
+ }
+</script>
<link href="libraries/bootstrap/css/bootstrap.min.css" rel="stylesheet">
</body>