Skip to content
This repository has been archived by the owner on Feb 10, 2021. It is now read-only.

Commit

Permalink
Dispose reminder when the extension was disabled, fix todolist.clearN…
Browse files Browse the repository at this point in the history
…otice bug
  • Loading branch information
voldikss committed Dec 30, 2019
1 parent 37fa6b3 commit fcff897
Show file tree
Hide file tree
Showing 6 changed files with 3,348 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"@octokit/rest": "^16.28.4",
"@types/node": "^12.0.10",
"@types/uuid": "^3.4.4",
"coc.nvim": "^0.0.73",
"coc.nvim": "^0.0.74",
"rimraf": "^2.6.3",
"ts-loader": "^6.0.4",
"tslint": "^5.18.0",
Expand Down
10 changes: 9 additions & 1 deletion src/commands/reminder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import { TodoItem, Notification } from '../types'
import DB from '../util/db'
import FloatWindow from '../ui/floatWindow'
import VirtualText from '../ui/virtualText'
import { Dispose } from '../util/dispose'

export default class Reminder {
export default class Reminder extends Dispose {
private interval: NodeJS.Timeout
private config: WorkspaceConfiguration
private floating: FloatWindow
private virtual: VirtualText

constructor(private nvim: Neovim, private remindList: DB) {
super()
this.config = workspace.getConfiguration('todolist.reminder')
workspace.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('todolist.reminder')) {
Expand Down Expand Up @@ -100,4 +102,10 @@ export default class Reminder {
public stopRemind(): void {
if (this.interval) clearInterval(this.interval)
}

public dispose(): void {
// tslint:disable-next-line: no-floating-promises
this.clearNotice()
this.stopRemind()
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export async function activate(context: ExtensionContext): Promise<void> {

const remindList = new DB(storagePath, 'remind', maxsize)
const reminder = new Reminder(nvim, remindList)
subscriptions.push(reminder)

const todoList = new DB(storagePath, 'todolist', maxsize)
const extCfg = new Config(storagePath)
Expand Down
4 changes: 2 additions & 2 deletions src/ui/floatWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default class FloatWindow {
resolve => setTimeout(resolve, 500 / (100 - winblend))
)
}
await discard.close()
await discard.close(true)
this.tempWins.shift()
})
}
Expand Down Expand Up @@ -128,7 +128,7 @@ export default class FloatWindow {
public async destroy(): Promise<void> {
for (const w of this.windows.concat(this.tempWins)) {
const isValid = await w.valid
if (isValid) await w.close()
if (isValid) await w.close(true)
}
}
}
18 changes: 18 additions & 0 deletions src/util/dispose.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Disposable } from 'coc.nvim'

export class Dispose implements Disposable {
private subscriptions: Disposable[] = []

push(subs: Disposable) {
this.subscriptions.push(subs)
}

dispose() {
if (this.subscriptions.length) {
this.subscriptions.forEach(subs => {
subs.dispose()
})
this.subscriptions = []
}
}
}
Loading

0 comments on commit fcff897

Please sign in to comment.