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": {
|
||||
"@electron-toolkit/preload": "^3.0.1",
|
||||
"@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": {
|
||||
"@electron-toolkit/eslint-config-prettier": "^3.0.0",
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { app, shell, BrowserWindow, ipcMain } from 'electron'
|
||||
import { join } from 'path'
|
||||
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
||||
import icon from '../../resources/icon.png?asset'
|
||||
import { electronApp, is, optimizer } from "@electron-toolkit/utils";
|
||||
import { app, BrowserWindow, shell } from "electron";
|
||||
import log from "electron-log/main";
|
||||
import { join } from "path";
|
||||
import icon from "../../resources/icon.png?asset";
|
||||
import ErrorTypeCheck from "../util/errorTypeCheck";
|
||||
|
||||
function createWindow(): void {
|
||||
// Create the browser window.
|
||||
@@ -10,65 +12,77 @@ function createWindow(): void {
|
||||
height: 670,
|
||||
show: false,
|
||||
autoHideMenuBar: true,
|
||||
...(process.platform === 'linux' ? { icon } : {}),
|
||||
...(process.platform === "linux" ? { icon } : {}),
|
||||
webPreferences: {
|
||||
preload: join(__dirname, '../preload/index.js'),
|
||||
sandbox: false
|
||||
}
|
||||
})
|
||||
preload: join(__dirname, "../preload/index.js"),
|
||||
sandbox: false,
|
||||
},
|
||||
});
|
||||
|
||||
mainWindow.on('ready-to-show', () => {
|
||||
mainWindow.show()
|
||||
})
|
||||
mainWindow.on("ready-to-show", () => {
|
||||
mainWindow.show();
|
||||
});
|
||||
|
||||
mainWindow.webContents.setWindowOpenHandler((details) => {
|
||||
shell.openExternal(details.url)
|
||||
return { action: 'deny' }
|
||||
})
|
||||
shell.openExternal(details.url);
|
||||
return { action: "deny" };
|
||||
});
|
||||
|
||||
// HMR for renderer base on electron-vite cli.
|
||||
// Load the remote URL for development or the local html file for production.
|
||||
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
||||
mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
|
||||
if (is.dev && process.env["ELECTRON_RENDERER_URL"]) {
|
||||
mainWindow.loadURL(process.env["ELECTRON_RENDERER_URL"]);
|
||||
} else {
|
||||
mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
|
||||
mainWindow.loadFile(join(__dirname, "../renderer/index.html"));
|
||||
}
|
||||
}
|
||||
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
app.whenReady().then(() => {
|
||||
app.whenReady().then(async () => {
|
||||
// Set app user model id for windows
|
||||
electronApp.setAppUserModelId('com.electron')
|
||||
electronApp.setAppUserModelId("com.electron");
|
||||
|
||||
// Default open or close DevTools by F12 in development
|
||||
// and ignore CommandOrControl + R in production.
|
||||
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
|
||||
app.on('browser-window-created', (_, window) => {
|
||||
optimizer.watchWindowShortcuts(window)
|
||||
})
|
||||
app.on("browser-window-created", (_, window) => {
|
||||
optimizer.watchWindowShortcuts(window);
|
||||
});
|
||||
|
||||
// IPC test
|
||||
ipcMain.on('ping', () => console.log('pong'))
|
||||
//Dynamically load ipcMain handlers once ready.
|
||||
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
|
||||
// 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
|
||||
// for applications and their menu bar to stay active until the user quits
|
||||
// explicitly with Cmd + Q.
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit()
|
||||
app.on("window-all-closed", () => {
|
||||
if (process.platform !== "darwin") {
|
||||
app.quit();
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
// 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.
|
||||
|
||||
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 { electronAPI } from '@electron-toolkit/preload'
|
||||
import 'electron-log/preload'
|
||||
|
||||
// Custom APIs for renderer
|
||||
const api = {}
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
import Versions from './components/Versions'
|
||||
import electronLogo from './assets/electron.svg'
|
||||
import ipcTypes from "../../util/ipcTypes.json";
|
||||
import electronLogo from "./assets/electron.svg";
|
||||
import Versions from "./components/Versions";
|
||||
import log from "electron-log/renderer";
|
||||
|
||||
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 (
|
||||
<>
|
||||
<img alt="logo" className="logo" src={electronLogo} />
|
||||
@@ -25,11 +30,14 @@ function App(): JSX.Element {
|
||||
<a target="_blank" rel="noreferrer" onClick={ipcHandle}>
|
||||
Send IPC
|
||||
</a>
|
||||
<a target="_blank" rel="noreferrer" onClick={ipcHandleWithType}>
|
||||
Send IPC written by me.
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<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",
|
||||
"include": ["electron.vite.config.*", "src/main/**/*", "src/preload/**/*"],
|
||||
"include": [
|
||||
"electron.vite.config.*",
|
||||
"src/main/**/*",
|
||||
"src/preload/**/*",
|
||||
"src/util/**/*",
|
||||
"src/interfaces/**/*"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"types": ["electron-vite/node"]
|
||||
|
||||
Reference in New Issue
Block a user