Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Christophe HAMERLING
committed
Feb 26, 2019
1 parent
2714d76
commit da01046
Showing
6 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import Notification from "@/services/notification"; | ||
|
||
export default { | ||
init | ||
}; | ||
|
||
function init(store) { | ||
Notification.enable() | ||
.then(status => { | ||
store.dispatch("setNotificationEnabled", status); | ||
}) | ||
.catch(err => { | ||
console.log(err); | ||
store.dispatch("setNotificationEnabled", false); | ||
}); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import Notify from "notifyjs"; | ||
|
||
export default { | ||
notify, | ||
enable, | ||
isSupported: Notify.isSupported | ||
}; | ||
|
||
function notify(type, title, options = {}) { | ||
isEnabled(type) | ||
.then(() => doNotify()) | ||
.catch(err => console.warn(err)); | ||
|
||
function doNotify() { | ||
new Notify(title, options).show(); | ||
} | ||
} | ||
|
||
function isEnabled() { | ||
// TODO: Check if yhe type is allowed to notify | ||
return enable(); | ||
} | ||
|
||
function enable() { | ||
return new Promise((resolve, reject) => { | ||
if (!Notify.needsPermission) { | ||
return resolve(true); | ||
} | ||
|
||
if (Notify.isSupported()) { | ||
Notify.requestPermission( | ||
() => resolve(true), | ||
() => reject(new Error("You denied permission to display notifications")) | ||
); | ||
} else { | ||
reject(new Error("Notification are not supported by your browser")); | ||
} | ||
}); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const state = { | ||
enabled: false // global notification state | ||
}; | ||
|
||
const getters = {}; | ||
|
||
const actions = { | ||
setNotificationEnabled({ commit }, value) { | ||
commit("setEnabled", value); | ||
} | ||
}; | ||
|
||
const mutations = { | ||
setEnabled(state, value) { | ||
state.enabled = value; | ||
} | ||
}; | ||
|
||
export default { | ||
namespaced: false, | ||
state, | ||
getters, | ||
actions, | ||
mutations | ||
}; |