Last active
March 27, 2021 04:59
-
-
Save erickzhao/c138356bf637ac8f35c54c1e546d43f7 to your computer and use it in GitHub Desktop.
sadapple
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!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> Save</button> | |
| </div> | |
| </header> | |
| <div class="window-content"> | |
| <textarea id="text-area"></textarea> | |
| </div> | |
| </div> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const {contextBridge,ipcRenderer} = require('electron'); | |
| contextBridge.exposeInMainWorld('electron', { | |
| saveToElectron: (text) => ipcRenderer.send('save', text), | |
| storeData: (channel, func) => { | |
| ipcRenderer.on(channel, func); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (() => { | |
| 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`; | |
| } | |
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Empty */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment