Skip to content

Commit edc114c

Browse files
feat: support win (#13)
1 parent e20fe2c commit edc114c

File tree

13 files changed

+61
-23
lines changed

13 files changed

+61
-23
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"main": "build/src/main/index.js",
88
"scripts": {
99
"dev": "run-p dev:watch dev:vue-devtools",
10-
"dev:watch": "tsc-watch -p tsconfig.electron.json --onFirstSuccess 'npm run dev:server'",
10+
"dev:watch": "tsc-watch -p tsconfig.electron.json --onFirstSuccess \"npm run dev:server\"",
1111
"dev:server": "node build/scripts/dev-server.js",
1212
"dev:vue-devtools": "vue-devtools",
1313
"build:ts": "tsc -p tsconfig.electron.json",

scripts/dev-server.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { spawn } from 'child_process'
2-
import type { ChildProcess, SpawnOptionsWithoutStdio } from 'child_process'
2+
import type { ChildProcess } from 'child_process'
33
import path from 'path'
44
import chalk from 'chalk'
55
import chokidar from 'chokidar'
@@ -23,9 +23,9 @@ async function startRenderer () {
2323
function startElectron () {
2424
if (electronProcess) return
2525

26-
const args = ['.', rendererPort] as SpawnOptionsWithoutStdio
27-
28-
electronProcess = spawn('electron', args)
26+
electronProcess = spawn('electron', ['.', (rendererPort || 0).toString()], {
27+
shell: true
28+
})
2929

3030
electronProcess?.stdout?.on('data', data => {
3131
console.log(chalk.blueBright('[Electron] ') + chalk.white(data.toString()))
@@ -34,6 +34,10 @@ function startElectron () {
3434
electronProcess?.stderr?.on('data', data => {
3535
console.log(chalk.redBright('[Electron] ') + chalk.white(data.toString()))
3636
})
37+
38+
electronProcess?.on('error', error => {
39+
console.log(chalk.redBright('[Electron] ', error))
40+
})
3741
}
3842

3943
function restartElectron () {

src/main/components/menu.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,3 @@ export const createMenu = (template: MenuItemConstructorOptions[]) => {
55
const menu = Menu.buildFromTemplate(template)
66
return menu
77
}
8-
9-
export const createPopupMenu = (template: MenuItemConstructorOptions[]) => {
10-
const menu = createMenu(template)
11-
menu.popup({ window: BrowserWindow.getFocusedWindow()! })
12-
13-
return menu
14-
}

src/main/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { subscribeToDialog } from './services/ipc/dialog'
1111
import { checkForUpdate } from './services/update-check'
1212

1313
const isDev = process.env.NODE_ENV === 'development'
14+
const isMac = process.platform === 'darwin'
1415

1516
createDb()
1617
const apiServer = new ApiServer()
@@ -24,7 +25,7 @@ function createWindow () {
2425
width: 1000,
2526
height: 600,
2627
...bounds,
27-
titleBarStyle: 'hidden',
28+
titleBarStyle: isMac ? 'hidden' : 'default',
2829
webPreferences: {
2930
preload: path.resolve(__dirname, 'preload.js'),
3031
nodeIntegration: true,

src/main/menu/main.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { createMenu } from '../components/menu'
22
import type { MenuItemConstructorOptions } from 'electron'
3-
import { app, BrowserWindow } from 'electron'
3+
import { dialog, app, BrowserWindow } from 'electron'
44
import { version, author } from '../../../package.json'
5+
import os from 'os'
56

67
const isDev = process.env.NODE_ENV === 'development'
78
const isMac = process.platform === 'darwin'
@@ -80,6 +81,25 @@ const helpMenu: MenuItemConstructorOptions[] = [
8081
{
8182
label: 'Toogle Dev tools',
8283
role: 'toggleDevTools'
84+
},
85+
{
86+
label: 'About',
87+
click () {
88+
dialog.showMessageBox(BrowserWindow.getFocusedWindow()!, {
89+
title: 'massCode',
90+
message: 'massCode',
91+
type: 'info',
92+
detail: `
93+
Version: ${version}
94+
Electron: ${process.versions.electron}
95+
Chrome: ${process.versions.chrome}
96+
Node.js: ${process.versions.node}
97+
V8: ${process.versions.v8}
98+
OS: ${os.type()} ${os.arch()} ${os.release()}
99+
©2019-${year} Anton Reshetov <[email protected]>
100+
`
101+
})
102+
}
83103
}
84104
]
85105

src/main/preload.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { ElectronBridge } from '@shared/types/main'
55
import { version } from '../../package.json'
66
import type { TrackEvents } from '@shared/types/main/analytics'
77
import { analytics } from './services/analytics'
8+
import { platform } from 'os'
89

910
const isDev = process.env.NODE_ENV === 'development'
1011

@@ -39,5 +40,6 @@ contextBridge.exposeInMainWorld('electron', {
3940
: `${version}/${event}`
4041

4142
analytics.pageview(path).send()
42-
}
43+
},
44+
platform: () => platform()
4345
} as ElectronBridge)

src/main/services/ipc/context-menu.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createPopupMenu } from '../../components/menu'
1+
import { createMenu } from '../../components/menu'
22
import type { MenuItemConstructorOptions } from 'electron'
33
import { BrowserWindow, MenuItem, dialog, ipcMain } from 'electron'
44
import type {
@@ -14,7 +14,7 @@ export const subscribeToContextMenu = () => {
1414
const { name, type } = payload
1515

1616
return new Promise(resolve => {
17-
createPopupMenu([
17+
const menu = createMenu([
1818
{
1919
label: `Rename "${name}"`,
2020
click: () =>
@@ -45,6 +45,8 @@ export const subscribeToContextMenu = () => {
4545
}
4646
}
4747
])
48+
49+
menu.popup({ window: BrowserWindow.getFocusedWindow()! })
4850
})
4951
}
5052
)
@@ -55,7 +57,7 @@ export const subscribeToContextMenu = () => {
5557
const { name, type, selectedCount } = payload
5658

5759
return new Promise(resolve => {
58-
const menu = createPopupMenu([])
60+
const menu = createMenu([])
5961

6062
const defaultMenu: MenuItemConstructorOptions[] = [
6163
{
@@ -151,18 +153,21 @@ export const subscribeToContextMenu = () => {
151153
if (type === 'folder' || type === 'all' || type === 'inbox') {
152154
defaultMenu.forEach(i => {
153155
menu.append(new MenuItem(i))
156+
menu.popup({ window: BrowserWindow.getFocusedWindow()! })
154157
})
155158
}
156159

157160
if (type === 'favorites') {
158161
favoritesMenu.forEach(i => {
159162
menu.append(new MenuItem(i))
163+
menu.popup({ window: BrowserWindow.getFocusedWindow()! })
160164
})
161165
}
162166

163167
if (type === 'trash') {
164168
trashMenu.forEach(i => {
165169
menu.append(new MenuItem(i))
170+
menu.popup({ window: BrowserWindow.getFocusedWindow()! })
166171
})
167172
}
168173

@@ -181,7 +186,7 @@ export const subscribeToContextMenu = () => {
181186
const { name, type, data } = payload
182187

183188
return new Promise(resolve => {
184-
const menu = createPopupMenu([])
189+
const menu = createMenu([])
185190

186191
const createLanguageMenu = () => {
187192
return languages.map(i => {
@@ -308,18 +313,21 @@ export const subscribeToContextMenu = () => {
308313
if (type === 'folder') {
309314
folderMenu.forEach(i => {
310315
menu.append(new MenuItem(i))
316+
menu.popup({ window: BrowserWindow.getFocusedWindow()! })
311317
})
312318
}
313319

314320
if (type === 'tag') {
315321
tagMenu.forEach(i => {
316322
menu.append(new MenuItem(i))
323+
menu.popup({ window: BrowserWindow.getFocusedWindow()! })
317324
})
318325
}
319326

320327
if (type === 'trash') {
321328
trashMenu.forEach(i => {
322329
menu.append(new MenuItem(i))
330+
menu.popup({ window: BrowserWindow.getFocusedWindow()! })
323331
})
324332
}
325333

src/renderer/App.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<template>
2-
<div class="app-title-bar" />
2+
<div
3+
class="app-title-bar"
4+
:class="{ 'is-win': appStore.platform === 'win32' }"
5+
/>
36
<RouterView />
47
<div
58
v-if="isUpdateAvailable"
@@ -63,6 +66,9 @@ body {
6366
-webkit-app-region: drag;
6467
z-index: 1010;
6568
transition: all 0.5s;
69+
&.is-win {
70+
border-top: 1px solid var(--color-border);
71+
}
6672
}
6773
}
6874
.update {

src/renderer/electron.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const { ipc, store, db, track } = window.electron
1+
const { ipc, store, db, track, platform } = window.electron
22

3-
export { ipc, store, db, track }
3+
export { ipc, store, db, track, platform }

src/renderer/store/app.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { platform } from '@/electron'
12
import type { State } from '@shared/types/renderer/store/app'
23
import { defineStore } from 'pinia'
34
import { version } from '../../../package.json'
@@ -16,6 +17,7 @@ export const useAppStore = defineStore('app', {
1617
footerHeight: 30
1718
}
1819
},
19-
version
20+
version,
21+
platform: platform()
2022
})
2123
})

0 commit comments

Comments
 (0)