mirror of
https://gitlab.com/ArkHost/HelixNotes.git
synced 2026-11-18 10:28:20 +01:00
fix(mobile): keep MCP settings and editor hooks desktop-only
This commit is contained in:
1 parent
b0b97dfb82
commit
962f3302f0
11 files changed
+67
-14
No files matched your search
@@ -4,6 +4,8 @@ Desktop integration for **1.3.8**, in release preparation. No 1.3.8 release tag
|
||||
|
||||
## Set it up
|
||||
|
||||
MCP is desktop-only. Android and iOS do not include its native runtime or commands, do not install its editor listeners, and do not show the Integrations tab in Settings. Mobile vault switching remains a separate feature and uses the platform's existing storage access flow.
|
||||
|
||||
Use an AI client that supports **local stdio MCP servers**. Web-only clients that accept only remote MCP URLs cannot use this configuration; the private bridge URL is not a public MCP endpoint.
|
||||
|
||||
1. Open **Settings → Integrations → MCP access** in a rebuilt HelixNotes desktop app.
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
localStorage.setItem('helix-tablet-nav-hidden', hidden ? '1' : '0');
|
||||
}
|
||||
import { openVault, restoreExternalVault, loadVaultState, saveVaultState, readNote, deleteNote, createDailyNote, createBackup, getPendingOpenFile, ackPendingOpenFile, addQuickAccess, removeQuickAccess, getQuickAccess, setTheme, syncNow, setTaskDone, setTaskPriority, setTaskDue } from '$lib/api';
|
||||
import { darkThemes, isAndroid } from '$lib/platform';
|
||||
import { darkThemes, isAndroid, isMobile as isMobileTarget } from '$lib/platform';
|
||||
import { openNoteWindow } from '$lib/utils/window';
|
||||
import { normalizeStartupView, resolveStartupTarget } from '$lib/utils/startup-view';
|
||||
import { isCurrentVaultEvent, sameNoteTags, updateNoteList } from '$lib/utils/note-list-updates';
|
||||
@@ -195,7 +195,7 @@
|
||||
// A fresh layout also reloads clean notes after returning from vault management.
|
||||
activateVaultData(ownerVault, ownerBookmark, true);
|
||||
let stateReady = false;
|
||||
const unregisterMcpReadiness = registerMcpReadiness(() => stateReady && !vaultSwitchBusy && !restoringNote && pendingOpenDrain === null);
|
||||
const unregisterMcpReadiness = isMobileTarget ? () => {} : registerMcpReadiness(() => stateReady && !vaultSwitchBusy && !restoringNote && pendingOpenDrain === null);
|
||||
onDestroy(unregisterMcpReadiness);
|
||||
let restoringNote = false;
|
||||
let disposed = false;
|
||||
|
||||
@@ -7618,7 +7618,7 @@
|
||||
window.addEventListener('helixnotes-open-note', handleOpenNote);
|
||||
|
||||
const mcpEditorReady = () => !(editorDisposed || isLoadingNote || pendingContent !== null || !$activeNotePath || !loadedPath || $editorDirty || externalOperationBusy || source.view?.compositionStarted || source.view?.composing || editor?.view.composing);
|
||||
const unregisterMcpEditor = registerMcpEditor(async () => {
|
||||
const unregisterMcpEditor = isMobile ? () => {} : registerMcpEditor(async () => {
|
||||
if (!mcpEditorReady()) return null;
|
||||
const path = $activeNotePath!, vault = $appConfig?.active_vault;
|
||||
const session = saves.capture();
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
import ThemedSelect from './ThemedSelect.svelte';
|
||||
import DailyNoteTemplate from './DailyNoteTemplate.svelte';
|
||||
import NewNoteEditorSetting from './NewNoteEditorSetting.svelte';
|
||||
import McpSettings from './McpSettings.svelte';
|
||||
import { newNoteEditorMode, type EditorMode } from '$lib/editor/mode';
|
||||
import { setNewNoteEditorMode } from '$lib/api';
|
||||
import AiModelPicker from './AiModelPicker.svelte';
|
||||
@@ -47,7 +46,7 @@
|
||||
$effect(() => {
|
||||
const tab = $settingsTab;
|
||||
if (tab) {
|
||||
activeTab = tab as Tab;
|
||||
activeTab = isMobile && tab === 'integrations' ? 'general' : tab as Tab;
|
||||
$settingsTab = null;
|
||||
}
|
||||
});
|
||||
@@ -1354,10 +1353,12 @@
|
||||
</svg>
|
||||
{$ui("ui.maintenance")}
|
||||
</button>
|
||||
{#if !isMobile}
|
||||
<button class="tab-btn" class:active={activeTab === 'integrations'} onclick={() => activeTab = 'integrations'}>
|
||||
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" aria-hidden="true"><path d="m8 3 2 4m6-4-2 4M7 7h10v4a5 5 0 0 1-10 0V7Zm5 9v5" /></svg>
|
||||
{$ui('mcp.integrations')}
|
||||
</button>
|
||||
{/if}
|
||||
<button class="tab-btn" class:active={activeTab === 'ai'} onclick={() => activeTab = 'ai'}>
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M12 8V4l-2-2"/><rect x="4" y="8" width="16" height="12" rx="2"/><path d="M2 14h2"/><path d="M20 14h2"/><path d="M9 13v2"/><path d="M15 13v2"/>
|
||||
@@ -2354,8 +2355,10 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{:else if activeTab === 'integrations'}
|
||||
<div class="settings-section"><McpSettings /></div>
|
||||
{:else if activeTab === 'integrations' && !isMobile}
|
||||
{#await import('./McpSettings.svelte') then { default: McpSettings }}
|
||||
<div class="settings-section"><McpSettings /></div>
|
||||
{/await}
|
||||
{:else if activeTab === 'ai'}
|
||||
<div class="tab-content">
|
||||
<div class="settings-section">
|
||||
|
||||
@@ -4,6 +4,7 @@ import { listen } from '@tauri-apps/api/event';
|
||||
import { get } from 'svelte/store';
|
||||
import { createMcpWindowGate, mcpBusy, type McpFinish } from './utils/mcp-editor';
|
||||
import type { VaultIdentity } from './types';
|
||||
import { isMobile } from './platform';
|
||||
|
||||
export type McpAccess = 'off' | 'read' | 'write';
|
||||
export interface McpStatus { mode: McpAccess; ready: boolean; error?: string | null }
|
||||
@@ -12,6 +13,8 @@ export const setMcpAccess = (vault: VaultIdentity, mode: McpAccess) => invoke<Mc
|
||||
export const getMcpClientConfig = (vault: VaultIdentity) => invoke<Record<string, unknown>>('mcp_client_config', { vault });
|
||||
|
||||
export async function installMcpWindow(ready: () => boolean): Promise<() => void> {
|
||||
// Mobile binaries do not contain an MCP runtime or its native commands.
|
||||
if (isMobile) return () => {};
|
||||
let focused: HTMLElement | null = null;
|
||||
const gate = createMcpWindowGate({ ready, reply: (id, accepted) => invoke('mcp_editor_ready', { id, accepted }),
|
||||
busy(value) {
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
import { applyUiScale, defaultUiScale } from '$lib/ui-scale';
|
||||
import { listen } from '@tauri-apps/api/event';
|
||||
import { getCurrentWindow } from '@tauri-apps/api/window';
|
||||
import { installMcpWindow } from '$lib/mcp';
|
||||
import { mcpBusy, mcpWindowReady } from '$lib/utils/mcp-editor';
|
||||
import { t } from '$lib/i18n';
|
||||
import VaultPicker from '$lib/components/VaultPicker.svelte';
|
||||
@@ -165,6 +164,7 @@
|
||||
|
||||
if (!isMobile) {
|
||||
try {
|
||||
const { installMcpWindow } = await import('$lib/mcp');
|
||||
const dispose = await installMcpWindow(() => !loading && (noteWindowPath ? !!$activeNotePath : !$vaultReady || mcpWindowReady()));
|
||||
if (pageDisposed) dispose(); else removeMcp = dispose;
|
||||
} catch (error) { console.error('MCP editor listener is unavailable:', error); }
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<script lang="ts">
|
||||
import SettingsPanel from '../../src/lib/components/SettingsPanel.svelte';
|
||||
import McpSettings from '../../src/lib/components/McpSettings.svelte';
|
||||
import { appConfig, showSettings, settingsTab, theme } from '../../src/lib/stores/app';
|
||||
import { applyLanguage } from '../../src/lib/i18n';
|
||||
import type { AppConfig } from '../../src/lib/types';
|
||||
@@ -12,7 +11,7 @@
|
||||
showSettings.set(true);settingsTab.set('integrations');
|
||||
(window as any).__TAURI_INTERNALS__.invoke=async(command:string,args:any)=>{
|
||||
calls.push({command,args});
|
||||
if(command==='plugin:app|version')return '1.3.7';
|
||||
if(command==='plugin:app|version')return '1.3.8';
|
||||
if(command==='plugin:event|listen')return 1;
|
||||
if(command.startsWith('plugin:event|')||command.startsWith('plugin:window|'))return;
|
||||
if(command==='mcp_status'){
|
||||
@@ -31,9 +30,9 @@
|
||||
throw Error(`Unexpected command: ${command}`);
|
||||
};
|
||||
$effect(()=>{document.documentElement.dataset.mcpDark=String(dark);});
|
||||
Object.assign(window,{mcpSettingsFixture:{snapshot:()=>({mode,modes:Object.fromEntries(modes),activeVault:'/notes/Private Project',calls:[...calls],clipboard}),confirm:(value:boolean)=>{confirmed=value;},fail:(value:boolean)=>{fail=value;},hold:()=>{hold=true;},release:()=>release?.(),offlineOther:()=>{offlineOther=true;modes.set('/offline/Archive','write');appConfig.update(config=>({...config!,vaults:[...config!.vaults,{path:'/offline/Archive',name:'Archive'}]}));},narrow:()=>{narrow=true;},dark:()=>{dark=!dark;theme.set(dark?'dark':'light');},language:applyLanguage}});
|
||||
Object.assign(window,{mcpSettingsFixture:{install:async()=>{const {installMcpWindow}=await import('../../src/lib/mcp');const dispose=await installMcpWindow(()=>true);dispose();},snapshot:()=>({mode,modes:Object.fromEntries(modes),activeVault:'/notes/Private Project',calls:[...calls],clipboard}),confirm:(value:boolean)=>{confirmed=value;},fail:(value:boolean)=>{fail=value;},hold:()=>{hold=true;},release:()=>release?.(),offlineOther:()=>{offlineOther=true;modes.set('/offline/Archive','write');appConfig.update(config=>({...config!,vaults:[...config!.vaults,{path:'/offline/Archive',name:'Archive'}]}));},narrow:()=>{narrow=true;},dark:()=>{dark=!dark;theme.set(dark?'dark':'light');},language:applyLanguage}});
|
||||
</script>
|
||||
{#if narrow}<main><McpSettings/></main>{:else}<SettingsPanel onBeforeVaultSwitch={async()=>true}/>{/if}
|
||||
{#if narrow}<main>{#await import('../../src/lib/components/McpSettings.svelte') then {default:McpSettings}}<McpSettings/>{/await}</main>{:else}<SettingsPanel onBeforeVaultSwitch={async()=>true}/>{/if}
|
||||
<style>
|
||||
:global(:root){--bg-primary:#fff;--bg-secondary:#f3f5f7;--bg-tertiary:#e8edf0;--bg-hover:#e7edf0;--text-primary:#20252b;--text-secondary:#626e79;--text-tertiary:#79838d;--accent:#276e68;--accent-light:#dfefeb;--border-color:#ced6dc;--border-light:#e4e9ed;--shadow-lg:0 14px 40px #0003;}
|
||||
:global(:root[data-mcp-dark='true']){--bg-primary:#182027;--bg-secondary:#222d36;--bg-tertiary:#303d48;--bg-hover:#303d48;--text-primary:#e5eaf0;--text-secondary:#a1acb8;--text-tertiary:#8b99a6;--border-color:#3c4b58;--border-light:#35434f;}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import VaultSwitchFrame from './VaultSwitchFrame.svelte';
|
||||
import { appConfig } from '../../src/lib/stores/app';
|
||||
import { applyLanguage } from '../../src/lib/i18n';
|
||||
import { isMobile } from '../../src/lib/platform';
|
||||
import { openVault, restoreExternalVault } from '../../src/lib/api';
|
||||
import { open as pickFolder } from '@tauri-apps/plugin-dialog';
|
||||
import { createVaultSwitch, activeVaultIdentity, mergeVaultActivation, vaultIdentityKey } from '../../src/lib/utils/vault-switch';
|
||||
@@ -14,7 +15,7 @@
|
||||
appConfig.set({ active_vault: a.path, active_bookmark_id: null, vaults, show_note_switcher: false, theme: 'light', language: 'en' } as AppConfig);
|
||||
const saved = new Map(vaults.map(vault => [vault.path, `# ${vault.name}\n\nSaved note in ${vault.path}`]));
|
||||
let frame = $state<VaultSwitchFrame>();
|
||||
let busy = $state(false), managing = $state(false), mobile = $state(false), dark = $state(false);
|
||||
let busy = $state(false), managing = $state(false), mobile = $state(isMobile), dark = $state(false);
|
||||
let failSave = false, failOpen = false, holdOpen = false, folder: string | null = null;
|
||||
let resolveOpen: (() => void) | null = null;
|
||||
const calls: {command: string; args?: any}[] = [];
|
||||
@@ -58,7 +59,7 @@
|
||||
saves++; if (failSave) return false;
|
||||
saved.set(get(appConfig)!.active_vault!, text); return true;
|
||||
}
|
||||
const add = () => switcher.add(async () => {
|
||||
const add = () => mobile ? switcher.manage() : switcher.add(async () => {
|
||||
const path = await pickFolder({ directory: true, multiple: false });
|
||||
return typeof path === 'string' ? { path, bookmarkId: null, existing: false } : null;
|
||||
});
|
||||
|
||||
@@ -23,6 +23,25 @@ test('real Settings Integrations defaults off, enables read-only and copies a pa
|
||||
await page.screenshot({path:testInfo.outputPath('mcp-settings-desktop.png'),fullPage:true});
|
||||
});
|
||||
|
||||
for (const platform of [{name:'Android',android:true,ios:false},{name:'iOS',android:false,ios:true}]) {
|
||||
test(`${platform.name} hides desktop MCP settings and never starts its listeners or native calls`,async({page})=>{
|
||||
const components:string[]=[];
|
||||
page.on('request',request=>{if(/\/McpSettings\.svelte(?:\?|$)/.test(request.url()))components.push(request.url());});
|
||||
await page.addInitScript(flags=>Object.assign(window,{__HELIX_PLATFORM__:{mobile:true,...flags}}),{android:platform.android,ios:platform.ios});
|
||||
await page.setViewportSize({width:390,height:844});
|
||||
await page.goto('/?fixture=mcp');
|
||||
await expect(page.getByRole('dialog')).toBeVisible();
|
||||
await expect(page.getByRole('button',{name:'General',exact:true})).toHaveClass(/active/);
|
||||
await expect(page.getByRole('button',{name:'Integrations',exact:true})).toHaveCount(0);
|
||||
await expect(page.locator('.mcp-settings')).toHaveCount(0);
|
||||
expect(components).toEqual([]);
|
||||
await page.evaluate(()=>(window as any).mcpSettingsFixture.install());
|
||||
expect((await settings(page)).calls.filter((call:any)=>call.command.startsWith('mcp_'))).toEqual([]);
|
||||
await page.getByRole('button',{name:'Editor',exact:true}).click();
|
||||
await expect(page.getByRole('button',{name:'Editor',exact:true})).toHaveClass(/active/);
|
||||
});
|
||||
}
|
||||
|
||||
test('editing needs confirmation and failed permission saves keep the previous grant selected',async({page})=>{
|
||||
await page.goto('/?fixture=mcp');const toggle=page.getByRole('switch',{name:'Allow MCP access to this vault'});await expect(toggle).toBeEnabled();await toggle.click();
|
||||
await page.getByRole('radio',{name:'Allow editing',exact:true}).click();
|
||||
|
||||
@@ -145,6 +145,28 @@ test('a long current name fits the real title bar at a narrow desktop width', as
|
||||
expect(await page.locator('.titlebar').evaluate(element=>element.scrollWidth)).toBeLessThanOrEqual(640);
|
||||
});
|
||||
|
||||
test.describe('mobile vault selection',()=>{
|
||||
test.use({hasTouch:true,viewport:{width:390,height:844}});
|
||||
for(const platform of [{name:'Android',android:true,ios:false},{name:'iOS',android:false,ios:true}]){
|
||||
test(`${platform.name} keeps saved-vault switching and sends Add through mobile management`,async({page})=>{
|
||||
await page.addInitScript(flags=>Object.assign(window,{__HELIX_PLATFORM__:{mobile:true,...flags}}),{android:platform.android,ios:platform.ios});
|
||||
await page.reload();await expect(page.locator('.cm-editor')).toBeVisible();
|
||||
await page.evaluate(()=>(window as any).vaultFixture.edit(' mobile draft'));
|
||||
const text=(await snapshot(page)).editor.text;
|
||||
await page.getByRole('button',{name:'Switch vault: Work',exact:true}).tap();
|
||||
await vaultRow(page,'/archive/Work').tap();
|
||||
await expect.poll(async()=>(await snapshot(page)).active.path).toBe('/archive/Work');
|
||||
await page.getByRole('button',{name:'Switch vault: Work',exact:true}).tap();
|
||||
await vaultRow(page,'/notes/Work').tap();
|
||||
await expect.poll(async()=>(await snapshot(page)).editor.text).toBe(text);
|
||||
await page.getByRole('button',{name:'Switch vault: Work',exact:true}).tap();
|
||||
await page.getByRole('menuitem',{name:'Add vault…'}).tap();
|
||||
await expect(page.getByRole('heading',{name:'Vault management fixture'})).toBeVisible();
|
||||
expect((await snapshot(page)).calls.some((call:any)=>call.command==='plugin:dialog|open'||call.command.startsWith('mcp_'))).toBe(false);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test('security-scoped vaults restore by bookmark and accept a refreshed provider path', async ({ page }) => {
|
||||
await page.evaluate(()=>(window as any).vaultFixture.bookmarks());
|
||||
await menu(page); await page.getByRole('menuitemradio').filter({hasText:'Files B'}).click();
|
||||
|
||||
@@ -59,6 +59,10 @@ test('production wiring guards dirty/IME edits, preserves presentation, and uses
|
||||
const editor=await readFile(new URL('../src/lib/components/Editor.svelte',import.meta.url),'utf8');
|
||||
assert.match(editor,/\$editorDirty \|\| externalOperationBusy \|\| source\.view\?\.compositionStarted \|\| source\.view\?\.composing \|\| editor\?\.view\.composing/);
|
||||
assert.match(editor,/loadNote\(path, content\.content, undefined, true\)/);
|
||||
assert.match(editor,/isMobile \? \(\) => \{\} : registerMcpEditor/);
|
||||
const client=await readFile(new URL('../src/lib/mcp.ts',import.meta.url),'utf8');assert.match(client,/mcp_request_state/);
|
||||
assert.match(client,/if \(isMobile\) return \(\) => \{\};/);
|
||||
const native=await readFile(new URL('../src-tauri/src/lib.rs',import.meta.url),'utf8');assert.match(native,/#\[cfg\(desktop\)\]\s*pub mod mcp;/);
|
||||
for(const command of ['mcp_status','mcp_set_access','mcp_client_config','mcp_editor_ready','mcp_request_state','mcp_active_request'])assert.match(native,new RegExp('#\\[cfg\\(desktop\\)\\]\\s*mcp::'+command));
|
||||
const page=await readFile(new URL('../src/routes/+page.svelte',import.meta.url),'utf8');assert.match(page,/inert=\{\$mcpBusy\}/);
|
||||
});
|
||||
Reference in new issue
Block a user