Skip to content
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

feat(stage-tamagotchi): allow resize window, save window size and position #37

Merged
merged 3 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions apps/stage-tamagotchi/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,24 @@ app.whenReady().then(() => {
rebuildTrayMenu()
createApplicationMenu(i18n, showQuitDialog, createSettingsWindow)
})

ipcMain.on('start-resize-window', () => {
mainWindow.setResizable(true)
})

ipcMain.on('stop-resize-window', () => {
mainWindow.setResizable(false)
})

ipcMain.handle('stop-move-window', () => {
return mainWindow.getPosition()
})

ipcMain.on('window-size-changed', (_, width: number, height: number) => {
mainWindow.setSize(width, height)
})

ipcMain.on('window-position-changed', (_, x: number, y: number) => {
mainWindow.setPosition(x, y)
})
})
11 changes: 11 additions & 0 deletions apps/stage-tamagotchi/src/renderer/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
<script setup lang="ts">
import { useSettings } from '@proj-airi/stage-ui/stores'
import { useEventListener } from '@vueuse/core'
import { onMounted, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { RouterView } from 'vue-router'

import { useWindowControlStore } from './stores/window-controls'

const settings = useSettings()
const i18n = useI18n()
const windowControlStore = useWindowControlStore()

useEventListener(window, 'resize', () => {
windowControlStore.size.width = window.innerWidth
windowControlStore.size.height = window.innerHeight
})

watch(() => settings.language, (language) => {
i18n.locale.value = language
Expand All @@ -15,6 +24,8 @@ watch(() => settings.language, (language) => {
// FIXME: store settings to file
onMounted(() => {
window.electron.ipcRenderer.send('locale-changed', settings.language)
window.electron.ipcRenderer.send('window-size-changed', windowControlStore.size.width, windowControlStore.size.height)
window.electron.ipcRenderer.send('window-position-changed', windowControlStore.position.x, windowControlStore.position.y)
})
</script>

Expand Down
15 changes: 15 additions & 0 deletions apps/stage-tamagotchi/src/renderer/src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ const modeIndicatorClass = computed(() => {
</div>
</div>
</Transition>
<Transition
enter-active-class="transition-opacity duration-250"
enter-from-class="opacity-0"
enter-to-class="opacity-100"
leave-active-class="transition-opacity duration-250"
leave-from-class="opacity-100"
leave-to-class="opacity-0"
>
<div
v-if="windowStore.controlMode === WindowControlMode.RESIZE"
class="absolute left-0 top-0 z-999 h-full w-full"
>
<div h-full w-full animate-flash animate-duration-2.5s animate-count-infinite b-8 b-pink rounded-2xl />
</div>
</Transition>
</template>

<style scoped>
Expand Down
15 changes: 15 additions & 0 deletions apps/stage-tamagotchi/src/renderer/src/stores/window-controls.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useLocalStorage } from '@vueuse/core'
import { defineStore } from 'pinia'
import { ref } from 'vue'

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

function setMode(mode: WindowControlMode) {
controlMode.value = mode

if (mode === WindowControlMode.RESIZE) {
window.electron.ipcRenderer.send('start-resize-window')
return
}

window.electron.ipcRenderer.invoke('stop-move-window').then((p: [number, number]) => {
position.value = { x: p[0], y: p[1] }
})
window.electron.ipcRenderer.send('stop-resize-window')
}

function toggleControl() {
Expand All @@ -21,6 +34,8 @@ export const useWindowControlStore = defineStore('windowControl', () => {
return {
controlMode,
isControlActive,
size,
position,
setMode,
toggleControl,
}
Expand Down