electron#Notification JavaScript Examples
The following examples show how to use
electron#Notification.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.js From desktop with GNU General Public License v3.0 | 6 votes |
configureRPC = win => {
rpc = createRPC(win);
rpc.on("open hamburger menu", () => {
hamburgerMenu.popup();
});
rpc.on("show notification", body => {
const notif = new Notification({
title: "VPN.ht",
body
});
notif.show();
});
rpc.on("set status login", () => {
isLogged = true;
updateHamburgerMenu();
});
rpc.on("set status logout", () => {
isLogged = false;
updateHamburgerMenu();
});
rpc.on("open url", url => {
shell.openExternal(url);
});
}
Example #2
Source File: background.js From linked with GNU General Public License v3.0 | 5 votes |
repairSearchDatabase = async () => {
searchIndex = new Document({
document: {
id: 'date',
index: ['content'],
store: true
},
tokenize: global.storage.get('searchMode')
})
const isYearFolder = (folder) => /\b\d{4}\b/g.test(folder)
const dataPath = global.storage.get('dataPath')
const getYearFolderFiles = (year) =>
fs.promises.readdir(getFilePath(year))
.then((files) => files.map((file) => `${year}/${file}`))
const years =
await fs.promises.readdir(`${dataPath}`)
.then((folders) => folders.filter(isYearFolder))
await Promise.all(years.map(getYearFolderFiles))
.then((yearFiles) => yearFiles.flat())
.then((dirtyFiles) => dirtyFiles.filter(file => file.match(/^(.*\.json$).*$/)))
.then((cleanFiles) =>
cleanFiles.map((file) => {
return {
data: JSON.parse(fs.readFileSync(`${dataPath}/${file}`, "utf8")),
date: file
}
})
)
.then((files) =>
files.forEach((file) => {
let fileName = file.date.substring(5)
fileName = fileName.slice(0, fileName.length-5)
try {
searchIndex.update(fileName, {
date: fileName,
content: tokenizer(file.data.content)
})
} catch (e) {
console.log('could not index day', fileName, file.data.content)
}
})
)
.then(() => exportIndex())
.then(() => {
new Notification({
title: 'Search Index Updated!',
body: 'Your database was successfully indexed! You may now search across all your data.'
}).show()
})
return true
}
Example #3
Source File: background.js From linked with GNU General Public License v3.0 | 5 votes |
ipcMain.handle('SET_DATA_PATH', async () => {
const currentPath = global.storage.get('dataPath')
const result = await dialog.showOpenDialog(win, {
properties: ['openDirectory', 'createDirectory']
})
if (result.canceled === true) {
new Notification({
title: 'Action aborted',
body: 'Your previous settings still apply.'
}).show()
return currentPath
}
const newPath = result.filePaths.length > 0
? result.filePaths[0]
: basePath
searchIndex = new Document({
document: {
id: 'date',
index: ['content'],
store: true
},
tokenize: global.storage.get('searchMode')
})
if ((await fs.promises.readdir(newPath)).length !== 0) {
await dialog.showMessageBox(win, {
message: 'Directory not empty!',
detail: `${newPath} is not empty, please choose another directory or add an empty directory at the desired location first.`,
type: 'error',
buttons: ['Close'],
defaultId: 1,
noLink: true
})
return global.storage.get('dataPath')
}
const fsEx = require('fs-extra')
try {
await fsEx.move(currentPath, newPath, { overwrite: true })
} catch (e) {
await dialog.showMessageBox(win, {
message: 'An error occured!',
detail: e.toString(),
type: 'error',
buttons: ['Close'],
defaultId: 1,
noLink: true
})
return global.storage.get('dataPath')
}
global.storage.set('dataPath', newPath)
await repairSearchDatabase()
new Notification({
title: 'Successfully set new path!',
body: `Your data now is being read from ${newPath}.`
}).show()
return global.storage.get('dataPath')
})
Example #4
Source File: updater.js From linked with GNU General Public License v3.0 | 5 votes |
autoUpdater.on('update-not-available', async () => {
await new Notification({
title: 'No updates',
body: 'You are already on the latest version of linked'
}).show()
})
Example #5
Source File: AlfwCommon.js From ntfstool with MIT License | 5 votes |
/**
* notice the system error
* @param _error
* @param setOption
*/
export function noticeTheSystemError(_error, setOption) {
var errorMap = {
system: 10000,
dialog: 10010,
dialog_save_err: 10011,
savePassword: 10020,
savePassword2: 10021,
getSudoPwdError: 10031,
checkSudoPasswordError: 10041,
opendevmod: 10030,
FEEDBACK_ERROR: 10040,
UNCLEANERROR:10050
};
var error = (typeof _error != "undefined") ? _error : "system";
console.warn(error, "error")
var errorNo = (typeof errorMap[error] != "undefined") ? errorMap[error] : 1000;
var option = {
title: "System Error: " + errorNo,
body: "please contact official technical support",
href: 'https://www.ntfstool.com'
};
if (typeof setOption == "object") {
option = setOption;
}
if (typeof setOption == "string") {
option.body = setOption;
}
saveLog.error({name: _error, text: JSON.stringify(option)}, "noticeTheSystemError");
new window.Notification(option.title, option).onclick = function () {
shell.openExternal(option.href)
}
}