UNPKG

kdj_singlish

Version:

KDJ Singlish is an app which created to help people to type in sinhala without making any mistakes. This will save your time and fix all the issues you are getting when you type. Just use it and let me know the issues.

352 lines (296 loc) 8.33 kB
const electron = require('electron'); const app = electron.app; const log = require('electron-log'); const BrowserWindow = electron.BrowserWindow; const ipcMain = electron.ipcMain; // const {BrowserWindow,ipcMain} = require('electron'); global.navigator = { userAgent: 'node.js' }; const { autoUpdater } = require('electron-updater'); var IMG_DIR = '/img/'; var APP_DIR = '/app/'; const path = require('path'); const url = require('url'); const windowStateKeeper = require('electron-window-state'); // main process const firstRun = require('electron-first-run'); const isFirstRun = firstRun() console.log(isFirstRun); //ANALYTICS const Analytics = require('electron-google-analytics'); const analytics = new Analytics.default('UA-97460624-3'); function mainReport() { return analytics.screen('Singlish App Opened (Screens)', '1.1.0', 'com.app.test', 'com.app.installer', 'KDJ Singlish') .then((response) => { return response; }).catch((err) => { return err; }); } mainReport(); function largeAdView() { return analytics.event('KDJ Singlish Main Banner', 'Seen', { evLabel: 'singappbanner', evValue: 100 }) .then((response) => { return response; }).catch((err) => { return err; }); } function aboutClicked() { return analytics.event('KDJ Singlish App (About)', 'Clicked', { evLabel: 'singappabout', evValue: 101 }) .then((response) => { return response; }).catch((err) => { return err; }); } function helpClicked() { return analytics.event('KDJ Singlish App (Help)', 'Clicked', { evLabel: 'singapphelp', evValue: 102 }) .then((response) => { return response; }).catch((err) => { return err; }); } function settingsClicked() { return analytics.event('KDJ Singlish App (Settings)', 'Clicked', { evLabel: 'singappsettings', evValue: 102 }) .then((response) => { return response; }).catch((err) => { return err; }); } function appOpened() { return analytics.event('KDJ Singlish (App Screen)', 'Opened', { evLabel: 'singappsccreen', evValue: 103 }) .then((response) => { return response; }).catch((err) => { return err; }); } //------------------------------------------------------------------- // Logging // // THIS SECTION IS NOT REQUIRED // // This logging setup is not required for auto-updates to work, // but it sure makes debugging easier :) //------------------------------------------------------------------- autoUpdater.logger = log; autoUpdater.logger.transports.file.level = 'info'; log.info('App starting...'); // Init Win let win; ipcMain.on('alwaystop', function (event) { win.setAlwaysOnTop(true); }); ipcMain.on('largeBannerShown', function (event) { largeAdView(); }); ipcMain.on('helpClicked', function (event) { helpClicked(); }); ipcMain.on('aboutClicked', function (event) { aboutClicked(); }); ipcMain.on('settingsClicked', function (event) { settingsClicked(); }); ipcMain.on('resizablefalse', function (event) { win.setResizable(false); }); ipcMain.on('resizabletrue', function (event) { win.setResizable(true); }); ipcMain.on('alwaystopfalse', function (event) { win.setAlwaysOnTop(false); }); ipcMain.on('resize', function (e, x, y) { win.setSize(x, y); }); ipcMain.on('reposition', function (e, x, y) { win.setPosition(x, y); }); require('electron-reload')(__dirname); process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'; function createWindow() { let winState = windowStateKeeper({ defaultWidth: 1200, defaultHeight: 600 }); // Create browser window win = new BrowserWindow({ webPreferences: { nodeIntegration: true }, titleBarStyle: 'hidden', width: winState.width, height: winState.height, x: winState.x, y: winState.y, minWidth: 400, minHeight: 560, icon: path.join(__dirname, IMG_DIR, 'icon.png'), frame: false, backgroundColor: '#ffffff', show: false, // alwaysOnTop: false }); winState.manage(win); // Load index.html win.loadURL( url.format({ pathname: path.join(__dirname, APP_DIR, 'index.html'), protocol: 'file', slashes: true }) ); win.on('closed', () => { }); win.once('ready-to-show', () => { win.show(); win.focus(); }); } function sendStatusToWindow(text) { log.info(text); win.webContents.send('message', text); } // when the app is loaded create a BrowserWindow and check for updates app.on('ready', async () => { console.log('Hello from Electron.'); createWindow(); autoUpdater.checkForUpdates(); appOpened(); // setTimeout(() => { // resetTempSave(); // }, 24000); }); autoUpdater.on('checking-for-update', () => { sendStatusToWindow('Checking for update...'); }); autoUpdater.on('update-available', (ev, info) => { sendStatusToWindow('Update available.'); }); autoUpdater.on('update-not-available', (ev, info) => { sendStatusToWindow('Update not available.'); }); autoUpdater.on('error', (ev, err) => { sendStatusToWindow('Error in auto-updater.'); }); autoUpdater.on('download-progress', (ev, progressObj) => { sendStatusToWindow('Download progress...'); }); // when the update has been downloaded and is ready to be installed, notify the BrowserWindow autoUpdater.on('update-downloaded', (info) => { win.webContents.send('updateReady'); }); // when receiving a quitAndInstall signal, quit and install the new version ;) ipcMain.on('quitAndInstall', (event, arg) => { autoUpdater.quitAndInstall(); }); //Quite when all windows are closed app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit(); } }); //------------------------------------------------------------------- // Auto updates // // For details about these events, see the Wiki: // https://github.com/electron-userland/electron-builder/wiki/Auto-Update#events // // The app doesn't need to listen to any events except `update-downloaded` // // Uncomment any of the below events to listen for them. Also, // look in the previous section to see them being used. //------------------------------------------------------------------- // autoUpdater.on('checking-for-update', () => { // }) // autoUpdater.on('update-available', (ev, info) => { // }) // autoUpdater.on('update-not-available', (ev, info) => { // }) // autoUpdater.on('error', (ev, err) => { // }) // autoUpdater.on('download-progress', (ev, progressObj) => { // }) autoUpdater.on('update-downloaded', (ev, info) => { // Wait 5 seconds, then quit and install // In your application, you don't need to wait 5 seconds. // You could call autoUpdater.quitAndInstall(); immediately setTimeout(function () { autoUpdater.quitAndInstall(); }, 5000); }); var fs = require('fs'); var basepath = app.getPath('userData'); const suggestionsFile = basepath + '\\suggestions.txt'; const tempSaveFile = basepath + '\\tempSave.txt'; /* ************** */ /* DIFFERENT PART */ /* ************** */ // WRITE IN TEXT DOCUMENT // console.log(app.getPath('userData') + "\\s"); // RESET TEMPSAVE FILE WHEN OPEN function resetTempSave() { fs.writeFile(tempSaveFile, '', function (err) { if (err) { return console.log(err); } else {} console.log("Temprary text file has reset.."); }); } try { if (fs.existsSync(suggestionsFile)) { //file exists console.log('All Filles are already in place...') } else { fs.writeFile(tempSaveFile, '', function (err) { if (err) { return console.log(err); } else { } console.log("Saved All Necessary Files"); }); // WRITE FILES const sinhalaSugDef = app.getAppPath() + "\\sinhalaSuggessions.txt"; // console.log(sinhalaSugDef) const contentSug = fs.readFileSync(sinhalaSugDef, 'utf8'); console.log(contentSug); fs.writeFile(suggestionsFile, contentSug, function (err) { if (err) { return console.log(err); } console.log("Saved Suggestion File"); }); } } catch (err) { console.error(err) } // function startResetTemp() { // setTimeout(() => { // resetTempSave(); // startResetTemp(); // }, 30000); // } // startResetTemp();