forked from desktop/desktop
-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an option to use the Windows title bar
Co-Authored-By: Brendan Forster <[email protected]>
- Loading branch information
Showing
17 changed files
with
286 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { writeFile } from 'fs/promises' | ||
import { existsSync, readFileSync } from 'fs' | ||
import { join } from 'path' | ||
import { app } from 'electron' | ||
import { TitleBarStyle } from '../ui/lib/title-bar-style' | ||
|
||
export type TitleBarConfig = { | ||
titleBarStyle: TitleBarStyle | ||
} | ||
|
||
let cachedTitleBarConfig: TitleBarConfig | null = null | ||
|
||
// The function has to be synchronous, | ||
// since we need its return value to create electron BrowserWindow | ||
export function readTitleBarConfigFileSync(): TitleBarConfig { | ||
if (cachedTitleBarConfig) { | ||
return cachedTitleBarConfig | ||
} | ||
|
||
const titleBarConfigPath = getTitleBarConfigPath() | ||
|
||
if (existsSync(titleBarConfigPath)) { | ||
const storedTitleBarConfig = JSON.parse( | ||
readFileSync(titleBarConfigPath, 'utf8') | ||
) | ||
|
||
if ( | ||
storedTitleBarConfig.titleBarStyle === 'native' || | ||
storedTitleBarConfig.titleBarStyle === 'custom' | ||
) { | ||
cachedTitleBarConfig = storedTitleBarConfig | ||
} | ||
} | ||
|
||
// Cache the default value if the config file is not found, or if it contains an invalid value. | ||
if (cachedTitleBarConfig == null) { | ||
cachedTitleBarConfig = { titleBarStyle: 'native' } | ||
} | ||
|
||
return cachedTitleBarConfig | ||
} | ||
|
||
export function saveTitleBarConfigFile(config: TitleBarConfig) { | ||
return writeFile(getTitleBarConfigPath(), JSON.stringify(config), 'utf8') | ||
} | ||
|
||
const getTitleBarConfigPath = () => | ||
join(app.getPath('userData'), '.title-bar-config') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* This string enum represents the supported modes for rendering the title bar | ||
* in the app. | ||
* | ||
* - 'native' - Use the default window style and chrome supported by the window | ||
* manager | ||
* | ||
* - 'custom' - Hide the default window style and chrome and display the menu | ||
* provided by GitHub Desktop | ||
* | ||
* This is only available on the Linux build. For other operating systems this | ||
* is not configurable: | ||
* | ||
* - macOS uses the native title bar | ||
* - Windows uses the custom title bar | ||
*/ | ||
export type TitleBarStyle = 'native' | 'custom' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.