Skip to content

Commit e2b9ea1

Browse files
committed
refactor: switch to preload script
- delete ipcCalls
1 parent 675066d commit e2b9ea1

19 files changed

+37
-208
lines changed

reports/commonExporter.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { t } from 'fyo';
22
import { Action } from 'fyo/model/types';
33
import { Verb } from 'fyo/telemetry/types';
4-
import { saveData } from 'src/utils/ipcCalls';
4+
import { getSavePath, showExportInFolder } from 'src/utils/ui';
55
import { getIsNullOrUndef } from 'utils';
66
import { generateCSV } from 'utils/csvParser';
77
import { Report } from './Report';
88
import { ExportExtention, ReportCell } from './types';
9-
import { getSavePath, showExportInFolder } from 'src/utils/ui';
109

1110
interface JSONExport {
1211
columns: { fieldname: string; label: string }[];
@@ -184,7 +183,7 @@ export async function saveExportData(
184183
filePath: string,
185184
message?: string
186185
) {
187-
await saveData(data, filePath);
186+
await ipc.saveData(data, filePath);
188187
message ??= t`Export Successful`;
189188
showExportInFolder(message, filePath);
190189
}

src/App.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ import { connectToDatabase, dbErrorActionSymbols } from './utils/db';
5353
import { initializeInstance } from './utils/initialization';
5454
import * as injectionKeys from './utils/injectionKeys';
5555
import { showDialog } from './utils/interactive';
56-
import { checkDbAccess, checkForUpdates } from './utils/ipcCalls';
5756
import { setLanguageMap } from './utils/language';
5857
import { updateConfigFiles } from './utils/misc';
5958
import { updatePrintTemplates } from './utils/printTemplates';
@@ -147,7 +146,7 @@ export default defineComponent({
147146
this.activeScreen = Screen.Desk;
148147
await this.setDeskRoute();
149148
await fyo.telemetry.start(true);
150-
await checkForUpdates();
149+
await ipc.checkForUpdates();
151150
await setLanguageMap();
152151
this.dbPath = filePath;
153152
this.companyName = (await fyo.getValue(
@@ -164,7 +163,7 @@ export default defineComponent({
164163
return;
165164
}
166165
167-
if (filePath !== ':memory:' && !(await checkDbAccess(filePath))) {
166+
if (filePath !== ':memory:' && !(await ipc.checkDbAccess(filePath))) {
168167
await showDialog({
169168
title: this.t`Cannot open file`,
170169
type: 'error',

src/components/Controls/AttachImage.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
<script lang="ts">
5858
import { Field } from 'schemas/types';
5959
import { fyo } from 'src/initFyo';
60-
import { selectFile } from 'src/utils/ipcCalls';
6160
import { getDataURL } from 'src/utils/misc';
6261
import { defineComponent, PropType } from 'vue';
6362
import FeatherIcon from '../FeatherIcon.vue';
@@ -105,7 +104,7 @@ export default defineComponent({
105104
],
106105
};
107106
108-
const { name, success, data } = await selectFile(options);
107+
const { name, success, data } = await ipc.selectFile(options);
109108
110109
if (!success) {
111110
return;

src/components/ExportWizard.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
</template>
8888
<script lang="ts">
8989
import { t } from 'fyo';
90+
import { Verb } from 'fyo/telemetry/types';
9091
import { Field, FieldTypeEnum } from 'schemas/types';
9192
import { fyo } from 'src/initFyo';
9293
import {
@@ -95,17 +96,15 @@ import {
9596
getExportTableFields,
9697
getJsonExportData,
9798
} from 'src/utils/export';
98-
import { saveData } from 'src/utils/ipcCalls';
9999
import { ExportField, ExportFormat, ExportTableField } from 'src/utils/types';
100+
import { getSavePath, showExportInFolder } from 'src/utils/ui';
100101
import { QueryFilter } from 'utils/db/types';
101-
import { defineComponent, PropType } from 'vue';
102+
import { PropType, defineComponent } from 'vue';
102103
import Button from './Button.vue';
103104
import Check from './Controls/Check.vue';
104105
import Int from './Controls/Int.vue';
105106
import Select from './Controls/Select.vue';
106107
import FormHeader from './FormHeader.vue';
107-
import { Verb } from 'fyo/telemetry/types';
108-
import { getSavePath, showExportInFolder } from 'src/utils/ui';
109108
110109
interface ExportWizardData {
111110
useListFilters: boolean;
@@ -258,7 +257,7 @@ export default defineComponent({
258257
return;
259258
}
260259
261-
await saveData(data, filePath);
260+
await ipc.saveData(data, filePath);
262261
this.fyo.telemetry.log(Verb.Exported, this.schemaName, {
263262
extension: this.exportFormat,
264263
});

src/components/HowTo.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
</button>
1010
</template>
1111
<script>
12-
import { openLink } from 'src/utils/ipcCalls';
1312
import FeatherIcon from './FeatherIcon.vue';
1413
1514
export default {
@@ -23,7 +22,7 @@ export default {
2322
},
2423
methods: {
2524
openHelpLink() {
26-
openLink(this.link);
25+
ipc.openLink(this.link);
2726
},
2827
},
2928
};

src/components/SearchBar.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,12 @@
197197
import { fyo } from 'src/initFyo';
198198
import { getBgTextColorClass } from 'src/utils/colors';
199199
import { searcherKey, shortcutsKey } from 'src/utils/injectionKeys';
200-
import { openLink } from 'src/utils/ipcCalls';
201200
import { docsPathMap } from 'src/utils/misc';
202201
import {
203-
getGroupLabelMap,
204202
SearchGroup,
205-
searchGroups,
206203
SearchItems,
204+
getGroupLabelMap,
205+
searchGroups,
207206
} from 'src/utils/search';
208207
import { defineComponent, inject, nextTick } from 'vue';
209208
import Button from './Button.vue';
@@ -305,7 +304,7 @@ export default defineComponent({
305304
},
306305
methods: {
307306
openDocs() {
308-
openLink('https://docs.frappebooks.com/' + docsPathMap.Search);
307+
ipc.openLink('https://docs.frappebooks.com/' + docsPathMap.Search);
309308
},
310309
getShortcuts() {
311310
const ifOpen = (cb: Function) => () => this.openModal && cb();

src/components/Sidebar.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@
182182
import { reportIssue } from 'src/errorHandling';
183183
import { fyo } from 'src/initFyo';
184184
import { languageDirectionKey, shortcutsKey } from 'src/utils/injectionKeys';
185-
import { openLink } from 'src/utils/ipcCalls';
186185
import { docsPathRef } from 'src/utils/refs';
187186
import { getSidebarConfig } from 'src/utils/sidebarConfig';
188187
import { SidebarConfig, SidebarItem, SidebarRoot } from 'src/utils/types';
@@ -255,7 +254,7 @@ export default defineComponent({
255254
reportIssue,
256255
toggleSidebar,
257256
openDocumentation() {
258-
openLink('https://docs.frappebooks.com/' + docsPathRef.value);
257+
ipc.openLink('https://docs.frappebooks.com/' + docsPathRef.value);
259258
},
260259
setActiveGroup() {
261260
const { fullPath } = this.$router.currentRoute.value;

src/errorHandling.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ import { showDialog } from 'src/utils/interactive';
77
import { fyo } from './initFyo';
88
import router from './router';
99
import { getErrorMessage, stringifyCircular } from './utils';
10-
import {
11-
sendError as ipcSendError,
12-
openExternalUrl,
13-
showError,
14-
} from './utils/ipcCalls';
1510
import type { DialogOptions, ToastOptions } from './utils/types';
1611

1712
function shouldNotStore(error: Error) {
@@ -46,7 +41,7 @@ export async function sendError(errorLogObj: ErrorLog) {
4641
console.log('sendError', body);
4742
}
4843

49-
await ipcSendError(JSON.stringify(body));
44+
await ipc.sendError(JSON.stringify(body));
5045
}
5146

5247
function getToastProps(errorLogObj: ErrorLog) {
@@ -157,7 +152,7 @@ export async function showErrorDialog(title?: string, content?: string) {
157152
// To be used for show stopper errors
158153
title ??= t`Error`;
159154
content ??= t`Something has gone terribly wrong. Please check the console and raise an issue.`;
160-
await showError(title, content);
155+
await ipc.showError(title, content);
161156
}
162157

163158
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -234,7 +229,7 @@ function getIssueUrlQuery(errorLogObj?: ErrorLog): string {
234229

235230
export function reportIssue(errorLogObj?: ErrorLog) {
236231
const urlQuery = getIssueUrlQuery(errorLogObj);
237-
openExternalUrl(urlQuery);
232+
ipc.openExternalUrl(urlQuery);
238233
}
239234

240235
function getErrorLabel(error: Error) {

src/pages/DatabaseSelector.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ import Loading from 'src/components/Loading.vue';
246246
import Modal from 'src/components/Modal.vue';
247247
import { fyo } from 'src/initFyo';
248248
import { showDialog } from 'src/utils/interactive';
249-
import { getDbList } from 'src/utils/ipcCalls';
250249
import { updateConfigFiles } from 'src/utils/misc';
251250
import { deleteDb, getSavePath, getSelectedFilePath } from 'src/utils/ui';
252251
import type { ConfigFilesWithModified } from 'utils/types';
@@ -359,7 +358,7 @@ export default defineComponent({
359358
this.creatingDemo = false;
360359
},
361360
async setFiles() {
362-
const dbList = await getDbList();
361+
const dbList = await ipc.getDbList();
363362
this.files = dbList?.sort(
364363
(a, b) => Date.parse(b.modified) - Date.parse(a.modified)
365364
);

src/pages/GetStarted.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,8 @@ import Icon from 'src/components/Icon.vue';
7676
import PageHeader from 'src/components/PageHeader.vue';
7777
import { fyo } from 'src/initFyo';
7878
import { getGetStartedConfig } from 'src/utils/getStartedConfig';
79-
import { openLink } from 'src/utils/ipcCalls';
8079
import { GetStartedConfigItem } from 'src/utils/types';
81-
import { Component } from 'vue';
82-
import { defineComponent, h } from 'vue';
80+
import { Component, defineComponent, h } from 'vue';
8381
8482
type ListItem = GetStartedConfigItem['items'][number];
8583
@@ -106,7 +104,7 @@ export default defineComponent({
106104
methods: {
107105
async handleDocumentation({ key, documentation }: ListItem) {
108106
if (documentation) {
109-
openLink(documentation);
107+
ipc.openLink(documentation);
110108
}
111109
112110
switch (key) {

0 commit comments

Comments
 (0)