Skip to content

Commit

Permalink
fixed tab selection
Browse files Browse the repository at this point in the history
Co-authored-by: lleyton <[email protected]>
  • Loading branch information
Adam and lleyton committed Oct 24, 2021
1 parent c0f16e0 commit 55b7c2f
Show file tree
Hide file tree
Showing 20 changed files with 80 additions and 84 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "skye",
"version": "6.0.4-nightly.2",
"version": "6.0.4-nightly.3",
"sideEffects": false,
"description": "Extensible, fast and innovative web browser with material UI.",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ ipcMain.handle(
return result;
}
} catch (e) {
console.log(e);
console.error(e);
}
},
);
Expand Down
4 changes: 2 additions & 2 deletions src/main/menus/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const getViewMenu = (
appWindow.viewManager.create(
{
url: params.linkURL,
active: false,
active: true,
},
true,
);
Expand Down Expand Up @@ -55,7 +55,7 @@ export const getViewMenu = (
appWindow.viewManager.create(
{
url: params.srcURL,
active: false,
active: true,
},
true,
);
Expand Down
4 changes: 2 additions & 2 deletions src/main/network/network-service-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export class NetworkServiceHandler implements RpcMainHandler<NetworkService> {
request(e: RpcMainEvent, url: string) {
try {
return requestURL(url);
} catch (e) {
console.log(e);
} catch (err) {
console.error(err);
return undefined;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/main/services/adblock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ let adblockRunning = false;
let adblockInitialized = false;

export const runAdblockService = async (ses: Electron.Session) => {
console.log();
if (!adblockInitialized) {
adblockInitialized = true;
await loadFilters();
Expand Down
5 changes: 3 additions & 2 deletions src/main/services/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,9 @@ export class StorageService {
} else {
return this.favicons.get(url);
}
} catch (e) {
console.log(e);
} catch (err) {
console.error(err);
return undefined;
}
};

Expand Down
2 changes: 0 additions & 2 deletions src/main/view-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,9 @@ export class ViewManager extends EventEmitter {
public select(id: number, focus = true) {
const { selected } = this;
const view = this.views.get(id);

if (!view) {
return;
}

this.selectedId = id;

if (selected) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class View {
this.window.viewManager.create({ url, active: true }, true);
} else if (disposition === 'background-tab') {
e.preventDefault();
this.window.viewManager.create({ url, active: false }, true);
this.window.viewManager.create({ url, active: true }, true);
}
},
);
Expand Down Expand Up @@ -234,7 +234,7 @@ export class View {
this.emitEvent('favicon-updated', fav);
} catch (e) {
this.favicon = '';
// console.error(e);
console.error(e);
}
},
);
Expand Down
7 changes: 6 additions & 1 deletion src/main/windows-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ export class WindowsService {
if (!win) throw new Error('Window not found');

const view = win.viewManager.create(details, false, false);
win.webContents.send('create-tab', { ...details }, false, view.id);
win.webContents.send(
'create-tab',
{ ...details, active: true },
false,
view.id,
);

await new Promise((resolve) => {
ipcMain.once('create-tab-reply-' + view.id, resolve);
Expand Down
2 changes: 1 addition & 1 deletion src/main/windows/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class AppWindow {
this.win = new BrowserWindow({
frame: false,
minWidth: 900,
minHeight: 450,
minHeight: 250,
width: 900,
height: 700,
titleBarStyle: 'hiddenInset',
Expand Down
1 change: 0 additions & 1 deletion src/preloads/view-preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ if (
contextBridge.exposeInMainWorld('process', process);
contextBridge.exposeInMainWorld('settings', settings);
contextBridge.exposeInMainWorld('require', (id: string) => {
console.log(id);
if (id === 'electron') {
return { ipcRenderer, app };
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/views/app/components/AddressBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const onKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
);
return;
} else if (isURL(value)) {
url = value.indexOf('://') === -1 ? `http://${value}` : value;
url = value.indexOf('://') === -1 ? `https://${value}` : value;
} else {
url = store.settings.searchEngine.url.replace('%s', value);
}
Expand Down
11 changes: 2 additions & 9 deletions src/renderer/views/app/components/RightButtons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { AddTab } from '../Tabbar/style';

let menuRef: HTMLDivElement = null;

const onAddTabClick = () => {
store.tabs.addTab();
const onAddTabClick = async () => {
await store.tabs.addTab();
};

const onDownloadsClick = async (e: React.MouseEvent<HTMLDivElement>) => {
Expand Down Expand Up @@ -102,19 +102,12 @@ export const RightButtons = observer(() => {
icon={ICON_MORE}
size={18}
/>

<ToolbarButton
badgeRight={10}
onMouseDown={onAddTabClick}
icon={ICON_ADD}
size={18}
/>

{/* <AddTab
icon={ICON_ADD}
onClick={onAddTabClick}
divRef={(r: any) => (store.addTab.ref = r)}
/> */}
</Buttons>
);
});
44 changes: 24 additions & 20 deletions src/renderer/views/app/components/Tab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ import store from '../../store';
import * as remote from '@electron/remote';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

const removeTab = (tab: ITab) => (e: React.MouseEvent<HTMLDivElement>) => {
const removeTab = (tab: ITab) => async (
e: React.MouseEvent<HTMLDivElement>,
) => {
e.stopPropagation();
tab.close();
await tab.close();
};

const toggleMuteTab = (tab: ITab) => (e: React.MouseEvent<HTMLDivElement>) => {
Expand Down Expand Up @@ -64,9 +66,9 @@ const onMouseDown = (tab: ITab) => (e: React.MouseEvent<HTMLDivElement>) => {
}
};

const onClick = (tab: ITab) => (e: React.MouseEvent<HTMLDivElement>) => {
const onClick = (tab: ITab) => async (e: React.MouseEvent<HTMLDivElement>) => {
if (e.button === 4) {
tab.close();
await tab.close();
return;
}

Expand All @@ -76,18 +78,20 @@ const onClick = (tab: ITab) => (e: React.MouseEvent<HTMLDivElement>) => {
}
};

const onMouseUp = (tab: ITab) => (e: React.MouseEvent<HTMLDivElement>) => {
const onMouseUp = (tab: ITab) => async (
e: React.MouseEvent<HTMLDivElement>,
) => {
if (e.button === 1) {
tab.close();
await tab.close();
}
};

const onContextMenu = (tab: ITab) => () => {
const menu = remote.Menu.buildFromTemplate([
{
label: 'New tab to the right',
click: () => {
store.tabs.addTab(
click: async () => {
await store.tabs.addTab(
{
index: store.tabs.list.indexOf(store.tabs.selectedTab) + 1,
},
Expand Down Expand Up @@ -116,14 +120,14 @@ const onContextMenu = (tab: ITab) => () => {
{
label: 'Reload',
accelerator: 'CmdOrCtrl+R',
click: () => {
tab.callViewMethod('webContents.reload');
click: async () => {
await tab.callViewMethod('webContents.reload');
},
},
{
label: 'Duplicate',
click: () => {
store.tabs.addTab({ active: true, url: tab.url });
click: async () => {
await store.tabs.addTab({ active: true, url: tab.url });
},
},
{
Expand All @@ -144,37 +148,37 @@ const onContextMenu = (tab: ITab) => () => {
{
label: 'Close tab',
accelerator: 'CmdOrCtrl+W',
click: () => {
tab.close();
click: async () => {
await tab.close();
},
},
{
label: 'Close other tabs',
click: () => {
click: async () => {
for (const t of store.tabs.list) {
if (t !== tab) {
t.close();
await t.close();
}
}
},
},
{
label: 'Close tabs to the left',
click: () => {
click: async () => {
for (let i = store.tabs.list.indexOf(tab) - 1; i >= 0; i--) {
store.tabs.list[i].close();
await store.tabs.list[i].close();
}
},
},
{
label: 'Close tabs to the right',
click: () => {
click: async () => {
for (
let i = store.tabs.list.length - 1;
i > store.tabs.list.indexOf(tab);
i--
) {
store.tabs.list[i].close();
await store.tabs.list[i].close();
}
},
},
Expand Down
10 changes: 5 additions & 5 deletions src/renderer/views/app/models/tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ export class ITab {
}

if (active) {
requestAnimationFrame(() => {
this.select();
requestAnimationFrame(async () => {
await this.select();
});
}

Expand Down Expand Up @@ -247,7 +247,7 @@ export class ITab {
}

@action
public close() {
public async close() {
store.tabs.closedUrl = this.url;
store.tabs.canShowPreview = false;
ipcRenderer.send(`hide-tab-preview-${store.windowId}`);
Expand Down Expand Up @@ -291,10 +291,10 @@ export class ITab {
!store.tabs.scrollable
) {
const nextTab = store.tabs.list[index + 1];
nextTab.select();
await nextTab.select();
} else if (index - 1 >= 0 && !store.tabs.list[index - 1].isClosing) {
const prevTab = store.tabs.list[index - 1];
prevTab.select();
await prevTab.select();
}
}

Expand Down
Loading

0 comments on commit 55b7c2f

Please sign in to comment.