Skip to content

Commit

Permalink
chore: add window comments
Browse files Browse the repository at this point in the history
  • Loading branch information
noob9527 committed Jan 14, 2024
1 parent 0f96994 commit 900f36f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/browser/utils/window-utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { WindowId } from '../../common/window-id';

function getCurrentWindowId() {
switch (window?.location?.hash) {
const hash = window?.location?.hash
switch (hash) {
case '#/main/search':
return WindowId.HOME;
case '#/setting':
Expand All @@ -13,7 +14,11 @@ function getCurrentWindowId() {
case '#/sync':
return WindowId.SYNC;
default:
throw new Error(`unknown window, hash = ${window?.location?.hash}`)
if (hash?.includes('/search')) {
return WindowId.HOME;
} else {
throw new Error(`unknown window, hash = ${hash}`)
}
}
}

Expand Down
21 changes: 18 additions & 3 deletions src/electron-main/window/home-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ function createWindow() {
// Menu.setApplicationMenu(null);
// window.setAutoHideMenuBar(true);

// todo: url might be incorrect
window.loadURL(getWindowHashUrl('main/search'))

window.once('ready-to-show', () => {
if (!process.argv.includes('--background')) {
window.show()
}
SearchHistorySyncTimer.setHandler(() => autoSyncSearchHistory())
})

window.on('close', async (e) => {
Expand All @@ -89,6 +89,13 @@ function createWindow() {
return
}

if (Runtime.isDev) {
logger.debug(
'no need to sync on quit in dev',
)
return
}

logger.debug('sync search history on quit')
// prevent window close
e.preventDefault()
Expand All @@ -103,9 +110,17 @@ function createWindow() {
getOrCreateTray()
logger.log('did-finish-load')

SearchHistorySyncTimer.setHandler(() => autoSyncSearchHistory(Infinity))

if (globalState.profile?.['search.syncHistory.syncOnStart']) {
logger.debug('sync search history on start')
await autoSyncSearchHistory(1)
if (Runtime.isDev) {
logger.debug('no need sync search history on start in dev environment')
} else {
logger.debug('sync search history on start')
await autoSyncSearchHistory(1)
}
// logger.debug('sync search history on start')
// await autoSyncSearchHistory(1)
} else {
logger.debug(
'no need to sync search history on start due to configuration',
Expand Down

0 comments on commit 900f36f

Please sign in to comment.