Skip to content

Commit e3d43ac

Browse files
committed
feat(stage-tamagotchi): allow resize window, save window size and position
1 parent 6d4b534 commit e3d43ac

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

apps/stage-tamagotchi/src/main/index.ts

+20
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,24 @@ app.whenReady().then(() => {
177177
rebuildTrayMenu()
178178
createApplicationMenu(i18n, showQuitDialog, createSettingsWindow)
179179
})
180+
181+
ipcMain.on('start-resize-window', () => {
182+
mainWindow.setResizable(true)
183+
})
184+
185+
ipcMain.on('stop-resize-window', () => {
186+
mainWindow.setResizable(false)
187+
})
188+
189+
ipcMain.handle('stop-move-window', () => {
190+
return mainWindow.getPosition()
191+
})
192+
193+
ipcMain.on('window-size-changed', (_, width: number, height: number) => {
194+
mainWindow.setSize(width, height)
195+
})
196+
197+
ipcMain.on('window-position-changed', (_, x: number, y: number) => {
198+
mainWindow.setPosition(x, y)
199+
})
180200
})

apps/stage-tamagotchi/src/renderer/src/App.vue

+11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
<script setup lang="ts">
22
import { useSettings } from '@proj-airi/stage-ui/stores'
3+
import { useEventListener } from '@vueuse/core'
34
import { onMounted, watch } from 'vue'
45
import { useI18n } from 'vue-i18n'
56
import { RouterView } from 'vue-router'
67
8+
import { useWindowControlStore } from './stores/window-controls'
9+
710
const settings = useSettings()
811
const i18n = useI18n()
12+
const windowControlStore = useWindowControlStore()
13+
14+
useEventListener(window, 'resize', () => {
15+
windowControlStore.size.width = window.innerWidth
16+
windowControlStore.size.height = window.innerHeight
17+
})
918
1019
watch(() => settings.language, (language) => {
1120
i18n.locale.value = language
@@ -15,6 +24,8 @@ watch(() => settings.language, (language) => {
1524
// FIXME: store settings to file
1625
onMounted(() => {
1726
window.electron.ipcRenderer.send('locale-changed', settings.language)
27+
window.electron.ipcRenderer.send('window-size-changed', windowControlStore.size.width, windowControlStore.size.height)
28+
window.electron.ipcRenderer.send('window-position-changed', windowControlStore.position.x, windowControlStore.position.y)
1829
})
1930
</script>
2031

apps/stage-tamagotchi/src/renderer/src/pages/index.vue

+15
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ const modeIndicatorClass = computed(() => {
7171
</div>
7272
</div>
7373
</Transition>
74+
<Transition
75+
enter-active-class="transition-opacity duration-250"
76+
enter-from-class="opacity-0"
77+
enter-to-class="opacity-100"
78+
leave-active-class="transition-opacity duration-250"
79+
leave-from-class="opacity-100"
80+
leave-to-class="opacity-0"
81+
>
82+
<div
83+
v-if="windowStore.controlMode === WindowControlMode.RESIZE"
84+
class="absolute left-0 top-0 z-999 h-full w-full"
85+
>
86+
<div h-full w-full animate-flash animate-duration-2.5s animate-count-infinite b-8 b-pink rounded-2xl />
87+
</div>
88+
</Transition>
7489
</template>
7590

7691
<style scoped>

apps/stage-tamagotchi/src/renderer/src/stores/window-controls.ts

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useLocalStorage } from '@vueuse/core'
12
import { defineStore } from 'pinia'
23
import { ref } from 'vue'
34

@@ -6,9 +7,21 @@ import { WindowControlMode } from '../types/window-controls'
67
export const useWindowControlStore = defineStore('windowControl', () => {
78
const controlMode = ref<WindowControlMode>(WindowControlMode.DEFAULT)
89
const isControlActive = ref(false)
10+
const size = useLocalStorage('window/control/size', { width: 0, height: 0 })
11+
const position = useLocalStorage('window/control/position', { x: 0, y: 0 })
912

1013
function setMode(mode: WindowControlMode) {
1114
controlMode.value = mode
15+
16+
if (mode === WindowControlMode.RESIZE) {
17+
window.electron.ipcRenderer.send('start-resize-window')
18+
return
19+
}
20+
21+
window.electron.ipcRenderer.invoke('stop-move-window').then((p: [number, number]) => {
22+
position.value = { x: p[0], y: p[1] }
23+
})
24+
window.electron.ipcRenderer.send('stop-resize-window')
1225
}
1326

1427
function toggleControl() {
@@ -21,6 +34,8 @@ export const useWindowControlStore = defineStore('windowControl', () => {
2134
return {
2235
controlMode,
2336
isControlActive,
37+
size,
38+
position,
2439
setMode,
2540
toggleControl,
2641
}

0 commit comments

Comments
 (0)