diff --git a/localization/locales/en/translation.json b/localization/locales/en/translation.json index 8310afa7..d64489dd 100644 --- a/localization/locales/en/translation.json +++ b/localization/locales/en/translation.json @@ -111,7 +111,10 @@ "RemoveWorkspace": "Remove workspace", "WorkspaceFolderRemoved": "Workspace folder is moved", "GithubUserInfoNoFound": "Github UserInfo No Found", - "GithubUserInfoNoFoundDetail": "Seems you haven't login to Github, so we disable syncing for this wiki." + "GithubUserInfoNoFoundDetail": "Seems you haven't login to Github, so we disable syncing for this wiki.", + "RestartMessage": "You need to restart the app for this change to take affect.", + "Later": "Later", + "RestartNow": "Restart Now" }, "Log": { "CantSyncGitNotInitialized": "Unable to sync, this folder is not initialized as a Git repository", @@ -176,6 +179,7 @@ "Token": "Git credentials", "TokenDescription": "The credentials used to authenticate to the Git server so you can securely synchronize content. Can be obtained by logging in to Github, or manually obtained and filled in here.", "Reset": "Are you sure? All preferences will be restored to their original defaults. Browsing data won't be affected. This action cannot be undone.", - "ResetNow": "Reset Now" + "ResetNow": "Reset Now", + "ClearBrowsingDataMessage": "Are you sure? All browsing data will be cleared. This action cannot be undone." } } diff --git a/localization/locales/ja/translation.json b/localization/locales/ja/translation.json index 942e5b44..617021a1 100644 --- a/localization/locales/ja/translation.json +++ b/localization/locales/ja/translation.json @@ -7,9 +7,15 @@ }, "Preference": { "Reset": "本気ですか?すべての設定が元のデフォルトに復元されます。閲覧データは影響を受けません。このアクションは元に戻せません。", - "ResetNow": "今すぐリセット" + "ResetNow": "今すぐリセット", + "ClearBrowsingDataMessage": "本気ですか?すべての閲覧データが消去されます。このアクションは元に戻せません。" }, "AddWorkspace": { "AddFileSystemPath": "サブウィキのFileSystemPathsを追加する" + }, + "Dialog": { + "Later": "後で", + "RestartMessage": "この変更を有効にするには、アプリを再起動する必要があります。", + "RestartNow": "今すぐ再起動" } } diff --git a/localization/locales/zh_CN/translation.json b/localization/locales/zh_CN/translation.json index ddd9fdcd..20b75416 100644 --- a/localization/locales/zh_CN/translation.json +++ b/localization/locales/zh_CN/translation.json @@ -143,7 +143,10 @@ "DoNotCare": "不管", "PathPassInCantUse": "传入的路径无法使用", "GithubUserInfoNoFound": "找不到 Github 用户信息", - "GithubUserInfoNoFoundDetail": "似乎你尚未登录 Github,因此此 Wiki 的同步暂时禁用,直到你登录以提供有可用于同步的登录信息。" + "GithubUserInfoNoFoundDetail": "似乎你尚未登录 Github,因此此 Wiki 的同步暂时禁用,直到你登录以提供有可用于同步的登录信息。", + "Later": "稍后", + "RestartMessage": "您需要重新启动本程序才能使此更改生效。", + "RestartNow": "现在重启" }, "Cancel": "取消", "Preference": { @@ -176,6 +179,7 @@ "SystemDefalutTheme": "系统默认主题色", "Theme": "主题色", "Reset": "你确定吗?所有首选项都将恢复为其原始默认值。浏览数据不会受到影响。此操作无法撤消。", - "ResetNow": "立即重置" + "ResetNow": "立即重置", + "ClearBrowsingDataMessage": "你确定吗?所有浏览数据将被清除。此操作无法撤消。" } } diff --git a/src/services/channels.ts b/src/services/channels.ts index 42d29c33..ec4b9172 100644 --- a/src/services/channels.ts +++ b/src/services/channels.ts @@ -5,9 +5,11 @@ export enum PreferenceChannel { getPreference = 'get-preference', getPreferences = 'get-preferences', requestSetPreference = 'request-set-preference', + requestClearBrowsingData = 'request-clear-browsing-data', } export enum WindowChannel { + requestShowRequireRestartDialog = 'request-show-require-restart-dialog', requestShowPreferencesWindow = 'request-show-preferences-window', requestShowAboutWindow = 'request-show-about-window', requestShowCustomUserAgentWindow = 'request-show-custom-user-agent-window', diff --git a/src/services/listeners/index.ts b/src/services/listeners/index.ts index 64575901..24cf9b6a 100755 --- a/src/services/listeners/index.ts +++ b/src/services/listeners/index.ts @@ -1,4 +1,3 @@ -/* eslint-disable sonarjs/no-duplicate-string */ /* eslint-disable no-param-reassign */ import path from 'path'; import { BrowserView, Notification, app, dialog, ipcMain, nativeTheme, shell } from 'electron'; @@ -23,7 +22,6 @@ import { } from '../libs/workspaces'; import { getWorkspaceMeta, getWorkspaceMetas } from '../libs/workspace-metas'; import { - clearBrowsingData, createWorkspaceView, hibernateWorkspaceView, loadURL, @@ -39,27 +37,10 @@ import { reloadViewsDarkReader, reloadViewsWebContentsIfDidFailLoad, getActiveBr import { updatePauseNotificationsInfo, getPauseNotificationsInfo } from '../libs/notifications'; import getViewBounds from '../libs/get-view-bounds'; import createMenu from '../libs/create-menu'; -// @ts-expect-error ts-migrate(1192) FIXME: Module '"/Users/linonetwo/Desktop/repo/TiddlyGit-D... Remove this comment to see the full error message -import aboutWindow from '../windows/about'; -// @ts-expect-error ts-migrate(1192) FIXME: Module '"/Users/linonetwo/Desktop/repo/TiddlyGit-D... Remove this comment to see the full error message -import addWorkspaceWindow from '../windows/add-workspace'; -// @ts-expect-error ts-migrate(1192) FIXME: Module '"/Users/linonetwo/Desktop/repo/TiddlyGit-D... Remove this comment to see the full error message -import codeInjectionWindow from '../windows/code-injection'; -// @ts-expect-error ts-migrate(1192) FIXME: Module '"/Users/linonetwo/Desktop/repo/TiddlyGit-D... Remove this comment to see the full error message -import customUserAgentWindow from '../windows/custom-user-agent'; + // @ts-expect-error ts-migrate(1192) FIXME: Module '"/Users/linonetwo/Desktop/repo/TiddlyGit-D... Remove this comment to see the full error message import displayMediaWindow from '../windows/display-media'; -// @ts-expect-error ts-migrate(1192) FIXME: Module '"/Users/linonetwo/Desktop/repo/TiddlyGit-D... Remove this comment to see the full error message -import editWorkspaceWindow from '../windows/edit-workspace'; -import * as mainWindow from '../windows/main'; -// @ts-expect-error ts-migrate(1192) FIXME: Module '"/Users/linonetwo/Desktop/repo/TiddlyGit-D... Remove this comment to see the full error message -import notificationsWindow from '../windows/notifications'; -// @ts-expect-error ts-migrate(1192) FIXME: Module '"/Users/linonetwo/Desktop/repo/TiddlyGit-D... Remove this comment to see the full error message -import preferencesWindow from '../windows/preferences'; -// @ts-expect-error ts-migrate(1192) FIXME: Module '"/Users/linonetwo/Desktop/repo/TiddlyGit-D... Remove this comment to see the full error message -import proxyWindow from '../windows/proxy'; -// @ts-expect-error ts-migrate(1192) FIXME: Module '"/Users/linonetwo/Desktop/repo/TiddlyGit-D... Remove this comment to see the full error message -import spellcheckLanguagesWindow from '../windows/spellcheck-languages'; + import bindI18nListener from './i18n'; const loadListeners = () => { bindI18nListener(); @@ -190,23 +171,6 @@ const loadListeners = () => { setSystemPreference(name, value); }); - ipcMain.on('request-show-require-restart-dialog', () => { - dialog - .showMessageBox(preferencesWindow.get() || mainWindow.get(), { - type: 'question', - buttons: ['Restart Now', 'Later'], - message: 'You need to restart the app for this change to take affect.', - cancelId: 1, - }) - .then(({ response }) => { - // eslint-disable-next-line promise/always-return - if (response === 0) { - app.relaunch(); - app.quit(); - } - }) - .catch(console.log); - }); // Notifications ipcMain.on('request-show-notification', (_, options) => { if ((Notification as any).isSupported()) { @@ -335,22 +299,7 @@ const loadListeners = () => { ipcMain.on('request-remove-workspace-picture', (_, id) => { removeWorkspacePicture(id); }); - ipcMain.on('request-clear-browsing-data', () => { - dialog - .showMessageBox(preferencesWindow.get() || mainWindow.get(), { - type: 'question', - buttons: ['Clear Now', 'Cancel'], - message: 'Are you sure? All browsing data will be cleared. This action cannot be undone.', - cancelId: 1, - }) - .then(({ response }) => { - // eslint-disable-next-line promise/always-return - if (response === 0) { - clearBrowsingData(); - } - }) - .catch(console.log); - }); + ipcMain.on('request-load-url', (_, url, id) => { loadURL(url, id); }); diff --git a/src/services/preferences.ts b/src/services/preferences.ts index 7b235928..64e7c90d 100755 --- a/src/services/preferences.ts +++ b/src/services/preferences.ts @@ -109,9 +109,28 @@ export class Preference { ipcMain.emit(PreferenceChannel.requestShowRequireRestartDialog); } }) - .catch(console.log); + .catch(console.error); } }); + ipcMain.on(PreferenceChannel.requestClearBrowsingData, () => { + const availableWindowToShowDialog = this.windowService.get(WindowNames.preferences) ?? this.windowService.get(WindowNames.main); + if (availableWindowToShowDialog !== undefined) { + dialog + .showMessageBox(availableWindowToShowDialog, { + type: 'question', + buttons: [i18n.t('Preference.ResetNow'), i18n.t('Cancel')], + message: i18n.t('Preference.ClearBrowsingDataMessage'), + cancelId: 1, + }) + .then(({ response }) => { + if (response === 0) { + // TODO: call clearBrowsingData from workspace view service clearBrowsingData(); + } + }) + .catch(console.error); + } + }); + ipcMain.on(PreferenceChannel.getPreference, (event, name: keyof IPreferences) => { event.returnValue = this.get(name); }); diff --git a/src/services/windows/index.ts b/src/services/windows/index.ts index 5b6c7c06..c8758c07 100644 --- a/src/services/windows/index.ts +++ b/src/services/windows/index.ts @@ -1,4 +1,4 @@ -import { BrowserWindow, ipcMain } from 'electron'; +import { BrowserWindow, ipcMain, dialog, app, App, remote } from 'electron'; import isDevelopment from 'electron-is-dev'; import { injectable, inject } from 'inversify'; @@ -6,6 +6,8 @@ import serviceIdentifiers from '@services/serviceIdentifier'; import { Preference } from '@services/preferences'; import { Channels, WindowChannel } from '@/services/channels'; import { WindowNames, windowDimension } from '@/services/windows/WindowProperties'; +import i18n from '@/services/libs/i18n'; + declare const MAIN_WINDOW_WEBPACK_ENTRY: string; declare const MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY: string; @@ -19,6 +21,27 @@ export class Window { } init(): void { + ipcMain.on(WindowChannel.requestShowRequireRestartDialog, () => { + const availableWindowToShowDialog = this.get(WindowNames.preferences) ?? this.get(WindowNames.main); + if (availableWindowToShowDialog !== undefined) { + dialog + .showMessageBox(availableWindowToShowDialog, { + type: 'question', + buttons: [i18n.t('Dialog.RestartNow'), i18n.t('Dialog.Later')], + message: i18n.t('Dialog.RestartMessage'), + cancelId: 1, + }) + .then(({ response }) => { + if (response === 0) { + const availableApp = (app as App | undefined) === undefined ? remote.app : app; + availableApp.relaunch(); + availableApp.quit(); + } + }) + .catch(console.error); + } + }); + ipcMain.on(WindowChannel.requestShowCodeInjectionWindow, (_, codeInjectionType: string) => { // FIXME: make codeInjectionType enum, and find places use this codeInjectionType void this.open(WindowNames.codeInjection, { codeInjectionType });