open browser

This commit is contained in:
richard-loafle 2020-02-12 17:25:06 +09:00
parent 2a05ada4c5
commit 43601951a4
8 changed files with 116 additions and 12 deletions

View File

@ -14,6 +14,8 @@ import fse from 'fs-extra';
import semver from 'semver'; import semver from 'semver';
import os from 'os'; import os from 'os';
import ChildProcess from 'child_process'; import ChildProcess from 'child_process';
import * as url from 'url';
import * as tmp from 'tmp';
import AutoLaunch from 'auto-launch'; import AutoLaunch from 'auto-launch';
@ -31,7 +33,8 @@ import {
MessengerChannel, MessengerChannel,
MessageChannel, MessageChannel,
AppChannel, AppChannel,
ClipboardChannel ClipboardChannel,
ExternalChannel
} from '@ucap-webmessenger/native-electron'; } from '@ucap-webmessenger/native-electron';
import { ElectronNotificationService } from '@ucap-webmessenger/electron-notification'; import { ElectronNotificationService } from '@ucap-webmessenger/electron-notification';
import { ElectronUpdateWindowService } from '@ucap-webmessenger/electron-update-window'; import { ElectronUpdateWindowService } from '@ucap-webmessenger/electron-update-window';
@ -92,6 +95,8 @@ let preventQuit = false;
let notificationService: ElectronNotificationService | null; let notificationService: ElectronNotificationService | null;
let updateWindowService: ElectronUpdateWindowService | null; let updateWindowService: ElectronUpdateWindowService | null;
tmp.setGracefulCleanup();
function handleUncaughtException(error: Error) { function handleUncaughtException(error: Error) {
preventQuit = true; preventQuit = true;
@ -771,6 +776,39 @@ ipcMain.on(AppChannel.Exit, (event: IpcMainEvent, ...args: any[]) => {
appExit(); appExit();
}); });
ipcMain.on(ExternalChannel.OpenUrl, (event: IpcMainEvent, ...args: any[]) => {
const targetUrl = args[0];
const options = JSON.stringify(args[1] || {});
tmp.file({ postfix: '.html' }, (err, name, fd, cb) => {
fse.writeFileSync(
name,
`
<!DOCTYPE html>
<html>
<head>
<title>DS Talk Link</title>
<meta charset="UTF-8" />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<script type="text/javascript">
function onLoad() {
const url = '${targetUrl}';
const options = ${options} || {};
window.open(url, !!options.name ? options.name : 'dstalklink', options.features, options.replace);
}
</script>
</head>
<body onload="onLoad()"></body>
</html>
`
);
shell.openExternal(name);
});
});
autoUpdater.on('checking-for-update', () => { autoUpdater.on('checking-for-update', () => {
log.info('Checking for update...'); log.info('Checking for update...');
}); });

56
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "ucap-webmessenger", "name": "ucap-webmessenger",
"version": "0.0.17", "version": "0.0.19",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -3494,6 +3494,12 @@
"integrity": "sha512-78AdXtlhpCHT0K3EytMpn4JNxaf5tbqbLcbIRoQIHzpTIyjpxLQKRoxU55ujBXAtg3Nl2h/XWvfDa9dsMOd0pQ==", "integrity": "sha512-78AdXtlhpCHT0K3EytMpn4JNxaf5tbqbLcbIRoQIHzpTIyjpxLQKRoxU55ujBXAtg3Nl2h/XWvfDa9dsMOd0pQ==",
"dev": true "dev": true
}, },
"@types/tmp": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/@types/tmp/-/tmp-0.1.0.tgz",
"integrity": "sha512-6IwZ9HzWbCq6XoQWhxLpDjuADodH/MKXRUIDFudvgjcVdjFknvmR+DNsoUeer4XPrEnrZs04Jj+kfV9pFsrhmA==",
"dev": true
},
"@types/tween.js": { "@types/tween.js": {
"version": "17.2.0", "version": "17.2.0",
"resolved": "https://registry.npmjs.org/@types/tween.js/-/tween.js-17.2.0.tgz", "resolved": "https://registry.npmjs.org/@types/tween.js/-/tween.js-17.2.0.tgz",
@ -7615,6 +7621,17 @@
"chardet": "^0.7.0", "chardet": "^0.7.0",
"iconv-lite": "^0.4.24", "iconv-lite": "^0.4.24",
"tmp": "^0.0.33" "tmp": "^0.0.33"
},
"dependencies": {
"tmp": {
"version": "0.0.33",
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz",
"integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==",
"dev": true,
"requires": {
"os-tmpdir": "~1.0.2"
}
}
} }
}, },
"extglob": { "extglob": {
@ -10449,6 +10466,15 @@
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
"dev": true "dev": true
}, },
"tmp": {
"version": "0.0.33",
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz",
"integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==",
"dev": true,
"requires": {
"os-tmpdir": "~1.0.2"
}
},
"to-regex-range": { "to-regex-range": {
"version": "2.1.1", "version": "2.1.1",
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-2.1.1.tgz", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-2.1.1.tgz",
@ -15119,12 +15145,23 @@
} }
}, },
"tmp": { "tmp": {
"version": "0.0.33", "version": "0.1.0",
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.1.0.tgz",
"integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", "integrity": "sha512-J7Z2K08jbGcdA1kkQpJSqLF6T0tdQqpR2pnSUXsIchbPdTI9v3e85cLW0d6WDhwuAleOV71j2xWs8qMPfK7nKw==",
"dev": true, "dev": true,
"requires": { "requires": {
"os-tmpdir": "~1.0.2" "rimraf": "^2.6.3"
},
"dependencies": {
"rimraf": {
"version": "2.7.1",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz",
"integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==",
"dev": true,
"requires": {
"glob": "^7.1.3"
}
}
} }
}, },
"to-array": { "to-array": {
@ -15694,6 +15731,15 @@
"yallist": "^2.1.2" "yallist": "^2.1.2"
} }
}, },
"tmp": {
"version": "0.0.33",
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz",
"integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==",
"dev": true,
"requires": {
"os-tmpdir": "~1.0.2"
}
},
"yallist": { "yallist": {
"version": "2.1.2", "version": "2.1.2",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz",

View File

@ -95,6 +95,7 @@
"@types/moment-timezone": "^0.5.12", "@types/moment-timezone": "^0.5.12",
"@types/node": "^10.17.13", "@types/node": "^10.17.13",
"@types/semver": "^6.2.0", "@types/semver": "^6.2.0",
"@types/tmp": "^0.1.0",
"@types/uglifyjs-webpack-plugin": "^1.1.0", "@types/uglifyjs-webpack-plugin": "^1.1.0",
"@types/webpack": "^4.41.2", "@types/webpack": "^4.41.2",
"@types/webpack-merge": "^4.1.5", "@types/webpack-merge": "^4.1.5",
@ -142,6 +143,7 @@
"protractor": "~5.4.0", "protractor": "~5.4.0",
"queueing-subject": "^0.3.4", "queueing-subject": "^0.3.4",
"rimraf": "^3.0.0", "rimraf": "^3.0.0",
"tmp": "^0.1.0",
"ts-node": "~7.0.0", "ts-node": "~7.0.0",
"tsickle": "^0.37.1", "tsickle": "^0.37.1",
"tslib": "^1.10.0", "tslib": "^1.10.0",

View File

@ -409,7 +409,10 @@ export class TopBarComponent implements OnInit, OnDestroy {
.replace(/(\(%USER_ID%\))/g, loginId) .replace(/(\(%USER_ID%\))/g, loginId)
.replace(/(\(%USER_PASS%\))/g, loginPw); .replace(/(\(%USER_PASS%\))/g, loginPw);
this.nativeService.openDefaultBrowser(url); this.nativeService.openDefaultBrowser(url, {
features:
'menubar=no,location=no,resizable=yes,scrollbars=yes,status=no,width=400,height=400'
});
} }
onClosedProfileMenu() { onClosedProfileMenu() {

View File

@ -277,7 +277,10 @@ export class BrowserNativeService extends NativeService {
return new TranslateLoaderService(this, prefix, suffix); return new TranslateLoaderService(this, prefix, suffix);
} }
openDefaultBrowser(url: string): void { openDefaultBrowser(
url: string,
options?: { name?: string; features?: string; replace?: boolean }
): void {
open(url); open(url);
} }

View File

@ -24,7 +24,8 @@ import {
MessageChannel, MessageChannel,
ProcessChannel, ProcessChannel,
AppChannel, AppChannel,
ClipboardChannel ClipboardChannel,
ExternalChannel
} from '../types/channel.type'; } from '../types/channel.type';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { TranslateLoaderService } from '../translate/electron-loader'; import { TranslateLoaderService } from '../translate/electron-loader';
@ -467,8 +468,12 @@ export class ElectronNativeService implements NativeService {
return new TranslateLoaderService(this, prefix, suffix); return new TranslateLoaderService(this, prefix, suffix);
} }
openDefaultBrowser(url: string): void { openDefaultBrowser(
this.shell.openExternal(url); url: string,
options?: { name?: string; features?: string; replace?: boolean }
): void {
// shell.openExternal(url);
this.ipcRenderer.send(ExternalChannel.OpenUrl, url, options);
} }
readFromClipboard(): Promise<{ readFromClipboard(): Promise<{

View File

@ -62,3 +62,7 @@ export enum ClipboardChannel {
export enum AppChannel { export enum AppChannel {
Exit = 'UCAP::app::exit' Exit = 'UCAP::app::exit'
} }
export enum ExternalChannel {
OpenUrl = 'UCAP::external::openUrl'
}

View File

@ -87,7 +87,10 @@ export abstract class NativeService {
suffix?: string suffix?: string
): TranslateLoader; ): TranslateLoader;
abstract openDefaultBrowser(url: string): void; abstract openDefaultBrowser(
url: string,
options?: { name?: string; features?: string; replace?: boolean }
): void;
abstract readFromClipboard(): Promise<{ abstract readFromClipboard(): Promise<{
text?: string; text?: string;