Skip to content

Instantly share code, notes, and snippets.

@erickzhao
Last active March 27, 2021 04:59
Show Gist options
  • Select an option

  • Save erickzhao/c138356bf637ac8f35c54c1e546d43f7 to your computer and use it in GitHub Desktop.

Select an option

Save erickzhao/c138356bf637ac8f35c54c1e546d43f7 to your computer and use it in GitHub Desktop.
sadapple
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!-- <meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'self' file://* 'unsafe-inline'; script-src 'self' file://* 'unsafe-inline' 'unsafe-eval'" /> -->
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Text App</title>
<script src="renderer.js" type="application/javascript" charset="UTF-8"></script>
</head>
<body>
<div class="window">
<header class="toolbar toolbar-header">
<!-- <h1 class="title">Photon</h1> -->
<div class="toolbar-actions">
<div class="btn-group">
<button class="btn btn-default" id="increase-font"><span class="icon icon-plus"></span></button>
<button class="btn btn-default" id="decrease-font"><span class="icon icon-minus"></span></button>
</div>
<button class="btn btn-default pull-right" id="save"><span class="icon icon-download"></span>&nbsp; Save</button>
</div>
</header>
<div class="window-content">
<textarea id="text-area"></textarea>
</div>
</div>
</body>
</html>
const electron = require('electron');
const {app, BrowserWindow, ipcMain} = electron;
const path = require('path');
let window = null;
app.on('ready', () => {
window = new BrowserWindow({
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
enableRemoteModule: false,
allowRunningInsecureContent: false,
experimentalFeatures: false,
preload: path.join(__dirname, "preload.js")
}
});
window.loadFile('index.html')
.then(() => {})
.catch(err => console.log(err));
});
ipcMain.on('save', (event,text) => {
setTimeout(()=>{
event.sender.send('store-data', text);
}, 1000)
});
const {contextBridge,ipcRenderer} = require('electron');
contextBridge.exposeInMainWorld('electron', {
saveToElectron: (text) => ipcRenderer.send('save', text),
storeData: (channel, func) => {
ipcRenderer.on(channel, func);
}
});
(() => {
let fontSize = 20;
document.addEventListener("DOMContentLoaded", () => {
let timeout = null;
let hold = null;
const mainTextArea = document.getElementById("text-area");
const increaseFontButton = document.getElementById("increase-font");
const decreaseFontButton = document.getElementById("decrease-font");
const saveButton = document.getElementById('save');
increaseFontButton.addEventListener('mousedown', () => {
increaseFont(mainTextArea);
timeout = setTimeout(()=> {
hold = setInterval(()=>{
increaseFont(mainTextArea);
}, 50);
}, 1000);
});
increaseFontButton.addEventListener('mouseup', () => {
clearTimeout(timeout);
clearInterval(hold);
});
decreaseFontButton.addEventListener('mousedown', () => {
decreaseFont(mainTextArea);
timeout = setTimeout(()=> {
hold = setInterval(()=>{
decreaseFont(mainTextArea);
}, 50);
}, 1000);
});
decreaseFontButton.addEventListener('mouseup', () => {
clearTimeout(timeout);
clearInterval(hold);
});
saveButton.addEventListener('click', () => {
window.electron.saveToElectron(mainTextArea.value);
});
window.electron.storeData('store-data', (event, data) =>{
console.log("From Server: "+ data);
});
});
function increaseFont(t){
fontSize++;
t.style.fontSize = `${fontSize}px`;
}
function decreaseFont(t){
fontSize--;
t.style.fontSize = `${fontSize}px`;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment