Skip to content

Commit 2a41f66

Browse files
Chugunov RomanChugunov Roman
authored andcommitted
Added the update tab title feature
and the open in new tab feature
1 parent 564dcf7 commit 2a41f66

16 files changed

Lines changed: 109 additions & 52 deletions

File tree

@types/common/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
interface Tab {
22
id: number;
3-
name: string;
3+
title: string;
44
url: string;
55
}

@types/renderer/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window
55
version: number;
66
fileBrowser: boolean;
77

8-
postMessage(name: string, args: Array<string>, transferList: Array<string>): void;
9-
promiseMessage(name: string, args: Array<string>, transferList: Array<string>): Promise<void>
8+
postMessage(name: string, args?: any, transferList?: Array<string>): void;
9+
promiseMessage(name: string, args?: any, transferList?: Array<string>): Promise<void>
1010
setMessageHandler(handler: Function): void;
1111
};
1212
}

config/webpack.config.renderer.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const rootFolder = process.cwd();
77
const dev = {
88

99
entry: {
10-
'../middleware/web': path.resolve(rootFolder, 'src/middleware/web.ts')
10+
'../middleware/loadMainContetnt': path.resolve(rootFolder, 'src/middleware/loadMainContetnt.ts'),
11+
'../middleware/loadContetnt': path.resolve(rootFolder, 'src/middleware/loadContetnt.ts')
1112
},
1213

1314
module: {
@@ -39,7 +40,8 @@ const dev = {
3940
extensions: ['.ts', '.tsx', ".js", ".jsx", ".json", ".scss"],
4041
modules: [
4142
"node_modules",
42-
"preact"],
43+
"preact"
44+
],
4345
alias: {
4446
'components': path.resolve(rootFolder, 'src/renderer/components'),
4547
'store': path.resolve(rootFolder, 'src/renderer/store'),

src/main/App.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ class App implements IApp {
2626
webPreferences: {
2727
zoomFactor: 0.9,
2828
nodeIntegration: true,
29+
nodeIntegrationInWorker: false,
30+
webviewTag: false,
2931
webSecurity: false,
3032
webgl: true,
3133
experimentalFeatures: true,
3234
experimentalCanvasFeatures: true
3335
}
34-
}
36+
};
3537

3638
const home = 'https://www.figma.com';
3739
this.windowManager = new WindowManager(options, home);

src/main/utils/Args.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default () => {
66
let withoutFrame = true;
77

88
if (argv.indexOf('-v') != -1) {
9-
console.log(typeof pjson.version === 'string' ? pjson.version : '0.0.4' );
9+
console.log(typeof pjson.version === 'string' ? pjson.version : '0.1.0' );
1010
process.exit(0);
1111
}
1212

src/main/utils/constants.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ const CLOSETAB = 'closetab';
55
const CLOSEALLTAB = 'closealltab';
66
const MAINTAB = 'maintab';
77

8+
const SETTITLE = 'setTitle';
9+
810
export {
911
NEWTAB,
1012
TABADDED,
1113
FOCUSTAB,
1214
CLOSETAB,
1315
MAINTAB,
14-
CLOSEALLTAB
16+
CLOSEALLTAB,
17+
18+
SETTITLE
1519
}

src/main/utils/index.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
export { winUrlDev, winUrlProd } from './common';
2-
export { NEWTAB, CLOSETAB, CLOSEALLTAB, TABADDED, FOCUSTAB, MAINTAB } from './constants';
3-
export { default as shortcuts } from './shortcuts';
4-
export { default as isDev } from './dev';
1+
export {
2+
winUrlDev,
3+
winUrlProd
4+
} from './common';
5+
6+
export {
7+
NEWTAB,
8+
CLOSETAB,
9+
CLOSEALLTAB,
10+
TABADDED,
11+
FOCUSTAB,
12+
MAINTAB,
13+
SETTITLE
14+
} from './constants';
15+
16+
export {
17+
default as shortcuts
18+
} from './shortcuts';
19+
20+
export {
21+
default as isDev
22+
} from './dev';

src/main/webContent/Tabs.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as E from "electron";
22
import * as path from "path";
33

4+
import { isDev } from "../utils";
5+
46
interface ITabs { }
57

68
class Tabs implements ITabs {
@@ -16,7 +18,7 @@ class Tabs implements ITabs {
1618
experimentalFeatures: true,
1719
experimentalCanvasFeatures: true,
1820
zoomFactor: 0.9,
19-
preload: path.resolve(`${process.cwd()}/dist/`, 'middleware', preloadScript || '')
21+
preload: path.resolve(isDev ? `${process.cwd()}/dist/` : `${__dirname}/../`, 'middleware', preloadScript || '')
2022
}
2123
});
2224

@@ -26,7 +28,7 @@ class Tabs implements ITabs {
2628
});
2729
tab.setBounds(options);
2830
tab.webContents.loadURL(url);
29-
tab.webContents.toggleDevTools();
31+
isDev && tab.webContents.toggleDevTools();
3032

3133
Tabs.tabs.push(tab);
3234

@@ -58,7 +60,7 @@ class Tabs implements ITabs {
5860
}
5961
});
6062
}
61-
63+
6264
public static focus = (id: number): E.BrowserView => {
6365
return Tabs.tabs.find(t => t.id === id) as E.BrowserView;
6466
}

src/main/webContent/WindowManager.ts

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
CLOSETAB,
1414
FOCUSTAB,
1515
CLOSEALLTAB,
16-
MAINTAB
16+
MAINTAB,
17+
SETTITLE
1718
} from "../utils";
1819

1920
interface IWindowManager {
@@ -37,26 +38,37 @@ class WindowManager implements IWindowManager {
3738
this.mainWindow = new E.BrowserWindow(options);
3839
this.mainWindow.loadURL(isDev ? winUrlDev : winUrlProd);
3940

40-
E.session.defaultSession!.setPermissionRequestHandler((webContents, permission, callback) => {
41-
const whitelist = [
42-
'fullscreen',
43-
'pointerLock',
44-
];
45-
callback(!!whitelist.indexOf(permission));
46-
});
47-
4841
const tab = Tabs.newTab(`${home}/login`, {
4942
x: 0,
5043
y: parseInt((28 * await this.getZoom()+'').substr(0,4)),
5144
width: this.mainWindow.getContentBounds().width,
5245
height: this.mainWindow.getContentBounds().height - parseInt((28 * await this.getZoom()+'').substr(0,4))
53-
}, 'web.js');
54-
tab.webContents.on('will-navigate', this.onMainWindowWillNavigate);
55-
46+
}, 'loadMainContetnt.js');
47+
5648
this.mainWindow.setBrowserView(tab);
49+
tab.webContents.on('will-navigate', this.onMainWindowWillNavigate);
50+
tab.webContents.on('new-window', (event: Event, url: string, fileName: string, disposition, options, additionalFeatures) => {
51+
// console.log('mainWindow.webContents will-navigate: ', url, fileName, disposition, options, additionalFeatures);
52+
let view;
53+
54+
this.getZoom().then(zoom => {
55+
view = Tabs.newTab(`${url}`, {
56+
x: 0,
57+
y: parseInt((28 * zoom+'').substr(0,4)),
58+
width: this.mainWindow.getContentBounds().width,
59+
height: this.mainWindow.getContentBounds().height - parseInt((28 * zoom+'').substr(0,4))
60+
}, 'loadContetnt.js');
61+
62+
view.webContents.on('will-navigate', this.onMainWindowWillNavigate);
63+
64+
this.mainWindow.setBrowserView(view);
65+
this.mainWindow.webContents.send(TABADDED, { id: view.id, url});
66+
})
67+
});
5768
this.mainWindow.on('resize', this.onResize);
5869
this.mainWindow.on('maximize', (e: Event) => setTimeout(() => this.onResize(e), 100));
5970
this.mainWindow.on('unmaximize', (e: Event) => setTimeout(() => this.onResize(e), 100));
71+
this.mainWindow.on('move', (e: Event) => setTimeout(() => this.onResize(e), 100));
6072
this.mainWindow.on('close', this.onWindowAllClosed);
6173

6274
shortcuts();
@@ -67,7 +79,7 @@ class WindowManager implements IWindowManager {
6779
}, 600);
6880

6981
if (isDev) this.devtools();
70-
// if (isDev) this.mainWindow.webContents.toggleDevTools();
82+
if (isDev) this.mainWindow.webContents.toggleDevTools();
7183
});
7284
E.app.on('window-all-closed', this.onWindowAllClosed);
7385

@@ -96,7 +108,7 @@ class WindowManager implements IWindowManager {
96108
y: parseInt((28 * await this.getZoom()+'').substr(0,4)),
97109
width: this.mainWindow.getContentBounds().width,
98110
height: this.mainWindow.getContentBounds().height - parseInt((28 * await this.getZoom()+'').substr(0,4))
99-
}, 'web.js');
111+
}, 'loadMainContetnt.js');
100112
this.mainWindow.setBrowserView(view);
101113
view.webContents.on('will-navigate', this.onMainWindowWillNavigate);
102114

@@ -121,6 +133,9 @@ class WindowManager implements IWindowManager {
121133
E.ipcMain.on(CLOSEALLTAB, () => {
122134
console.log('Close all tab');
123135
});
136+
E.ipcMain.on(SETTITLE, (event: Event, title: string) => {
137+
this.mainWindow.webContents.send(SETTITLE, { id: this.mainWindow.getBrowserView()!.id, title })
138+
});
124139
}
125140

126141

@@ -154,7 +169,6 @@ class WindowManager implements IWindowManager {
154169
if (response.statusCode >= 200 && response.statusCode <= 299) {
155170

156171
E.session.defaultSession!.cookies.flushStore(() => {
157-
158172
const view = Tabs.focus(1);
159173
this.mainWindow.setBrowserView(view);
160174
view.webContents.reload();
@@ -190,13 +204,6 @@ class WindowManager implements IWindowManager {
190204
private onResize = async (event?: Event) => {
191205
const browserViews = E.BrowserView.getAllViews();
192206

193-
console.log('onResize, event: ', event && event!.target);
194-
console.log('onResize, bounds: ', {
195-
x: 0,
196-
y: parseInt((28 * await this.getZoom()+'').substr(0,4)),
197-
width: this.mainWindow.getContentBounds().width,
198-
height: this.mainWindow.getContentBounds().height - parseInt((28 * await this.getZoom()+'').substr(0,4))
199-
});
200207
browserViews.forEach(async bw => bw.setBounds({
201208
x: 0,
202209
y: parseInt((28 * await this.getZoom()+'').substr(0,4)),

src/middleware/loadContetnt.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import init from "./webBinding";
2+
3+
init(false);

0 commit comments

Comments
 (0)