-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Electron-Forge source directory structure
- Loading branch information
1 parent
663b8ab
commit efd59a7
Showing
66 changed files
with
1,715 additions
and
877 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} |
Oops, something went wrong.