forked from desktop/desktop
-
Notifications
You must be signed in to change notification settings - Fork 522
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
- Loading branch information
Showing
17 changed files
with
255 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,43 @@ | ||
import { writeFile } from 'fs/promises' | ||
import { 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 | ||
} | ||
|
||
try { | ||
const titleBarConfig = JSON.parse( | ||
readFileSync(getTitleBarConfigPath(), 'utf8') | ||
) | ||
|
||
// Return if we found valid values | ||
if ( | ||
titleBarConfig.titleBarStyle === 'native' || | ||
titleBarConfig.titleBarStyle === 'custom' | ||
) { | ||
cachedTitleBarConfig = titleBarConfig | ||
return titleBarConfig | ||
} | ||
} catch (error) {} | ||
|
||
return { titleBarStyle: 'native' } | ||
} | ||
|
||
export async 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 @@ | ||
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.