Skip to content

Commit

Permalink
feat: adaptive window height, close #147 (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayangweb committed Apr 4, 2023
1 parent ce07ffd commit 4d9f234
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
1 change: 1 addition & 0 deletions .eslintrc-auto-import.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"readonly": true,
"ref": true,
"request": true,
"resizeWindow": true,
"resolveComponent": true,
"saveImage": true,
"saveImageFromBase64": true,
Expand Down
5 changes: 3 additions & 2 deletions src/components/Settings/components/Modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ watch(
([newValue]) => {
if (newValue.length !== 51) return
getCredit()
// getCredit()
},
{
immediate: true
Expand Down Expand Up @@ -77,7 +77,8 @@ watch(
</li>

<div class="flex justify-between text-sm text-[var(--color-text-3)]">
<div>账户余额:&dollar; {{ usedCredit }} / {{ totalCredit }}</div>
<!-- <div>账户余额:&dollar; {{ usedCredit }} / {{ totalCredit }}</div> -->
<div>余额查询暂不可用</div>
<div>
温馨提示:软件使用 <span class="mark">gpt-3.5-turbo-0301</span> 模型
</div>
Expand Down
8 changes: 8 additions & 0 deletions src/hooks/useInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export const useInit = () => {

invoke('close_splashscreen')

resizeWindow()

useObserverLink()

useDisableShortcuts()
Expand All @@ -24,6 +26,12 @@ export const useInit = () => {
}, 100)
})

// 监听显示设备变化时,重置窗口位置到中间,以防止窗口位置偏移到屏幕外
appWindow.onScaleChanged(() => {
resizeWindow()
appWindow.center()
})

if (import.meta.env.PROD) {
document.addEventListener('contextmenu', function (event) {
if (!window.getSelection()?.toString()) {
Expand Down
5 changes: 0 additions & 5 deletions src/stores/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,6 @@ export const useSettingsStore = defineStore(
autoStart.value ? enable() : disable()
})

// 监听显示设备变化时,重置窗口位置到中间,以防止窗口位置偏移到屏幕外
appWindow.onScaleChanged(() => {
appWindow.center()
})

return {
themeMode,
uuid,
Expand Down
5 changes: 2 additions & 3 deletions src/utils/saveMarkdown.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { getName } from '@tauri-apps/api/app'
import { writeTextFile, BaseDirectory } from '@tauri-apps/api/fs'

export const saveMarkdown = throttle(async (content: any) => {
try {
const { currentSession } = useSessionStore()

const file = `${currentSession?.title.slice(0, 10)}-${Date.now()}.md`
const file = `${await getName()}-${Date.now()}.md`

await writeTextFile(file, content?.prompt || content, {
dir: BaseDirectory.Download
Expand Down
14 changes: 13 additions & 1 deletion src/utils/tauri.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { invoke } from '@tauri-apps/api/tauri'
import { downloadDir } from '@tauri-apps/api/path'
import { type } from '@tauri-apps/api/os'
import { appWindow } from '@tauri-apps/api/window'
import { appWindow, PhysicalSize } from '@tauri-apps/api/window'
import { hide, show } from '@tauri-apps/api/app'
import { currentMonitor } from '@tauri-apps/api/window'

/**
* 打开文件所在位置
Expand Down Expand Up @@ -43,3 +44,14 @@ export const hideWindow = async () => {
appWindow.hide()
}
}

export const resizeWindow = async () => {
const monitor = await currentMonitor()

if (!monitor) return

const resizeHeight = Math.ceil(monitor.size.height * (600 / 1080))
const resizeWidth = Math.ceil(resizeHeight * 1.3)

appWindow.setSize(new PhysicalSize(resizeWidth, resizeHeight))
}

0 comments on commit 4d9f234

Please sign in to comment.