-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adapting code to make holidays work even though we use esm
- Loading branch information
1 parent
2bbe9fc
commit a3b36ca
Showing
6 changed files
with
157 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,75 @@ | ||
'use strict'; | ||
|
||
// This file intentionally uses 'require' and is used without esm | ||
// because 'date-holidays' doesn't play nice with esm | ||
|
||
const { ipcMain } = require('electron'); | ||
|
||
const Store = require('electron-store'); | ||
const waiverStore = new Store({name: 'waived-workdays'}); | ||
|
||
function getWaiverStore() | ||
const Holidays = require('date-holidays'); | ||
const hd = new Holidays(); | ||
|
||
// Waiver Store handlers | ||
|
||
ipcMain.handle('GET_WAIVER_STORE_CONTENTS', () => | ||
{ | ||
return waiverStore.store; | ||
} | ||
}); | ||
|
||
function setupWorkdayWaiverStore() | ||
ipcMain.handle('SET_WAIVER', (_event, key, contents) => | ||
{ | ||
ipcMain.handle('GET_WAIVER_STORE_CONTENTS', () => | ||
{ | ||
return getWaiverStore(); | ||
}); | ||
waiverStore.set(key, contents); | ||
return true; | ||
}); | ||
|
||
ipcMain.handle('SET_WAIVER', (event, key, contents) => | ||
{ | ||
waiverStore.set(key, contents); | ||
return true; | ||
}); | ||
ipcMain.handle('HAS_WAIVER', (_event, key) => | ||
{ | ||
return waiverStore.has(key); | ||
}); | ||
|
||
ipcMain.handle('HAS_WAIVER', (event, key) => | ||
{ | ||
return waiverStore.has(key); | ||
}); | ||
ipcMain.handle('DELETE_WAIVER', (_event, key) => | ||
{ | ||
waiverStore.delete(key); | ||
return true; | ||
}); | ||
|
||
// Holiday handlers | ||
|
||
ipcMain.handle('DELETE_WAIVER', (event, key) => | ||
function InitHolidays(country, state, city) | ||
{ | ||
if (state !== undefined && city !== undefined) | ||
{ | ||
hd.init(country, state, city); | ||
} | ||
else if (state !== undefined && state !== '--' ) | ||
{ | ||
hd.init(country, state); | ||
} | ||
else | ||
{ | ||
waiverStore.delete(key); | ||
return true; | ||
}); | ||
hd.init(country); | ||
} | ||
} | ||
|
||
export { | ||
setupWorkdayWaiverStore | ||
}; | ||
ipcMain.handle('GET_HOLIDAYS', (_event, country, state, city, year) => | ||
{ | ||
InitHolidays(country, state, city); | ||
return hd.getHolidays(year); | ||
}); | ||
|
||
ipcMain.handle('GET_COUNTRIES', () => | ||
{ | ||
return hd.getCountries(); | ||
}); | ||
|
||
ipcMain.handle('GET_STATES', (_event, country) => | ||
{ | ||
return hd.getStates(country); | ||
}); | ||
|
||
ipcMain.handle('GET_REGIONS', (_event, country, state) => | ||
{ | ||
return hd.getRegions(country, state); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.