Skip to content

Commit

Permalink
feat: allow configuring initial focus
Browse files Browse the repository at this point in the history
  • Loading branch information
YurySolovyov committed Jul 6, 2024
1 parent 3d69501 commit 127d049
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 11 deletions.
5 changes: 4 additions & 1 deletion src/backend/defaults-installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const defaults = [{
}, {
key: 'initialComponent',
value: 'my'
}, {
key: 'initialFocus',
value: 'bookmarks'
}, {
key: 'tiles',
value: []
Expand All @@ -29,7 +32,7 @@ const installIfNeeded = (settings, item) => {
if (value[item.key] !== undefined) {
return;
}

return settings.set(item.key, item.value);
});
};
Expand Down
4 changes: 2 additions & 2 deletions src/backend/tab-opener.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ export default (url, callback) => {
} else {
chrome.tabs.create({ url: url });
}

if (typeof callback === 'function') {
callback();
}
});

return true;
};
17 changes: 13 additions & 4 deletions src/frontend/components/SearchField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import messageService from '../message-service';
import { mapState, mapGetters } from 'vuex';
const state = mapState(['inputValue']);
const getters = mapGetters(['selectedBookmark', 'openNew']);
const getters = mapGetters(['selectedBookmark', 'openNew', 'initialFocus']);
export default {
computed: { ...getters, ...state },
Expand Down Expand Up @@ -48,11 +48,20 @@ export default {
},
onFocus() {
this.$el.querySelector('input').focus();
}
},
},
mounted() {
this.onFocus();
window.onfocus = () => this.onFocus();
const search = new URLSearchParams(window.location.search);
if (this.initialFocus === 'bookmarks') {
if (search.get('bookmarks') === null) {
window.location.search = '?bookmarks';
} else {
this.onFocus();
}
}
window.addEventListener('focus', () => this.onFocus());
messageService.on('focus', () => this.onFocus());
}
};
Expand Down
11 changes: 10 additions & 1 deletion src/frontend/components/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@
:values="['recent', 'my']"
:value-labels="['Recent Bookmarks', 'My Bookmarks']" />

<settings-section
title="On New tab open"
@save="saveSetting"
name="initialFocus"
:active-value="initialFocus"
:values="['url', 'bookmarks']"
:value-labels="['Browser URL', 'Bookmarks Filter']" />

<settings-section
title="Open In The New Tab"
@save="saveSetting"
Expand Down Expand Up @@ -79,7 +87,8 @@ const getters = mapGetters([
'openNew',
'showChromeUrls',
'accent',
'initialComponent'
'initialComponent',
'initialFocus'
]);
const state = mapState(['theme']);
Expand Down
3 changes: 3 additions & 0 deletions src/frontend/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ const store = createStore({
initialComponent(state) {
return state.settings.initialComponent;
},
initialFocus(state) {
return state.settings.initialFocus;
},
shouldDisplayBookmarksList(state, getters) {
return getters.showRecent || getters.hasInputValue;
},
Expand Down
6 changes: 3 additions & 3 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ export default defineConfig({
rollupOptions: {
input: {
main: './src/frontend/main.js',
background: '/src/backend/background.js'
background: './src/backend/background.js',
},
output: {
entryFileNames: 'scripts/[name].js',
assetFileNames: 'assets/[name].[ext]',
}
},
},
sourcemap: process.env.CI === undefined,
},

plugins: [vue()],
});

0 comments on commit 127d049

Please sign in to comment.