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

feat: allow configuring initial focus #150

Merged
merged 1 commit into from
Jul 6, 2024
Merged
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
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()],
});
Loading