mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-04-24 23:16:53 -05:00
Fix modal window width on Windows
This commit is contained in:
parent
95c2664678
commit
ce0fd9cf9b
|
|
@ -6,7 +6,7 @@ import * as persist from 'node-persist';
|
|||
import MenuApp from './menu.js';
|
||||
import { handleOpenWebServiceUri } from './webservices.js';
|
||||
import { EmbeddedPresenceMonitor, PresenceMonitorManager } from './monitor.js';
|
||||
import { createWindow } from './windows.js';
|
||||
import { createModalWindow, createWindow } from './windows.js';
|
||||
import { setupIpc } from './ipc.js';
|
||||
import { askUserForUri } from './util.js';
|
||||
import { setAppInstance } from './app-menu.js';
|
||||
|
|
@ -99,17 +99,7 @@ export class App {
|
|||
return this.preferences_window;
|
||||
}
|
||||
|
||||
const window = createWindow(WindowType.PREFERENCES, {}, {
|
||||
show: false,
|
||||
maximizable: false,
|
||||
minimizable: false,
|
||||
width: 580,
|
||||
height: 400,
|
||||
minWidth: 580,
|
||||
maxWidth: 580,
|
||||
minHeight: 400,
|
||||
maxHeight: 400,
|
||||
});
|
||||
const window = createModalWindow(WindowType.PREFERENCES, {});
|
||||
|
||||
window.on('closed', () => this.preferences_window = null);
|
||||
|
||||
|
|
@ -242,19 +232,9 @@ export async function handleOpenFriendCodeUri(store: Store, uri: string) {
|
|||
const selected_user = await askUserForUri(store, uri, 'Select a user to add friends');
|
||||
if (!selected_user) return;
|
||||
|
||||
createWindow(WindowType.ADD_FRIEND, {
|
||||
createModalWindow(WindowType.ADD_FRIEND, {
|
||||
user: selected_user[1].user.id,
|
||||
friendcode,
|
||||
}, {
|
||||
// show: false,
|
||||
maximizable: false,
|
||||
minimizable: false,
|
||||
width: 560,
|
||||
height: 300,
|
||||
minWidth: 450,
|
||||
maxWidth: 700,
|
||||
minHeight: 300,
|
||||
maxHeight: 300,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { BrowserWindow, clipboard, dialog, IpcMain, KeyboardEvent, Menu, MenuIte
|
|||
import * as util from 'node:util';
|
||||
import { User } from 'discord-rpc';
|
||||
import openWebService, { QrCodeReaderOptions, WebServiceIpc, WebServiceValidationError } from './webservices.js';
|
||||
import { createWindow, getWindowConfiguration } from './windows.js';
|
||||
import { createModalWindow, createWindow, getWindowConfiguration, setWindowHeight } from './windows.js';
|
||||
import { askAddNsoAccount, askAddPctlAccount } from './na-auth.js';
|
||||
import { App } from './index.js';
|
||||
import { EmbeddedPresenceMonitor } from './monitor.js';
|
||||
|
|
@ -20,8 +20,6 @@ import type { AddFriendProps } from '../browser/add-friend/index.js';
|
|||
|
||||
const debug = createDebug('app:main:ipc');
|
||||
|
||||
const shown_modal_windows = new WeakSet<BrowserWindow>();
|
||||
|
||||
export function setupIpc(appinstance: App, ipcMain: IpcMain) {
|
||||
const store = appinstance.store;
|
||||
const storage = appinstance.store.storage;
|
||||
|
|
@ -83,61 +81,15 @@ export function setupIpc(appinstance: App, ipcMain: IpcMain) {
|
|||
ipcMain.handle('nxapi:coral:addfriend', (e, token: string, nsaid: string) => store.users.get(token).then(u => u.addFriend(nsaid)));
|
||||
|
||||
ipcMain.handle('nxapi:window:showpreferences', () => appinstance.showPreferencesWindow().id);
|
||||
ipcMain.handle('nxapi:window:showfriend', (e, props: FriendProps) => createWindow(WindowType.FRIEND, props, {
|
||||
parent: BrowserWindow.fromWebContents(e.sender) ?? undefined,
|
||||
modal: true,
|
||||
show: false,
|
||||
maximizable: false,
|
||||
minimizable: false,
|
||||
width: 560,
|
||||
height: 300,
|
||||
minWidth: 450,
|
||||
maxWidth: 700,
|
||||
minHeight: 300,
|
||||
maxHeight: 300,
|
||||
}).id);
|
||||
ipcMain.handle('nxapi:window:discord', (e, props: DiscordSetupProps) => createWindow(WindowType.DISCORD_PRESENCE, props, {
|
||||
parent: BrowserWindow.fromWebContents(e.sender) ?? undefined,
|
||||
modal: true,
|
||||
show: false,
|
||||
maximizable: false,
|
||||
minimizable: false,
|
||||
width: 560,
|
||||
height: 300,
|
||||
minWidth: 450,
|
||||
maxWidth: 700,
|
||||
minHeight: 300,
|
||||
maxHeight: 300,
|
||||
}).id);
|
||||
ipcMain.handle('nxapi:window:addfriend', (e, props: AddFriendProps) => createWindow(WindowType.ADD_FRIEND, props, {
|
||||
parent: BrowserWindow.fromWebContents(e.sender) ?? undefined,
|
||||
modal: true,
|
||||
show: false,
|
||||
maximizable: false,
|
||||
minimizable: false,
|
||||
width: 560,
|
||||
height: 300,
|
||||
minWidth: 450,
|
||||
maxWidth: 700,
|
||||
minHeight: 300,
|
||||
maxHeight: 300,
|
||||
}).id);
|
||||
ipcMain.handle('nxapi:window:showfriend', (e, props: FriendProps) =>
|
||||
createModalWindow(WindowType.FRIEND, props, e.sender).id);
|
||||
ipcMain.handle('nxapi:window:discord', (e, props: DiscordSetupProps) =>
|
||||
createModalWindow(WindowType.DISCORD_PRESENCE, props).id);
|
||||
ipcMain.handle('nxapi:window:addfriend', (e, props: AddFriendProps) =>
|
||||
createModalWindow(WindowType.ADD_FRIEND, props, e.sender).id);
|
||||
ipcMain.handle('nxapi:window:setheight', (e, height: number) => {
|
||||
const window = BrowserWindow.fromWebContents(e.sender)!;
|
||||
const [curWidth, curHeight] = window.getSize();
|
||||
const [curContentWidth, curContentHeight] = window.getContentSize();
|
||||
const [minWidth, minHeight] = window.getMinimumSize();
|
||||
const [maxWidth, maxHeight] = window.getMaximumSize();
|
||||
if (height !== curContentHeight && curHeight === minHeight && curHeight === maxHeight) {
|
||||
window.setMinimumSize(minWidth, height + (curHeight - curContentHeight));
|
||||
window.setMaximumSize(maxWidth, height + (curHeight - curContentHeight));
|
||||
}
|
||||
window.setContentSize(curContentWidth, height);
|
||||
|
||||
if (!shown_modal_windows.has(window)) {
|
||||
window.show();
|
||||
shown_modal_windows.add(window);
|
||||
}
|
||||
setWindowHeight(window, height);
|
||||
});
|
||||
|
||||
ipcMain.handle('nxapi:discord:config', () => appinstance.monitors.getDiscordPresenceConfiguration());
|
||||
|
|
@ -249,21 +201,9 @@ function buildUserMenu(app: App, user: NintendoAccountUser, nso?: CurrentUser, m
|
|||
click: () => app.menu?.setActiveDiscordPresenceUser(null)}),
|
||||
] : [
|
||||
new MenuItem({label: 'Enable Discord presence for this user...',
|
||||
click: () => createWindow(WindowType.DISCORD_PRESENCE, {
|
||||
click: () => createModalWindow(WindowType.DISCORD_PRESENCE, {
|
||||
friend_nsa_id: nso.nsaId,
|
||||
}, {
|
||||
parent: window,
|
||||
modal: true,
|
||||
show: false,
|
||||
maximizable: false,
|
||||
minimizable: false,
|
||||
width: 560,
|
||||
height: 300,
|
||||
minWidth: 450,
|
||||
maxWidth: 700,
|
||||
minHeight: 300,
|
||||
maxHeight: 300,
|
||||
})}),
|
||||
}, window)}),
|
||||
]),
|
||||
new MenuItem({label: 'Enable friend notifications', type: 'checkbox',
|
||||
checked: monitor?.friend_notifications,
|
||||
|
|
@ -272,21 +212,9 @@ function buildUserMenu(app: App, user: NintendoAccountUser, nso?: CurrentUser, m
|
|||
click: () => monitor?.skipIntervalInCurrentLoop(true)}),
|
||||
new MenuItem({type: 'separator'}),
|
||||
new MenuItem({label: 'Add friend',
|
||||
click: () => createWindow(WindowType.ADD_FRIEND, {
|
||||
click: () => createModalWindow(WindowType.ADD_FRIEND, {
|
||||
user: user.id,
|
||||
}, {
|
||||
parent: window,
|
||||
modal: true,
|
||||
show: false,
|
||||
maximizable: false,
|
||||
minimizable: false,
|
||||
width: 560,
|
||||
height: 300,
|
||||
minWidth: 450,
|
||||
maxWidth: 700,
|
||||
minHeight: 300,
|
||||
maxHeight: 300,
|
||||
})}),
|
||||
}, window)}),
|
||||
] : []),
|
||||
new MenuItem({type: 'separator'}),
|
||||
new MenuItem({label: 'Use the nxapi command to remove this user', enabled: false}),
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { askAddNsoAccount, askAddPctlAccount } from './na-auth.js';
|
|||
import { App } from './index.js';
|
||||
import openWebService, { WebServiceValidationError } from './webservices.js';
|
||||
import { EmbeddedPresenceMonitor, EmbeddedProxyPresenceMonitor } from './monitor.js';
|
||||
import { createWindow } from './windows.js';
|
||||
import { createModalWindow, createWindow } from './windows.js';
|
||||
import { WindowType } from '../common/types.js';
|
||||
import CoralApi from '../../api/coral.js';
|
||||
import { WebService } from '../../api/coral-types.js';
|
||||
|
|
@ -286,18 +286,8 @@ export default class MenuApp {
|
|||
}
|
||||
|
||||
showAddFriendWindow(user: string) {
|
||||
createWindow(WindowType.ADD_FRIEND, {
|
||||
createModalWindow(WindowType.ADD_FRIEND, {
|
||||
user,
|
||||
}, {
|
||||
show: false,
|
||||
maximizable: false,
|
||||
minimizable: false,
|
||||
width: 560,
|
||||
height: 300,
|
||||
minWidth: 450,
|
||||
maxWidth: 700,
|
||||
minHeight: 300,
|
||||
maxHeight: 300,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import process from 'node:process';
|
|||
import * as crypto from 'node:crypto';
|
||||
import * as persist from 'node-persist';
|
||||
import { protocol_registration_options } from './index.js';
|
||||
import { createWindow } from './windows.js';
|
||||
import { createModalWindow, createWindow } from './windows.js';
|
||||
import { tryGetNativeImageFromUrl } from './util.js';
|
||||
import { WindowType } from '../common/types.js';
|
||||
import { getNintendoAccountSessionToken, NintendoAccountAuthError, NintendoAccountSessionToken } from '../../api/na.js';
|
||||
|
|
@ -313,19 +313,9 @@ function askUserForRedirectUri(
|
|||
authoriseurl: string, client_id: string,
|
||||
handleAuthUrl: (url: URL) => void, rj: (reason: any) => void
|
||||
) {
|
||||
const window = createWindow(WindowType.ADD_ACCOUNT_MANUAL_PROMPT, {
|
||||
const window = createModalWindow(WindowType.ADD_ACCOUNT_MANUAL_PROMPT, {
|
||||
authoriseurl,
|
||||
client_id,
|
||||
}, {
|
||||
show: false,
|
||||
maximizable: false,
|
||||
minimizable: false,
|
||||
width: 560,
|
||||
height: 300,
|
||||
minWidth: 450,
|
||||
maxWidth: 700,
|
||||
minHeight: 300,
|
||||
maxHeight: 300,
|
||||
});
|
||||
|
||||
window.webContents.on('will-navigate', (event, url_string) => {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ app.on('browser-window-blur', (event, window) => {
|
|||
|
||||
export function createWindow<T extends WindowType>(
|
||||
type: T, props: WindowConfiguration<T>['props'],
|
||||
options?: BrowserWindowConstructorOptions
|
||||
options?: BrowserWindowConstructorOptions,
|
||||
) {
|
||||
// Create the browser window
|
||||
const window = new BrowserWindow({
|
||||
|
|
@ -61,6 +61,62 @@ export function getWindowConfiguration(webcontents: WebContents): WindowConfigur
|
|||
return data;
|
||||
}
|
||||
|
||||
const modal_window_width = new WeakMap<BrowserWindow, number>();
|
||||
const modal_window_shown = new WeakSet<BrowserWindow>();
|
||||
|
||||
export function createModalWindow<T extends WindowType>(
|
||||
type: T, props: WindowConfiguration<T>['props'],
|
||||
parent?: BrowserWindow | WebContents,
|
||||
options?: BrowserWindowConstructorOptions,
|
||||
) {
|
||||
if (parent && !(parent instanceof BrowserWindow)) {
|
||||
parent = BrowserWindow.fromWebContents(parent) ?? undefined;
|
||||
}
|
||||
|
||||
const window = createWindow(type, props, {
|
||||
parent,
|
||||
modal: !!parent,
|
||||
show: false,
|
||||
maximizable: false,
|
||||
minimizable: false,
|
||||
width: 560,
|
||||
height: 300,
|
||||
minWidth: 450,
|
||||
maxWidth: 700,
|
||||
minHeight: 300,
|
||||
maxHeight: 300,
|
||||
|
||||
...options,
|
||||
});
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
// Use a fixed window width on Windows due to a bug getting/setting window size
|
||||
window.setResizable(false);
|
||||
modal_window_width.set(window, options?.width ?? 560);
|
||||
}
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
export function setWindowHeight(window: BrowserWindow, height: number) {
|
||||
const [curWidth, curHeight] = window.getSize();
|
||||
const [curContentWidth, curContentHeight] = window.getContentSize();
|
||||
const [minWidth, minHeight] = window.getMinimumSize();
|
||||
const [maxWidth, maxHeight] = window.getMaximumSize();
|
||||
|
||||
if (height !== curContentHeight && curHeight === minHeight && curHeight === maxHeight) {
|
||||
window.setMinimumSize(minWidth, height + (curHeight - curContentHeight));
|
||||
window.setMaximumSize(maxWidth, height + (curHeight - curContentHeight));
|
||||
}
|
||||
|
||||
window.setContentSize(modal_window_width.get(window) ?? curContentWidth, height);
|
||||
|
||||
if (!modal_window_shown.has(window)) {
|
||||
window.show();
|
||||
modal_window_shown.add(window);
|
||||
}
|
||||
}
|
||||
|
||||
const BACKGROUND_COLOUR_MAIN_LIGHT = process.platform === 'win32' ? '#ffffff' : '#ececec';
|
||||
const BACKGROUND_COLOUR_MAIN_DARK = process.platform === 'win32' ? '#000000' : '#252424';
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user