mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-07-18 16:32:17 -05:00
Fix auth protocol registration on Windows when running from source
This commit is contained in:
parent
99f263cef8
commit
6310485db7
|
|
@ -23,8 +23,17 @@ import { handleAuthUri } from './na-auth.js';
|
|||
|
||||
const debug = createDebug('app:main');
|
||||
|
||||
export const protocol_registration_options = dev && process.platform === 'win32' ? {
|
||||
path: process.execPath,
|
||||
argv: [
|
||||
path.join(dir, 'dist', 'app', 'main', 'app-entry.cjs'),
|
||||
],
|
||||
} : null;
|
||||
export const login_item_options: LoginItemSettingsOptions = {};
|
||||
|
||||
debug('Protocol registration options', protocol_registration_options);
|
||||
debug('Login item registration options', login_item_options);
|
||||
|
||||
export class App {
|
||||
readonly store: Store;
|
||||
readonly monitors: PresenceMonitorManager;
|
||||
|
|
@ -141,13 +150,8 @@ export async function init() {
|
|||
}
|
||||
});
|
||||
|
||||
if (dev && process.platform === 'win32') {
|
||||
app.setAsDefaultProtocolClient('com.nintendo.znca', process.execPath, [
|
||||
path.join(dir, 'dist', 'app', 'main', 'app-entry.cjs'),
|
||||
]);
|
||||
} else {
|
||||
app.setAsDefaultProtocolClient('com.nintendo.znca');
|
||||
}
|
||||
app.setAsDefaultProtocolClient('com.nintendo.znca',
|
||||
protocol_registration_options?.path, protocol_registration_options?.argv);
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) appinstance.showMainWindow();
|
||||
|
|
@ -175,6 +179,8 @@ export async function init() {
|
|||
}
|
||||
|
||||
function tryHandleUrl(app: App, url: string) {
|
||||
debug('Attempting to handle URL', url);
|
||||
|
||||
if (url.match(/^npf[0-9a-f]{16}:\/\/auth($|\?|\#)/i)) {
|
||||
handleAuthUri(url);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import { tryGetNativeImageFromUrl } from './util.js';
|
|||
import { ZNCA_API_USE_URL } from '../../common/constants.js';
|
||||
import { createWindow } from './windows.js';
|
||||
import { WindowType } from '../common/types.js';
|
||||
import { protocol_registration_options } from './index.js';
|
||||
|
||||
const debug = createDebug('app:main:na-auth');
|
||||
|
||||
|
|
@ -256,14 +257,18 @@ export function getSessionTokenCodeByDefaultBrowser(
|
|||
if (force_manual) {
|
||||
debug('Manual entry forced, prompting for redirect URI');
|
||||
window = askUserForRedirectUri(authoriseurl, client_id, handleAuthUrl, rj);
|
||||
} else if (app.isDefaultProtocolClient(protocol)) {
|
||||
} else if (app.isDefaultProtocolClient(protocol,
|
||||
protocol_registration_options?.path, protocol_registration_options?.argv
|
||||
)) {
|
||||
debug('App is already default protocol handler, opening browser');
|
||||
auth_state.set(state, [handleAuthUrl, rj, protocol]);
|
||||
shell.openExternal(authoriseurl);
|
||||
} else {
|
||||
const registered_app = app.getApplicationNameForProtocol(protocol);
|
||||
|
||||
if (registered_app || !app.setAsDefaultProtocolClient(protocol)) {
|
||||
if (registered_app || !app.setAsDefaultProtocolClient(protocol,
|
||||
protocol_registration_options?.path, protocol_registration_options?.argv
|
||||
)) {
|
||||
debug('Another app is using the auth protocol or registration failed, prompting for redirect URI');
|
||||
window = askUserForRedirectUri(authoriseurl, client_id, handleAuthUrl, rj);
|
||||
} else {
|
||||
|
|
@ -298,7 +303,8 @@ export function handleAuthUri(url_string: string) {
|
|||
|
||||
app.on('quit', () => {
|
||||
for (const [,, protocol] of auth_state.values()) {
|
||||
app.removeAsDefaultProtocolClient(protocol);
|
||||
app.removeAsDefaultProtocolClient(protocol,
|
||||
protocol_registration_options?.path, protocol_registration_options?.argv);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user