Skip to content

Commit a028ec2

Browse files
authoredJul 5, 2021
Merge pull request #12 from BUPTlhuanyu/restructure
fix(menu & background): menu & background
2 parents cb6b3e1 + 461a01f commit a028ec2

File tree

9 files changed

+138
-11
lines changed

9 files changed

+138
-11
lines changed
 

‎doc/home.png

762 KB
Loading
355 KB
Loading

‎packages/views/src/pages/home/container/content/index.scss

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.pandora-home-content {
2+
z-index: 1;
23
flex: 1;
34
width: 100%;
45
padding: 40px 8vw 0;

‎packages/views/src/pages/home/container/header/index.scss

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.pandora-home-header {
2+
z-index: 1;
23
-webkit-app-region: drag;
3-
background-color: #231F20;
4+
background-color: rgba(35, 31, 32, 0.65);
45
width: 100%;
56
height: 30px;
67
padding: 0 8vw;

‎packages/views/src/pages/home/index.scss

+13
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,23 @@ body, html, #root, .pandora-home {
33
margin: 0;
44
height: 100%;
55
font-size: 18px;
6+
background: url('../../assets/img/sky.jpeg');
7+
background-size: cover;
68
}
79

810
.pandora-home {
911
display: flex;
1012
align-items: center;
1113
flex-direction: column;
14+
&::before {
15+
content: '';
16+
background: inherit;
17+
position: absolute;
18+
left: 0;
19+
right: 0;
20+
top: 0;
21+
bottom: 0;
22+
box-shadow: inset 0 0 0 3000px rgba(255,255,255,0.3);
23+
filter: blur(1px);
24+
}
1225
}

‎packages/workbench-electron/main/editor/editorMain.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @file
33
*/
4-
import {Menubar} from '../menu/menubar';
4+
import {Menubar, HomeMenubar} from '../menu/menubar';
55
import {registerContextMenuListener} from '../contextmenu/electron-main/contextmenu';
66

77
import path from 'path';
@@ -61,22 +61,16 @@ function createWindow(dispose: Function) {
6161
}
6262

6363
export class CodeMain {
64-
private oldMenus: Menu | null;
6564
constructor() {
6665
this.initServices();
67-
const oldMenu = Menu.getApplicationMenu();
68-
this.oldMenus = null;
69-
if (oldMenu) {
70-
this.oldMenus = oldMenu;
71-
}
7266
}
7367
async startUp(): Promise<void> {
7468
createWindow(this.resetMenu.bind(this));
7569
registerContextMenuListener();
7670
}
7771

7872
private resetMenu () {
79-
this.oldMenus && Menu.setApplicationMenu(this.oldMenus);
73+
new HomeMenubar();
8074
}
8175

8276
private initServices() {

‎packages/workbench-electron/main/main.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
* @file app
33
*/
44
import path from 'path';
5-
import {app, BrowserWindow, ipcMain, Menu} from 'electron';
5+
import {app, BrowserWindow, ipcMain} from 'electron';
6+
import {HomeMenubar} from './menu/menubar';
67
import {DEVELOP_PORT} from 'shared/common/constant';
78

89
import {registerContextMenuListener} from './contextmenu/electron-main/contextmenu';
@@ -51,6 +52,7 @@ function createHome() {
5152

5253
class Home {
5354
constructor () {
55+
new HomeMenubar();
5456
this.registerListeners();
5557
}
5658
private registerListeners () {

‎packages/workbench-electron/main/menu/menubar.ts

+116
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* src/vs/platform/actions/common/actions.ts
66
* vscode 对 menu 的实现都归于 action,非常复杂
77
*/
8+
// TODO:
9+
// 1. 复用
10+
// 2. 设置 settings 方案
811
import {Menu, MenuItem} from 'electron';
912
import {camelToWords} from '../../lib/utils';
1013
import {ICommandService} from 'services/command';
@@ -269,3 +272,116 @@ export class Menubar {
269272
this.appendRoleMenu(windowMenu, roles);
270273
}
271274
}
275+
276+
export class HomeMenubar {
277+
constructor(
278+
// @ICommandService private readonly commandService: ICommandService
279+
) {
280+
this.install();
281+
}
282+
283+
// private addFallbackHandlers(): void {}
284+
285+
private install(): void {
286+
// Menus
287+
const menubar = new Menu();
288+
289+
// app
290+
const applicationMenu = new Menu();
291+
this.setMacApplicationMenu(applicationMenu);
292+
const macApplicationMenuItem = new MenuItem({label: 'Pandora', submenu: applicationMenu});
293+
menubar.append(macApplicationMenuItem);
294+
295+
// Window
296+
const windowMenu = new Menu();
297+
this.setWindowMenu(windowMenu);
298+
const windowItem = new MenuItem({label: 'Window', submenu: windowMenu});
299+
menubar.append(windowItem);
300+
301+
// Help
302+
const helpMenu = new Menu();
303+
this.setHelpMenu(helpMenu);
304+
const helpMenuItem = new MenuItem({label: 'Help', submenu: helpMenu, role: 'help'});
305+
menubar.append(helpMenuItem);
306+
307+
// 设置成窗口顶部菜单
308+
if (menubar.items && menubar.items.length > 0) {
309+
Menu.setApplicationMenu(menubar);
310+
} else {
311+
Menu.setApplicationMenu(null);
312+
}
313+
}
314+
315+
private setMacApplicationMenu(macApplicationMenu: Menu): void {
316+
// const preferences = new MenuItem({
317+
// label: 'preferences',
318+
// click() {}
319+
// });
320+
321+
const services = new MenuItem({
322+
label: 'services',
323+
role: 'services'
324+
});
325+
326+
const quit = new MenuItem({
327+
label: 'quit',
328+
role: 'quit'
329+
});
330+
331+
const actions = [
332+
// about,
333+
// __separator__(),
334+
// preferences,
335+
// update,
336+
__separator__(),
337+
services,
338+
__separator__(),
339+
quit
340+
];
341+
actions.forEach(i => macApplicationMenu.append(i));
342+
}
343+
344+
private setHelpMenu(helpMenu: Menu): void {
345+
// Toggle Developer Tools
346+
const toggleDevtools = new MenuItem({
347+
label: 'Toggle Developer Tools',
348+
role: 'toggleDevTools'
349+
});
350+
const actions = [__separator__(), toggleDevtools];
351+
actions.forEach(i => helpMenu.append(i));
352+
}
353+
354+
private appendRoleMenu(menu: Menu, roles: Role[]) {
355+
roles.forEach(role => {
356+
if (role === '|') {
357+
menu.append(__separator__());
358+
} else {
359+
menu.append(
360+
new MenuItem({
361+
label: camelToWords(role),
362+
role
363+
})
364+
);
365+
}
366+
});
367+
}
368+
369+
private setWindowMenu(windowMenu: Menu): void {
370+
const roles: Role[] = [
371+
'reload',
372+
'forceReload',
373+
'|',
374+
'resetZoom',
375+
'zoomIn',
376+
'zoomOut',
377+
'togglefullscreen',
378+
'minimize',
379+
'|',
380+
'close',
381+
'hide',
382+
'hideOthers',
383+
'unhide'
384+
];
385+
this.appendRoleMenu(windowMenu, roles);
386+
}
387+
}

‎packages/workbench-electron/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "workbench-electron",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"description": "Pandora Workbench",
55
"productName": "Pandora Workbench",
66
"private": true,

0 commit comments

Comments
 (0)
Please sign in to comment.