-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add a callback for closing the window #9128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
监听这个事件试试 |
试了下,分别用不同的方法尝试了都有问题:
|
看了下代码,目前没有办法把 Event bus 做成同步的。但是关闭 Electron 时,内核还在运行的,应该可以在回调里面直接调用内核 API 对数据进行保存。
|
不太行,我试了在addTab里的destroy里调用内核API(删除指定的一个文档),但是关闭窗口之后该文档并没有删除,应该就是没有执行。与此对比的是,如果我往新窗口中拖进一个新的tab,然后再关闭原先的tab,就成功删除了文档,说明函数运行的没问题,就是函数没执行就给截断了 destroy就是这么写的 destroy() {
removeDoc(_this.newWindowBlock.box, _this.newWindowBlock.path)
} 也就是说调用内核api都没用,直接给截断了 有没有可能通过内核给新窗口和创建它的主线程之间加个通信管道?感觉会比较麻烦但是似乎没有更好的方法了,毕竟内核是一直开的,只要在关闭前能往主线程发一些东西就行了 |
关闭窗口现在直接调用的 Electron 接口,没有做其他判断。 |
嗯嗯,就是说能不能在调用接口之前先同步执行一个回调函数? |
目前修改为在关闭窗口的时候执行一个同步的 |
okk,等dev版本我试试,看代码应该是可以 |
太棒了,感觉可以用上了。 再也不用天天切屏记笔记了😭 |
In what scenarios do you need this feature?
思源现在tab关闭的回调逻辑应该是直接异步执行,但是关闭窗口的时候这个进程会直接被关闭,也就是说onDestroy中的异步语句会直接被跳过,然而openWindow本身没有提供任何的关闭回调或者监听,因此想要在关闭窗口的时候进行一些操作(例如检测打开的笔记是否有添加内容,没有内容就直接删除临时文件)目前来说是不可能的
Describe the optimal solution
我感觉像关闭思源的时候会等待自动同步一样。关闭新窗口的时候也同步等待一下onDestroy完成会比较好。
Describe the candidate solution
当然也可以单独给openWindow加一个关闭的回调,但是这个的话如果中间又操作关闭打开了别的东西也会很混乱。
Other information
No response
The text was updated successfully, but these errors were encountered: