Switch electron.js to typescript
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,6 +2,7 @@ node_modules
|
|||||||
backend/coverage
|
backend/coverage
|
||||||
backend/.nyc_output
|
backend/.nyc_output
|
||||||
build
|
build
|
||||||
|
/dist
|
||||||
.DS_Store
|
.DS_Store
|
||||||
test.dot
|
test.dot
|
||||||
test.png
|
test.png
|
||||||
|
|||||||
@@ -1,49 +1,53 @@
|
|||||||
const { app, BrowserWindow } = require('electron')
|
import { UpdateInfo } from './events'
|
||||||
const { autoUpdater } = require("electron-updater")
|
import { BrowserWindow, app } from 'electron'
|
||||||
const log = require('electron-log');
|
import * as path from 'path'
|
||||||
const { ConnectionManager, updateNotifier } = require('./backend/build/backend/src/index.js')
|
import * as fs from 'fs'
|
||||||
const fs = require('fs')
|
|
||||||
const path = require('path')
|
|
||||||
require('electron-debug')({enabled: process.argv[2] === '--debug'});
|
|
||||||
|
|
||||||
autoUpdater.logger = log;
|
const { autoUpdater } = require('electron-updater')
|
||||||
autoUpdater.logger.transports.file.level = 'info';
|
const log = require('electron-log')
|
||||||
log.info('App starting...');
|
import { ConnectionManager, updateNotifier } from './backend/src/index'
|
||||||
|
|
||||||
|
const isDebugEnabled = Boolean(process.argv.find(arg => arg === 'debug'))
|
||||||
|
require('electron-debug')({ enabled: isDebugEnabled })
|
||||||
|
|
||||||
|
autoUpdater.logger = log
|
||||||
|
autoUpdater.logger.transports.file.level = 'info'
|
||||||
|
log.info('App starting...')
|
||||||
|
|
||||||
const connectionManager = new ConnectionManager()
|
const connectionManager = new ConnectionManager()
|
||||||
connectionManager.manageConnections()
|
connectionManager.manageConnections()
|
||||||
|
|
||||||
// Keep a global reference of the window object, if you don't, the window will
|
// Keep a global reference of the window object, if you don't, the window will
|
||||||
// be closed automatically when the JavaScript object is garbage collected.
|
// be closed automatically when the JavaScript object is garbage collected.
|
||||||
let mainWindow
|
let mainWindow: BrowserWindow | undefined
|
||||||
|
|
||||||
function createWindow () {
|
function createWindow() {
|
||||||
const icon = path.join(__dirname, 'icon.png')
|
const iconPath = path.join(__dirname, 'icon.png')
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
width: 1024,
|
width: 1024,
|
||||||
height: 700,
|
height: 700,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
nodeIntegration: true
|
nodeIntegration: true,
|
||||||
},
|
},
|
||||||
icon
|
icon: iconPath,
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(icon)
|
console.log(iconPath)
|
||||||
// and load the index.html of the app.
|
// and load the index.html of the app.
|
||||||
mainWindow.loadFile('app/index.html')
|
mainWindow.loadFile('app/index.html')
|
||||||
|
|
||||||
// Emitted when the window is closed.
|
// Emitted when the window is closed.
|
||||||
mainWindow.on('close', function () {
|
mainWindow.on('close', () => {
|
||||||
connectionManager.closeAllConnections()
|
connectionManager.closeAllConnections()
|
||||||
})
|
})
|
||||||
|
|
||||||
// Emitted when the window is closed.
|
// Emitted when the window is closed.
|
||||||
mainWindow.on('closed', function () {
|
mainWindow.on('closed', () => {
|
||||||
// Dereference the window object, usually you would store windows
|
// Dereference the window object, usually you would store windows
|
||||||
// in an array if your app supports multi windows, this is the time
|
// in an array if your app supports multi windows, this is the time
|
||||||
// when you should delete the corresponding element.
|
// when you should delete the corresponding element.
|
||||||
mainWindow = null
|
mainWindow = undefined
|
||||||
app.quit()
|
app.quit()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -54,8 +58,8 @@ function createWindow () {
|
|||||||
app.on('ready', () => {
|
app.on('ready', () => {
|
||||||
createWindow()
|
createWindow()
|
||||||
|
|
||||||
let updateInfo
|
let updateInfo: UpdateInfo
|
||||||
autoUpdater.on('update-available', (info) => {
|
autoUpdater.on('update-available', (info: UpdateInfo) => {
|
||||||
console.log('there is an update')
|
console.log('there is an update')
|
||||||
updateInfo = info
|
updateInfo = info
|
||||||
})
|
})
|
||||||
@@ -78,7 +82,7 @@ app.on('ready', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Quit when all windows are closed.
|
// Quit when all windows are closed.
|
||||||
app.on('window-all-closed', function () {
|
app.on('window-all-closed', () => {
|
||||||
// On macOS it is common for applications and their menu bar
|
// On macOS it is common for applications and their menu bar
|
||||||
// to stay active until the user quits explicitly with Cmd + Q
|
// to stay active until the user quits explicitly with Cmd + Q
|
||||||
if (process.platform !== 'darwin') {
|
if (process.platform !== 'darwin') {
|
||||||
@@ -86,7 +90,7 @@ app.on('window-all-closed', function () {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
app.on('activate', function () {
|
app.on('activate', () => {
|
||||||
// On macOS it's common to re-create a window in the app when the
|
// On macOS it's common to re-create a window in the app when the
|
||||||
// dock icon is clicked and there are no other windows open.
|
// dock icon is clicked and there are no other windows open.
|
||||||
if (mainWindow === null) {
|
if (mainWindow === null) {
|
||||||
@@ -2,12 +2,12 @@
|
|||||||
"name": "MQTT-Explorer",
|
"name": "MQTT-Explorer",
|
||||||
"version": "0.0.7",
|
"version": "0.0.7",
|
||||||
"description": "Explore your message queues",
|
"description": "Explore your message queues",
|
||||||
"main": "electron.js",
|
"main": "dist/electron.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "electron .",
|
"start": "electron .",
|
||||||
"install": "cd app; npm install; cd ..",
|
"install": "cd app; npm install; cd ..",
|
||||||
"test": "npm run test-backend",
|
"test": "npm run test-backend",
|
||||||
"build": "cd app; npm run build; cd ..; cd backend; npm run build; cd ..",
|
"build": "tsc && cd app && npm run build && cd ..",
|
||||||
"test-backend": "cd backend && npm run test && cd ..",
|
"test-backend": "cd backend && npm run test && cd ..",
|
||||||
"prepare-release": "./prepare-release.sh",
|
"prepare-release": "./prepare-release.sh",
|
||||||
"package": "ts-node package.ts",
|
"package": "ts-node package.ts",
|
||||||
|
|||||||
@@ -3,9 +3,10 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
"strictNullChecks": true,
|
"strictNullChecks": true,
|
||||||
"outDir": "./build",
|
"outDir": "./dist",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"lib": ["es2017"],
|
"lib": ["es2017", "dom"],
|
||||||
"sourceMap": true
|
"sourceMap": true
|
||||||
}
|
},
|
||||||
|
"include": ["electron.ts"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user