From 8eae4a84f9beda9e0ef2f24bccfe9a18ff9e0b3c Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Wed, 25 May 2022 13:31:30 +0200 Subject: [PATCH] #57: Fix for mobile --- src/main.ts | 17 ++++++++++++++--- src/settings.ts | 28 ++++++++++++++++++---------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/main.ts b/src/main.ts index 8391618..1d36441 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,14 +9,23 @@ import { import { OmnisearchInFileModal, OmnisearchVaultModal } from './modals' import { loadSettings, settings, SettingsTab } from './settings' -const mainWindow = require('electron').remote.getCurrentWindow() +let mainWindow: { on: any; off: any } | null = null +try { + mainWindow = require('electron').remote.getCurrentWindow() +} +catch (e) { + console.log("Can't load electron, mobile platform") +} + const onBlur = (): void => { reindexNotes() } export default class OmnisearchPlugin extends Plugin { async onload(): Promise { - mainWindow.on('blur', onBlur) + if (mainWindow) { + mainWindow.on('blur', onBlur) + } await loadSettings(this) this.addSettingTab(new SettingsTab(this)) @@ -75,6 +84,8 @@ export default class OmnisearchPlugin extends Plugin { } onunload(): void { - mainWindow.off('blur', onBlur) + if (mainWindow) { + mainWindow.off('blur', onBlur) + } } } diff --git a/src/settings.ts b/src/settings.ts index a2379aa..799406b 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -53,16 +53,24 @@ export class SettingsTab extends PluginSettingTab { }), ) - // Index in real-time - new Setting(containerEl) - .setName('Reindex in real-time') - .setDesc('By default, notes a reindexed when Obsidian focus is lost. Enable this to reindex in real-time. May affect performances.') - .addToggle(toggle => - toggle.setValue(settings.reindexInRealTime).onChange(async v => { - settings.reindexInRealTime = v - await saveSettings(this.plugin) - }), - ) + // Index in real-time, desktop only + if (require('electron')) { + new Setting(containerEl) + .setName('Reindex in real-time') + .setDesc( + 'By default, notes a reindexed when Obsidian focus is lost. Enable this to reindex in real-time. May affect performances.', + ) + .addToggle(toggle => + toggle.setValue(settings.reindexInRealTime).onChange(async v => { + settings.reindexInRealTime = v + await saveSettings(this.plugin) + }), + ) + } + else { + // No real time indexing on mobile + settings.reindexInRealTime = false + } new Setting(containerEl).setName('Results weighting').setHeading()