FIX: ipc & app id
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { app, shell, BrowserWindow, ipcMain, Menu, MenuItem, globalShortcut } from 'electron'
|
import { app, shell, BrowserWindow, ipcMain, Menu, MenuItem } from 'electron'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
||||||
import icon from '../../resources/icon.png?asset'
|
import icon from '../../resources/icon.png?asset'
|
||||||
@@ -28,40 +28,6 @@ const appMenu = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default main window function from electron-vite
|
|
||||||
// Kept for reference
|
|
||||||
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/index.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'))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const createMainWindow = () => {
|
const createMainWindow = () => {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
const mainWindow = new BrowserWindow({
|
const mainWindow = new BrowserWindow({
|
||||||
@@ -100,6 +66,11 @@ const createMainWindow = () => {
|
|||||||
mainWindow.webContents.send('electron:unmaximized')
|
mainWindow.webContents.send('electron:unmaximized')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
mainWindow.webContents.setWindowOpenHandler((details) => {
|
||||||
|
shell.openExternal(details.url)
|
||||||
|
return { action: 'deny' }
|
||||||
|
})
|
||||||
|
|
||||||
// HMR for renderer base on electron-vite cli.
|
// HMR for renderer base on electron-vite cli.
|
||||||
// Load the remote URL for development or the local html file for production.
|
// Load the remote URL for development or the local html file for production.
|
||||||
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
||||||
@@ -165,7 +136,7 @@ const createLoadingWindow = (mainWindow) => {
|
|||||||
// Some APIs can only be used after this event occurs.
|
// Some APIs can only be used after this event occurs.
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(() => {
|
||||||
// Set app user model id for windows
|
// Set app user model id for windows
|
||||||
electronApp.setAppUserModelId('com.electron')
|
electronApp.setAppUserModelId('ZERO/ONE')
|
||||||
|
|
||||||
// Default open or close DevTools by F12 in development
|
// Default open or close DevTools by F12 in development
|
||||||
// and ignore CommandOrControl + R in production.
|
// and ignore CommandOrControl + R in production.
|
||||||
@@ -257,7 +228,13 @@ app.whenReady().then(() => {
|
|||||||
app.on('activate', function () {
|
app.on('activate', function () {
|
||||||
// On macOS it's common to re-create a window in the app when the
|
// 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.
|
// dock icon is clicked and there are no other windows open.
|
||||||
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
if (BrowserWindow.getAllWindows().length === 0) {
|
||||||
|
const mainWindow = createMainWindow()
|
||||||
|
mainWindow.webContents.once('did-finish-load', () => {
|
||||||
|
mainWindow.show()
|
||||||
|
mainWindow.focus()
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -4,36 +4,46 @@ import DevicePreview from '@renderer/components/device/DevicePreview.vue'
|
|||||||
import ConfigPane from '@renderer/components/config/ConfigPane.vue'
|
import ConfigPane from '@renderer/components/config/ConfigPane.vue'
|
||||||
import Navbar from '@renderer/components/navbar/Navbar.vue'
|
import Navbar from '@renderer/components/navbar/Navbar.vue'
|
||||||
import { useStore } from '@renderer/store'
|
import { useStore } from '@renderer/store'
|
||||||
// import { useMessageHandlers } from '@renderer/device'
|
import { useMessageHandlers } from '@renderer/device'
|
||||||
|
|
||||||
// const { electron } = window
|
const { electron } = window
|
||||||
const store = useStore()
|
const store = useStore()
|
||||||
|
|
||||||
// const menuActions = {
|
const menuActions = {
|
||||||
// connect: () => store.setConnected(!store.connected),
|
connect: () => store.setConnected(!store.connected),
|
||||||
// orientation: () => store.cycleScreenOrientation(),
|
orientation: () => store.cycleScreenOrientation(),
|
||||||
// skin: () => store.switchPreviewDeviceModel(),
|
skin: () => store.switchPreviewDeviceModel()
|
||||||
// }
|
}
|
||||||
|
|
||||||
// electron?.onMenu((key) => {
|
electron?.onMenu((key) => {
|
||||||
// console.log('menu', key)
|
console.log('menu', key)
|
||||||
// if (menuActions[key]) {
|
if (menuActions[key]) {
|
||||||
// menuActions[key]()
|
menuActions[key]()
|
||||||
// }
|
}
|
||||||
// })
|
})
|
||||||
|
|
||||||
// store.fetchProfiles() // TODO remove me!
|
store.fetchProfiles() // TODO remove me!
|
||||||
|
|
||||||
// // handle device events
|
// handle device events
|
||||||
// const handlers = useMessageHandlers(store)
|
const handlers = useMessageHandlers(store)
|
||||||
// window.nanodevices.on_event('device-attached', (evt, deviceid, data) => store.device_attached(deviceid))
|
window.nanodevices.on_event('device-attached', (evt, deviceid, data) =>
|
||||||
// window.nanodevices.on_event('device-detached', (evt, deviceid, data) => store.device_detached(deviceid))
|
store.device_attached(deviceid)
|
||||||
// window.nanodevices.on_event('device-error', (evt, deviceid, data) => { /* TODO handle connection errors */ })
|
)
|
||||||
// window.nanodevices.on_event('connected', (evt, deviceid, data) => store.device_connected(deviceid))
|
window.nanodevices.on_event('device-detached', (evt, deviceid, data) =>
|
||||||
// window.nanodevices.on_event('disconnected', (evt, deviceid, data) => store.device_disconnected(deviceid))
|
store.device_detached(deviceid)
|
||||||
// window.nanodevices.on_event('update', (evt, deviceid, data) => { handlers.handle_message(data) })
|
)
|
||||||
// // get list of the currently attached devices
|
window.nanodevices.on_event('device-error', (evt, deviceid, data) => {
|
||||||
// window.nanodevices.list_devices().then((devs)=>store.init_devices(devs))
|
/* TODO handle connection errors */
|
||||||
|
})
|
||||||
|
window.nanodevices.on_event('connected', (evt, deviceid, data) => store.device_connected(deviceid))
|
||||||
|
window.nanodevices.on_event('disconnected', (evt, deviceid, data) =>
|
||||||
|
store.device_disconnected(deviceid)
|
||||||
|
)
|
||||||
|
window.nanodevices.on_event('update', (evt, deviceid, data) => {
|
||||||
|
handlers.handle_message(data)
|
||||||
|
})
|
||||||
|
// get list of the currently attached devices
|
||||||
|
window.nanodevices.list_devices().then((devs) => store.init_devices(devs))
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<main class="select-none w-screen h-screen flex flex-col">
|
<main class="select-none w-screen h-screen flex flex-col">
|
||||||
|
|||||||
Reference in New Issue
Block a user