-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtray.js
71 lines (66 loc) · 3.89 KB
/
tray.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
const { app, Menu, Tray, nativeImage } = require('electron');
const path = require("path")
const config = require('./config');
const prompt = require('electron-prompt');
const { set } = require('./config');
let tray = null;
console.log("tray");
function urlPrompt(win, tray) {
prompt({
title: 'Prompt example',
label: 'URL:',
value: config.get('backgroundUrl'),
inputAttrs: {
type: 'url' // TODO: better validation
},
type: 'input'
})
.then(r => {
if (r === null) {
console.log('user cancelled');
} else {
(async () => {
console.log('result', r);
await win.loadURL(r);
config.set('backgroundUrl', r);
setTray(win, tray);
})();
}
})
.catch(console.error);
}
function setTray(win, tray) {
const contextMenu = Menu.buildFromTemplate([
{ label: win.getTitle(), type: 'normal', enabled: false },
{ label: config.get('backgroundUrl'), type: 'normal', enabled: false },
{ type: 'separator' },
{
label: 'Set URL…', type: 'normal', click() {
urlPrompt(win, tray);
}
},
{ type: 'separator' },
{
label: 'Reload', type: 'normal', click() {
win.reload();
}
},
// { type: 'separator' },
// { label: 'Desktop Background Mode', type: 'normal'/*, checked: true*/, click() { win.type = "desktop"; } },
// { label: 'Browsing Mode', type: 'normal', click() { win.type = "textured"; } },
{ type: 'separator' },
{ role: 'about', label: 'About' },
// { label: 'Preferences…', type: 'normal' },
{ type: 'separator' },
{ role: 'quit' }
]);
tray.setToolTip('Electron Desktop background');
tray.setContextMenu(contextMenu);
}
function createTray(win) {
const icon = nativeImage.createFromDataURL('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAAAAAXNSR0IB2cksfwAAAAlwSFlzAAALEwAACxMBAJqcGAAABN1JREFUeJzFVllsVFUY/u499850ZmgLLW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