OSDN Git Service

v1.3.1
authorAoichaan0513 <aoichaan0513@gmail.com>
Fri, 17 May 2019 19:14:44 +0000 (04:14 +0900)
committerAoichaan0513 <aoichaan0513@gmail.com>
Fri, 17 May 2019 19:14:44 +0000 (04:14 +0900)
・Floating Windowsのベータ対応
・マウスの戻る・進むボタンの対応
・その他バグ・不具合の修正

.babelrc [deleted file]
electron/Application.js
electron/Preload.js
electron/WindowManager.js
package.json
src/App.js
src/Authentication.js
src/Browser.js

diff --git a/.babelrc b/.babelrc
deleted file mode 100644 (file)
index 1a244bb..0000000
--- a/.babelrc
+++ /dev/null
@@ -1,12 +0,0 @@
-{
-    "presets": [
-        [
-            "env",
-            {
-                "targets": {
-                    "node": "current"
-                }
-            }
-        ]
-    ]
-}
\ No newline at end of file
index 7e55656..fcd394d 100644 (file)
@@ -4,76 +4,6 @@ const fs = require('fs');
 const url = require('url');
 const os = require('os');
 
-const localShortcut = require("electron-localshortcut");
-
-const Config = require('electron-store');
-const config = new Config({
-    defaults: {
-        design: {
-            homeButton: false,
-            darkTheme: false,
-            theme: 'default'
-        },
-        homePage: {
-            defaultPage: 'my://newtab',
-            defaultEngine: 'Google',
-            searchEngines: [
-                {
-                    name: 'Google',
-                    url: 'https://www.google.com/search?q=%s'
-                },
-                {
-                    name: 'Bing',
-                    url: 'https://www.bing.com/search?q=%s'
-                },
-                {
-                    name: 'Yahoo! Japan',
-                    url: 'https://search.yahoo.co.jp/search?p=%s'
-                },
-                {
-                    name: 'goo',
-                    url: 'https://search.goo.ne.jp/web.jsp?MT=%s'
-                },
-                {
-                    name: 'Google Translate',
-                    url: 'https://translate.google.com/?text=%s'
-                },
-                {
-                    name: 'Youtube',
-                    url: 'https://www.youtube.com/results?search_query=%s'
-                },
-                {
-                    name: 'Twitter',
-                    url: 'https://www.twitter.com/search?q=%s'
-                },
-                {
-                    name: 'GitHub',
-                    url: 'https://github.com/search?q=%s'
-                }
-            ]
-        },
-        adBlocker: true,
-        window: {
-            isCustomTitlebar: true,
-            isMaximized: false,
-            bounds: {
-                width: 1100,
-                height: 680
-            }
-        }
-    },
-});
-
-const Datastore = require('nedb');
-let db = {};
-
-db.history = new Datastore({
-    filename: path.join(app.getPath('userData'), 'Files', 'History.db'),
-    autoload: true,
-    timestampData: true
-});
-
-const { loadFilters, updateFilters, removeAds } = require('./AdBlocker');
 const WindowManager = require('./WindowManager');
 const windowManager = new WindowManager();
 
@@ -94,25 +24,6 @@ getBaseWindow = (width = 1100, height = 680, minWidth = 320, minHeight = 600, x,
     });
 }
 
-/*
-showFilterDialog = () => {
-    if (!hasFile()) {
-        const dialogResult = dialog.showMessageBox({
-            type: 'info',
-            buttons: ['Ok'],
-            title: '本当にデータをリセットしてよろしいですか?',
-            message: '"続行"を押した場合データのリセット後アプリが再起動します。',
-            defaultId: 0,
-            cancelId: 1
-        });
-
-        if (dialogResult === 0) {
-            showFilterDialog();
-        }
-    }
-}
-*/
-
 registerProtocols = () => {
     protocol.registerFileProtocol('my', (request, callback) => {
         const parsed = url.parse(request.url);
@@ -138,7 +49,6 @@ module.exports = class Application {
         ]);
 
         app.on('ready', () => {
-            loadFilters();
             registerProtocols();
             
             Menu.setApplicationMenu(null);
@@ -168,7 +78,7 @@ module.exports = class Application {
                 pathname: path.join(__dirname, '/../build/index.html'), // 警告:このファイルを移動する場合ここの相対パスの指定に注意してください
                 protocol: 'file:',
                 slashes: true,
-                hash: '/auth',
+                hash: '/authentication',
             });
 
             subWindow.loadURL(startUrl);
@@ -179,40 +89,6 @@ module.exports = class Application {
             loginCallback(arg.username, arg.password);
             subWindow.close();
         });
-
-        ipcMain.on('data-history-get', (e, args) => {
-            db.history.find({}).sort({ createdAt: -1 }).exec((err, docs) => {
-                e.sender.send('data-history-get', { historys: docs });
-            });
-        });
-
-        ipcMain.on('data-history-clear', (e, args) => {
-            db.history.remove({}, { multi: true });
-        });
-
-        ipcMain.on('clear-browsing-data', () => {
-            const ses = session.defaultSession;
-            ses.clearCache((err) => {
-                if (err) log.error(err);
-            });
-
-            ses.clearStorageData({
-                storages: [
-                    'appcache',
-                    'cookies',
-                    'filesystem',
-                    'indexdb',
-                    'localstorage',
-                    'shadercache',
-                    'websql',
-                    'serviceworkers',
-                    'cachestorage',
-                ],
-            });
-
-            config.clear();
-            db.history.remove({}, { multi: true });
-        });
     }
 
     loadExtension = (id) => {
index 95843eb..7f8210b 100644 (file)
@@ -4,60 +4,60 @@ const fs = require('fs');
 
 const Config = require('electron-store');
 const config = new Config({
-       defaults: {
-               design: {
-                       homeButton: false,
-                       darkTheme: false,
-                       theme: 'default'
-               },
-               homePage: {
-                       defaultPage: 'my://newtab',
-                       defaultEngine: 'Google',
-                       searchEngines: [
-                               {
-                                       name: 'Google',
-                                       url: 'https://www.google.com/search?q=%s'
-                               },
-                               {
-                                       name: 'Bing',
-                                       url: 'https://www.bing.com/search?q=%s'
-                               },
-                               {
-                                       name: 'Yahoo! Japan',
-                                       url: 'https://search.yahoo.co.jp/search?p=%s'
-                               },
-                               {
-                                       name: 'goo',
-                                       url: 'https://search.goo.ne.jp/web.jsp?MT=%s'
-                               },
-                               {
-                                       name: 'Google Translate',
-                                       url: 'https://translate.google.com/?text=%s'
-                               },
-                               {
-                                       name: 'Youtube',
-                                       url: 'https://www.youtube.com/results?search_query=%s'
-                               },
-                               {
-                                       name: 'Twitter',
-                                       url: 'https://www.twitter.com/search?q=%s'
-                               },
-                               {
-                                       name: 'GitHub',
-                                       url: 'https://github.com/search?q=%s'
-                               }
-                       ]
-               },
-               adBlocker: true,
-               window: {
-                       isCustomTitlebar: true,
-                       isMaximized: false,
-                       bounds: {
-                               width: 1100,
-                               height: 680
-                       }
-               }
-       },
+    defaults: {
+        design: {
+            homeButton: false,
+            darkTheme: false,
+            theme: 'default'
+        },
+        homePage: {
+            defaultPage: 'my://newtab',
+            defaultEngine: 'Google',
+            searchEngines: [
+                {
+                    name: 'Google',
+                    url: 'https://www.google.com/search?q=%s'
+                },
+                {
+                    name: 'Bing',
+                    url: 'https://www.bing.com/search?q=%s'
+                },
+                {
+                    name: 'Yahoo! Japan',
+                    url: 'https://search.yahoo.co.jp/search?p=%s'
+                },
+                {
+                    name: 'goo',
+                    url: 'https://search.goo.ne.jp/web.jsp?MT=%s'
+                },
+                {
+                    name: 'Google Translate',
+                    url: 'https://translate.google.com/?text=%s'
+                },
+                {
+                    name: 'Youtube',
+                    url: 'https://www.youtube.com/results?search_query=%s'
+                },
+                {
+                    name: 'Twitter',
+                    url: 'https://www.twitter.com/search?q=%s'
+                },
+                {
+                    name: 'GitHub',
+                    url: 'https://github.com/search?q=%s'
+                }
+            ]
+        },
+        adBlocker: true,
+        window: {
+            isCustomTitlebar: true,
+            isMaximized: false,
+            bounds: {
+                width: 1100,
+                height: 680
+            }
+        }
+    },
 });
 
 // ファイルタイプの列挙体(のつもり)
@@ -279,6 +279,7 @@ global.isURL = (input) => {
 };
 
 onload = function () {
+    // console.log(document.documentElement.innerText);
     if (location.protocol == 'my:') return;
 
     delete global.getConfigPath;
@@ -302,4 +303,17 @@ onload = function () {
     delete global.setCustomTitlebar;
     delete global.restart;
     delete global.isURL;
+}
+
+onmousedown = (e) => {
+    if (remote.getCurrentWindow().getBrowserView() == undefined) return;
+    const view = remote.getCurrentWindow().getBrowserView();
+
+    if (e.button == 3) {
+        if (view.webContents.canGoBack())
+            view.webContents.goBack();
+    } else if (e.button == 4) {
+        if (view.webContents.canGoForward())
+            view.webContents.goForward();
+    }
 }
\ No newline at end of file
index 0dee560..b1cb64a 100644 (file)
@@ -75,10 +75,11 @@ db.history = new Datastore({
 
 const { loadFilters, updateFilters, removeAds } = require('./AdBlocker');
 
+let floatingWindows = [];
 let views = [];
 let tabCount = 0;
 
-getBaseWindow = (width = 1100, height = 680, minWidth = 320, minHeight = 600, x, y, frame = false) => {
+getBaseWindow = (width = 1100, height = 680, minWidth = 320, minHeight = 200, x, y, frame = false) => {
     return new BrowserWindow({
         width, height, minWidth, minHeight, x, y, 'titleBarStyle': 'hidden', frame, fullscreenable: true,
         webPreferences: {
@@ -152,13 +153,47 @@ module.exports = class WindowManager {
         ipcMain.on('window-add', (e, args) => {
             this.addWindow(args.isPrivate);
         });
+
+        ipcMain.on('data-history-get', (e, args) => {
+            db.history.find({}).sort({ createdAt: -1 }).exec((err, docs) => {
+                e.sender.send('data-history-get', { historys: docs });
+            });
+        });
+
+        ipcMain.on('data-history-clear', (e, args) => {
+            db.history.remove({}, { multi: true });
+        });
+
+        ipcMain.on('clear-browsing-data', () => {
+            const ses = session.defaultSession;
+            ses.clearCache((err) => {
+                if (err) log.error(err);
+            });
+
+            ses.clearStorageData({
+                storages: [
+                    'appcache',
+                    'cookies',
+                    'filesystem',
+                    'indexdb',
+                    'localstorage',
+                    'shadercache',
+                    'websql',
+                    'serviceworkers',
+                    'cachestorage',
+                ],
+            });
+
+            config.clear();
+            db.history.remove({}, { multi: true });
+        });
     }
 
     addWindow = (isPrivate = false) => {
         loadFilters();
 
         const { width, height, x, y } = config.get('window.bounds');
-        const window = getBaseWindow(config.get('window.isMaximized') ? 1110 : width, config.get('window.isMaximized') ? 680 : height, 320, 600, x, y, !config.get('window.isCustomTitlebar'));
+        const window = getBaseWindow(config.get('window.isMaximized') ? 1110 : width, config.get('window.isMaximized') ? 680 : height, 320, 200, x, y, !config.get('window.isCustomTitlebar'));
 
         const id = (!isPrivate ? window.id : `private-${window.id}`);
 
@@ -168,15 +203,15 @@ module.exports = class WindowManager {
             pathname: path.join(__dirname, '/../build/index.html'), // 警告:このファイルを移動する場合ここの相対パスの指定に注意してください
             protocol: 'file:',
             slashes: true,
-            hash: `/${id}`,
+            hash: `/window/${id}`,
         });
 
         window.loadURL(startUrl);
 
         localShortcut.register(window, 'CmdOrCtrl+Shift+I', () => {
             if (window.getBrowserView() == undefined) return;
-
             const view = window.getBrowserView();
+
             if (view.webContents.isDevToolsOpened()) {
                 view.webContents.devToolsWebContents.focus();
             } else {
@@ -186,15 +221,15 @@ module.exports = class WindowManager {
 
         localShortcut.register(window, 'CmdOrCtrl+R', () => {
             if (window.getBrowserView() == undefined) return;
-
             const view = window.getBrowserView();
+
             view.webContents.reload();
         });
 
         localShortcut.register(window, 'CmdOrCtrl+Shift+R', () => {
             if (window.getBrowserView() == undefined) return;
-
             const view = window.getBrowserView();
+
             view.webContents.reloadIgnoringCache();
         });
 
@@ -217,12 +252,12 @@ module.exports = class WindowManager {
             }
         });
 
-        window.on('maximize', this.fixBounds.bind(this, id));
-        window.on('unmaximize', this.fixBounds.bind(this, id));
-        window.on('enter-full-screen', this.fixBounds.bind(this, id));
-        window.on('leave-full-screen', this.fixBounds.bind(this, id));
-        window.on('enter-html-full-screen', this.fixBounds.bind(this, id));
-        window.on('leave-html-full-screen', this.fixBounds.bind(this, id));
+        window.on('maximize', this.fixBounds.bind(this, id, (floatingWindows.indexOf(id) != -1)));
+        window.on('unmaximize', this.fixBounds.bind(this, id, (floatingWindows.indexOf(id) != -1)));
+        window.on('enter-full-screen', this.fixBounds.bind(this, id, (floatingWindows.indexOf(id) != -1)));
+        window.on('leave-full-screen', this.fixBounds.bind(this, id, (floatingWindows.indexOf(id) != -1)));
+        window.on('enter-html-full-screen', this.fixBounds.bind(this, id, (floatingWindows.indexOf(id) != -1)));
+        window.on('leave-html-full-screen', this.fixBounds.bind(this, id, (floatingWindows.indexOf(id) != -1)));
 
         // registerProtocols();
         this.registerListeners(id);
@@ -329,28 +364,46 @@ module.exports = class WindowManager {
         });
     }
 
-    fixBounds = (windowId) => {
+    fixBounds = (windowId, isFloating = false) => {
         const window = this.windows.get(windowId);
-        if (window.getBrowserView() == undefined) return;
 
+        if (window.getBrowserView() == undefined) return;
         const view = window.getBrowserView();
+
         const { width, height } = window.getContentBounds();
 
         view.setAutoResize({ width: true, height: true });
-        if (window.isFullScreen()) {
-            view.setBounds({
-                x: 0,
-                y: 0,
-                width: width,
-                height: height,
-            });
-        } else {
+        if (isFloating) {
+            window.setMinimizable(false);
+            window.setMaximizable(false);
+            window.setAlwaysOnTop(true);
+            window.setVisibleOnAllWorkspaces(true);
             view.setBounds({
                 x: 1,
-                y: 73 + 1,
+                y: 1,
                 width: width - 2,
-                height: window.isMaximized() ? height - 73 : (height - 73) - 2,
+                height: height - 2,
             });
+        } else {
+            window.setMinimizable(true);
+            window.setMaximizable(true);
+            window.setAlwaysOnTop(false);
+            window.setVisibleOnAllWorkspaces(false);
+            if (window.isFullScreen()) {
+                view.setBounds({
+                    x: 0,
+                    y: 0,
+                    width: width,
+                    height: height,
+                });
+            } else {
+                view.setBounds({
+                    x: 1,
+                    y: 73 + 1,
+                    width: width - 2,
+                    height: window.isMaximized() ? height - 73 : (height - 73) - 2,
+                });
+            }
         }
         view.setAutoResize({ width: true, height: true });
     }
@@ -375,7 +428,7 @@ module.exports = class WindowManager {
                 window.setBrowserView(views[i].view);
                 window.setTitle(views[i].view.webContents.getTitle());
                 window.webContents.send(`browserview-set-${windowId}`, { id: id });
-                this.fixBounds(windowId);
+                this.fixBounds(windowId, (floatingWindows.indexOf(windowId) != -1));
             }
         });
     }
@@ -600,6 +653,25 @@ module.exports = class WindowManager {
                     },
                     { type: 'separator' },
                     {
+                        label: 'Floating Window (Beta)',
+                        type: 'checkbox',
+                        checked: (floatingWindows.indexOf(windowId) != -1),
+                        enabled: (!window.isFullScreen() && !window.isMaximized()),
+                        click: () => {
+                            if (floatingWindows.indexOf(windowId) != -1) {
+                                floatingWindows.filter((win, i) => {
+                                    if (windowId == win) {
+                                        floatingWindows.splice(i, 1);
+                                    }
+                                });
+                            } else {
+                                floatingWindows.push(windowId);
+                            }
+                            this.fixBounds(windowId, (floatingWindows.indexOf(windowId) != -1));
+                        }
+                    },
+                    { type: 'separator' },
+                    {
                         label: 'ページの保存',
                         accelerator: 'CmdOrCtrl+S',
                         enabled: !view.webContents.getURL().startsWith('my://'),
@@ -676,8 +748,8 @@ module.exports = class WindowManager {
             window.webContents.send(`browserview-set-${windowId}`, { id: id });
             window.setBrowserView(view);
         }
-        this.fixBounds(windowId);
 
+        this.fixBounds(windowId, (floatingWindows.indexOf(windowId) != -1));
         this.getViews(windowId);
     }
 }
\ No newline at end of file
index b0b7a8d..079e2e2 100644 (file)
@@ -1,6 +1,6 @@
 {
        "name": "MyBrowser-Stable",
-       "version": "1.2.4",
+       "version": "1.3.1",
        "private": true,
        "main": "electron/Starter.js",
        "homepage": "./",
index 94c131f..a0d80bb 100644 (file)
@@ -12,8 +12,8 @@ class App extends Component {
                return (
                        <HashRouter>
                                <div>
-                                       <Route exact path='/:windowId' component={Browser} />
-                                       <Route path='/auth' component={Authentication} />
+                                       <Route exact path='/window/:windowId' component={Browser} />
+                                       <Route path='/authentication' component={Authentication} />
                                </div>
                        </HashRouter>
                );
index dbf24f5..436ae8a 100644 (file)
@@ -5,32 +5,70 @@ import WindowButtons from './Components/WindowButtons';
 import WindowButton from './Components/WindowButton';
 import WindowContent from './Components/WindowContent';
 import TitleBar from './Components/TitleBar';
-import Tabs from './Components/Tabs';
-import { Tab, TabTitle, TabCloseButton } from './Components/Tab';
-import TabButton from './Components/TabButton';
-import TabContent from './Components/TabContent';
-import ToolBar from './Components/ToolBar';
-import ToolBarButton from './Components/ToolBarButton';
-import ToolBarTextBox from './Components/ToolBarTextBox';
-import ContentWrapper from './Components/ContentWrapper';
-
-import WindowMinimizeIcon from './Resources/windows/minimize.svg';
-import WindowMaximizeIcon from './Resources/windows/maximize.svg';
-import WindowCloseIcon from './Resources/windows/close.svg';
-
-import BackIcon from './Resources/arrow_back.svg';
-import ForwardIcon from './Resources/arrow_forward.svg';
-import ReloadIcon from './Resources/reload.svg';
-import HomeIcon from './Resources/home.svg';
-import MoreIcon from './Resources/more.svg';
-import AddIcon from './Resources/add.svg';
-import CloseIcon from './Resources/close.svg';
 
 const { remote, ipcRenderer, shell } = window.require('electron');
 const systemPreferences = remote.systemPreferences;
 
 const platform = require('electron-platform');
 
+const Config = window.require('electron-store');
+const config = new Config({
+       defaults: {
+               design: {
+                       homeButton: false,
+                       darkTheme: false,
+                       theme: 'default'
+               },
+               homePage: {
+                       defaultPage: 'my://newtab',
+                       defaultEngine: 'Google',
+                       searchEngines: [
+                               {
+                                       name: 'Google',
+                                       url: 'https://www.google.com/search?q=%s'
+                               },
+                               {
+                                       name: 'Bing',
+                                       url: 'https://www.bing.com/search?q=%s'
+                               },
+                               {
+                                       name: 'Yahoo! Japan',
+                                       url: 'https://search.yahoo.co.jp/search?p=%s'
+                               },
+                               {
+                                       name: 'goo',
+                                       url: 'https://search.goo.ne.jp/web.jsp?MT=%s'
+                               },
+                               {
+                                       name: 'Google Translate',
+                                       url: 'https://translate.google.com/?text=%s'
+                               },
+                               {
+                                       name: 'Youtube',
+                                       url: 'https://www.youtube.com/results?search_query=%s'
+                               },
+                               {
+                                       name: 'Twitter',
+                                       url: 'https://www.twitter.com/search?q=%s'
+                               },
+                               {
+                                       name: 'GitHub',
+                                       url: 'https://github.com/search?q=%s'
+                               }
+                       ]
+               },
+               adBlocker: true,
+               window: {
+                       isCustomTitlebar: true,
+                       isMaximized: false,
+                       bounds: {
+                               width: 1100,
+                               height: 680
+                       }
+               }
+       },
+});
+
 class Authentication extends Component {
        constructor(props) {
                super(props);
@@ -45,17 +83,25 @@ class Authentication extends Component {
        submit = () => {
                const username = this.state.userName;
                const password = this.state.passWord;
-               ipcRenderer.send("authorization", { username, password });
+               ipcRenderer.send('authorization', { username, password });
+       }
+
+       getForegroundColor = (hexColor) => {
+               var r = parseInt(hexColor.substr(1, 2), 16);
+               var g = parseInt(hexColor.substr(3, 2), 16);
+               var b = parseInt(hexColor.substr(5, 2), 16);
+
+               return ((((r * 299) + (g * 587) + (b * 114)) / 1000) < 128) ? '#ffffff' : '#000000';
        }
 
        render() {
                return (
-                       <Window color={platform.isWin32 || platform.isDarwin ? `#${systemPreferences.getAccentColor()}` : `#353535`}>
-                               <TitleBar color={platform.isWin32 || platform.isDarwin ? `#${systemPreferences.getAccentColor()}` : `#353535`}>
-                                       <WindowButtons>
-                                               <WindowButton isClose={true} onClick={() => { remote.getCurrentWindow().close(); }}>
+                       <Window isCustomTitlebar={config.get('window.isCustomTitlebar')}>
+                               <TitleBar color={platform.isWin32 || platform.isDarwin ? `#${systemPreferences.getAccentColor()}` : '#353535'}>
+                                       <WindowButtons isCustomTitlebar={config.get('window.isCustomTitlebar')}>
+                                               <WindowButton isClose={true} title="閉じる" onClick={() => { remote.getCurrentWindow().close(); }}>
                                                        <svg name="TitleBarClose" width="12" height="12" viewBox="0 0 12 12">
-                                                               <polygon fill="#ffffff" fill-rule="evenodd" points="11 1.576 6.583 6 11 10.424 10.424 11 6 6.583 1.576 11 1 10.424 5.417 6 1 1.576 1.576 1 6 5.417 10.424 1"></polygon>
+                                                               <polygon fill={this.getForegroundColor(platform.isWin32 || platform.isDarwin ? `#${systemPreferences.getAccentColor()}` : '#353535')} fill-rule="evenodd" points="11 1.576 6.583 6 11 10.424 10.424 11 6 6.583 1.576 11 1 10.424 5.417 6 1 1.576 1.576 1 6 5.417 10.424 1" />
                                                        </svg>
                                                </WindowButton>
                                        </WindowButtons>
index 0de7501..840f36e 100644 (file)
@@ -425,7 +425,6 @@ class App extends Component {
        }
 
        addTab = (url = config.get('homePage.defaultPage')) => {
-               console.log(this.props)
                ipcRenderer.send(`browserview-add-${this.props.match.params.windowId}`, { url, isActive: true });
                ipcRenderer.send(`browserview-get-${this.props.match.params.windowId}`, {});
                this.setState({ current: this.state.tabs.length });