forked from openai-translator/openai-translator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optimize: modified sth about action and adaption of window (openai-tr…
…anslator#370) * fix: Fix the offset problem when arrow to right by setting placement * fix: add 2 more offset postion * feat: adaptive header width to prevent unnecessary horizontal-scroll * fix: header gap changed smooth * feat: overflow area * feat: memorized widnow props * fix: lint * fix: lint * fix: lint * fix: lint 😓 * fix: lint 😓
- Loading branch information
Showing
6 changed files
with
163 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { listen, TauriEvent } from '@tauri-apps/api/event' | ||
import { appWindow, PhysicalPosition, PhysicalSize } from '@tauri-apps/api/window' | ||
import { useEffect, useLayoutEffect } from 'react' | ||
|
||
export type WindowMemoProps = { | ||
size: boolean | ||
position: boolean | ||
} | ||
|
||
/** | ||
* memorized window props | ||
*/ | ||
export const useMemoWindow = (props: WindowMemoProps) => { | ||
useLayoutEffect(() => { | ||
if (props.position) { | ||
const storagePosition = localStorage.getItem('_position') | ||
if (storagePosition) { | ||
const { x, y } = JSON.parse(storagePosition) | ||
appWindow.setPosition(new PhysicalPosition(x, y)) | ||
} | ||
} else { | ||
localStorage.removeItem('_position') | ||
} | ||
if (props.size) { | ||
const storageSize = localStorage.getItem('_size') | ||
if (storageSize) { | ||
const { height, width } = JSON.parse(storageSize) | ||
appWindow.setSize(new PhysicalSize(width, height)) | ||
} | ||
} else { | ||
localStorage.removeItem('_size') | ||
} | ||
appWindow.show() | ||
}, []) | ||
|
||
useEffect(() => { | ||
const unListenMove = listen(TauriEvent.WINDOW_MOVED, (event: { payload: any }) => { | ||
localStorage.setItem('_position', JSON.stringify(event.payload)) | ||
}) | ||
const unListenResize = listen(TauriEvent.WINDOW_RESIZED, (event: { payload: any }) => { | ||
localStorage.setItem('_size', JSON.stringify(event.payload)) | ||
}) | ||
return () => { | ||
unListenMove.then | ||
unListenResize.then | ||
} | ||
}, []) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,56 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta | ||
name="viewport" | ||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" | ||
/> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | ||
<link rel="stylesheet" href="index.css" /> | ||
<script src="index.js" type="application/javascript" defer></script> | ||
<title>OpenAI Translator</title> | ||
<style> | ||
body { | ||
overscroll-behavior: none; | ||
} | ||
.titlebar { | ||
height: 30px; | ||
background: transparent; | ||
user-select: none; | ||
display: flex; | ||
justify-content: flex-end; | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
z-index: 2147483647; | ||
} | ||
.titlebar-button { | ||
display: inline-flex; | ||
justify-content: center; | ||
align-items: center; | ||
width: 30px; | ||
height: 30px; | ||
} | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta | ||
name="viewport" | ||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" | ||
/> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | ||
<link rel="stylesheet" href="index.css" /> | ||
<script src="index.js" type="application/javascript" defer></script> | ||
<title>OpenAI Translator</title> | ||
<style> | ||
body { | ||
overscroll-behavior: none; | ||
scrollbar-width: none; | ||
-ms-overflow-style: none; | ||
} | ||
|
||
body::-webkit-scrollbar { | ||
display: none; | ||
} | ||
|
||
.titlebar { | ||
height: 30px; | ||
background: transparent; | ||
user-select: none; | ||
display: flex; | ||
justify-content: flex-end; | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
z-index: 2147483647; | ||
} | ||
.titlebar-button { | ||
display: inline-flex; | ||
justify-content: center; | ||
align-items: center; | ||
width: 30px; | ||
height: 30px; | ||
} | ||
.titlebar-button:hover { | ||
background: #e9e9e9; | ||
} | ||
@media (prefers-color-scheme: dark) { | ||
.titlebar-button:hover { | ||
background: #e9e9e9; | ||
} | ||
@media (prefers-color-scheme: dark) { | ||
.titlebar-button:hover { | ||
background: #353535; | ||
} | ||
background: #353535; | ||
} | ||
</style> | ||
</head> | ||
<body style="position: relative; min-height: 100vh"> | ||
<div id="root"></div> | ||
</body> | ||
} | ||
</style> | ||
</head> | ||
<body style="position: relative; min-height: 100vh"> | ||
<div id="root"></div> | ||
</body> | ||
</html> |