Skip to content

Commit

Permalink
New Electron-Forge source directory structure
Browse files Browse the repository at this point in the history
  • Loading branch information
fjwillemsen committed Jul 13, 2024
1 parent 663b8ab commit efd59a7
Show file tree
Hide file tree
Showing 66 changed files with 1,715 additions and 877 deletions.
5 changes: 5 additions & 0 deletions src/@types/electron-forge.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This allows TypeScript to pick up the magic constants that's auto-generated by Forge's Vite
// plugin that tells the Electron app where to look for the Vite-bundled app code (depending on
// whether you're running in development or production).
declare const MAIN_WINDOW_VITE_DEV_SERVER_URL: string
declare const MAIN_WINDOW_VITE_NAME: string
11 changes: 11 additions & 0 deletions src/@types/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { globals } from 'src/preload'

declare global {
const electron: typeof globals
const __WIN32__: boolean
const __DARWIN__: boolean
const __LINUX__: boolean
const __DEV__: boolean
const __APP_NAME__: string
const __APP_VERSION__: string
}
5 changes: 5 additions & 0 deletions src/@types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module '*.css'
declare module '*.png'
declare module '*.jpg'
declare module '*.jpeg'
declare module '*.svg'
100 changes: 100 additions & 0 deletions src/appWindow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { app, BrowserWindow, Menu } from 'electron'
import path from 'path'

import Store from 'electron-store'
import windowStateKeeper from 'electron-window-state'

import { registerMenuIpc } from './ipc/menuIPC'
import { registerProjectIpc } from './ipc/projectIPC'
import { registerSettingsIpc } from './ipc/settingsIPC'
import appMenu from './menu/appMenu'
import { registerWindowStateChangedEvents } from './windowState'

Store.initRenderer()

let appWindow: BrowserWindow

/**
* Create Application Window
* @returns BrowserWindow - Application Window Instance
*/
export function createAppWindow(): BrowserWindow {
const minWidth = 960
const minHeight = 660

const savedWindowState = windowStateKeeper({
defaultWidth: minWidth,
defaultHeight: minHeight,
maximize: false,
})

const windowOptions: Electron.BrowserWindowConstructorOptions = {
x: savedWindowState.x,
y: savedWindowState.y,
width: savedWindowState.width,
height: savedWindowState.height,
minWidth: minWidth,
minHeight: minHeight,
show: false,
autoHideMenuBar: true,
frame: false,
backgroundColor: '#1a1a1a',
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
nodeIntegrationInWorker: false,
nodeIntegrationInSubFrames: false,
preload: path.join(__dirname, 'preload.js'),
},
}

if (process.platform === 'darwin') {
windowOptions.titleBarStyle = 'hidden'
}

// Create new window instance
appWindow = new BrowserWindow(windowOptions)

// Load the index.html of the app window.
if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {
appWindow.loadURL(MAIN_WINDOW_VITE_DEV_SERVER_URL)
} else {
appWindow.loadFile(path.join(__dirname, `../renderer/${MAIN_WINDOW_VITE_NAME}/index.html`))
}

// Build the application menu
const menu = Menu.buildFromTemplate(appMenu)
Menu.setApplicationMenu(menu)

// Show window when is ready to
appWindow.on('ready-to-show', () => {
appWindow.show()
})

// Register Inter Process Communication for main process
registerMainIPC()

savedWindowState.manage(appWindow)

// Close all windows when main window is closed
appWindow.on('close', () => {
appWindow = null
app.quit()
})

return appWindow
}

/**
* Register Inter Process Communication
*/
function registerMainIPC() {
/**
* Here you can assign IPC related codes for the application window
* to Communicate asynchronously from the main process to renderer processes.
*/
registerWindowStateChangedEvents(appWindow)
registerMenuIpc(appWindow)
registerSettingsIpc()
registerProjectIpc()
}
8 changes: 0 additions & 8 deletions src/assets/logo-electron.svg

This file was deleted.

1 change: 0 additions & 1 deletion src/assets/logo-v1.svg

This file was deleted.

20 changes: 0 additions & 20 deletions src/assets/logo-vite.svg

This file was deleted.

Binary file removed src/assets/logo_nobg.png
Binary file not shown.
15 changes: 15 additions & 0 deletions src/channels/menuChannels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export enum MenuChannels {
WINDOW_MINIMIZE = 'window-minimize',
WINDOW_MAXIMIZE = 'window-maximize',
WINDOW_TOGGLE_MAXIMIZE = 'window-toggle-maximize',
WINDOW_CLOSE = 'window-close',
WEB_TOGGLE_DEVTOOLS = 'web-toggle-devtools',
WEB_ACTUAL_SIZE = 'web-actual-size',
WEB_ZOOM_IN = 'web-zoom-in',
WEB_ZOOM_OUT = 'web-zoom-out',
WEB_TOGGLE_FULLSCREEN = 'web-toggle-fullscreen',
OPEN_GITHUB_PROFILE = 'open-github-profile',
MENU_EVENT = 'menu-event',
EXECUTE_MENU_ITEM_BY_ID = 'execute-menu-item-by-id',
SHOW_CONTEXT_MENU = 'show-context-menu',
}
Loading

0 comments on commit efd59a7

Please sign in to comment.