Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"main": "build/src/main/index.js",
"scripts": {
"dev": "run-p dev:watch dev:vue-devtools",
"dev:watch": "tsc-watch -p tsconfig.electron.json --onFirstSuccess 'npm run dev:server'",
"dev:watch": "tsc-watch -p tsconfig.electron.json --onFirstSuccess \"npm run dev:server\"",
"dev:server": "node build/scripts/dev-server.js",
"dev:vue-devtools": "vue-devtools",
"build:ts": "tsc -p tsconfig.electron.json",
Expand Down
12 changes: 8 additions & 4 deletions scripts/dev-server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { spawn } from 'child_process'
import type { ChildProcess, SpawnOptionsWithoutStdio } from 'child_process'
import type { ChildProcess } from 'child_process'
import path from 'path'
import chalk from 'chalk'
import chokidar from 'chokidar'
Expand All @@ -23,9 +23,9 @@ async function startRenderer () {
function startElectron () {
if (electronProcess) return

const args = ['.', rendererPort] as SpawnOptionsWithoutStdio

electronProcess = spawn('electron', args)
electronProcess = spawn('electron', ['.', (rendererPort || 0).toString()], {
shell: true
})

electronProcess?.stdout?.on('data', data => {
console.log(chalk.blueBright('[Electron] ') + chalk.white(data.toString()))
Expand All @@ -34,6 +34,10 @@ function startElectron () {
electronProcess?.stderr?.on('data', data => {
console.log(chalk.redBright('[Electron] ') + chalk.white(data.toString()))
})

electronProcess?.on('error', error => {
console.log(chalk.redBright('[Electron] ', error))
})
}

function restartElectron () {
Expand Down
7 changes: 0 additions & 7 deletions src/main/components/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,3 @@ export const createMenu = (template: MenuItemConstructorOptions[]) => {
const menu = Menu.buildFromTemplate(template)
return menu
}

export const createPopupMenu = (template: MenuItemConstructorOptions[]) => {
const menu = createMenu(template)
menu.popup({ window: BrowserWindow.getFocusedWindow()! })

return menu
}
3 changes: 2 additions & 1 deletion src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { subscribeToDialog } from './services/ipc/dialog'
import { checkForUpdate } from './services/update-check'

const isDev = process.env.NODE_ENV === 'development'
const isMac = process.platform === 'darwin'

createDb()
const apiServer = new ApiServer()
Expand All @@ -24,7 +25,7 @@ function createWindow () {
width: 1000,
height: 600,
...bounds,
titleBarStyle: 'hidden',
titleBarStyle: isMac ? 'hidden' : 'default',
webPreferences: {
preload: path.resolve(__dirname, 'preload.js'),
nodeIntegration: true,
Expand Down
22 changes: 21 additions & 1 deletion src/main/menu/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { createMenu } from '../components/menu'
import type { MenuItemConstructorOptions } from 'electron'
import { app, BrowserWindow } from 'electron'
import { dialog, app, BrowserWindow } from 'electron'
import { version, author } from '../../../package.json'
import os from 'os'

const isDev = process.env.NODE_ENV === 'development'
const isMac = process.platform === 'darwin'
Expand Down Expand Up @@ -80,6 +81,25 @@ const helpMenu: MenuItemConstructorOptions[] = [
{
label: 'Toogle Dev tools',
role: 'toggleDevTools'
},
{
label: 'About',
click () {
dialog.showMessageBox(BrowserWindow.getFocusedWindow()!, {
title: 'massCode',
message: 'massCode',
type: 'info',
detail: `
Version: ${version}
Electron: ${process.versions.electron}
Chrome: ${process.versions.chrome}
Node.js: ${process.versions.node}
V8: ${process.versions.v8}
OS: ${os.type()} ${os.arch()} ${os.release()}
©2019-${year} Anton Reshetov <reshetov.art@gmail.com>
`
})
}
}
]

Expand Down
4 changes: 3 additions & 1 deletion src/main/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { ElectronBridge } from '@shared/types/main'
import { version } from '../../package.json'
import type { TrackEvents } from '@shared/types/main/analytics'
import { analytics } from './services/analytics'
import { platform } from 'os'

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

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

analytics.pageview(path).send()
}
},
platform: () => platform()
} as ElectronBridge)
16 changes: 12 additions & 4 deletions src/main/services/ipc/context-menu.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createPopupMenu } from '../../components/menu'
import { createMenu } from '../../components/menu'
import type { MenuItemConstructorOptions } from 'electron'
import { BrowserWindow, MenuItem, dialog, ipcMain } from 'electron'
import type {
Expand All @@ -14,7 +14,7 @@ export const subscribeToContextMenu = () => {
const { name, type } = payload

return new Promise(resolve => {
createPopupMenu([
const menu = createMenu([
{
label: `Rename "${name}"`,
click: () =>
Expand Down Expand Up @@ -45,6 +45,8 @@ export const subscribeToContextMenu = () => {
}
}
])

menu.popup({ window: BrowserWindow.getFocusedWindow()! })
})
}
)
Expand All @@ -55,7 +57,7 @@ export const subscribeToContextMenu = () => {
const { name, type, selectedCount } = payload

return new Promise(resolve => {
const menu = createPopupMenu([])
const menu = createMenu([])

const defaultMenu: MenuItemConstructorOptions[] = [
{
Expand Down Expand Up @@ -151,18 +153,21 @@ export const subscribeToContextMenu = () => {
if (type === 'folder' || type === 'all' || type === 'inbox') {
defaultMenu.forEach(i => {
menu.append(new MenuItem(i))
menu.popup({ window: BrowserWindow.getFocusedWindow()! })
})
}

if (type === 'favorites') {
favoritesMenu.forEach(i => {
menu.append(new MenuItem(i))
menu.popup({ window: BrowserWindow.getFocusedWindow()! })
})
}

if (type === 'trash') {
trashMenu.forEach(i => {
menu.append(new MenuItem(i))
menu.popup({ window: BrowserWindow.getFocusedWindow()! })
})
}

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

return new Promise(resolve => {
const menu = createPopupMenu([])
const menu = createMenu([])

const createLanguageMenu = () => {
return languages.map(i => {
Expand Down Expand Up @@ -308,18 +313,21 @@ export const subscribeToContextMenu = () => {
if (type === 'folder') {
folderMenu.forEach(i => {
menu.append(new MenuItem(i))
menu.popup({ window: BrowserWindow.getFocusedWindow()! })
})
}

if (type === 'tag') {
tagMenu.forEach(i => {
menu.append(new MenuItem(i))
menu.popup({ window: BrowserWindow.getFocusedWindow()! })
})
}

if (type === 'trash') {
trashMenu.forEach(i => {
menu.append(new MenuItem(i))
menu.popup({ window: BrowserWindow.getFocusedWindow()! })
})
}

Expand Down
8 changes: 7 additions & 1 deletion src/renderer/App.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<template>
<div class="app-title-bar" />
<div
class="app-title-bar"
:class="{ 'is-win': appStore.platform === 'win32' }"
/>
<RouterView />
<div
v-if="isUpdateAvailable"
Expand Down Expand Up @@ -63,6 +66,9 @@ body {
-webkit-app-region: drag;
z-index: 1010;
transition: all 0.5s;
&.is-win {
border-top: 1px solid var(--color-border);
}
}
}
.update {
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/electron.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const { ipc, store, db, track } = window.electron
const { ipc, store, db, track, platform } = window.electron

export { ipc, store, db, track }
export { ipc, store, db, track, platform }
4 changes: 3 additions & 1 deletion src/renderer/store/app.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { platform } from '@/electron'
import type { State } from '@shared/types/renderer/store/app'
import { defineStore } from 'pinia'
import { version } from '../../../package.json'
Expand All @@ -16,6 +17,7 @@ export const useAppStore = defineStore('app', {
footerHeight: 30
}
},
version
version,
platform: platform()
})
})
Empty file added src/renderer/types/.keep
Empty file.
1 change: 1 addition & 0 deletions src/shared/types/main/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,5 @@ export interface ElectronBridge {
isExist: (path: string) => boolean
}
track: (event: TrackEvents, payload?: string) => void
platform: () => NodeJS.Platform
}
1 change: 1 addition & 0 deletions src/shared/types/renderer/store/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface AppSizes {
}

export interface State {
platform: NodeJS.Platform
theme: string
sizes: AppSizes
showTags: boolean
Expand Down