Skip to content

Commit

Permalink
Autofill default options without opening settings page
Browse files Browse the repository at this point in the history
Closes #1
  • Loading branch information
pgarrison committed Jan 5, 2024
1 parent 96c80bf commit d229177
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/service-worker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SupportQuery, Supported, TimeCardOptions, TimeCardOptionsMessage } from './time-card'
import defaultSettings from './settings-page/defaultSettings'

function setSupported(isSupported: boolean) {
const icon = isSupported ? 'icons/icon16.png' : 'icons/gray16.png';
Expand All @@ -22,6 +23,7 @@ chrome.runtime.onMessage.addListener((message: Supported) => {

chrome.action.onClicked.addListener((tab) => {
chrome.storage.sync.get().then((settings: TimeCardOptions) => {
settings = Object.assign(settings, defaultSettings);
const options: TimeCardOptionsMessage = { messageType: 'click', ...settings };
chrome.tabs.sendMessage(tab.id, options);
});
Expand Down
5 changes: 5 additions & 0 deletions src/settings-page/defaultSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
projectCode: '103-01-001-10 : Allen Cell Science Activities',
task: 'Default : Default',
expenditureType: 'Regular - Straight Time',
};
8 changes: 3 additions & 5 deletions src/settings-page/settings.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import defaultSettings from "./defaultSettings";

// Saves options to chrome.storage
const saveOptions = () => {
const projectCode = document.getElementById('project-code').value;
Expand All @@ -18,11 +20,7 @@ const saveOptions = () => {
// stored in chrome.storage.
const restoreOptions = () => {
chrome.storage.sync.get(
{
projectCode: '103-01-001-10 : Allen Cell Science Activities',
task: 'Default : Default',
expenditureType: 'Regular - Straight Time',
},
defaultSettings,
(items) => {
document.getElementById('project-code').value = items.projectCode;
document.getElementById('task').value = items.task;
Expand Down

0 comments on commit d229177

Please sign in to comment.