Skip to content

Commit

Permalink
Avoid the volatile for pluginsUpdated, and instead update directly in
Browse files Browse the repository at this point in the history
setPluginsUpdated to avoid 1s delay
  • Loading branch information
cmdcolin committed Sep 22, 2021
1 parent 56d67ed commit 897ce63
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
7 changes: 4 additions & 3 deletions products/jbrowse-desktop/public/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,13 @@ ipcMain.handle('loadSession', (_event: unknown, sessionName: string) => {
return readFile(getPath(sessionName), 'utf8')
})

ipcMain.on('saveSession', async (_event: unknown, snap: SessionSnap) => {
ipcMain.handle('saveSession', async (_event: unknown, snap: SessionSnap) => {
const page = await mainWindow?.capturePage()
const name = snap.defaultSession.name
if (page) {
writeFile(getPath(snap.defaultSession.name, 'thumbnail'), page.toDataURL())
await writeFile(getPath(name, 'thumbnail'), page.toDataURL())
}
writeFile(getPath(snap.defaultSession.name), JSON.stringify(snap, null, 2))
await writeFile(getPath(name), JSON.stringify(snap, null, 2))
})

ipcMain.handle(
Expand Down
38 changes: 16 additions & 22 deletions products/jbrowse-desktop/src/rootModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,18 @@ export default function rootModelFactory(pluginManager: PluginManager) {
isAssemblyEditing: false,
})
.volatile(() => ({
pluginsUpdated: false,
error: undefined as Error | undefined,
textSearchManager: new TextSearchManager(pluginManager),
}))
.actions(self => ({
async saveSession() {
if (self.session) {
await ipcRenderer.invoke('saveSession', {
...getSnapshot(self.jbrowse),
defaultSession: getSnapshot(self.session),
})
}
},
setSavedSessionNames(sessionNames: string[]) {
self.savedSessionNames = cast(sessionNames)
},
Expand All @@ -76,9 +83,7 @@ export default function rootModelFactory(pluginManager: PluginManager) {
setAssemblyEditing(flag: boolean) {
self.isAssemblyEditing = flag
},
setPluginsUpdated(flag: boolean) {
self.pluginsUpdated = flag
},

renameCurrentSession(sessionName: string) {
if (self.session) {
const snapshot = JSON.parse(JSON.stringify(getSnapshot(self.session)))
Expand Down Expand Up @@ -155,6 +160,12 @@ export default function rootModelFactory(pluginManager: PluginManager) {
setMenus(newMenus: Menu[]) {
self.menus = newMenus
},
async setPluginsUpdated() {
await self.saveSession()
const url = window.location.href.split('?')[0]
const name = self.session?.name || ''
window.location.href = `${url}?config=${encodeURIComponent(name)}`
},
/**
* Add a top-level menu
* @param menuName - Name of the menu to insert.
Expand Down Expand Up @@ -286,24 +297,7 @@ export default function rootModelFactory(pluginManager: PluginManager) {
afterCreate() {
addDisposer(
self,
autorun(
() => {
if (self.session) {
ipcRenderer.send('saveSession', {
...getSnapshot(self.jbrowse),
defaultSession: getSnapshot(self.session),
})
}
if (self.pluginsUpdated) {
const url = window.location.href.split('?')[0]

window.location.href = `${url}?config=${encodeURIComponent(
self.session?.name || '',
)}`
}
},
{ delay: 1000 },
),
autorun(() => self.saveSession(), { delay: 1000 }),
)
},
}))
Expand Down

0 comments on commit 897ce63

Please sign in to comment.