@@ -27,6 +27,8 @@ import { save } from '@tauri-apps/plugin-dialog';
2727import { writeTextFile } from '@tauri-apps/plugin-fs' ;
2828import { error } from '@/utils/logging' ;
2929import { waitUntil } from '@/utils/a11y' ;
30+ import { PauseIcon } from '@/components/commons/icon/PauseIcon' ;
31+ import { PlayIcon } from '@/components/commons/icon/PlayIcon' ;
3032
3133export interface SerialForm {
3234 port : string ;
@@ -64,6 +66,8 @@ export function Serial() {
6466 setConsole ( '' ) ;
6567 } ;
6668
69+ const [ isPaused , setPaused ] = useState ( false ) ;
70+
6771 const openSerial = ( port : string ) => {
6872 sendRPCPacket ( RpcMessage . CloseSerialRequest , new CloseSerialRequestT ( ) ) ;
6973 const req = new OpenSerialRequestT ( ) ;
@@ -115,12 +119,35 @@ export function Serial() {
115119 ) ;
116120
117121 useEffect ( ( ) => {
118- if ( consoleRef . current )
119- consoleRef . current . scrollTo ( {
120- top : consoleRef . current . scrollHeight ,
121- } ) ;
122+ if ( isPaused ) {
123+ return ;
124+ }
125+ if ( ! consoleRef . current ) {
126+ return ;
127+ }
128+
129+ consoleRef . current . scrollTo ( {
130+ top : consoleRef . current . scrollHeight ,
131+ } ) ;
122132 } , [ consoleContent ] ) ;
123133
134+ useEffect ( ( ) => {
135+ if ( ! consoleRef . current ) {
136+ return ;
137+ }
138+
139+ consoleRef . current . addEventListener ( 'scroll' , ( ) => {
140+ if ( ! consoleRef . current ) {
141+ return ;
142+ }
143+ setPaused (
144+ consoleRef . current . scrollTop +
145+ consoleRef . current . getBoundingClientRect ( ) . height !==
146+ consoleRef . current . scrollHeight
147+ ) ;
148+ } ) ;
149+ } , [ consoleRef . current ] ) ;
150+
124151 useEffect ( ( ) => {
125152 const id = setInterval ( ( ) => {
126153 if ( ! isSerialOpen ) {
@@ -206,6 +233,14 @@ export function Serial() {
206233 }
207234 } ;
208235
236+ const pauseScroll = ( ) => {
237+ setPaused ( ! isPaused ) ;
238+
239+ consoleRef . current ?. scrollTo ( {
240+ top : consoleRef . current . scrollHeight ,
241+ } ) ;
242+ } ;
243+
209244 return (
210245 < >
211246 < BaseModal
@@ -281,6 +316,19 @@ export function Serial() {
281316 >
282317 { l10n . getString ( 'settings-serial-save_logs' ) }
283318 </ Button >
319+ < div className = "ml-auto" >
320+ < Button
321+ variant = "quaternary"
322+ onClick = { pauseScroll }
323+ icon = {
324+ isPaused ? (
325+ < PlayIcon width = { 16 } />
326+ ) : (
327+ < PauseIcon width = { 16 } />
328+ )
329+ }
330+ > </ Button >
331+ </ div >
284332 < div className = "w-full mobile:col-span-2" >
285333 < Dropdown
286334 control = { control }
0 commit comments