mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-15 15:10:31 -08:00
refactor: language menu
This commit is contained in:
parent
7b4ae85109
commit
c53a82140f
4 changed files with 15 additions and 15 deletions
24
src/main.ts
24
src/main.ts
|
|
@ -1,12 +1,11 @@
|
||||||
import 'reflect-metadata';
|
import 'reflect-metadata';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import { ipcMain, protocol, session, powerMonitor, app } from 'electron';
|
import { ipcMain, protocol, powerMonitor, app } from 'electron';
|
||||||
import isDev from 'electron-is-dev';
|
import isDev from 'electron-is-dev';
|
||||||
import settings from 'electron-settings';
|
import settings from 'electron-settings';
|
||||||
import { autoUpdater } from 'electron-updater';
|
import { autoUpdater } from 'electron-updater';
|
||||||
import unhandled from 'electron-unhandled';
|
import unhandled from 'electron-unhandled';
|
||||||
import { openNewGitHubIssue, debugInfo } from 'electron-util';
|
import { openNewGitHubIssue, debugInfo } from 'electron-util';
|
||||||
import i18n from 'i18next';
|
|
||||||
|
|
||||||
import { clearMainBindings } from '@services/libs/i18n/i18nMainBindings';
|
import { clearMainBindings } from '@services/libs/i18n/i18nMainBindings';
|
||||||
import { buildLanguageMenu } from '@services/libs/i18n/buildLanguageMenu';
|
import { buildLanguageMenu } from '@services/libs/i18n/buildLanguageMenu';
|
||||||
|
|
@ -15,7 +14,7 @@ import { container } from '@services/container';
|
||||||
import { logger } from '@services/libs/log';
|
import { logger } from '@services/libs/log';
|
||||||
import extractHostname from '@services/libs/extract-hostname';
|
import extractHostname from '@services/libs/extract-hostname';
|
||||||
import MAILTO_URLS from '@services/constants/mailto-urls';
|
import MAILTO_URLS from '@services/constants/mailto-urls';
|
||||||
import { initRendererI18NHandler } from '@services/libs/i18n';
|
import i18next, { initRendererI18NHandler } from '@services/libs/i18n';
|
||||||
|
|
||||||
import serviceIdentifier from '@services/serviceIdentifier';
|
import serviceIdentifier from '@services/serviceIdentifier';
|
||||||
import { WindowNames } from '@services/windows/WindowProperties';
|
import { WindowNames } from '@services/windows/WindowProperties';
|
||||||
|
|
@ -39,6 +38,11 @@ if (!gotTheLock) {
|
||||||
console.info('Quitting dut to we only allow one instance to run.');
|
console.info('Quitting dut to we only allow one instance to run.');
|
||||||
app.quit();
|
app.quit();
|
||||||
} else {
|
} else {
|
||||||
|
protocol.registerSchemesAsPrivileged([
|
||||||
|
{ scheme: 'http', privileges: { standard: true } },
|
||||||
|
{ scheme: 'https', privileges: { standard: true } },
|
||||||
|
{ scheme: 'mailto', privileges: { standard: true } },
|
||||||
|
]);
|
||||||
bindServiceAndProxy();
|
bindServiceAndProxy();
|
||||||
const menuService = container.get<IMenuService>(serviceIdentifier.MenuService);
|
const menuService = container.get<IMenuService>(serviceIdentifier.MenuService);
|
||||||
const nativeService = container.get<INativeService>(serviceIdentifier.NativeService);
|
const nativeService = container.get<INativeService>(serviceIdentifier.NativeService);
|
||||||
|
|
@ -57,7 +61,6 @@ if (!gotTheLock) {
|
||||||
mainWindow.focus();
|
mainWindow.focus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
void initRendererI18NHandler();
|
|
||||||
// make sure "Settings" file exists
|
// make sure "Settings" file exists
|
||||||
// if not, ignore this chunk of code
|
// if not, ignore this chunk of code
|
||||||
// as using electron-settings before app.on('ready') and "Settings" is created
|
// as using electron-settings before app.on('ready') and "Settings" is created
|
||||||
|
|
@ -93,12 +96,9 @@ if (!gotTheLock) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
protocol.registerSchemesAsPrivileged([
|
|
||||||
{ scheme: 'http', privileges: { standard: true } },
|
|
||||||
{ scheme: 'https', privileges: { standard: true } },
|
|
||||||
{ scheme: 'mailto', privileges: { standard: true } },
|
|
||||||
]);
|
|
||||||
const commonInit = async (): Promise<void> => {
|
const commonInit = async (): Promise<void> => {
|
||||||
|
await initRendererI18NHandler();
|
||||||
|
|
||||||
// eslint-disable-next-line promise/catch-or-return
|
// eslint-disable-next-line promise/catch-or-return
|
||||||
await app.whenReady();
|
await app.whenReady();
|
||||||
if (isDev) {
|
if (isDev) {
|
||||||
|
|
@ -113,8 +113,6 @@ if (!gotTheLock) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
await windowService.open(WindowNames.main);
|
await windowService.open(WindowNames.main);
|
||||||
// set language async on main process
|
|
||||||
void i18n.changeLanguage(preferenceService.get('language'));
|
|
||||||
await workspaceViewService.initializeAllWorkspaceView();
|
await workspaceViewService.initializeAllWorkspaceView();
|
||||||
|
|
||||||
ipcMain.emit('request-update-pause-notifications-info');
|
ipcMain.emit('request-update-pause-notifications-info');
|
||||||
|
|
@ -146,9 +144,9 @@ if (!gotTheLock) {
|
||||||
}
|
}
|
||||||
// trigger whenTrulyReady
|
// trigger whenTrulyReady
|
||||||
ipcMain.emit(MainChannel.commonInitFinished);
|
ipcMain.emit(MainChannel.commonInitFinished);
|
||||||
|
|
||||||
// build menu at last, this is not noticeable to user, so do it last
|
// build menu at last, this is not noticeable to user, so do it last
|
||||||
buildLanguageMenu();
|
buildLanguageMenu();
|
||||||
menuService.buildMenu();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
app.on('ready', () => {
|
app.on('ready', () => {
|
||||||
|
|
@ -253,7 +251,7 @@ if (!gotTheLock) {
|
||||||
|
|
||||||
unhandled({
|
unhandled({
|
||||||
showDialog: true,
|
showDialog: true,
|
||||||
// logger: logger.error,
|
logger: logger.error,
|
||||||
reportButton: (error) => {
|
reportButton: (error) => {
|
||||||
openNewGitHubIssue({
|
openNewGitHubIssue({
|
||||||
user: 'TiddlyGit Desktop User',
|
user: 'TiddlyGit Desktop User',
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ const logger = winston.createLogger({
|
||||||
debug: 8,
|
debug: 8,
|
||||||
},
|
},
|
||||||
transports: [
|
transports: [
|
||||||
|
new winston.transports.Console(),
|
||||||
new winston.transports.DailyRotateFile({
|
new winston.transports.DailyRotateFile({
|
||||||
filename: 'TiddlyGit-%DATE%.log',
|
filename: 'TiddlyGit-%DATE%.log',
|
||||||
datePattern: 'YYYY-MM-DD',
|
datePattern: 'YYYY-MM-DD',
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
// Ported from
|
// Ported from
|
||||||
// https://github.com/electron-userland/electron-spellchecker/blob/master/src/context-menu-builder.js
|
// https://github.com/electron-userland/electron-spellchecker/blob/master/src/context-menu-builder.js
|
||||||
import { clipboard, shell, Menu, MenuItem, WebContents } from 'electron';
|
import { clipboard, shell, Menu, MenuItem, WebContents } from 'electron';
|
||||||
import i18next from 'i18next';
|
import i18next from '@services/libs/i18n';
|
||||||
import { IOnContextMenuInfo } from './interface';
|
import { IOnContextMenuInfo } from './interface';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ import { WindowNames } from '@services/windows/WindowProperties';
|
||||||
import { lazyInject } from '@services/container';
|
import { lazyInject } from '@services/container';
|
||||||
import serviceIdentifier from '@services/serviceIdentifier';
|
import serviceIdentifier from '@services/serviceIdentifier';
|
||||||
import { IWindowService } from '@services/windows/interface';
|
import { IWindowService } from '@services/windows/interface';
|
||||||
|
import i18next from '@services/libs/i18n';
|
||||||
import ContextMenuBuilder from './contextMenuBuilder';
|
import ContextMenuBuilder from './contextMenuBuilder';
|
||||||
import i18next from 'i18next';
|
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class MenuService implements IMenuService {
|
export class MenuService implements IMenuService {
|
||||||
|
|
@ -196,6 +196,7 @@ export class MenuService implements IMenuService {
|
||||||
submenu: menuItems,
|
submenu: menuItems,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
this.buildMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
public buildContextMenuAndPopup(
|
public buildContextMenuAndPopup(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue