完成deploy服务与基础的通信

This commit is contained in:
dinglili 2024-07-04 10:10:32 +08:00 committed by wangpenglong
parent 1ff8658052
commit c5500f93a5
9 changed files with 951 additions and 0 deletions

View File

@ -0,0 +1,330 @@
// @ts-check
(function () {
'use strict';
const { ipcRenderer, webFrame, contextBridge } = require('electron');
//#region Utilities
/**
* @param {string} channel
* @returns {true | never}
*/
function validateIPC(channel) {
if (!channel) {
throw new Error(`Unsupported event IPC channel '${channel}'`);
}
return true;
}
/**
* @param {string} key the name of the process argument to parse
* @returns {string | undefined}
*/
function parseArgv(key) {
for (const arg of process.argv) {
if (arg.indexOf(`--${key}=`) === 0) {
return arg.split('=')[1];
}
}
return undefined;
}
//#endregion
//#region Resolve Configuration
/**
* @typedef {import('../common/sandboxTypes').ISandboxConfiguration} ISandboxConfiguration
*/
/** @type {ISandboxConfiguration | undefined} */
let configuration = undefined;
/** @type {Promise<ISandboxConfiguration>} */
const resolveConfiguration = (async () => {
const windowConfigIpcChannel = parseArgv('vscode-window-config');
if (!windowConfigIpcChannel) {
throw new Error('Preload: did not find expected vscode-window-config in renderer process arguments list.');
}
try {
validateIPC(windowConfigIpcChannel);
// Resolve configuration from electron-main
const resolvedConfiguration = configuration = await ipcRenderer.invoke(windowConfigIpcChannel);
// Apply `userEnv` directly
Object.assign(process.env, resolvedConfiguration.userEnv);
// Apply zoom level early before even building the
// window DOM elements to avoid UI flicker. We always
// have to set the zoom level from within the window
// because Chrome has it's own way of remembering zoom
// settings per origin (if vscode-file:// is used) and
// we want to ensure that the user configuration wins.
webFrame.setZoomLevel(resolvedConfiguration.zoomLevel ?? 0);
return resolvedConfiguration;
} catch (error) {
throw new Error(`Preload: unable to fetch vscode-window-config: ${error}`);
}
})();
//#endregion
//#region Resolve Shell Environment
/**
* If VSCode is not run from a terminal, we should resolve additional
* shell specific environment from the OS shell to ensure we are seeing
* all development related environment variables. We do this from the
* main process because it may involve spawning a shell.
*
* @type {Promise<typeof process.env>}
*/
const resolveShellEnv = (async () => {
// Resolve `userEnv` from configuration and
// `shellEnv` from the main side
const [userEnv, shellEnv] = await Promise.all([
(async () => (await resolveConfiguration).userEnv)(),
ipcRenderer.invoke('vscode:fetchShellEnv')
]);
return { ...process.env, ...shellEnv, ...userEnv };
})();
//#endregion
//#region Globals Definition
// #######################################################################
// ### ###
// ### !!! DO NOT USE GET/SET PROPERTIES ANYWHERE HERE !!! ###
// ### !!! UNLESS THE ACCESS IS WITHOUT SIDE EFFECTS !!! ###
// ### (https://github.com/electron/electron/issues/25516) ###
// ### ###
// #######################################################################
/**
* @type {import('./globals')}
*/
const globals = {
/**
* A minimal set of methods exposed from Electron's `ipcRenderer`
* to support communication to main process.
*
* @typedef {import('./electronTypes').IpcRenderer} IpcRenderer
* @typedef {import('electron').IpcRendererEvent} IpcRendererEvent
*
* @type {IpcRenderer}
*/
ipcRenderer: {
/**
* @param {string} channel
* @param {any[]} args
*/
send(channel, ...args) {
if (validateIPC(channel)) {
ipcRenderer.send(channel, ...args);
}
},
/**
* @param {string} channel
* @param {any[]} args
* @returns {Promise<any>}
*/
invoke(channel, ...args) {
validateIPC(channel);
return ipcRenderer.invoke(channel, ...args);
},
/**
* @param {string} channel
* @param {(event: IpcRendererEvent, ...args: any[]) => void} listener
* @returns {IpcRenderer}
*/
on(channel, listener) {
validateIPC(channel);
ipcRenderer.on(channel, listener);
return this;
},
/**
* @param {string} channel
* @param {(event: IpcRendererEvent, ...args: any[]) => void} listener
* @returns {IpcRenderer}
*/
once(channel, listener) {
validateIPC(channel);
ipcRenderer.once(channel, listener);
return this;
},
/**
* @param {string} channel
* @param {(event: IpcRendererEvent, ...args: any[]) => void} listener
* @returns {IpcRenderer}
*/
removeListener(channel, listener) {
validateIPC(channel);
ipcRenderer.removeListener(channel, listener);
return this;
}
},
/**
* @type {import('./globals').IpcMessagePort}
*/
ipcMessagePort: {
/**
* @param {string} responseChannel
* @param {string} nonce
*/
acquire(responseChannel, nonce) {
if (validateIPC(responseChannel)) {
const responseListener = (/** @type {IpcRendererEvent} */ e, /** @type {string} */ responseNonce) => {
// validate that the nonce from the response is the same
// as when requested. and if so, use `postMessage` to
// send the `MessagePort` safely over, even when context
// isolation is enabled
if (nonce === responseNonce) {
ipcRenderer.off(responseChannel, responseListener);
window.postMessage(nonce, '*', e.ports);
}
};
// handle reply from main
ipcRenderer.on(responseChannel, responseListener);
}
}
},
/**
* Support for subset of methods of Electron's `webFrame` type.
*
* @type {import('./electronTypes').WebFrame}
*/
webFrame: {
/**
* @param {number} level
*/
setZoomLevel(level) {
if (typeof level === 'number') {
webFrame.setZoomLevel(level);
}
}
},
/**
* Support for a subset of access to node.js global `process`.
*
* Note: when `sandbox` is enabled, the only properties available
* are https://github.com/electron/electron/blob/master/docs/api/process.md#sandbox
*
* @typedef {import('./globals').ISandboxNodeProcess} ISandboxNodeProcess
*
* @type {ISandboxNodeProcess}
*/
process: {
get platform() { return process.platform; },
get arch() { return process.arch; },
get env() { return { ...process.env }; },
get versions() { return process.versions; },
get type() { return 'renderer'; },
get execPath() { return process.execPath; },
/**
* @returns {string}
*/
cwd() {
return process.env['VSCODE_CWD'] || process.execPath.substr(0, process.execPath.lastIndexOf(process.platform === 'win32' ? '\\' : '/'));
},
/**
* @returns {Promise<typeof process.env>}
*/
shellEnv() {
return resolveShellEnv;
},
/**
* @returns {Promise<import('electron').ProcessMemoryInfo>}
*/
getProcessMemoryInfo() {
return process.getProcessMemoryInfo();
},
/**
* @param {string} type
* @param {Function} callback
* @returns {void}
*/
on(type, callback) {
// @ts-ignore
process.on(type, callback);
}
},
/**
* Some information about the context we are running in.
*
* @type {import('./globals').ISandboxContext}
*/
context: {
/**
* A configuration object made accessible from the main side
* to configure the sandbox browser window.
*
* Note: intentionally not using a getter here because the
* actual value will be set after `resolveConfiguration`
* has finished.
*
* @returns {ISandboxConfiguration | undefined}
*/
configuration() {
return configuration;
},
/**
* Allows to await the resolution of the configuration object.
*
* @returns {Promise<ISandboxConfiguration>}
*/
async resolveConfiguration() {
return resolveConfiguration;
}
}
};
// Use `contextBridge` APIs to expose globals to VSCode
// only if context isolation is enabled, otherwise just
// add to the DOM global.
if (process.contextIsolated) {
try {
contextBridge.exposeInMainWorld('vscode', globals);
} catch (error) {
console.error(error);
}
} else {
// @ts-ignore
window.vscode = globals;
}
}());

View File

@ -120,6 +120,8 @@ import { NODE_REMOTE_RESOURCE_CHANNEL_NAME, NODE_REMOTE_RESOURCE_IPC_METHOD_NAME
import { Lazy } from 'vs/base/common/lazy';
import { IAuxiliaryWindowsMainService, isAuxiliaryWindow } from 'vs/platform/auxiliaryWindow/electron-main/auxiliaryWindows';
import { AuxiliaryWindowsMainService } from 'vs/platform/auxiliaryWindow/electron-main/auxiliaryWindowsMainService';
import { IDeployMainService } from 'vs/platform/issue/common/deploy';
import { DeployMainService } from 'vs/platform/issue/electron-main/deployMainService';
/**
* The main VS Code application. There will only ever be one instance,
@ -631,6 +633,8 @@ export class CodeApplication extends Disposable {
// Signal phase: ready - before opening first window
this.lifecycleMainService.phase = LifecycleMainPhase.Ready;
//install window wait to do by dll
await appInstantiationService.invokeFunction(accessor => this.openDeploylWindow(accessor));
// Open Windows
await appInstantiationService.invokeFunction(accessor => this.openFirstWindow(accessor, initialProtocolUrls));
@ -1122,6 +1126,8 @@ export class CodeApplication extends Disposable {
backupMainService.initialize(),
workspacesManagementMainService.initialize()
]);
// deployMainService
services.set(IDeployMainService, new SyncDescriptor(DeployMainService, [this.userEnv]));
return this.mainInstantiationService.createChild(services);
}
@ -1237,6 +1243,10 @@ export class CodeApplication extends Disposable {
// Utility Process Worker
const utilityProcessWorkerChannel = ProxyChannel.fromService(accessor.get(IUtilityProcessWorkerMainService), disposables);
mainProcessElectronServer.registerChannel(ipcUtilityProcessWorkerChannelName, utilityProcessWorkerChannel);
// Deploy
const deployChannel = ProxyChannel.fromService(accessor.get(IDeployMainService), disposables);
mainProcessElectronServer.registerChannel('deploy', deployChannel);
}
private async openFirstWindow(accessor: ServicesAccessor, initialProtocolUrls: IInitialProtocolUrls | undefined): Promise<ICodeWindow[]> {
@ -1354,6 +1364,17 @@ export class CodeApplication extends Disposable {
forceTempProfile
});
}
//wait to do create install window
private async openDeploylWindow(accessor: ServicesAccessor): Promise<void> {
const DeployMainService = accessor.get(IDeployMainService);
await new Promise((resolve, reject) => {
DeployMainService.openDeployWindow().then(() => {
resolve(void 0);
}).catch(() => {
reject(-1);
})
});
}
private afterWindowOpen(): void {

View File

@ -0,0 +1,52 @@
<!-- Copyright (C) Microsoft Corporation. All rights reserved. -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta
http-equiv="Content-Security-Policy"
content="
default-src
'none'
;
img-src
'self'
data:
;
script-src
'self'
;
style-src
'self'
'unsafe-inline'
;
connect-src
'self'
https:
;
font-src
'self'
;
">
</head>
<style>
</style>
<body aria-label="">
<!-- <div id="loader"></div> -->
<h1>hello</h1>
<div>
<button class="prevStep" id="prevStep" ></button>
<button class="cancel" id="cancel" style="display:none"></button>
<button class="nextStep" id="nextStep" type="submit"></button>
<button id="justfortest" style="width: 100px; height: 50px;">Click me</button>
</div>
</body>
<!-- Startup (do not modify order of script tags!) -->
<script src="../../../../bootstrap.js"></script>
<script src="../../../../vs/loader.js"></script>
<script src="../../../../bootstrap-window.js"></script>
<script src="deployWindow.js"></script>
</html>

View File

@ -0,0 +1,48 @@
<!-- Copyright (C) Microsoft Corporation. All rights reserved. -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta
http-equiv="Content-Security-Policy"
content="
default-src
'none'
;
img-src
'self'
data:
;
script-src
'self'
;
style-src
'self'
'unsafe-inline'
;
connect-src
'self'
https:
;
font-src
'self'
;
">
</head>
<style>
</style>
<body aria-label="">
<div id="loader"></div>
<p>hello</p>
<div id="process-list"></div>
</body>
<!-- Startup (do not modify order of script tags!) -->
<script src="../../../../bootstrap.js"></script>
<script src="../../../../vs/loader.js"></script>
<script src="../../../../bootstrap-window.js"></script>
<script src="deployWindow.js"></script>
</html>

View File

@ -0,0 +1,46 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
//@ts-check
(function () {
'use strict';
const bootstrapWindow = bootstrapWindowLib();
console.log("-----------------dll------deploy load before--js-----function");
// Load deploy into window
bootstrapWindow.load(['vs/code/electron-sandbox/deploy/deployWindowMain'], function (deployMain, configuration) {
console.log("-----------------dll--------js-----startupdeploy");
return deployMain.startup(configuration);
}, {
configureDeveloperSettings: function () {
return {
forceEnableDeveloperKeybindings: true
};
},
});
/**
* @typedef {import('../../../base/parts/sandbox/common/sandboxTypes').ISandboxConfiguration} ISandboxConfiguration
*
* @returns {{
* load: (
* modules: string[],
* resultCallback: (result, configuration: ISandboxConfiguration) => unknown,
* options?: {
* configureDeveloperSettings?: (config: ISandboxConfiguration) => {
* forceEnableDeveloperKeybindings?: boolean,
* disallowReloadKeybinding?: boolean,
* removeDeveloperKeybindingsAfterLoad?: boolean
* }
* }
* ) => Promise<unknown>
* }}
*/
function bootstrapWindowLib() {
console.log("---------deploy-----bootstrapWindowLib---------------------");
// @ts-ignore (defined in bootstrap-window.js)
return window.MonacoBootstrapWindow;
}
}());

View File

@ -0,0 +1,61 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import 'vs/css!./media/deploy';
import 'vs/base/browser/ui/codicons/codiconStyles'; // make sure codicon css is loaded
import { localize } from 'vs/nls';
import { $, append, createStyleSheet } from 'vs/base/browser/dom';
import { IListVirtualDelegate } from 'vs/base/browser/ui/list/list';
import { DataTree } from 'vs/base/browser/ui/tree/dataTree';
import { IDataSource, ITreeNode, ITreeRenderer } from 'vs/base/browser/ui/tree/tree';
import { RunOnceScheduler } from 'vs/base/common/async';
import { ProcessItem } from 'vs/base/common/processes';
import { IContextMenuItem } from 'vs/base/parts/contextmenu/common/contextmenu';
import { popup } from 'vs/base/parts/contextmenu/electron-sandbox/contextmenu';
import { ipcRenderer } from 'vs/base/parts/sandbox/electron-sandbox/globals';
import { IRemoteDiagnosticError, isRemoteDiagnosticError } from 'vs/platform/diagnostics/common/diagnostics';
import { ByteSize } from 'vs/platform/files/common/files';
import { ElectronIPCMainProcessService } from 'vs/platform/ipc/electron-sandbox/mainProcessService';
import { DeployData, DeployWindowConfiguration } from 'vs/platform/issue/common/deploy';
import { INativeHostService } from 'vs/platform/native/common/native';
import { NativeHostService } from 'vs/platform/native/common/nativeHostService';
import { getIconsStyleSheet } from 'vs/platform/theme/browser/iconsStyleSheet';
import { applyZoom, zoomIn, zoomOut } from 'vs/platform/window/electron-sandbox/window';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { KeyCode } from 'vs/base/common/keyCodes';
import { mainWindow } from 'vs/base/browser/window';
class deployWindow {
private nativeHostService: INativeHostService;
constructor(windowId: number, private data: DeployData) {
const mainProcessService = new ElectronIPCMainProcessService(windowId);
this.nativeHostService = new NativeHostService(windowId, mainProcessService) as INativeHostService;
console.log("------------dll------------------justfortest button");
document.getElementById('justfortest')?.addEventListener('click', () => {
console.log("------------dll--------send----------vscode:kylinide.installWizard.minw");
ipcRenderer.send('vscode:kylinide.installWizard.minw');
// ipcRenderer.send('kylin:kylinide.installWizard.minw');
});
ipcRenderer.on('vscode:kylinide.installWizard.minw.response', (event: unknown) => {
console.log("------------dll--------rev---------vscode:kylinide.installWizard.minw.response");
});
}
}
export function startup(configuration: DeployWindowConfiguration): void {
console.log("-----------------dll---------head----startupdeploy");
// const platformClass = configuration.data.platform === 'win32' ? 'windows' : configuration.data.platform === 'linux' ? 'linux' : 'mac';
// mainWindow.document.body.classList.add(platformClass); // used by our fonts
// createCodiconStyleSheet();
// applyZoom(configuration.data.zoomLevel);
console.log("-----------------dll-------------startupdeploy");
new deployWindow(configuration.windowId, configuration.data);
}

View File

@ -0,0 +1,65 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { URI } from 'vs/base/common/uri';
import { ISandboxConfiguration } from 'vs/base/parts/sandbox/common/sandboxTypes';
import { PerformanceInfo, SystemInfo } from 'vs/platform/diagnostics/common/diagnostics';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
// Since data sent through the service is serialized to JSON, functions will be lost, so Color objects
// should not be sent as their 'toString' method will be stripped. Instead convert to strings before sending.
export interface WindowStyles {
backgroundColor?: string;
color?: string;
}
export interface WindowData {
styles: WindowStyles;
zoomLevel: number;
}
export const enum DeployType {
OnlineDeploy,
OnlineDownLoad,
OfflineDeploy,
SkipAll
}
export interface ISettingSearchResult {
extensionId: string;
key: string;
score: number;
}
export interface DeployStyles extends WindowStyles {
listHoverBackground?: string;
listHoverForeground?: string;
listFocusBackground?: string;
listFocusForeground?: string;
listFocusOutline?: string;
listActiveSelectionBackground?: string;
listActiveSelectionForeground?: string;
listHoverOutline?: string;
scrollbarShadowColor?: string;
scrollbarSliderBackgroundColor?: string;
scrollbarSliderHoverBackgroundColor?: string;
scrollbarSliderActiveBackgroundColor?: string;
}
export interface DeployData extends WindowData {
pid: number;
styles: DeployStyles;
platform: string;
applicationName: string;
}
export interface DeployWindowConfiguration extends ISandboxConfiguration {
data: DeployData;
}
export const IDeployMainService = createDecorator<IDeployMainService>('deployService');
export interface IDeployMainService {
readonly _serviceBrand: undefined;
openDeployWindow(): Promise<any>;
}

View File

@ -0,0 +1,328 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { BrowserWindow, BrowserWindowConstructorOptions, contentTracing, Display, ipcMain, IpcMainEvent, screen, Menu } from 'electron';
import { arch, release, type } from 'os';
import { resolve } from 'path';
import { Promises, raceTimeout, timeout } from 'vs/base/common/async';
import { CancellationTokenSource } from 'vs/base/common/cancellation';
import { randomPath } from 'vs/base/common/extpath';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { FileAccess } from 'vs/base/common/network';
import { IProcessEnvironment, isMacintosh } from 'vs/base/common/platform';
import { URI } from 'vs/base/common/uri';
import { listProcesses } from 'vs/base/node/ps';
import { validatedIpcMain } from 'vs/base/parts/ipc/electron-main/ipcMain';
import { localize } from 'vs/nls';
import { IDiagnosticsService, isRemoteDiagnosticError, PerformanceInfo, SystemInfo } from 'vs/platform/diagnostics/common/diagnostics';
import { IDiagnosticsMainService } from 'vs/platform/diagnostics/electron-main/diagnosticsMainService';
import { IDialogMainService } from 'vs/platform/dialogs/electron-main/dialogMainService';
import { IEnvironmentMainService } from 'vs/platform/environment/electron-main/environmentMainService';
import { IDeployMainService, DeployWindowConfiguration, DeployData } from 'vs/platform/issue/common/deploy';
import { ILogService } from 'vs/platform/log/common/log';
import { INativeHostMainService } from 'vs/platform/native/electron-main/nativeHostMainService';
import product from 'vs/platform/product/common/product';
import { IProductService } from 'vs/platform/product/common/productService';
import { IIPCObjectUrl, IProtocolMainService } from 'vs/platform/protocol/electron-main/protocol';
import { IStateService } from 'vs/platform/state/node/state';
import { UtilityProcess } from 'vs/platform/utilityProcess/electron-main/utilityProcess';
import { zoomLevelToZoomFactor } from 'vs/platform/window/common/window';
import { ICodeWindow, IWindowState } from 'vs/platform/window/electron-main/window';
import { IWindowsMainService } from 'vs/platform/windows/electron-main/windows';
// import { IColorTheme, IThemeService } from 'vs/platform/theme/common/themeService';
import { INativeWorkbenchEnvironmentService } from 'vs/workbench/services/environment/electron-sandbox/environmentService';
import { activeContrastBorder, buttonBackground, buttonForeground, buttonHoverBackground, editorBackground, editorForeground, foreground, inputActiveOptionBorder, inputBackground, inputBorder, inputForeground, inputValidationErrorBackground, inputValidationErrorBorder, inputValidationErrorForeground, listActiveSelectionBackground, listActiveSelectionForeground, listFocusBackground, listFocusForeground, listFocusOutline, listHoverBackground, listHoverForeground, scrollbarShadow, scrollbarSliderActiveBackground, scrollbarSliderBackground, scrollbarSliderHoverBackground, textLinkActiveForeground, textLinkForeground } from 'vs/platform/theme/common/colorRegistry';
// import { getZoomLevel } from 'vs/base/browser/browser';
import { IThemeMainService } from 'vs/platform/theme/electron-main/themeMainService'
import { platform } from 'vs/base/common/process';
const deployWindowState = 'deploy.deployWindowState';
interface IBrowserWindowOptions {
backgroundColor: string | undefined;
title: string;
zoomLevel: number;
alwaysOnTop: boolean;
}
type IStrictWindowState = Required<Pick<IWindowState, 'x' | 'y' | 'width' | 'height'>>;
export class DeployMainService implements IDeployMainService {
declare readonly _serviceBrand: undefined;
private static readonly DEFAULT_BACKGROUND_COLOR = '#1E1E1E';
private DeployWindow: BrowserWindow | null = null;
constructor(
private userEnv: IProcessEnvironment,
@IEnvironmentMainService private readonly environmentMainService: IEnvironmentMainService,
@ILogService private readonly logService: ILogService,
@IDiagnosticsService private readonly diagnosticsService: IDiagnosticsService,
@IDiagnosticsMainService private readonly diagnosticsMainService: IDiagnosticsMainService,
@IDialogMainService private readonly dialogMainService: IDialogMainService,
@INativeHostMainService private readonly nativeHostMainService: INativeHostMainService,
@IProtocolMainService private readonly protocolMainService: IProtocolMainService,
@IProductService private readonly productService: IProductService,
@IStateService private readonly stateService: IStateService,
@IWindowsMainService private readonly windowsMainService: IWindowsMainService,
// @IThemeMainService private readonly themeMainService: IThemeMainService,
// @IThemeService private readonly themeService: IThemeService,
// @INativeWorkbenchEnvironmentService private readonly environmentService: INativeWorkbenchEnvironmentService,
) {
this.registerListeners();
}
//#region Register Listeners
private registerListeners(): void {
//接收从渲染进程发送的消息
console.log(" ipcmain on ------------dlll----------registerListeners");
validatedIpcMain.on('vscode:justfortest', event => {
console.log(" ipcmain on ------------dlll----------vscode:justfortest");
// ipcMain.send("");
});
}
//#endregion
//#region Used by renderer
async openDeployWindow(): Promise<void> {
return new Promise(async (resolve, reject) => {
if (!this.DeployWindow) {
const data = {} as DeployData;
const DeployDisposables = new DisposableStore();
const deployWindowConfigUrl = DeployDisposables.add(this.protocolMainService.createIPCObjectUrl<DeployWindowConfiguration>());
console.log("---------------------deployWindowConfigUrl", deployWindowConfigUrl.resource.toString());
const position = this.getDeployWindowPosition(582, 486);
this.DeployWindow = this.createDeployBrowserWindow(position, deployWindowConfigUrl, 'deploy');
// // Store into config object URL
deployWindowConfigUrl.update({
appRoot: this.environmentMainService.appRoot,
windowId: this.DeployWindow.id,
userEnv: this.userEnv,
data,
product
});
this.DeployWindow.loadURL(
FileAccess.asBrowserUri(`vs/code/electron-sandbox/deploy/deployWindow${this.environmentMainService.isBuilt ? '' : '-dev'}.html`).toString(true)
);
// this.DeployWindow.setMenu(null);
// this.DeployWindow.setMenuBarVisibility(false);
// // Menu.setApplicationMenu(null);
this.DeployWindow.on('close', () => {
console.log("-----------------window close\n");
this.DeployWindow = null;
DeployDisposables.dispose();
});
validatedIpcMain.on('vscode:kylinide.installWizard.minw', async (event) => {
console.log(" ipcmain on ------------dlll----------kylinide.installWizard.minw");
// this.safeSend(event, "vscode:kylinide.installWizard.minw.response");
if (this.DeployWindow && this.DeployWindow != undefined) {
this.DeployWindow.close();
resolve(void 0);
}
});
}
if (this.DeployWindow) {
this.focusWindow(this.DeployWindow);
}
});
}
async openDeployWindowEn2(): Promise<void> {
//获取所有的窗口id
// return new Promise(async (resolve, reject) => {
// if (!this.DeployWindow) {
// const data = {} as DeployData;
// const DeployDisposables = new DisposableStore();
// const deployWindowConfigUrl = DeployDisposables.add(this.protocolMainService.createIPCObjectUrl<DeployWindowConfiguration>());
// console.log("---------------------deployWindowConfigUrl", deployWindowConfigUrl.resource.toString());
// const position = this.getDeployWindowPosition(800, 800);
// this.DeployWindow = this.createDeployBrowserWindow(position, deployWindowConfigUrl, 'deploy');
// // Store into config object URL
// deployWindowConfigUrl.update({
// appRoot: this.environmentMainService.appRoot,
// windowId: this.DeployWindow.id,
// userEnv: this.userEnv,
// data,
// product
// });
// this.DeployWindow.loadURL(
// FileAccess.asBrowserUri(`vs/code/electron-sandbox/deploy/deploy${this.environmentMainService.isBuilt ? '' : '-dev'}.html`).toString(true)
// );
// this.DeployWindow.on('close', () => {
// console.log("-----------------window close\n");
// this.DeployWindow = null;
// DeployDisposables.dispose();
// });
// validatedIpcMain.on('vscode:kylinide.installWizard.minw', async (event) => {
// console.log(" ipcmain on ------------dlll----------kylinide.installWizard.minw");
// // this.safeSend(event, "vscode:kylinide.installWizard.minw.response");
// if (this.DeployWindow && this.DeployWindow != undefined) {
// this.DeployWindow.close();
// resolve(void 0);
// }
// });
// }
// if (this.DeployWindow) {
// this.focusWindow(this.DeployWindow);
// }
// });
}
private focusWindow(window: BrowserWindow): void {
if (window.isMinimized()) {
window.restore();
}
window.focus();
}
private safeSend(event: IpcMainEvent, channel: string, ...args: unknown[]): void {
if (!event.sender.isDestroyed()) {
event.sender.send(channel, ...args);
}
}
private createDeployBrowserWindow<T>(position: IWindowState, ipcObjectUrl: IIPCObjectUrl<T>, windowKind: string): BrowserWindow {
const window = new BrowserWindow({
fullscreen: false,
resizable: true,
width: position.width,
height: position.height,
minWidth: 300,
minHeight: 200,
x: position.x,
y: position.y,
backgroundColor: DeployMainService.DEFAULT_BACKGROUND_COLOR,
webPreferences: {
preload: FileAccess.asFileUri('vs/base/parts/sandbox/electron-sandbox/deploypreload.js').fsPath,
additionalArguments: [`--vscode-window-config=${ipcObjectUrl.resource.toString()}`],
v8CacheOptions: this.environmentMainService.useCodeCache ? 'bypassHeatCheck' : 'none',
enableWebSQL: false,
spellcheck: false,
sandbox: true
},
alwaysOnTop: false,
titleBarStyle: 'hidden',
icon: '/home/kylin/project/kylin-ide/kylin-ide/resources/linux/code.png',
frame: false
} as BrowserWindowConstructorOptions & { experimentalDarkMode: true })
// window.setAutoHideMenuBar(true);
// window.setMenuBarVisibility(false);
return window;
}
private getDeployWindowPosition(defaultWidth: number, defaultHeight: number): IStrictWindowState {
// We want the new window to open on the same display that the parent is in
let displayToUse: Display | undefined;
const displays = screen.getAllDisplays();
// Single Display
if (displays.length === 1) {
displayToUse = displays[0];
}
// Multi Display
else {
// on mac there is 1 menu per window so we need to use the monitor where the cursor currently is
if (isMacintosh) {
const cursorPoint = screen.getCursorScreenPoint();
displayToUse = screen.getDisplayNearestPoint(cursorPoint);
}
// fallback to primary display or first display
if (!displayToUse) {
displayToUse = screen.getPrimaryDisplay() || displays[0];
}
}
const displayBounds = displayToUse.bounds;
const state: IStrictWindowState = {
width: defaultWidth,
height: defaultHeight,
x: displayBounds.x + (displayBounds.width / 2) - (defaultWidth / 2),
y: displayBounds.y + (displayBounds.height / 2) - (defaultHeight / 2)
};
if (displayBounds.width > 0 && displayBounds.height > 0 /* Linux X11 sessions sometimes report wrong display bounds */) {
if (state.x < displayBounds.x) {
state.x = displayBounds.x; // prevent window from falling out of the screen to the left
}
if (state.y < displayBounds.y) {
state.y = displayBounds.y; // prevent window from falling out of the screen to the top
}
if (state.x > (displayBounds.x + displayBounds.width)) {
state.x = displayBounds.x; // prevent window from falling out of the screen to the right
}
if (state.y > (displayBounds.y + displayBounds.height)) {
state.y = displayBounds.y; // prevent window from falling out of the screen to the bottom
}
if (state.width! > displayBounds.width) {
state.width = displayBounds.width; // prevent window from exceeding display bounds width
}
if (state.height! > displayBounds.height) {
state.height = displayBounds.height; // prevent window from exceeding display bounds height
}
}
return state;
}
}
// function isStrictWindowState(obj: unknown): obj is IStrictWindowState {
// if (typeof obj !== 'object' || obj === null) {
// return false;
// }
// return (
// 'x' in obj &&
// 'y' in obj &&
// 'width' in obj &&
// 'height' in obj
// );
// }
// function getColor(theme: IColorTheme, key: string): string | undefined {
// const color = theme.getColor(key);
// return color ? color.toString() : undefined;
// }