Merge pull request #3942 from TheFreeman193/hide-on-start

Add hide-to-tray on start option
This commit is contained in:
AkiraFukushima 2023-01-12 23:49:05 +09:00 committed by GitHub
commit 463fc4f210
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 45 additions and 5 deletions

View File

@ -19,7 +19,8 @@ const state = (): GeneralState => {
hideAllAttachments: false
},
other: {
launch: false
launch: false,
hideOnLaunch: false
}
},
loading: false

View File

@ -15,7 +15,8 @@ describe('Preferences/General', () => {
hideAllAttachments: false
},
other: {
launch: false
launch: false,
hideOnLaunch: false
}
},
loading: false

View File

@ -172,7 +172,8 @@
},
"other": {
"title": "Other options",
"launch": "Launch app on login"
"launch": "Launch app on login",
"hideOnLaunch": "Hide window on launch"
},
"reset": {
"button": "Reset preferences"

View File

@ -24,7 +24,8 @@ const timeline: Timeline = {
}
const other: Other = {
launch: false
launch: false,
hideOnLaunch: false
}
const general: General = {

View File

@ -51,6 +51,7 @@ import ProxyConfiguration from './proxy'
import confirm from './timelines'
import { EnabledTimelines } from '~/src/types/enabledTimelines'
import { Menu as MenuPreferences } from '~/src/types/preference'
import { General as GeneralPreferences } from '~/src/types/preference'
import { LocalMarker } from '~/src/types/localMarker'
import Marker from './marker'
import newDB from './database'
@ -225,6 +226,12 @@ const getMenuPreferences = async (): Promise<MenuPreferences> => {
return conf.menu
}
const getGeneralPreferences = async (): Promise<GeneralPreferences> => {
const preferences = new Preferences(preferencesDBPath)
const conf = await preferences.load()
return conf.general
}
/**
* Set application menu
* @return Whether the menu bar is auto hide.
@ -281,6 +288,11 @@ async function createWindow() {
*/
const spellcheck = await getSpellChecker()
/**
* Get general preferences
*/
const generalPreferences = await getGeneralPreferences()
/**
* Load system theme color for dark mode
*/
@ -391,6 +403,15 @@ async function createWindow() {
mainWindow!.setSkipTaskbar(true)
event.preventDefault()
})
// Minimize to tray immediately if "hide on launch" selected
// or if --hidden arg is passed
if ((generalPreferences.other.hideOnLaunch || args.hidden) && !args.show) {
mainWindow.once('show', () => {
mainWindow?.hide()
mainWindow?.setSkipTaskbar(true)
})
}
} else {
mainWindow.on('closed', () => {
mainWindow = null
@ -409,6 +430,8 @@ Usage
Options
--help show help
--hidden start Whalebird hidden to tray
--show start Whalebird with a window
`)
process.exit(0)
}

View File

@ -33,6 +33,9 @@
<el-form-item for="launch" :label="$t('preferences.general.other.launch')">
<el-switch id="launch" v-model="other_launch" active-color="#13ce66"> </el-switch>
</el-form-item>
<el-form-item for="hideOnLaunch" :label="$t('preferences.general.other.hideOnLaunch')">
<el-switch id="hideOnLaunch" v-model="other_hideOnLaunch" active-color="#13ce66"> </el-switch>
</el-form-item>
</el-form>
<el-form class="reset section">
<el-button type="info" @click="reset">{{ $t('preferences.general.reset.button') }}</el-button>
@ -99,6 +102,13 @@ export default defineComponent({
launch: value
})
})
const other_hideOnLaunch = computed({
get: () => store.state.Preferences.General.general.other.hideOnLaunch,
set: (value: boolean) =>
store.dispatch(`${space}/${ACTION_TYPES.UPDATE_OTHER}`, {
hideOnLaunch: value
})
})
onMounted(() => {
store.dispatch(`${space}/${ACTION_TYPES.LOAD_GENERAL}`).catch(() => {
@ -133,6 +143,7 @@ export default defineComponent({
timeline_nsfw,
timeline_hide_attachments,
other_launch,
other_hideOnLaunch,
reset
}
}

View File

@ -25,7 +25,8 @@ const state = (): GeneralState => ({
hideAllAttachments: false
},
other: {
launch: false
launch: false,
hideOnLaunch: false
}
},
loading: false

View File

@ -7,6 +7,7 @@ import { Proxy } from '~/src/types/proxy'
export type Other = {
launch: boolean
hideOnLaunch: boolean
}
export type General = {