Add basic logging, debugging and store.
This commit is contained in:
39
.vscode/launch.json
vendored
Normal file
39
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Debug Main Process",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-vite",
|
||||||
|
"windows": {
|
||||||
|
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-vite.cmd"
|
||||||
|
},
|
||||||
|
"runtimeArgs": ["--sourcemap"],
|
||||||
|
"env": {
|
||||||
|
"REMOTE_DEBUGGING_PORT": "9222"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Debug Renderer Process",
|
||||||
|
"port": 9222,
|
||||||
|
"request": "attach",
|
||||||
|
"type": "chrome",
|
||||||
|
"webRoot": "${workspaceFolder}/src/renderer",
|
||||||
|
"timeout": 60000,
|
||||||
|
"presentation": {
|
||||||
|
"hidden": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"compounds": [
|
||||||
|
{
|
||||||
|
"name": "Debug All",
|
||||||
|
"configurations": ["Debug Main Process", "Debug Renderer Process"],
|
||||||
|
"presentation": {
|
||||||
|
"order": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
2204
package-lock.json
generated
2204
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -23,7 +23,14 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@electron-toolkit/preload": "^3.0.1",
|
"@electron-toolkit/preload": "^3.0.1",
|
||||||
"@electron-toolkit/utils": "^4.0.0",
|
"@electron-toolkit/utils": "^4.0.0",
|
||||||
"electron-updater": "^6.3.9"
|
"antd": "^5.24.3",
|
||||||
|
"chokidar": "^4.0.3",
|
||||||
|
"dbffile": "^1.12.0",
|
||||||
|
"electron-log": "^5.3.2",
|
||||||
|
"electron-store": "^10.0.1",
|
||||||
|
"electron-updater": "^6.3.9",
|
||||||
|
"firebase": "^11.4.0",
|
||||||
|
"lodash": "^4.17.21"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@electron-toolkit/eslint-config-prettier": "^3.0.0",
|
"@electron-toolkit/eslint-config-prettier": "^3.0.0",
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import { app, shell, BrowserWindow, ipcMain } from 'electron'
|
import { electronApp, is, optimizer } from "@electron-toolkit/utils";
|
||||||
import { join } from 'path'
|
import { app, BrowserWindow, shell } from "electron";
|
||||||
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
import log from "electron-log/main";
|
||||||
import icon from '../../resources/icon.png?asset'
|
import { join } from "path";
|
||||||
|
import icon from "../../resources/icon.png?asset";
|
||||||
|
import ErrorTypeCheck from "../util/errorTypeCheck";
|
||||||
|
|
||||||
function createWindow(): void {
|
function createWindow(): void {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
@@ -10,65 +12,77 @@ function createWindow(): void {
|
|||||||
height: 670,
|
height: 670,
|
||||||
show: false,
|
show: false,
|
||||||
autoHideMenuBar: true,
|
autoHideMenuBar: true,
|
||||||
...(process.platform === 'linux' ? { icon } : {}),
|
...(process.platform === "linux" ? { icon } : {}),
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload: join(__dirname, '../preload/index.js'),
|
preload: join(__dirname, "../preload/index.js"),
|
||||||
sandbox: false
|
sandbox: false,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
mainWindow.on('ready-to-show', () => {
|
mainWindow.on("ready-to-show", () => {
|
||||||
mainWindow.show()
|
mainWindow.show();
|
||||||
})
|
});
|
||||||
|
|
||||||
mainWindow.webContents.setWindowOpenHandler((details) => {
|
mainWindow.webContents.setWindowOpenHandler((details) => {
|
||||||
shell.openExternal(details.url)
|
shell.openExternal(details.url);
|
||||||
return { action: 'deny' }
|
return { action: "deny" };
|
||||||
})
|
});
|
||||||
|
|
||||||
// HMR for renderer base on electron-vite cli.
|
// HMR for renderer base on electron-vite cli.
|
||||||
// Load the remote URL for development or the local html file for production.
|
// Load the remote URL for development or the local html file for production.
|
||||||
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
if (is.dev && process.env["ELECTRON_RENDERER_URL"]) {
|
||||||
mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
|
mainWindow.loadURL(process.env["ELECTRON_RENDERER_URL"]);
|
||||||
} else {
|
} else {
|
||||||
mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
|
mainWindow.loadFile(join(__dirname, "../renderer/index.html"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method will be called when Electron has finished
|
// This method will be called when Electron has finished
|
||||||
// initialization and is ready to create browser windows.
|
// initialization and is ready to create browser windows.
|
||||||
// Some APIs can only be used after this event occurs.
|
// Some APIs can only be used after this event occurs.
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(async () => {
|
||||||
// Set app user model id for windows
|
// Set app user model id for windows
|
||||||
electronApp.setAppUserModelId('com.electron')
|
electronApp.setAppUserModelId("com.electron");
|
||||||
|
|
||||||
// Default open or close DevTools by F12 in development
|
// Default open or close DevTools by F12 in development
|
||||||
// and ignore CommandOrControl + R in production.
|
// and ignore CommandOrControl + R in production.
|
||||||
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
|
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
|
||||||
app.on('browser-window-created', (_, window) => {
|
app.on("browser-window-created", (_, window) => {
|
||||||
optimizer.watchWindowShortcuts(window)
|
optimizer.watchWindowShortcuts(window);
|
||||||
})
|
});
|
||||||
|
|
||||||
// IPC test
|
//Dynamically load ipcMain handlers once ready.
|
||||||
ipcMain.on('ping', () => console.log('pong'))
|
try {
|
||||||
|
// Replace 'path/to/your/file' with the actual path to your file
|
||||||
|
const module = await import("./ipc/ipcMainConfig");
|
||||||
|
|
||||||
createWindow()
|
// You can now use anything exported from the module
|
||||||
|
// For example:
|
||||||
|
// module.someFunction()
|
||||||
|
log.debug("Successfully loaded ipcMainConfig", module);
|
||||||
|
} catch (error) {
|
||||||
|
log.error("Failed to load ipcMainconfig", {
|
||||||
|
...ErrorTypeCheck(error),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
app.on('activate', function () {
|
createWindow();
|
||||||
|
|
||||||
|
app.on("activate", function () {
|
||||||
// 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 (BrowserWindow.getAllWindows().length === 0) createWindow()
|
if (BrowserWindow.getAllWindows().length === 0) createWindow();
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
|
|
||||||
// Quit when all windows are closed, except on macOS. There, it's common
|
// Quit when all windows are closed, except on macOS. There, it's common
|
||||||
// for applications and their menu bar to stay active until the user quits
|
// for applications and their menu bar to stay active until the user quits
|
||||||
// explicitly with Cmd + Q.
|
// explicitly with Cmd + Q.
|
||||||
app.on('window-all-closed', () => {
|
app.on("window-all-closed", () => {
|
||||||
if (process.platform !== 'darwin') {
|
if (process.platform !== "darwin") {
|
||||||
app.quit()
|
app.quit();
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
// In this file you can include the rest of your app's specific main process
|
// In this file you can include the rest of your app's specific main process
|
||||||
// code. You can also put them in separate files and require them here.
|
// code. You can also put them in separate files and require them here.
|
||||||
|
|||||||
6
src/main/ipc/ipcMainConfig.ts
Normal file
6
src/main/ipc/ipcMainConfig.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { ipcMain } from "electron";
|
||||||
|
import ipcTypes from "../../util/ipcTypes.json";
|
||||||
|
|
||||||
|
ipcMain.on(ipcTypes.toMain.test, (payload: any) =>
|
||||||
|
console.log("** Verify that ipcMain is loaded and working.", payload)
|
||||||
|
);
|
||||||
14
src/main/store/store.ts
Normal file
14
src/main/store/store.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import Store from "electron-store";
|
||||||
|
|
||||||
|
const store = new Store({
|
||||||
|
defaults: {
|
||||||
|
filePaths: [],
|
||||||
|
runWatcherOnStartup: true,
|
||||||
|
polling: {
|
||||||
|
enabled: false,
|
||||||
|
pollingInterval: 30000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default store;
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { contextBridge } from 'electron'
|
import { contextBridge } from 'electron'
|
||||||
import { electronAPI } from '@electron-toolkit/preload'
|
import { electronAPI } from '@electron-toolkit/preload'
|
||||||
|
import 'electron-log/preload'
|
||||||
|
|
||||||
// Custom APIs for renderer
|
// Custom APIs for renderer
|
||||||
const api = {}
|
const api = {}
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
import Versions from './components/Versions'
|
import ipcTypes from "../../util/ipcTypes.json";
|
||||||
import electronLogo from './assets/electron.svg'
|
import electronLogo from "./assets/electron.svg";
|
||||||
|
import Versions from "./components/Versions";
|
||||||
|
import log from "electron-log/renderer";
|
||||||
|
|
||||||
function App(): JSX.Element {
|
function App(): JSX.Element {
|
||||||
const ipcHandle = (): void => window.electron.ipcRenderer.send('ping')
|
const ipcHandle = (): void => window.electron.ipcRenderer.send("ping");
|
||||||
|
const ipcHandleWithType = (): void => {
|
||||||
|
log.error("Test from renderer.");
|
||||||
|
window.electron.ipcRenderer.send(ipcTypes.toMain.test, { test: "test" });
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<img alt="logo" className="logo" src={electronLogo} />
|
<img alt="logo" className="logo" src={electronLogo} />
|
||||||
@@ -25,11 +30,14 @@ function App(): JSX.Element {
|
|||||||
<a target="_blank" rel="noreferrer" onClick={ipcHandle}>
|
<a target="_blank" rel="noreferrer" onClick={ipcHandle}>
|
||||||
Send IPC
|
Send IPC
|
||||||
</a>
|
</a>
|
||||||
|
<a target="_blank" rel="noreferrer" onClick={ipcHandleWithType}>
|
||||||
|
Send IPC written by me.
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Versions></Versions>
|
<Versions></Versions>
|
||||||
</>
|
</>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default App
|
export default App;
|
||||||
|
|||||||
17
src/util/errorTypeCheck.ts
Normal file
17
src/util/errorTypeCheck.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
function ErrorTypeCheck(passedError: any): ParsedError {
|
||||||
|
const errorMessage =
|
||||||
|
passedError instanceof Error ? passedError.message : String(passedError);
|
||||||
|
const errorStack =
|
||||||
|
passedError instanceof Error ? passedError.stack : "unknown";
|
||||||
|
|
||||||
|
return {
|
||||||
|
message: errorMessage,
|
||||||
|
stack: errorStack,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
export default ErrorTypeCheck;
|
||||||
|
|
||||||
|
interface ParsedError {
|
||||||
|
message: string;
|
||||||
|
stack: string;
|
||||||
|
}
|
||||||
8
src/util/ipcTypes.json
Normal file
8
src/util/ipcTypes.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"toMain": {
|
||||||
|
"test": "toMain_test"
|
||||||
|
},
|
||||||
|
"toRenderer": {
|
||||||
|
"test": "toRenderer_test"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,12 @@
|
|||||||
{
|
{
|
||||||
"extends": "@electron-toolkit/tsconfig/tsconfig.node.json",
|
"extends": "@electron-toolkit/tsconfig/tsconfig.node.json",
|
||||||
"include": ["electron.vite.config.*", "src/main/**/*", "src/preload/**/*"],
|
"include": [
|
||||||
|
"electron.vite.config.*",
|
||||||
|
"src/main/**/*",
|
||||||
|
"src/preload/**/*",
|
||||||
|
"src/util/**/*",
|
||||||
|
"src/interfaces/**/*"
|
||||||
|
],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"composite": true,
|
"composite": true,
|
||||||
"types": ["electron-vite/node"]
|
"types": ["electron-vite/node"]
|
||||||
|
|||||||
Reference in New Issue
Block a user