Skip to content

Commit 3e213f5

Browse files
committed
added unsaved changes safeguard
1 parent 030baf8 commit 3e213f5

File tree

6 files changed

+35
-6
lines changed

6 files changed

+35
-6
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "window-reader",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"scripts": {
55
"dev": "tauri dev",
66
"build": "tauri build"

src-tauri/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "window_reader"
3-
version = "1.1.3"
3+
version = "1.1.4"
44
description = "A transparent notepad-like app"
55
authors = ["Ripwords"]
66
license = ""

src-tauri/tauri.conf.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"package": {
33
"productName": "window-reader",
4-
"version": "1.1.3"
4+
"version": "1.1.4"
55
},
66
"build": {
77
"distDir": "../dist",

src/App.vue

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ onMounted(() => {
88
appWindow.setDecorations(true)
99
appWindow.setSkipTaskbar(false)
1010
})
11-
1211
</script>
1312

1413
<template>

src/components/Content.vue

+31-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const toolbar = ref<any>(null)
2121
const shortcutModal = ref(false)
2222
const exportModal_1 = ref(false)
2323
const exportModal_2 = ref(false)
24+
const exitModal = ref(false)
2425
const message = useMessage()
2526
2627
const shortcutRegister = async () => {
@@ -70,7 +71,7 @@ const export2Word = async () => {
7071
} catch (e) {
7172
message.error('Word export failed, file is empty')
7273
}
73-
}
74+
}
7475
7576
onMounted(() => {
7677
toolbar.value.style.backgroundColor = `rgba(255, 255, 255, 0.95)`
@@ -89,6 +90,22 @@ appWindow.listen("tauri://focus", () => {
8990
shortcutRegister()
9091
})
9192
93+
appWindow.listen("tauri://close-requested", async () => {
94+
if (store.content.ops.ops) {
95+
if (store.content.ops.ops[0].insert !== ('\n' || '')) {
96+
exitModal.value = true
97+
return
98+
}
99+
}
100+
await appWindow.close()
101+
})
102+
103+
watch(() => store.content.ops, () => {
104+
console.log(store.content.ops)
105+
console.log(store.content.ops.ops.length)
106+
console.log(store.content.ops.ops[0].insert.toString())
107+
})
108+
92109
await shortcutRegister()
93110
</script>
94111

@@ -212,6 +229,19 @@ await shortcutRegister()
212229
<button :theme-overridess="themeOverrides"><i-mdi:file-word class="m-[0.7rem]" @click="export2Word()"></i-mdi:file-word></button>
213230
</div>
214231
</n-modal>
232+
<n-modal
233+
class="mx-30vw"
234+
v-model:show="exitModal"
235+
:mask-closable="false"
236+
preset="dialog"
237+
title="Unsaved changes"
238+
content="Are you sure?"
239+
positive-text="Yes"
240+
negative-text="Cancel"
241+
@positive-click="appWindow.close()"
242+
@negative-click="exitModal = false"
243+
>
244+
</n-modal>
215245
</div>
216246
</template>
217247

0 commit comments

Comments
 (0)