+ Implemented method that opens passed URLs in the external browser, either the custom one or the default one
x Fixed settings not being properly set from modal
This commit is contained in:
		
							parent
							
								
									0015494e19
								
							
						
					
					
						commit
						d038654538
					
				@ -20,7 +20,7 @@
 | 
			
		||||
            <label class="control-label" for="browserPath">{{l('settings.browserOptionPath')}}</label>
 | 
			
		||||
            <div class="row">
 | 
			
		||||
              <div class="col-10">
 | 
			
		||||
                <input class="form-control" id="browserPath" v-model="this.browserPath"/>
 | 
			
		||||
                <input class="form-control" id="browserPath" v-model="browserPath"/>
 | 
			
		||||
              </div>
 | 
			
		||||
              <div class="col-2">
 | 
			
		||||
                <button class="btn btn-primary" @click.prevent.stop="browseForPath()">{{l('settings.browserOptionBrowse')}}</button>
 | 
			
		||||
@ -31,7 +31,7 @@
 | 
			
		||||
            <label class="control-label" for="browserArgs">{{l('settings.browserOptionArguments')}}</label>
 | 
			
		||||
            <div class="row">
 | 
			
		||||
              <div class="col-12">
 | 
			
		||||
                <input class="form-control" id="browserArgs" v-model="this.browserArgs"/>
 | 
			
		||||
                <input class="form-control" id="browserArgs" v-model="browserArgs"/>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="row">
 | 
			
		||||
@ -43,7 +43,7 @@
 | 
			
		||||
          <div class="form-group col-12">
 | 
			
		||||
            <div class="row">
 | 
			
		||||
              <div class="col-2">
 | 
			
		||||
                <button class="btn btn-primary" @click="">{{l('settings.browserOptionSave')}}</button>
 | 
			
		||||
                <button class="btn btn-primary"  @click.prevent.stop="submit()">{{l('settings.browserOptionSave')}}</button>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
@ -139,9 +139,9 @@ export default class BrowserOption extends Vue {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async submit(): Promise<void> {
 | 
			
		||||
    this.settings.browserPath = this.browserPath;
 | 
			
		||||
    this.settings.browserArgs = this.browserArgs;
 | 
			
		||||
  submit(): void {
 | 
			
		||||
    ipcRenderer.send('browser-option-update', this.browserPath, this.browserArgs);
 | 
			
		||||
    this.close();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  browseForPath(): void {
 | 
			
		||||
 | 
			
		||||
@ -496,7 +496,8 @@
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        async openProfileInBrowser(): Promise<void> {
 | 
			
		||||
            await remote.shell.openExternal(`https://www.f-list.net/c/${this.profileName}`);
 | 
			
		||||
            electron.ipcRenderer.send('open-url-externally', `https://www.f-list.net/c/${this.profileName}`);
 | 
			
		||||
            //await remote.shell.openExternal(`https://www.f-list.net/c/${this.profileName}`);
 | 
			
		||||
 | 
			
		||||
            // tslint:disable-next-line: no-any no-unsafe-any
 | 
			
		||||
            (this.$refs.profileViewer as any).hide();
 | 
			
		||||
@ -628,7 +629,8 @@
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        async openWordDefinitionInBrowser(): Promise<void> {
 | 
			
		||||
          await remote.shell.openExternal((this.$refs.wordDefinitionLookup as any).getWebUrl());
 | 
			
		||||
          electron.ipcRenderer.send('open-url-externally', (this.$refs.wordDefinitionLookup as any).getWebUrl());
 | 
			
		||||
          //await remote.shell.openExternal((this.$refs.wordDefinitionLookup as any).getWebUrl());
 | 
			
		||||
 | 
			
		||||
          // tslint:disable-next-line: no-any no-unsafe-any
 | 
			
		||||
          (this.$refs.wordDefinitionViewer as any).hide();
 | 
			
		||||
 | 
			
		||||
@ -172,14 +172,38 @@ async function addSpellcheckerItems(menu: electron.Menu): Promise<void> {
 | 
			
		||||
        }));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function openURLExternally(linkUrl: string): void {
 | 
			
		||||
    // check if user set a path, whether it exists and if it is a file
 | 
			
		||||
    if(settings.browserPath !== '' &&
 | 
			
		||||
        fs.existsSync(settings.browserPath) &&
 | 
			
		||||
        fs.lstatSync(settings.browserPath).isFile()) {
 | 
			
		||||
        // encode URL so if it contains spaces, it remains a single argument for the browser
 | 
			
		||||
        linkUrl= encodeURI(linkUrl);
 | 
			
		||||
 | 
			
		||||
        // replace %s in arguments with URL, otherwise add the URL at the end
 | 
			
		||||
        let link = settings.browserArgs.includes('%s') ? settings.browserArgs.replace('%s', linkUrl) : `${settings.browserArgs} ${linkUrl}`;
 | 
			
		||||
 | 
			
		||||
        const execFile = require('child_process').exec;
 | 
			
		||||
        execFile(`"${settings.browserPath}" ${link}`);
 | 
			
		||||
    } else {
 | 
			
		||||
        electron.shell.openExternal(linkUrl);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function setUpWebContents(webContents: electron.WebContents): void {
 | 
			
		||||
    remoteMain.enable(webContents);
 | 
			
		||||
 | 
			
		||||
    const openLinkExternally = (e: Event, linkUrl: string) => {
 | 
			
		||||
        e.preventDefault();
 | 
			
		||||
        const profileMatch = linkUrl.match(/^https?:\/\/(www\.)?f-list.net\/c\/([^/#]+)\/?#?/);
 | 
			
		||||
        if(profileMatch !== null && settings.profileViewer) webContents.send('open-profile', decodeURIComponent(profileMatch[2]));
 | 
			
		||||
        else return electron.shell.openExternal(linkUrl);
 | 
			
		||||
        if(profileMatch !== null && settings.profileViewer) {
 | 
			
		||||
            webContents.send('open-profile', decodeURIComponent(profileMatch[2]));
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // otherwise, try to open externally
 | 
			
		||||
        openURLExternally(linkUrl);
 | 
			
		||||
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    webContents.setVisualZoomLevelLimits(1, 5);
 | 
			
		||||
@ -282,7 +306,7 @@ function createWindow(): electron.BrowserWindow | undefined {
 | 
			
		||||
 | 
			
		||||
function showPatchNotes(): void {
 | 
			
		||||
    //tslint:disable-next-line: no-floating-promises
 | 
			
		||||
    electron.shell.openExternal('https://github.com/hearmeneigh/fchat-rising/blob/master/CHANGELOG.md');
 | 
			
		||||
    openURLExternally('https://github.com/hearmeneigh/fchat-rising/blob/master/CHANGELOG.md');
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function openBrowserSettings(): electron.BrowserWindow | undefined {
 | 
			
		||||
@ -615,23 +639,23 @@ function onReady(): void {
 | 
			
		||||
            submenu: [
 | 
			
		||||
                {
 | 
			
		||||
                    label: l('help.fchat'),
 | 
			
		||||
                    click: () => electron.shell.openExternal('https://github.com/hearmeneigh/fchat-rising/blob/master/README.md')
 | 
			
		||||
                    click: () => openURLExternally('https://github.com/hearmeneigh/fchat-rising/blob/master/README.md')
 | 
			
		||||
                },
 | 
			
		||||
                // {
 | 
			
		||||
                //     label: l('help.feedback'),
 | 
			
		||||
                //     click: () => electron.shell.openExternal('https://goo.gl/forms/WnLt3Qm3TPt64jQt2')
 | 
			
		||||
                //     click: () => openURLExternally('https://goo.gl/forms/WnLt3Qm3TPt64jQt2')
 | 
			
		||||
                // },
 | 
			
		||||
                {
 | 
			
		||||
                    label: l('help.rules'),
 | 
			
		||||
                    click: () => electron.shell.openExternal('https://wiki.f-list.net/Rules')
 | 
			
		||||
                    click: () => openURLExternally('https://wiki.f-list.net/Rules')
 | 
			
		||||
                },
 | 
			
		||||
                {
 | 
			
		||||
                    label: l('help.faq'),
 | 
			
		||||
                    click: () => electron.shell.openExternal('https://wiki.f-list.net/Frequently_Asked_Questions')
 | 
			
		||||
                    click: () => openURLExternally('https://wiki.f-list.net/Frequently_Asked_Questions')
 | 
			
		||||
                },
 | 
			
		||||
                {
 | 
			
		||||
                    label: l('help.report'),
 | 
			
		||||
                    click: () => electron.shell.openExternal('https://wiki.f-list.net/How_to_Report_a_User#In_chat')
 | 
			
		||||
                    click: () => openURLExternally('https://wiki.f-list.net/How_to_Report_a_User#In_chat')
 | 
			
		||||
                },
 | 
			
		||||
                {label: l('version', app.getVersion()), click: showPatchNotes}
 | 
			
		||||
            ]
 | 
			
		||||
@ -714,13 +738,25 @@ function onReady(): void {
 | 
			
		||||
                filters: [{ name: 'Executables', extensions: ['exe'] }]
 | 
			
		||||
            });
 | 
			
		||||
        if(dir !== undefined) {
 | 
			
		||||
            settings.browserPath = dir[0];
 | 
			
		||||
            setGeneralSettings(settings);
 | 
			
		||||
            return dir[0];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // we keep the current path if the user cancels the dialog
 | 
			
		||||
        return settings.browserPath;
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    electron.ipcMain.on('browser-option-update', (_e, _path: string, _args: string) => {
 | 
			
		||||
        log.debug('Browser Path settings update:', _path, _args);
 | 
			
		||||
        // store the new path and args in our general settings
 | 
			
		||||
        settings.browserPath = _path;
 | 
			
		||||
        settings.browserArgs = _args;
 | 
			
		||||
        setGeneralSettings(settings);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    electron.ipcMain.on('open-url-externally', (_e, _url: string) => {
 | 
			
		||||
        openURLExternally(_url);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    createWindow();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user