diff --git a/src/service-worker.ts b/src/service-worker.ts index de966f8..c9c11f2 100644 --- a/src/service-worker.ts +++ b/src/service-worker.ts @@ -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'; @@ -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); }); diff --git a/src/settings-page/defaultSettings.ts b/src/settings-page/defaultSettings.ts new file mode 100644 index 0000000..5579056 --- /dev/null +++ b/src/settings-page/defaultSettings.ts @@ -0,0 +1,5 @@ +export default { + projectCode: '103-01-001-10 : Allen Cell Science Activities', + task: 'Default : Default', + expenditureType: 'Regular - Straight Time', +}; \ No newline at end of file diff --git a/src/settings-page/settings.js b/src/settings-page/settings.js index 63ac5bc..3164c5d 100644 --- a/src/settings-page/settings.js +++ b/src/settings-page/settings.js @@ -1,3 +1,5 @@ +import defaultSettings from "./defaultSettings"; + // Saves options to chrome.storage const saveOptions = () => { const projectCode = document.getElementById('project-code').value; @@ -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;