Skip to content

Commit

Permalink
feat: add shortcut to open web console
Browse files Browse the repository at this point in the history
Signed-off-by: seven <[email protected]>
  • Loading branch information
Blankll committed Feb 20, 2024
1 parent a49dbae commit 15f4ccf
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 41 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "DocKit",
"productName": "DocKit",
"private": true,
"version": "0.0.14",
"version": "0.0.15",
"description": "A faster, better and more stable NoSQL desktop tools",
"author": "geekfun <[email protected]>",
"license": "Apache-2.0",
Expand Down
21 changes: 12 additions & 9 deletions src/electron/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app, BrowserWindow, autoUpdater, ipcMain, shell } from 'electron';
import { app, autoUpdater, BrowserWindow, ipcMain, shell } from 'electron';
import path from 'path';
import { createMenu } from './menu';
import { debug } from '../common';
Expand Down Expand Up @@ -34,16 +34,19 @@ const createWindow = async () => {
minHeight: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
devTools: isDev,
webSecurity: false,
},
icon: path.resolve(__dirname, '../../dockit.png'),
});
createMenu(mainWindow);
// and load the index.html of the app.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {
for (let i = 0; i < 10; i++) {
try {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const response = await fetch(MAIN_WINDOW_VITE_DEV_SERVER_URL);
if (response.ok) {
break;
Expand All @@ -54,18 +57,17 @@ const createWindow = async () => {

await new Promise(resolve => setTimeout(resolve, 2000));
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
await mainWindow.loadURL(MAIN_WINDOW_VITE_DEV_SERVER_URL);
} else {
await mainWindow.loadFile(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
path.join(__dirname, `../renderer/${MAIN_WINDOW_VITE_NAME}/index.html`),
);
}

// Open the DevTools.
if (isDev) {
mainWindow.webContents.openDevTools();
}

ipcMain.handle('versions', () => ({
node: process.versions.chrome,
chrome: process.versions.chrome,
Expand Down Expand Up @@ -94,9 +96,9 @@ app.on('window-all-closed', () => {

// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
app.on('activate', () => {
app.on('activate', async () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
await createWindow();
}
});

Expand All @@ -114,5 +116,6 @@ try {
} catch (err) {
/* empty */
}

// 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 import them here.
12 changes: 12 additions & 0 deletions src/electron/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ const buildMenuTemplate = (mainWindow: BrowserWindow) =>
},
],
},
{
label: 'Developer',
submenu: [
{
label: 'Toggle Developer Tools',
accelerator: 'F12',
click: () => {
mainWindow.webContents.toggleDevTools();
},
},
],
},
] as Array<MenuItemConstructorOptions>;

export const createMenu = (mainWindow: BrowserWindow) => {
Expand Down
4 changes: 2 additions & 2 deletions src/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createPinia } from 'pinia';
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate';
import piniaPluginPersistence from 'pinia-plugin-persistedstate';

const store = createPinia();
store.use(piniaPluginPersistedstate);
store.use(piniaPluginPersistence);

export default store;

Expand Down
2 changes: 2 additions & 0 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/// <reference types="vite/client" />
declare const MAIN_WINDOW_VITE_DEV_SERVER_URL: string;
declare const MAIN_WINDOW_VITE_NAME: string;

declare module '*.vue' {
import type { DefineComponent } from 'vue';
Expand Down
27 changes: 0 additions & 27 deletions types.d.ts

This file was deleted.

0 comments on commit 15f4ccf

Please sign in to comment.