m19e/nextron-template

How can the macOS app icon be changed in a Nextron application, and what steps are involved in the process, including preparing the icon file, specifying its location in the package.json file, rebuilding the app, and testing the changes on macOS? If the app icon is visible on Windows, but not on macOS

AmanJangid1980 opened this issue · 0 comments

import {
screen,
BrowserWindow,
BrowserWindowConstructorOptions,
Rectangle,
} from 'electron'
import Store from 'electron-store';
import {setDataInDB} from '../models/index'

export const createWindow = (
windowName: string,
options: BrowserWindowConstructorOptions
): BrowserWindow => {
const key = 'window-state'
const name = window-state-${windowName}
const store = new Store({ name })
const defaultSize = {
width: options.width,
height: options.height,
}
let state = {}
const restore = () => store.get(key, defaultSize)
type IpcMainEvent = /unresolved/ any
const getCurrentPosition = () => {
const position = win.getPosition()
const size = win.getSize()
return {
x: position[0],
y: position[1],
width: size[0],
height: size[1],
}
}

const windowWithinBounds = (windowState, bounds) => {
return (
windowState.x >= bounds.x &&
windowState.y >= bounds.y &&
windowState.x + windowState.width <= bounds.x + bounds.width &&
windowState.y + windowState.height <= bounds.y + bounds.height
)
}

const resetToDefaults = () => {
const bounds = screen.getPrimaryDisplay().bounds
return Object.assign({}, defaultSize, {
x: (bounds.width - defaultSize.width) / 2,
y: (bounds.height - defaultSize.height) / 2,
})
}
setDataInDB()
const ensureVisibleOnSomeDisplay = (windowState) => {
const visible = screen.getAllDisplays().some((display) => {
return windowWithinBounds(windowState, display.bounds)
})
if (!visible) {
// Window is partially or fully not visible now.
// Reset it to safe defaults.
return resetToDefaults()
}
return windowState
}

const saveState = () => {
if (!win.isMinimized() && !win.isMaximized()) {
Object.assign(state, getCurrentPosition())
}
store.set(key, state)
}

state = ensureVisibleOnSomeDisplay(restore())

const win = new BrowserWindow({
...state,
...options,
minWidth: 1000,
minHeight: 680,
icon: __dirname + '../../resources/icon.ico',
webPreferences: {
nodeIntegration: true,
contextIsolation: true,
...options.webPreferences,
},
})

win.on('close', saveState)

return win
}