Keep preferences in one settings file and move tab transfer to the host
Keep the user preferences in settings.json in the app config folder. WebView storage can be lost, and the host cannot read it. The file has a schema number, a revision number, and one value for each section: general, appearance, customThemes, customThemesLegacy, and language. - settings_read gives all sections, the revision, and a one-time notice. - settings_write replaces one section, writes the file atomically, and sends settings-changed to all windows. The limit is 8 MiB. - settings_migrate writes the first file only when no file exists. - The host moves a damaged file to settings.corrupt-<seconds>.json, starts from the defaults, and reports this one time. Each window loads the sections before its first render. One store in src/lib/settings/store.ts replaces the storage listeners. When no file exists, the window normalizes the old localStorage values and migrates them. The old keys stay in place for one release. The window layout and the open tabs stay in localStorage on purpose. The browser preview keeps all preferences in localStorage. Keep tab transfer offers in host memory, not in localStorage, because an offer can hold unsaved text. A window takes an offer once. The host checks the workspace root and a 120 second expiry. When the receiver accepts the tab, the host sends tab-transfer-accepted to the source window only. A refused offer stays open, and the source tab stays open. A new window and a drop on the tab ribbon use one check. The smoke harness serves the new commands from one shared state for each browser context. Tests read saved values from the mock settings file. Rust, unit, and smoke tests cover the changes.
This commit is contained in:
@@ -15,11 +15,17 @@ try {
|
||||
const identity=await page.evaluate(async()=> (await import('/node_modules/@tauri-apps/api/path.js')).appDataDir());
|
||||
assert.match(identity, /[\\/]com\.runestone\.spelling-test[\\/]?$/);
|
||||
const pending=context.waitForEvent('page');
|
||||
// The source window offers the tab through the host and waits for the acknowledgement that the host sends to it alone.
|
||||
const token=await page.evaluate(async()=>{
|
||||
const {invoke}=await import('/node_modules/@tauri-apps/api/core.js');
|
||||
const {listen}=await import('/node_modules/@tauri-apps/api/event.js');
|
||||
const {getCurrentWindow}=await import('/node_modules/@tauri-apps/api/window.js');
|
||||
const root=await invoke('workspace_last_path');
|
||||
const token=crypto.randomUUID(), id=crypto.randomUUID();
|
||||
localStorage.setItem('runestone.tab-transfer.'+token,JSON.stringify({root,created:Date.now(),reading:false,buffer:{id,relPath:'empty:'+id,name:'New tab',kind:'empty',imageUrl:null,contents:'',saved:'',chrome:'Writing',chromeOverride:null}}));
|
||||
window.__nativeTransferAccepted=false;
|
||||
await listen('tab-transfer-accepted',event=>{ if(event.payload.id===token) window.__nativeTransferAccepted=true; },{target:getCurrentWindow().label});
|
||||
const payload=JSON.stringify({reading:false,buffer:{id,relPath:'empty:'+id,name:'New tab',kind:'empty',imageUrl:null,contents:'',saved:'',chrome:'Writing',chromeOverride:null}});
|
||||
await invoke('tab_transfer_offer',{id:token,root,payload});
|
||||
await invoke('workspace_open_window',{path:root,transfer:token});
|
||||
return token;
|
||||
});
|
||||
@@ -28,7 +34,7 @@ try {
|
||||
assert.ok(transferred.url().includes('?tabTransfer='+token));
|
||||
assert.ok(!transferred.url().includes('index.html'));
|
||||
assert.equal(await transferred.getByText('404',{exact:true}).count(),0);
|
||||
await page.waitForFunction(token=>localStorage.getItem('runestone.tab-transfer.'+token+'.accepted') === 'true',token);
|
||||
await page.waitForFunction(()=>window.__nativeTransferAccepted===true);
|
||||
console.log('PASS: native empty-tab transfer loads the splash screen and acknowledges its saved tab state.');
|
||||
await transferred.evaluate(async()=> (await import('/node_modules/@tauri-apps/api/window.js')).getCurrentWindow().close()); transferred=undefined;
|
||||
settings=context.pages().find(page => page.url().includes('settingsWindow=true'));
|
||||
|
||||
@@ -88,7 +88,8 @@ try {
|
||||
const pixel = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jM1sAAAAASUVORK5CYII=', 'base64');
|
||||
const largeImage = Buffer.concat([pixel, Buffer.alloc(1_900_000 - pixel.length)]);
|
||||
await page.getByLabel('Background image file', { exact: true }).setInputFiles({ name: 'native-large.png', mimeType: 'image/png', buffer: largeImage });
|
||||
await page.waitForFunction(() => !!JSON.parse(localStorage.getItem('runestone.appearance'))?.newTabBackground?.imageId);
|
||||
// The appearance is in the settings file of the host.
|
||||
await page.waitForFunction(() => window.__TAURI_INTERNALS__.invoke('settings_read').then(file => !!file.sections.appearance?.newTabBackground?.imageId));
|
||||
await page.goto(`${origin}/`);
|
||||
// The image is on the work area layer behind the empty tab (src/lib/layout/Workbench.svelte:1258, :1543-1549).
|
||||
await page.locator('.empty').waitFor();
|
||||
|
||||
Reference in New Issue
Block a user