Skip to content

Commit f5ddb31

Browse files
committed
customizable show/hide delay
1 parent ab411fe commit f5ddb31

File tree

5 files changed

+142
-9
lines changed

5 files changed

+142
-9
lines changed

src/pages/Background/index.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,22 @@ const persistAutoShowHideStatus = (status) => {
111111
});
112112
};
113113

114+
let autoShowHideDelay = 500;
115+
116+
chrome.storage.sync.get(['autoShowHideDelay'], (result) => {
117+
if (result.autoShowHideDelay !== undefined) {
118+
autoShowHideDelay = result.autoShowHideDelay;
119+
} else {
120+
persistAutoShowHideDelayStatus(500); // default to be 500 ms
121+
}
122+
});
123+
124+
const persistAutoShowHideDelayStatus = (status) => {
125+
chrome.storage.sync.set({
126+
autoShowHideDelay: status,
127+
});
128+
};
129+
114130
/**
115131
* Dark Mode
116132
*/
@@ -258,6 +274,23 @@ const updateAutoShowHideStatus = (toStatus) => {
258274
);
259275
};
260276

277+
const updateAutoShowHideDelayStatus = (toStatus) => {
278+
chrome.tabs.query(
279+
{
280+
currentWindow: true,
281+
},
282+
function(tabs) {
283+
tabs.forEach((tab) => {
284+
chrome.tabs.sendMessage(tab.id, {
285+
from: 'background',
286+
msg: 'UPDATE_AUTO_SHOW_HIDE_DELAY_STATUS',
287+
toStatus,
288+
});
289+
});
290+
}
291+
);
292+
};
293+
261294
const updateDarkModeStatus = (toStatus) => {
262295
chrome.tabs.query(
263296
{
@@ -361,6 +394,14 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
361394
autoShowHide = toStatus;
362395
persistAutoShowHideStatus(autoShowHide);
363396
updateAutoShowHideStatus(autoShowHide);
397+
} else if (
398+
request.from === 'settings' &&
399+
request.msg === 'USER_CHANGE_AUTO_SHOW_HIDE_DELAY'
400+
) {
401+
const { toStatus } = request;
402+
autoShowHideDelay = toStatus;
403+
persistAutoShowHideDelayStatus(autoShowHideDelay);
404+
updateAutoShowHideDelayStatus(autoShowHideDelay);
364405
} else if (
365406
request.from === 'settings' &&
366407
request.msg === 'USER_CHANGE_DARK_MODE'

src/pages/Content/index.jsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { SIDEBAR_CONTAINER_ID } from '../../shared/constants';
88
let shouldShrinkBody = true;
99
let sidebarLocation = 'left';
1010
let autoShowHide = false;
11+
let autoShowHideDelay = 500;
1112
const toggleButtonLocation = 'bottom';
1213
let sidebarWidth = 280;
1314

@@ -140,6 +141,12 @@ chrome.storage.sync.get(['autoShowHide'], (result) => {
140141
}
141142
});
142143

144+
chrome.storage.sync.get(['autoShowHideDelay'], (result) => {
145+
if (result.autoShowHideDelay !== undefined) {
146+
autoShowHideDelay = result.autoShowHideDelay;
147+
}
148+
});
149+
143150
const checkSidebarStatus = () => {
144151
chrome.runtime.sendMessage(
145152
{
@@ -185,27 +192,27 @@ const mouseEnteredSidebarHandler = (event) => {
185192
if (isToggledOpenGloballyFromBackground === true) {
186193
return;
187194
}
188-
console.log('mouse entered');
195+
// console.log('mouse entered');
189196
clearTimeout(mouseLeftSidebarTimer);
190197
};
191198

192199
const mouseLeftSidebarHandler = (event) => {
193200
if (isToggledOpenGloballyFromBackground === true) {
194201
return;
195202
}
196-
console.log('mouse left');
203+
// console.log('mouse left');
197204
mouseLeftSidebarTimer = setTimeout(() => {
198205
if (Frame.isReady()) {
199206
Frame.toggle(false);
200207
}
201-
}, 500);
208+
}, autoShowHideDelay);
202209
};
203210

204211
const focusOffSidebarHandler = (event) => {
205212
if (isToggledOpenGloballyFromBackground === true) {
206213
return;
207214
}
208-
console.log('mouse left');
215+
// console.log('mouse left');
209216
if (Frame.isReady()) {
210217
Frame.toggle(false);
211218
}
@@ -308,6 +315,12 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
308315
} else {
309316
unmountAutoShowHideListener();
310317
}
318+
} else if (
319+
request.from === 'background' &&
320+
request.msg === 'UPDATE_AUTO_SHOW_HIDE_DELAY_STATUS'
321+
) {
322+
const { toStatus } = request;
323+
autoShowHideDelay = toStatus;
311324
}
312325
});
313326

src/pages/Sidebar/containers/Title/SettingsBox/SettingsBox.css

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,20 @@
7878
}
7979

8080
.PopoverContent .SettingEntryContent label {
81-
flex: 0;
82-
margin-right: 8px;
81+
/* flex: 0; */
82+
margin-right: 3px;
8383
display: flex;
8484
align-items: center;
8585
cursor: pointer;
86-
padding: 4px 6px;
86+
padding: 3px 3px;
8787

8888
transition: all 0.1s ease-in;
8989
}
9090

91+
.PopoverContent .SettingEntryContent label:last-child {
92+
margin-right: 0px;
93+
}
94+
9195
.PopoverContent .SettingEntryContent label:hover,
9296
.PopoverContent .SettingEntryContent label.Active {
9397
background-color: #f2f0f0;
@@ -116,3 +120,27 @@
116120
margin-right: 6px;
117121
flex-shrink: 0;
118122
}
123+
124+
.PopoverContent .SettingEntryContent label .AdditionalSettingItemContainer {
125+
margin-left: 4px;
126+
}
127+
128+
.PopoverContent
129+
.SettingEntryContent
130+
label
131+
.AdditionalSettingItemContainer
132+
input {
133+
width: 35px;
134+
margin: 0px 0px 0px 2px;
135+
}
136+
137+
.PopoverContent
138+
.SettingEntryContent
139+
label
140+
.AdditionalSettingItemContainer
141+
input:focus {
142+
outline: none;
143+
}
144+
145+
input.MillSecondsInput {
146+
}

src/pages/Sidebar/containers/Title/SettingsBox/SettingsBox.jsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const SettingsBox = ({
2525
setSettingDisplayTabTitleInFull,
2626
settingAutoShowHide,
2727
setSettingAutoShowHide,
28+
settingAutoShowHideDelay,
29+
setSettingAutoShowHideDelay,
2830
settingDarkMode,
2931
setSettingDarkMode,
3032
}) => {
@@ -209,7 +211,22 @@ const SettingsBox = ({
209211
name="radio"
210212
/>
211213
<FaCheck className="SettingEntryOptionIcon" />
212-
Yes
214+
Yes{' '}
215+
<div className="AdditionalSettingItemContainer">
216+
(hide in
217+
<input
218+
disabled={!settingAutoShowHide}
219+
type="number"
220+
min="0"
221+
className="MillSecondsInput"
222+
placeholder={500}
223+
value={settingAutoShowHideDelay}
224+
onChange={(e) => {
225+
setSettingAutoShowHideDelay(e.target.value);
226+
}}
227+
/>{' '}
228+
ms)
229+
</div>
213230
</label>
214231
<label
215232
className={classNames({

src/pages/Sidebar/containers/Title/Title.jsx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ import DarkModeContext from '../../context/dark-mode-context';
1717
class Title extends Component {
1818
state = {
1919
sidebarOnLeft: null,
20-
isSettingsPopoverOpen: false,
20+
isSettingsPopoverOpen: true,
2121

2222
// settings
2323
settingSidebarLocation: 'left',
2424
settingSidebarShouldShrinkBody: true,
2525
settingDisplayTabTitleInFull: true,
2626
settingAutoShowHide: false,
27+
settingAutoShowHideDelay: 500,
2728
settingDarkMode: 'auto',
2829
};
2930

@@ -63,6 +64,15 @@ class Title extends Component {
6364
}
6465
});
6566

67+
chrome.storage.sync.get(['autoShowHideDelay'], (result) => {
68+
if (result.autoShowHideDelay !== undefined) {
69+
console.log(result.autoShowHideDelay);
70+
this.setState({
71+
settingAutoShowHideDelay: result.autoShowHideDelay,
72+
});
73+
}
74+
});
75+
6676
chrome.storage.sync.get(['darkMode'], (result) => {
6777
if (result.darkMode !== undefined) {
6878
this.setState({
@@ -104,6 +114,12 @@ class Title extends Component {
104114
) {
105115
const { toStatus } = request;
106116
this.setState({ settingAutoShowHide: toStatus === true });
117+
} else if (
118+
request.from === 'background' &&
119+
request.msg === 'UPDATE_AUTO_SHOW_HIDE_DELAY_STATUS'
120+
) {
121+
const { toStatus } = request;
122+
this.setState({ settingAutoShowHideDelay: toStatus });
107123
} else if (
108124
request.from === 'background' &&
109125
request.msg === 'UPDATE_DARK_MODE_STATUS'
@@ -174,6 +190,19 @@ class Title extends Component {
174190
});
175191
};
176192

193+
setSettingAutoShowHideDelay = (toStatus) => {
194+
if (toStatus === this.state.settingAutoShowHideDelay) {
195+
return;
196+
}
197+
198+
this.setState({ settingAutoShowHideDelay: toStatus });
199+
chrome.runtime.sendMessage({
200+
from: 'settings',
201+
msg: 'USER_CHANGE_AUTO_SHOW_HIDE_DELAY',
202+
toStatus,
203+
});
204+
};
205+
177206
static contextType = DarkModeContext;
178207

179208
setSettingDarkMode = (toStatus) => {
@@ -203,6 +232,7 @@ class Title extends Component {
203232
settingSidebarShouldShrinkBody,
204233
settingDisplayTabTitleInFull,
205234
settingAutoShowHide,
235+
settingAutoShowHideDelay,
206236
settingDarkMode,
207237
} = this.state;
208238

@@ -262,6 +292,10 @@ class Title extends Component {
262292
}
263293
settingAutoShowHide={settingAutoShowHide}
264294
setSettingAutoShowHide={this.setSettingAutoHideShow}
295+
settingAutoShowHideDelay={settingAutoShowHideDelay}
296+
setSettingAutoShowHideDelay={
297+
this.setSettingAutoShowHideDelay
298+
}
265299
settingDarkMode={settingDarkMode}
266300
setSettingDarkMode={this.setSettingDarkMode}
267301
/>

0 commit comments

Comments
 (0)