-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change header bar for adapt it with the current environnement (#43)
- Loading branch information
Showing
13 changed files
with
829 additions
and
826 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
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 |
---|---|---|
@@ -1,70 +1,23 @@ | ||
<script> | ||
import { onMount } from 'svelte'; | ||
const { remote } = require('electron'); | ||
const { getCurrentWindow } = require('electron').remote; | ||
import WindowsBar from './WindowsBar.svelte'; | ||
import MacosBar from './MacosBar.svelte'; | ||
let currentPlatform = 'Others'; | ||
onMount(() => { | ||
init(); | ||
if (navigator.platform === 'Win32') { | ||
currentPlatform = 'Windows'; | ||
} else { | ||
currentPlatform = 'Others'; | ||
} | ||
}); | ||
const init = () => { | ||
let window = remote.getCurrentWindow(); | ||
const minButton = document.getElementById('minimize'); | ||
const maxButton = document.getElementById('maximize'); | ||
const restoreButton = document.getElementById('restore'); | ||
const closeButton = document.getElementById('close'); | ||
minButton.addEventListener('click', event => { | ||
window = remote.getCurrentWindow(); | ||
window.minimize(); | ||
}); | ||
maxButton.addEventListener('click', event => { | ||
window = remote.getCurrentWindow(); | ||
window.maximize(); | ||
toggleMaxRestoreButtons(); | ||
}); | ||
restoreButton.addEventListener('click', event => { | ||
window = remote.getCurrentWindow(); | ||
window.unmaximize(); | ||
toggleMaxRestoreButtons(); | ||
}); | ||
const toggleMaxRestoreButtons = () => { | ||
window = remote.getCurrentWindow(); | ||
if (window.isMaximized()) { | ||
maxButton.style.display = 'none'; | ||
restoreButton.style.display = 'flex'; | ||
} else { | ||
restoreButton.style.display = 'none'; | ||
maxButton.style.display = 'flex'; | ||
} | ||
}; | ||
toggleMaxRestoreButtons(); | ||
window.on('maximize', toggleMaxRestoreButtons); | ||
window.on('unmaximize', toggleMaxRestoreButtons); | ||
closeButton.addEventListener('click', event => { | ||
window = remote.getCurrentWindow(); | ||
window.hide(); | ||
}); | ||
}; | ||
let currentPlatform = navigator.platform === 'Win32' ? 'windows' : 'others'; | ||
let isMaximized = getCurrentWindow().isMaximized(); | ||
getCurrentWindow().on('maximize', () => isMaximized = true); | ||
getCurrentWindow().on('unmaximize', () => isMaximized = false); | ||
</script> | ||
|
||
<style src="./Header.scss"></style> | ||
|
||
<header class="titlebar"> | ||
<div class="drag-region"> | ||
<div class="window-controls"> | ||
<button id="minimize" class="button min-button" data-icon="—"></button> | ||
<button id="maximize" class="button max-button" data-icon="➕"></button> | ||
<button | ||
id="restore" | ||
class="button restore-button" | ||
data-icon="➕"></button> | ||
<button id="close" class="button close-button" data-icon="❌"></button> | ||
</div> | ||
<div class="drag-region {currentPlatform ? `drag-region--${currentPlatform}` : ''}"> | ||
{#if currentPlatform === 'others'} | ||
<MacosBar bind:isMaximized /> | ||
{:else} | ||
<WindowsBar bind:isMaximized /> | ||
{/if} | ||
</div> | ||
</header> |
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,62 @@ | ||
$close-color: #fe6057; | ||
$close-color-active: #e9574f; | ||
$min-color: #ffbf2b; | ||
$min-color-active: #d8a225; | ||
$max-color: #28cd41; | ||
$max-color-active: #22aa36; | ||
|
||
.window-controls { | ||
align-items: center; | ||
display: flex; | ||
-webkit-app-region: no-drag; | ||
justify-content: space-evenly; | ||
padding-left: 0.75rem; | ||
} | ||
|
||
.window-controls .button { | ||
position: relative; | ||
width: 16px; | ||
height: 16px; | ||
border-radius: 50%; | ||
margin: 0 0.25rem; | ||
transition: 200ms; | ||
|
||
& svg { | ||
transition: 200ms; | ||
transition-timing-function: ease-in-out; | ||
display: none; | ||
} | ||
} | ||
|
||
.window-controls:hover svg { | ||
display: flex; | ||
} | ||
|
||
.close-button { | ||
background-color: $close-color; | ||
|
||
&:active { | ||
background-color: $close-color-active; | ||
} | ||
} | ||
|
||
.min-button { | ||
background-color: $min-color; | ||
|
||
&:active { | ||
background-color: $min-color-active; | ||
} | ||
} | ||
|
||
.restore-button, | ||
.max-button { | ||
background-color: $max-color; | ||
|
||
&:active { | ||
background-color: $max-color-active; | ||
} | ||
|
||
& svg { | ||
transform: rotate(-45deg); | ||
} | ||
} |
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,25 @@ | ||
<script> | ||
const { getCurrentWindow } = require('electron').remote; | ||
export let isMaximized; | ||
</script> | ||
|
||
<style src="./MacosBar.scss"></style> | ||
|
||
<div class="window-controls"> | ||
<button on:click={() => getCurrentWindow().hide()} class="button close-button"> | ||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z" fill="#000"/></svg> | ||
</button> | ||
<button on:click={() => getCurrentWindow().minimize()} class="button min-button"> | ||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M19 13H5v-2h14v2z" fill="#000"/></svg> | ||
</button> | ||
{#if !isMaximized} | ||
<button on:click={() => getCurrentWindow().maximize()} class="button max-button"> | ||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M18.17 12L15 8.83l1.41-1.42L21 12l-4.59 4.58L15 15.17 18.17 12M5.83 12L9 15.17l-1.41 1.42L3 12l4.59-4.58L9 8.83 5.83 12z" fill="#000"/></svg> | ||
</button> | ||
{:else} | ||
<button on:click={() => getCurrentWindow().unmaximize()} class="button restore-button"> | ||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M5.41 7.41L10 12l-4.59 4.59L4 15.17 7.17 12 4 8.83l1.41-1.42m13.18 9.18L14 12l4.59-4.58L20 8.83 16.83 12 20 15.17l-1.41 1.42z" fill="#000"/></svg> | ||
</button> | ||
{/if} | ||
</div> |
Oops, something went wrong.