Skip to content

Commit aa3827b

Browse files
committed
set up auto show/hide setting entry
1 parent e959a46 commit aa3827b

File tree

5 files changed

+165
-0
lines changed

5 files changed

+165
-0
lines changed

src/pages/Background/index.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@ const persistdisplayTabInFullStatus = (status) => {
9292
});
9393
};
9494

95+
/**
96+
* Auto Show Hide
97+
*/
98+
let autoShowHide = false;
99+
100+
chrome.storage.sync.get(['autoShowHide'], (result) => {
101+
if (result.autoShowHide !== undefined) {
102+
autoShowHide = result.autoShowHide === true;
103+
} else {
104+
persistAutoShowHideStatus(false); // default to not auto show hide
105+
}
106+
});
107+
108+
const persistAutoShowHideStatus = (status) => {
109+
chrome.storage.sync.set({
110+
autoShowHide: status,
111+
});
112+
};
113+
95114
/**
96115
* Dark Mode
97116
*/
@@ -222,6 +241,23 @@ const updateDisplayTabInFullStatus = (toStatus) => {
222241
);
223242
};
224243

244+
const updateAutoShowHideStatus = (toStatus) => {
245+
chrome.tabs.query(
246+
{
247+
currentWindow: true,
248+
},
249+
function(tabs) {
250+
tabs.forEach((tab) => {
251+
chrome.tabs.sendMessage(tab.id, {
252+
from: 'background',
253+
msg: 'UPDATE_AUTO_SHOW_HIDE_STATUS',
254+
toStatus,
255+
});
256+
});
257+
}
258+
);
259+
};
260+
225261
const updateDarkModeStatus = (toStatus) => {
226262
chrome.tabs.query(
227263
{
@@ -317,6 +353,14 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
317353
displayTabInFull = toStatus;
318354
persistdisplayTabInFullStatus(displayTabInFull);
319355
updateDisplayTabInFullStatus(displayTabInFull);
356+
} else if (
357+
request.from === 'settings' &&
358+
request.msg === 'USER_CHANGE_AUTO_SHOW_HIDE'
359+
) {
360+
const { toStatus } = request;
361+
autoShowHide = toStatus;
362+
persistAutoShowHideStatus(autoShowHide);
363+
updateAutoShowHideStatus(autoShowHide);
320364
} else if (
321365
request.from === 'settings' &&
322366
request.msg === 'USER_CHANGE_DARK_MODE'

src/pages/Content/index.jsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import $ from 'jquery';
12
import React from 'react';
23
import ReactDOM from 'react-dom';
34
import Frame from './modules/frame/frame';
45
import UpdateNotice from './modules/UpdateNotice/UpdateNotice';
56

67
let shouldShrinkBody = true;
78
let sidebarLocation = 'left';
9+
let autoShowHide = false;
810
const toggleButtonLocation = 'bottom';
911
let sidebarWidth = 280;
1012

@@ -126,6 +128,12 @@ chrome.storage.sync.get(['sidebarOnLeft'], (result) => {
126128
mountSidebar();
127129
});
128130

131+
chrome.storage.sync.get(['autoShowHide'], (result) => {
132+
if (result.autoShowHide !== undefined) {
133+
autoShowHide = result.autoShowHide === true;
134+
}
135+
});
136+
129137
const checkSidebarStatus = () => {
130138
chrome.runtime.sendMessage(
131139
{
@@ -164,6 +172,12 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
164172
const { toStatus } = request;
165173
shouldShrinkBody = toStatus;
166174
Frame.shrinkBody();
175+
} else if (
176+
request.from === 'background' &&
177+
request.msg === 'UPDATE_AUTO_SHOW_HIDE_STATUS'
178+
) {
179+
const { toStatus } = request;
180+
autoShowHide = toStatus;
167181
}
168182
});
169183

@@ -181,3 +195,25 @@ window.addEventListener('keydown', (event) => {
181195
});
182196
}
183197
});
198+
199+
const openSidebarUponMouseOverWindowEdge = () => {
200+
chrome.runtime.sendMessage({
201+
from: 'content',
202+
msg: 'REQUEST_OPEN_SIDEBAR_UPON_MOUSE_OVER_WINDOW_EDGE',
203+
});
204+
};
205+
206+
$(document).on('mousemove', (event) => {
207+
// console.log(event.clientX);
208+
const delta = 5;
209+
if (sidebarLocation === 'left' && event.clientX < delta) {
210+
// console.log('reached left side');
211+
openSidebarUponMouseOverWindowEdge();
212+
} else if (
213+
sidebarLocation === 'right' &&
214+
event.clientX > $(document).width() - delta
215+
) {
216+
// console.log('reached right side');
217+
openSidebarUponMouseOverWindowEdge();
218+
}
219+
});

src/pages/Content/modules/frame/frame.jsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,14 @@ export class Frame extends Component {
355355
src={url}
356356
ref={(frame) => (this.frame = frame)}
357357
onLoad={this.onLoad}
358+
onMouseEnter={() => {
359+
// TODO: implement auto show/hide here
360+
console.log('mouse entered');
361+
}}
362+
onMouseLeave={() => {
363+
// TODO: implement auto show/hide here
364+
console.log('mouse left');
365+
}}
358366
></iframe>
359367
</div>
360368
</div>

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from 'react-icons/fa';
1313
import { IoIosBarcode, IoIosMoon, IoIosSunny } from 'react-icons/io';
1414
import { WiMoonAltNew, WiMoonAltWaxingCrescent3 } from 'react-icons/wi';
15+
import { MdFontDownload } from 'react-icons/md';
1516

1617
import './SettingsBox.css';
1718

@@ -22,6 +23,8 @@ const SettingsBox = ({
2223
setSettingSidebarShouldShrinkBody,
2324
settingDisplayTabTitleInFull,
2425
setSettingDisplayTabTitleInFull,
26+
settingAutoShowHide,
27+
setSettingAutoShowHide,
2528
settingDarkMode,
2629
setSettingDarkMode,
2730
}) => {
@@ -184,6 +187,49 @@ const SettingsBox = ({
184187
</form>
185188
</div>
186189

190+
{divider}
191+
{/* AUTO SHOW HIDE SIDEBAR */}
192+
<div className="SettingEntryContainer">
193+
<div className="SettingEntryTitle">
194+
<MdFontDownload className="SettingEntryTitleIcon" />
195+
Auto show/hide sidebar:
196+
</div>
197+
<form className="SettingEntryContent">
198+
<div style={{ display: 'flex', alignItems: 'center' }}>
199+
<label
200+
className={classNames({
201+
Active: settingAutoShowHide,
202+
Dark: isDark,
203+
})}
204+
>
205+
<input
206+
type="radio"
207+
checked={settingAutoShowHide}
208+
onChange={() => setSettingAutoShowHide(true)}
209+
name="radio"
210+
/>
211+
<FaCheck className="SettingEntryOptionIcon" />
212+
Yes
213+
</label>
214+
<label
215+
className={classNames({
216+
Active: !settingAutoShowHide,
217+
Dark: isDark,
218+
})}
219+
>
220+
<input
221+
type="radio"
222+
checked={!settingAutoShowHide}
223+
onChange={() => setSettingAutoShowHide(false)}
224+
name="radio"
225+
/>
226+
<FaTimes className="SettingEntryOptionIcon" />
227+
No
228+
</label>
229+
</div>
230+
</form>
231+
</div>
232+
187233
{divider}
188234
{/* DARK THEME */}
189235
<div className="SettingEntryContainer">

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Title extends Component {
2323
settingSidebarLocation: 'left',
2424
settingSidebarShouldShrinkBody: true,
2525
settingDisplayTabTitleInFull: true,
26+
settingAutoShowHide: false,
2627
settingDarkMode: 'auto',
2728
};
2829

@@ -54,6 +55,14 @@ class Title extends Component {
5455
}
5556
});
5657

58+
chrome.storage.sync.get(['autoShowHide'], (result) => {
59+
if (result.autoShowHide !== undefined) {
60+
this.setState({
61+
settingAutoShowHide: result.autoShowHide === true,
62+
});
63+
}
64+
});
65+
5766
chrome.storage.sync.get(['darkMode'], (result) => {
5867
if (result.darkMode !== undefined) {
5968
this.setState({
@@ -89,6 +98,12 @@ class Title extends Component {
8998
) {
9099
const { toStatus } = request;
91100
this.setState({ settingSidebarShouldShrinkBody: toStatus === true });
101+
} else if (
102+
request.from === 'background' &&
103+
request.msg === 'UPDATE_AUTO_SHOW_HIDE_STATUS'
104+
) {
105+
const { toStatus } = request;
106+
this.setState({ settingAutoShowHide: toStatus === true });
92107
} else if (
93108
request.from === 'background' &&
94109
request.msg === 'UPDATE_DARK_MODE_STATUS'
@@ -146,6 +161,19 @@ class Title extends Component {
146161
});
147162
};
148163

164+
setSettingAutoHideShow = (toStatus) => {
165+
if (toStatus === this.state.settingAutoShowHide) {
166+
return;
167+
}
168+
169+
this.setState({ settingAutoShowHide: toStatus });
170+
chrome.runtime.sendMessage({
171+
from: 'settings',
172+
msg: 'USER_CHANGE_AUTO_SHOW_HIDE',
173+
toStatus,
174+
});
175+
};
176+
149177
static contextType = DarkModeContext;
150178

151179
setSettingDarkMode = (toStatus) => {
@@ -174,6 +202,7 @@ class Title extends Component {
174202
settingSidebarLocation,
175203
settingSidebarShouldShrinkBody,
176204
settingDisplayTabTitleInFull,
205+
settingAutoShowHide,
177206
settingDarkMode,
178207
} = this.state;
179208

@@ -231,6 +260,8 @@ class Title extends Component {
231260
setSettingDisplayTabTitleInFull={
232261
this.setSettingDisplayTabTitleInFull
233262
}
263+
settingAutoShowHide={settingAutoShowHide}
264+
setSettingAutoShowHide={this.setSettingAutoHideShow}
234265
settingDarkMode={settingDarkMode}
235266
setSettingDarkMode={this.setSettingDarkMode}
236267
/>

0 commit comments

Comments
 (0)