Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(create-electron): Changed names for electron main and preload files #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 packages/create-electron/template/react-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "react-ts",
"version": "1.0.0",
"description": "An Electron application with React and TypeScript",
"main": "./out/main/index.js",
"main": "./out/main/main.js",
"author": "example.com",
"homepage": "https://electron-vite.org",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function createWindow(): void {
autoHideMenuBar: true,
...(process.platform === 'linux' ? { icon } : {}),
webPreferences: {
preload: join(__dirname, '../preload/index.js'),
preload: join(__dirname, '../preload/preload.js'),
sandbox: false
}
})
Expand Down
2 changes: 1 addition & 1 deletion packages/create-electron/template/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "react",
"version": "1.0.0",
"description": "An Electron application with React",
"main": "./out/main/index.js",
"main": "./out/main/main.js",
"author": "example.com",
"homepage": "https://electron-vite.org",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function createWindow() {
autoHideMenuBar: true,
...(process.platform === 'linux' ? { icon } : {}),
webPreferences: {
preload: join(__dirname, '../preload/index.js'),
preload: join(__dirname, '../preload/preload.js'),
sandbox: false
}
})
Expand Down
2 changes: 1 addition & 1 deletion packages/create-electron/template/solid-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "solid-ts",
"version": "1.0.0",
"description": "An Electron application with Solid and TypeScript",
"main": "./out/main/index.js",
"main": "./out/main/main.js",
"author": "example.com",
"homepage": "https://electron-vite.org",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function createWindow(): void {
autoHideMenuBar: true,
...(process.platform === 'linux' ? { icon } : {}),
webPreferences: {
preload: join(__dirname, '../preload/index.js'),
preload: join(__dirname, '../preload/preload.js'),
sandbox: false
}
})
Expand Down
2 changes: 1 addition & 1 deletion packages/create-electron/template/solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "solid",
"version": "1.0.0",
"description": "An Electron application with Solid",
"main": "./out/main/index.js",
"main": "./out/main/main.js",
"author": "example.com",
"homepage": "https://electron-vite.org",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function createWindow() {
autoHideMenuBar: true,
...(process.platform === 'linux' ? { icon } : {}),
webPreferences: {
preload: join(__dirname, '../preload/index.js'),
preload: join(__dirname, '../preload/preload.js'),
sandbox: false
}
})
Expand Down
2 changes: 1 addition & 1 deletion packages/create-electron/template/svelte-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "svelte-ts",
"version": "1.0.0",
"description": "An Electron application with Svelte and TypeScript",
"main": "./out/main/index.js",
"main": "./out/main/main.js",
"author": "example.com",
"homepage": "https://electron-vite.org",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function createWindow(): void {
autoHideMenuBar: true,
...(process.platform === 'linux' ? { icon } : {}),
webPreferences: {
preload: join(__dirname, '../preload/index.js'),
preload: join(__dirname, '../preload/preload.js'),
sandbox: false
}
})
Expand Down
2 changes: 1 addition & 1 deletion packages/create-electron/template/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "svelte",
"version": "1.0.0",
"description": "An Electron application with Svelte",
"main": "./out/main/index.js",
"main": "./out/main/main.js",
"author": "example.com",
"homepage": "https://electron-vite.org",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function createWindow() {
autoHideMenuBar: true,
...(process.platform === 'linux' ? { icon } : {}),
webPreferences: {
preload: join(__dirname, '../preload/index.js'),
preload: join(__dirname, '../preload/preload.js'),
sandbox: false
}
})
Expand Down
2 changes: 1 addition & 1 deletion packages/create-electron/template/vanilla-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vanilla-ts",
"version": "1.0.0",
"description": "A minimal Electron application with TypeScript",
"main": "./out/main/index.js",
"main": "./out/main/main.js",
"author": "example.com",
"homepage": "https://electron-vite.org",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function createWindow(): void {
autoHideMenuBar: true,
...(process.platform === 'linux' ? { icon } : {}),
webPreferences: {
preload: join(__dirname, '../preload/index.js'),
preload: join(__dirname, '../preload/preload.js'),
sandbox: false
}
})
Expand Down
2 changes: 1 addition & 1 deletion packages/create-electron/template/vanilla/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vanilla",
"version": "1.0.0",
"description": "A minimal Electron application with JavaScript",
"main": "./out/main/index.js",
"main": "./out/main/main.js",
"author": "example.com",
"homepage": "https://electron-vite.org",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function createWindow() {
autoHideMenuBar: true,
...(process.platform === 'linux' ? { icon } : {}),
webPreferences: {
preload: join(__dirname, '../preload/index.js'),
preload: join(__dirname, '../preload/preload.js'),
sandbox: false
}
})
Expand Down
2 changes: 1 addition & 1 deletion packages/create-electron/template/vue-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vue-ts",
"version": "1.0.0",
"description": "An Electron application with Vue and TypeScript",
"main": "./out/main/index.js",
"main": "./out/main/main.js",
"author": "example.com",
"homepage": "https://electron-vite.org",
"scripts": {
Expand Down
74 changes: 0 additions & 74 deletions packages/create-electron/template/vue-ts/src/main/index.ts

This file was deleted.

74 changes: 74 additions & 0 deletions packages/create-electron/template/vue-ts/src/main/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { app, shell, BrowserWindow, ipcMain } from 'electron'
import { join } from 'path'
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
import icon from '../../resources/icon.png?asset'

function createWindow(): void {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 900,
height: 670,
show: false,
autoHideMenuBar: true,
...(process.platform === 'linux' ? { icon } : {}),
webPreferences: {
preload: join(__dirname, '../preload/preload.js'),
sandbox: false
}
})

mainWindow.on('ready-to-show', () => {
mainWindow.show()
})

mainWindow.webContents.setWindowOpenHandler((details) => {
shell.openExternal(details.url)
return { action: 'deny' }
})

// HMR for renderer base on electron-vite cli.
// Load the remote URL for development or the local html file for production.
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
} else {
mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
}
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
// Set app user model id for windows
electronApp.setAppUserModelId('com.electron')

// Default open or close DevTools by F12 in development
// and ignore CommandOrControl + R in production.
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
app.on('browser-window-created', (_, window) => {
optimizer.watchWindowShortcuts(window)
})

// IPC test
ipcMain.on('ping', () => console.log('pong'))

createWindow()

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

// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})

// 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 require them here.
2 changes: 1 addition & 1 deletion packages/create-electron/template/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vue",
"version": "1.0.0",
"description": "An Electron application with Vue",
"main": "./out/main/index.js",
"main": "./out/main/main.js",
"author": "example.com",
"homepage": "https://electron-vite.org",
"scripts": {
Expand Down
74 changes: 0 additions & 74 deletions packages/create-electron/template/vue/src/main/index.js

This file was deleted.

Loading