Add logs to help debugging and bug reporting

This commit is contained in:
Alice Gaudon 2020-01-04 15:56:37 +01:00
parent 8e7e78b2df
commit 5143d5f8e9
2 changed files with 18 additions and 1 deletions

View File

@ -36,7 +36,9 @@ export default class Config {
} }
save() { save() {
console.log('Saving config');
this.services = this.services.filter(s => s !== null); this.services = this.services.filter(s => s !== null);
fs.writeFileSync(configFile, JSON.stringify(this, null, 4)); fs.writeFileSync(configFile, JSON.stringify(this, null, 4));
console.log('> Config saved');
} }
} }

View File

@ -25,8 +25,10 @@ let serviceSettingsWindow;
function toggleMainWindow() { function toggleMainWindow() {
if (window != null) { if (window != null) {
if (!window.isFocused()) { if (!window.isFocused()) {
console.log('Showing main window');
window.show(); window.show();
} else { } else {
console.log('Hiding main window');
window.hide(); window.hide();
} }
} }
@ -34,6 +36,7 @@ function toggleMainWindow() {
function createWindow() { function createWindow() {
// System tray // System tray
console.log('Loading system Tray');
tray = new Tray(iconPath); tray = new Tray(iconPath);
tray.setToolTip('Tabs'); tray.setToolTip('Tabs');
tray.setContextMenu(Menu.buildFromTemplate([ tray.setContextMenu(Menu.buildFromTemplate([
@ -45,6 +48,7 @@ function createWindow() {
tray.on('click', () => toggleMainWindow()); tray.on('click', () => toggleMainWindow());
// Create the browser window. // Create the browser window.
console.log('Creating main window');
window = new BrowserWindow({ window = new BrowserWindow({
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
@ -68,6 +72,7 @@ function createWindow() {
// Open external links in default OS browser // Open external links in default OS browser
app.on('web-contents-created', (e, contents) => { app.on('web-contents-created', (e, contents) => {
if (contents.getType() === 'webview') { if (contents.getType() === 'webview') {
console.log('Setting external links to open in default OS browser');
contents.on('new-window', (e, url) => { contents.on('new-window', (e, url) => {
e.preventDefault(); e.preventDefault();
shell.openExternal(url); shell.openExternal(url);
@ -75,7 +80,7 @@ function createWindow() {
} }
}); });
// Sync services with navigation // Sync data
window.webContents.on('dom-ready', sendData); window.webContents.on('dom-ready', sendData);
// Load navigation view // Load navigation view
@ -89,6 +94,7 @@ function createWindow() {
// Set a service's favicon // Set a service's favicon
ipcMain.on('setServiceFavicon', (event, index, favicon) => { ipcMain.on('setServiceFavicon', (event, index, favicon) => {
console.log('Setting service', index, 'favicon', favicon);
config.services[index].favicon = favicon; config.services[index].favicon = favicon;
config.save(); config.save();
}); });
@ -96,6 +102,7 @@ function createWindow() {
// Open add service window // Open add service window
ipcMain.on('openServiceSettings', (e, serviceId) => { ipcMain.on('openServiceSettings', (e, serviceId) => {
if (!serviceSettingsWindow) { if (!serviceSettingsWindow) {
console.log('Opening service settings', serviceId);
serviceSettingsWindow = new BrowserWindow({ serviceSettingsWindow = new BrowserWindow({
webPreferences: { webPreferences: {
nodeIntegration: true, nodeIntegration: true,
@ -125,6 +132,7 @@ function createWindow() {
}); });
ipcMain.on('saveService', (e, id, data) => { ipcMain.on('saveService', (e, id, data) => {
console.log('Saving service', id, data);
const newService = new Service(data); const newService = new Service(data);
if (typeof id === 'number') { if (typeof id === 'number') {
config.services[id] = newService; config.services[id] = newService;
@ -137,22 +145,28 @@ function createWindow() {
}); });
ipcMain.on('deleteService', (e, id) => { ipcMain.on('deleteService', (e, id) => {
console.log('Deleting service', id);
delete config.services[id]; delete config.services[id];
config.save(); config.save();
window.webContents.send('deleteService', id); window.webContents.send('deleteService', id);
}); });
console.log('> App started');
} }
function sendData() { function sendData() {
console.log('Syncing data');
window.webContents.send('data', brandIcons, solidIcons, config.services, selectedService); window.webContents.send('data', brandIcons, solidIcons, config.services, selectedService);
} }
function setActiveService(index) { function setActiveService(index) {
console.log('Selected service is now', index);
selectedService = index; selectedService = index;
} }
function listIcons(set) { function listIcons(set) {
console.log('Loading icon set', set);
const directory = path.resolve(resourcesDir, 'icons/' + set); const directory = path.resolve(resourcesDir, 'icons/' + set);
const icons = []; const icons = [];
const dir = set === 'brands' ? 'fab' : 'fas'; const dir = set === 'brands' ? 'fab' : 'fas';
@ -163,4 +177,5 @@ function listIcons(set) {
return icons; return icons;
} }
console.log('Starting app');
app.on('ready', createWindow); app.on('ready', createWindow);