Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default screen logic #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,12 @@ a:not(.button):not(.url):visited {
margin: 0.5rem 1.5rem;
}

.options-grid {
display: grid;
grid-template-columns: 1fr 1fr;
column-gap: 10px;
}

.menu-option:hover:not(.disabled) {
background: var(--input-background);
}
Expand Down
28 changes: 27 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ const showEditor = () => {
quill.focus()
}

loadDefaultScreen = () => {
store.get(['defaultScreen'], (settings) => {
const preset = {
defaultScreen: localStorage.getItem('defaultScreen') || 'default',
...settings
}
if (preset.defaultScreen === 'writing') {
$('#editor-container').classList.remove('hidden')
quill.focus()
}
if (preset.defaultScreen === 'default') {
hideEditor()
}
})
}

const hideEditor = () => {
quill.blur()
$('#editor-container').classList.add('hidden')
Expand Down Expand Up @@ -59,17 +75,19 @@ const setupSettingsDialog = () => {
const devicesInput = $('#settings-devices-input')
const cssTextarea = $('#settings-css-textarea')
const doneButton = $('#settings-done-button')
const defaultScreenInput = $('#settings-default-screen-input')

// keyboard shortcut overrides
const writingModeShortcutInput = $('#settings-writing-mode-shortcut-input')

store.get(['theme', 'mode', 'css', 'favicons', 'timeformat', 'battery', 'connection', 'devices'], (settings) => {
store.get(['theme', 'mode', 'css', 'favicons', 'timeformat', 'defaultScreen', 'battery', 'connection', 'devices'], (settings) => {
let preset = {
mode: localStorage.getItem('mode') || 'system',
theme: localStorage.getItem('theme') || 'smooth-dark',
css: localStorage.getItem('css') || '',
favicons: localStorage.getItem('favicons') || 'hide',
timeformat: localStorage.getItem('timeformat') || '12',
defaultScreen: localStorage.getItem('defaultScreen') || 'default',
battery: localStorage.getItem('battery') || 'show',
connection: localStorage.getItem('connection') || 'show',
devices: localStorage.getItem('devices') || 'show',
Expand Down Expand Up @@ -153,6 +171,12 @@ const setupSettingsDialog = () => {
})
})

defaultScreenInput.addEventListener('change', (ev) => {
store.set({ defaultScreen: ev.target.value }, () => {
localStorage.setItem('defaultScreen', ev.target.value)
})
})

batteryInput.addEventListener('change', (ev) => {
store.set({ battery: ev.target.checked ? 'show' : 'hide' }, () => {
localStorage.setItem('battery', ev.target.checked ? 'show' : 'hide')
Expand All @@ -174,6 +198,7 @@ const setupSettingsDialog = () => {

doneButton.addEventListener('click', () => {
$('.overlay').classList.add('hidden')
loadDefaultScreen()
$('#settings-dialog').classList.add('hidden')
$('#settings-dialog').classList.remove('animate')
})
Expand Down Expand Up @@ -510,6 +535,7 @@ refreshDate()
loadBookmarks()
loadSyncedTabs()
setupSettingsDialog()
loadDefaultScreen()

// refresh the clock
setInterval(refreshDate, 1000)
Expand Down
21 changes: 15 additions & 6 deletions src/new-tab-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,21 @@
<div class="menu-divider" style="margin-bottom: 1rem;"></div>
<details>
<summary>Advanced Settings</summary>
<div class="input-container">
<label for="settings-timeformat-input">Time format</label>
<select id="settings-timeformat-input">
<option value="12">12h</option>
<option value="24">24h</option>
</select>
<div class="options-grid">
<div class="input-container">
<label for="settings-timeformat-input">Time format</label>
<select id="settings-timeformat-input">
<option value="12">12h</option>
<option value="24">24h</option>
</select>
</div>
<div class="input-container">
<label for="settings-default-screen-input">Default screen</label>
<select id="settings-default-screen-input">
<option value="default">Default</option>
<option value="writing">Writing</option>
</select>
</div>
</div>
<div class="input-container">
<label for="settings-writing-mode-shortcut-input">Writing Mode Keyboard Shortcut</label>
Expand Down