I figure out temporary solution, is a little bit goofy, but work
def on_close_event(e):
if e.data == "close":
print("Saving unfinished tasks...")
un_tasks = dict()
i = 0
for tt in tab_download.tasks.controls:
if type(tt.value) == str:
un_tasks[i] = {"ttask": tt.ttask, "value": {"name": "", "path": ""}}
else:
un_tasks[i] = {"ttask": tt.ttask, "value": {"name": tt.value.name, "path": tt.value.path}}
i += 1
write_unfinished_tasks(un_tasks)
page.window.prevent_close = False
page.window.on_event = None
page.update()
page.window.close()
page.window.prevent_close = True
page.window.on_event = lambda e: on_close_event(e)
page.update()