concept default in category electron
appears as: default, default, defaults, defaults

This is an excerpt from Manning's book Electron in Action.
Listing 2. Fire Sale’s renderer process: ./app/renderer.js
const { remote, ipcRenderer } = require('electron'); const path = require('path'); const mainProcess = remote.require('./main.js'); const currentWindow = remote.getCurrentWindow(); const marked = require('marked'); const markdownView = document.querySelector('#markdown'); const htmlView = document.querySelector('#html'); const newFileButton = document.querySelector('#new-file'); const openFileButton = document.querySelector('#open-file'); const saveMarkdownButton = document.querySelector('#save-markdown'); const revertButton = document.querySelector('#revert'); const saveHtmlButton = document.querySelector('#save-html'); const showFileButton = document.querySelector('#show-file'); const openInDefaultButton = document.querySelector('#open-in-default'); let filePath = null; let originalContent = ''; const isDifferentContent = (content) => content !== markdownView.value; const renderMarkdownToHtml = (markdown) => { htmlView.innerHTML = marked(markdown, { sanitize: true }); }; const renderFile = (file, content) => { filePath = file; originalContent = content; markdownView.value = content; renderMarkdownToHtml(content); updateUserInterface(false); }; const updateUserInterface = (isEdited) => { let title = 'Fire Sale'; if (filePath) { title = `${path.basename(filePath)} - ${title}`; } if (isEdited) { title = `${title} (Edited)`; } currentWindow.setTitle(title); currentWindow.setDocumentEdited(isEdited); saveMarkdownButton.disabled = !isEdited; revertButton.disabled = !isEdited; }; markdownView.addEventListener('keyup', (event) => { const currentContent = event.target.value; renderMarkdownToHtml(currentContent); updateUserInterface(currentContent !== originalContent); }); newFileButton.addEventListener('click', () => { mainProcess.createWindow(); }); openFileButton.addEventListener('click', () => { mainProcess.getFileFromUser(currentWindow); }); saveMarkdownButton.addEventListener('click', () => { mainProcess.saveMarkdown(currentWindow, filePath, markdownView.value); }); revertButton.addEventListener('click', () => { markdownView.value = originalContent; renderMarkdownToHtml(originalContent); }); saveHtmlButton.addEventListener('click', () => { mainProcess.saveHtml(currentWindow, htmlView.innerHTML); }); ipcRenderer.on('file-opened', (event, file, content) => { if (currentWindow.isDocumentEdited() && isDifferentContent(content)) { const result = remote.dialog.showMessageBox(currentWindow, { type: 'warning', title: 'Overwrite Current Unsaved Changes?', message: 'Opening a new file in this window will overwrite your unsaved changes. Open this file anyway?', buttons: [ 'Yes', 'Cancel', ], defaultId: 0, cancelId: 1, }); if (result === 1) { return; } } renderFile(file, content); }); ipcRenderer.on('file-changed', (event, file, content) => { if (isDifferentContent(content)) return; const result = remote.dialog.showMessageBox(currentWindow, { type: 'warning', title: 'Overwrite Current Unsaved Changes?', message: 'Another application has changed this file. Load changes?', buttons: [ 'Yes', 'Cancel', ], defaultId: 0, cancelId: 1 }); renderFile(file, content); }); /* Implement Drag and Drop */ document.addEventListener('dragstart', event => event.preventDefault()); document.addEventListener('dragover', event => event.preventDefault()); document.addEventListener('dragleave', event => event.preventDefault()); document.addEventListener('drop', event => event.preventDefault()); const getDraggedFile = (event) => event.dataTransfer.items[0]; const getDroppedFile = (event) => event.dataTransfer.files[0]; const fileTypeIsSupported = (file) => { return ['text/plain', 'text/markdown'].includes(file.type); }; markdownView.addEventListener('dragover', (event) => { const file = getDraggedFile(event); if (fileTypeIsSupported(file)) { markdownView.classList.add('drag-over'); } else { markdownView.classList.add('drag-error'); } }); markdownView.addEventListener('dragleave', () => { markdownView.classList.remove('drag-over'); markdownView.classList.remove('drag-error'); }); markdownView.addEventListener('drop', (event) => { const file = getDroppedFile(event); if (fileTypeIsSupported(file)) { mainProcess.openFile(currentWindow, file.path); } else { alert('That file type is not supported'); } markdownView.classList.remove('drag-over'); markdownView.classList.remove('drag-error'); });
By default, the application’s window displays the title of the HTML page, which is defined in app/index.html. This is a reasonable default, but many native desktop applications display the name or path of the current file. One approach is to update the title of the window whenever the user opens a new file. In addition to displaying the name of the currently open file (as in listing 6.3), we may want to display other information in the window’s title such as whether the current file has been edited since it was saved. We also need to update the window’s title for a few different contexts, such as editing and saving the file.
By default, Electron windows display the contents of the HTML documents’ <title> tag. The setTitle() method on all BrowserWindow instances allows users to update and customize a window’s title based on the state of the application.