Skip to content

Commit

Permalink
Merge pull request #164 from viktor44/feature/electron_14
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor44 authored Jun 23, 2023
2 parents f6eafe5 + aa825c5 commit 3fbec12
Show file tree
Hide file tree
Showing 52 changed files with 2,450 additions and 2,502 deletions.
37 changes: 19 additions & 18 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@ jobs:
- uses: actions/checkout@master
- uses: actions/setup-node@master
with:
node-version: "14"
node-version: "18"
cache: "yarn"
- name: Update node-gyp
run: |
npm install --global [email protected]
npm config set node_gyp $(npm prefix -g)/lib/node_modules/node-gyp/bin/node-gyp.js
- name: Install dependencies
run: yarn install --frozen-lockfile && yarn run rebuild-all-native
# See https://github.com/nodejs/node-gyp/blob/main/docs/Force-npm-to-use-global-node-gyp.md
# https://github.com/nodejs/node-gyp/blob/main/docs/Updating-npm-bundled-node-gyp.md
# - name: Update node-gyp
# run: |
# npm install --global [email protected]
# npm config set node_gyp $(npm prefix -g)/lib/node_modules/node-gyp/bin/node-gyp.js
- name: Install dependencies
run: yarn install --frozen-lockfile && yarn run rebuild-all-native
- name: GQL Codegen
run: yarn run gql-gen
- name: Build and Release
run: yarn run release

MacOs:
runs-on: macos-latest
env:
Expand All @@ -42,14 +43,14 @@ jobs:
- uses: actions/checkout@master
- uses: actions/setup-node@master
with:
node-version: "14"
node-version: "18"
cache: "yarn"
- name: Install dependencies
run: yarn install --frozen-lockfile && yarn run rebuild-all-native
- name: Update node-gyp
run: |
npm install --global [email protected]
npm config set node_gyp $(npm prefix -g)/lib/node_modules/node-gyp/bin/node-gyp.js
# - name: Update node-gyp
# run: |
# npm install --global [email protected]
# npm config set node_gyp $(npm prefix -g)/lib/node_modules/node-gyp/bin/node-gyp.js
- name: GQL Codegen
run: yarn run gql-gen
- name: Build and Release
Expand All @@ -67,14 +68,14 @@ jobs:
- uses: actions/checkout@master
- uses: actions/setup-node@master
with:
node-version: "14"
cache: "yarn"
- name: Update node-gyp
node-version: "18"
- name: Configure Node
shell: powershell
run: |
npm install --global [email protected]
# npm v9 doesn't allow custom config parameters (i.e. node_gyp) anymode, so we have to downgrade it to v8
npm install -g npm@8
npm install -g node-gyp@latest
npm prefix -g | % {npm config set node_gyp "$_\node_modules\node-gyp\bin\node-gyp.js"}
- name: Update registry URL
run: |
npm config set registry "http://registry.npmjs.org"
yarn config set registry "http://registry.npmjs.org"
yarn config set network-timeout 300000
Expand Down
33 changes: 17 additions & 16 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ jobs:
- uses: actions/checkout@master
- uses: actions/setup-node@master
with:
node-version: "14"
node-version: "18"
cache: "yarn"
- name: Update node-gyp
run: |
npm install --global [email protected]
npm config set node_gyp $(npm prefix -g)/lib/node_modules/node-gyp/bin/node-gyp.js
# - name: Update node-gyp
# run: |
# npm install --global [email protected]
# npm config set node_gyp $(npm prefix -g)/lib/node_modules/node-gyp/bin/node-gyp.js
- name: Install dependencies
run: yarn install --frozen-lockfile --prefer-offline && yarn run rebuild-all-native
- name: GQL Codegen
Expand All @@ -33,6 +33,7 @@ jobs:
# run: yarn run lint:ci
- name: Build
run: yarn run build

MacOs:
runs-on: macos-latest
env:
Expand All @@ -41,12 +42,12 @@ jobs:
- uses: actions/checkout@master
- uses: actions/setup-node@master
with:
node-version: "14"
node-version: "18"
cache: "yarn"
- name: Update node-gyp
run: |
npm install --global [email protected]
npm config set node_gyp $(npm prefix -g)/lib/node_modules/node-gyp/bin/node-gyp.js
# - name: Update node-gyp
# run: |
# npm install --global [email protected]
# npm config set node_gyp $(npm prefix -g)/lib/node_modules/node-gyp/bin/node-gyp.js
- name: Install dependencies
run: yarn install --frozen-lockfile --prefer-offline && yarn run rebuild-all-native
- name: GQL Codegen
Expand All @@ -66,14 +67,14 @@ jobs:
- uses: actions/checkout@master
- uses: actions/setup-node@master
with:
node-version: "14"
cache: "yarn"
- name: Update node-gyp
node-version: "18"
- name: Configure Node
shell: powershell
run: |
npm install --global [email protected]
# npm v9 doesn't allow custom config parameters (i.e. node_gyp) anymode, so we have to downgrade it to v8
npm install -g npm@8
npm install -g node-gyp@latest
npm prefix -g | % {npm config set node_gyp "$_\node_modules\node-gyp\bin\node-gyp.js"}
- name: Update registry URL
run: |
npm config set registry "http://registry.npmjs.org"
yarn config set registry "http://registry.npmjs.org"
yarn config set network-timeout 300000
Expand Down
2 changes: 1 addition & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
runtime = electron
disturl = https://electronjs.org/headers
target = 13.6.9
target = 24.4.0
arch = x64
#arch = arm64
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14.21.3
18.14.0
2 changes: 1 addition & 1 deletion app/about-window/Presenter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { remote } from 'electron';
import * as remote from '@electron/remote';
import PropTypes from 'prop-types';
import React from 'react';
import injectSheet from 'react-jss';
Expand Down
2 changes: 1 addition & 1 deletion app/app-store/sagas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { remote } from 'electron';
import * as remote from '@electron/remote';
import * as isBlank from 'is-blank';
import * as _ from 'lodash';
import { SagaIterator } from 'redux-saga';
Expand Down
3 changes: 2 additions & 1 deletion app/app-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
process.worker = true;
// tslint:disable:no-import-side-effect
import './dotenv';
import { ipcRenderer, remote } from 'electron';
import { ipcRenderer } from 'electron';
import * as remote from '@electron/remote';
import { InMemoryCache, NormalizedCacheObject } from 'apollo-cache-inmemory';
import ApolloClient from 'apollo-client';
import { join } from 'path';
Expand Down
10 changes: 6 additions & 4 deletions app/applications/Application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import * as slack from 'slack';
import { GradientType, withGradient } from '@getstation/theme';
import ElectronWebview from 'app/common/components/ElectronWebview';
import classNames from 'classnames';
import { clipboard, remote } from 'electron';
import { clipboard } from 'electron';
import * as remote from '@electron/remote';
// @ts-ignore no declaration file
import { fetchFavicon, setFetchFaviconTimeout } from '@getstation/fetch-favicon';
import Maybe from 'graphql/tsutils/Maybe';
Expand Down Expand Up @@ -381,7 +382,7 @@ class ApplicationImpl extends React.PureComponent {
if (this.webView && this.webView.view) {
const webview = this.webView.view;

webview.addEventListener('did-attach', () => {
webview.addEventListener('dom-ready', () => {
const webContents = remote.webContents.fromId(webview.getWebContentsId());

webview.addEventListener('did-navigate-in-page', (e: any) => this.handleDidNavigateInPage(e));
Expand All @@ -395,6 +396,7 @@ class ApplicationImpl extends React.PureComponent {
render() {
const { notUseNativeWindowOpen, tab } = this.props;
const tabUrl = tab.get('url', '');
const nodeIntegrationEnabled = tabUrl.startsWith('station://')

const {
applicationId, applicationName, applicationIcon, themeColor, manifestURL,
Expand Down Expand Up @@ -446,7 +448,7 @@ class ApplicationImpl extends React.PureComponent {
hidden={this.props.hidden}
className="l-webview__content"
preload={preloadUrl}
allowpopups="true"
allowpopups={true}
loading={this.props.loading}
webviewRef={this.setWebviewRef}
onPageTitleUpdated={this.handleTitleUpdated}
Expand All @@ -456,7 +458,7 @@ class ApplicationImpl extends React.PureComponent {
onDidFailLoad={this.handleDidFailLoad}
onDomReady={this.handleDomReady}
onCrashed={this.handleWebcontentsCrashed}
webpreferences={`allowDisplayingInsecureContent,nativeWindowOpen=${notUseNativeWindowOpen ? 'no' : 'yes'},contextIsolation=no`}
webpreferences={`allowRunningInsecureContent=true,nativeWindowOpen=${notUseNativeWindowOpen},contextIsolation=false,nodeIntegration=${nodeIntegrationEnabled}`}
/>

</div>
Expand Down
2 changes: 1 addition & 1 deletion app/applications/components/ConfirmResetApplication.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Modal } from '@getstation/theme';
import { remote } from 'electron';
import * as remote from '@electron/remote';
import * as React from 'react';
// @ts-ignore: no declaration file
import injectSheet from 'react-jss';
Expand Down
2 changes: 1 addition & 1 deletion app/auto-update/components/AutoUpdateSubdock.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, ThemeTypes as Theme } from '@getstation/theme';
import { remote } from 'electron';
import * as remote from '@electron/remote';
import * as React from 'react';
// @ts-ignore: no declaration file
import injectSheet from 'react-jss';
Expand Down
2 changes: 1 addition & 1 deletion app/bang/search/providers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
import { LocalStorage } from 'node-localstorage';
import { remote } from 'electron';
import * as remote from '@electron/remote';
import * as moment from 'moment';
import { reverse } from 'ramda';
import { SDK, activity } from '@getstation/sdk';
Expand Down
78 changes: 59 additions & 19 deletions app/bang/search/searchEngine.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,103 @@
import { applyTo, compose, identity, negate, pipe, filter, sortBy, take } from 'ramda';
import {
applyTo,
compose,
identity,
negate,
pipe,
filter,
sortBy,
take
} from 'ramda';

import { Transformer } from '../../utils/fp';
import createComputeScore, { Loggers, getFrecencyEnv, getTotalScore } from './score';
import createComputeScore, {
Loggers,
getFrecencyEnv,
getTotalScore
} from './score';
import { FrecencyWeightOptions } from './score/frecency';
import { WEIGHT_CONTEXTUAL_FRECENCY_RECENT_SELECTIONS_MATCH, WEIGHT_GLOBAL_FRECENCY_RECENT_SELECTIONS_MATCH } from './score/config';
import {
WEIGHT_CONTEXTUAL_FRECENCY_RECENT_SELECTIONS_MATCH,
WEIGHT_GLOBAL_FRECENCY_RECENT_SELECTIONS_MATCH
} from './score/config';

import {
ScoredItem,
SearchFunction,
SaveGlobalSelectionFunction,
SaveContextualSelectionFunction,
SearchEngine,
SearchEngineEnv,
SearchEngineEnv
} from './types';

const defaultLoggers: Loggers = {
fuseLogger: identity,
contextualFrecencyLogger: identity,
globalFrecencyLogger: identity,
globalFrecencyLogger: identity
};

const contextualFrecencyOptions: FrecencyWeightOptions = {
recentSelectionsMatchWeight: WEIGHT_CONTEXTUAL_FRECENCY_RECENT_SELECTIONS_MATCH,
recentSelectionsMatchWeight: WEIGHT_CONTEXTUAL_FRECENCY_RECENT_SELECTIONS_MATCH
};

const globalFrecencyOptions: FrecencyWeightOptions = {
recentSelectionsMatchWeight: WEIGHT_GLOBAL_FRECENCY_RECENT_SELECTIONS_MATCH,
recentSelectionsMatchWeight: WEIGHT_GLOBAL_FRECENCY_RECENT_SELECTIONS_MATCH
};

const hasPositiveScore = (scoredItem: ScoredItem) => getTotalScore(scoredItem) > 0;
const hasPositiveScore = (scoredItem: ScoredItem) =>
getTotalScore(scoredItem) > 0;

/**
* This function create a SearchEngine, it needs a contextual FrecencyStorageProvider
* and a global FrecencyStorageProvider in order to work.
*
* expose a search function and 2 methods to save selections (global or contextual)
*/
export const createSearchEngine = (searchEngineEnv: SearchEngineEnv, loggers: Loggers = defaultLoggers): SearchEngine => {
const contextual = getFrecencyEnv(searchEngineEnv.contextualFrecencyStorageProvider, contextualFrecencyOptions);
const global = getFrecencyEnv(searchEngineEnv.globalFrecencyStorageProvider, globalFrecencyOptions);
export const createSearchEngine = (
searchEngineEnv: SearchEngineEnv,
loggers: Loggers = defaultLoggers
): SearchEngine => {
const contextual = getFrecencyEnv(
searchEngineEnv.contextualFrecencyStorageProvider,
contextualFrecencyOptions
);
const global = getFrecencyEnv(
searchEngineEnv.globalFrecencyStorageProvider,
globalFrecencyOptions
);

const computeScore = createComputeScore({ contextual, global }, loggers);

const searchFn: SearchFunction = (items, context, limit) => {
const scoredItems: ScoredItem[] = computeScore(items, context);

return applyTo(scoredItems)(pipe(
sortBy(compose(negate, getTotalScore)), // negate scores in order to make a descending sort
filter(hasPositiveScore) as Transformer<ScoredItem[]>,
take(limit) as Transformer<ScoredItem[]>,
));
return applyTo(scoredItems)(
pipe(
sortBy(
compose(
negate,
getTotalScore
)
), // negate scores in order to make a descending sort
filter(hasPositiveScore) as Transformer<ScoredItem[]>,
take(limit) as Transformer<ScoredItem[]>
)
);
};

const saveContextualSelection: SaveContextualSelectionFunction = (saveParams) => {
const saveContextualSelection: SaveContextualSelectionFunction = saveParams => {
return contextual.frecencyEngine.save(saveParams);
};

const saveGlobalSelection: SaveGlobalSelectionFunction = (selectedId, dateSelection) => {
return global.frecencyEngine.save({ searchQuery: '', selectedId, dateSelection });
const saveGlobalSelection: SaveGlobalSelectionFunction = (
selectedId,
dateSelection
) => {
return global.frecencyEngine.save({
searchQuery: '',
selectedId,
dateSelection
});
};

return { search: searchFn, saveContextualSelection, saveGlobalSelection };
Expand Down
3 changes: 2 additions & 1 deletion app/cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ipcRenderer, remote } from 'electron';
import { ipcRenderer } from 'electron';
import * as remote from '@electron/remote';

const exit = () => remote.app.exit(0);

Expand Down
4 changes: 2 additions & 2 deletions app/common/components/ElectronWebview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as ReactDOM from 'react-dom';
import { logger } from '../../api/logger';
import { Omit } from '../../types';
import { dissoc } from 'ramda';
import { remote } from 'electron';
import * as remote from '@electron/remote';

export interface ElectronWebviewProps extends Omit<Electron.WebviewTag, 'src'> {
// webview `src` is updated by the webview itself, so we do not want to
Expand Down Expand Up @@ -265,7 +265,6 @@ class ElectronWebview extends React.Component<ElectronWebviewProps, {}> {

this.view.addEventListener('did-attach', (...attachArgs: any[]) => {
this.ready = true;
this.forwardKeyboardEvents();
events.forEach((event) => {
const propName = camelCase(`on-${event}`);
if (this.props[propName]) {
Expand All @@ -276,6 +275,7 @@ class ElectronWebview extends React.Component<ElectronWebviewProps, {}> {
});

this.view.addEventListener('dom-ready', () => {
this.forwardKeyboardEvents();
// Remove this once https://github.com/electron/electron/issues/14474 is fixed
this.view.blur();
this.view.focus();
Expand Down
2 changes: 1 addition & 1 deletion app/containers/AppSub.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GradientType, withGradient } from '@getstation/theme';
import classNames from 'classnames';
import { remote } from 'electron';
import * as remote from '@electron/remote';
import PropTypes from 'prop-types';
import React from 'react';
import injectSheet from 'react-jss';
Expand Down
Loading

0 comments on commit 3fbec12

Please sign in to comment.